make_view_popups(): Catch import error which can occur if a viewer is

dynamically imported when Pynche is running via askcolor out of a
package.  If the ImportError occurs, try again, prepending the package
name and digging out the module.
This commit is contained in:
Barry Warsaw 1999-07-06 22:00:52 +00:00
parent 6166b871a2
commit 17a8b5d473
1 changed files with 7 additions and 1 deletions

View File

@ -294,7 +294,13 @@ def make_view_popups(switchboard, root, extrapath):
for file in os.listdir(dir): for file in os.listdir(dir):
if file[-9:] == 'Viewer.py': if file[-9:] == 'Viewer.py':
name = file[:-3] name = file[:-3]
module = __import__(name) try:
module = __import__(name)
except ImportError:
# Pynche is running from inside a package, so get the
# module using the explicit path.
pkg = __import__('pynche.'+name)
module = getattr(pkg, name)
if hasattr(module, 'ADDTOVIEW') and module.ADDTOVIEW: if hasattr(module, 'ADDTOVIEW') and module.ADDTOVIEW:
# this is an external viewer # this is an external viewer
v = PopupViewer(module, name, switchboard, root) v = PopupViewer(module, name, switchboard, root)