[Python-checkins] python/dist/src/Tools/idle EditorWindow.py,1.42,1.43

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Sat, 07 Sep 2002 20:42:03 -0700


Update of /cvsroot/python/python/dist/src/Tools/idle
In directory usw-pr-cvs1:/tmp/cvs-serv8518

Modified Files:
	EditorWindow.py 
Log Message:
Extended IDLE's open module menu item to handle hierarchical module names.

Will look at doing something similar in import.c so that the effort won't
have to be repeated elsewhere.

Closes SF patch 600152.


Index: EditorWindow.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/idle/EditorWindow.py,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -d -r1.42 -r1.43
*** EditorWindow.py	21 May 2002 17:00:19 -0000	1.42
--- EditorWindow.py	8 Sep 2002 03:42:01 -0000	1.43
***************
*** 82,85 ****
--- 82,99 ----
  """ % idlever.IDLE_VERSION
  
+ def _find_module(fullname, path=None):
+     """Version of imp.find_module() that handles hierarchical module names"""
+ 
+     file = None
+     for tgt in fullname.split('.'):
+         if file is not None:
+             file.close()            # close intermediate files
+         (file, filename, descr) = imp.find_module(tgt, path)
+         if descr[2] == imp.PY_SOURCE:
+             break                   # find but not load the source file
+         module = imp.load_module(tgt, file, filename, descr)
+         path = module.__path__
+     return file, filename, descr
+ 
  class EditorWindow:
  
***************
*** 341,348 ****
              if not name:
                  return
-         # XXX Ought to support package syntax
          # XXX Ought to insert current file's directory in front of path
          try:
!             (f, file, (suffix, mode, type)) = imp.find_module(name)
          except (NameError, ImportError), msg:
              tkMessageBox.showerror("Import error", str(msg), parent=self.text)
--- 355,361 ----
              if not name:
                  return
          # XXX Ought to insert current file's directory in front of path
          try:
!             (f, file, (suffix, mode, type)) = _find_module(name)
          except (NameError, ImportError), msg:
              tkMessageBox.showerror("Import error", str(msg), parent=self.text)