]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
make_view_popups(): Catch import error which can occur if a viewer is
authorBarry Warsaw <barry@python.org>
Tue, 6 Jul 1999 22:00:52 +0000 (22:00 +0000)
committerBarry Warsaw <barry@python.org>
Tue, 6 Jul 1999 22:00:52 +0000 (22:00 +0000)
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.

Tools/pynche/PyncheWidget.py

index d8ff8facdb819ba9cce0b5290e4b6847f5d1d4cf..4cddff1771e92d19a0ba6dda1abfd8d30f46d427 100644 (file)
@@ -294,7 +294,13 @@ def make_view_popups(switchboard, root, extrapath):
         for file in os.listdir(dir):
             if file[-9:] == 'Viewer.py':
                 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:
                     # this is an external viewer
                     v = PopupViewer(module, name, switchboard, root)