[Idle-dev] Open Module patch

Haertle Daniel haertle@iqe.phys.ethz.ch
Mon, 27 Aug 2001 21:47:45 +0200


Every time I open a project, I open a lot of modules, and this was 
usually done by double-clicking each module in

import myModule1, myModule2, myModule3, myModule4, myModule5, myModule6

and pressing Alt-M to open it.

Now I patched EditorWindow.py to extend the ability of open_module to 
open a list of modules (and ignore the import keyword), so that one 
can select the whole line and open all modules with one Alt-M.

Below is the changed method open_module in EditorWindow.py, which can 
be substituted to the original to obtain the new behaviour.


     def open_module(self, event=None):
         # XXX Shouldn't this be in IOBinding or in FileList?
         try:
             name = self.text.get("sel.first", "sel.last")
         except TclError:
             name = ""
         else:
             name = string.strip(name)
         if not name:
             name = tkSimpleDialog.askstring("Module",
                      "Enter the name of a Python module\n"
                      "to search on sys.path and open:",
                      parent=self.text)
         name = string.replace(name, ",", " ")
         name = string.replace(name, ";", " ")
         nameList = string.split(name)
         # XXX Ought to support package syntax
         # XXX Ought to insert current file's directory in front of path
         for name in nameList:
             if name in ["", "import"]: continue
             try:
                 (f, file, (suffix, mode, type)) = imp.find_module(name)
             except (NameError, ImportError), msg:
                 tkMessageBox.showerror("Import error", str(msg), 
parent=self.text)
                 return
             if type != imp.PY_SOURCE:
                 tkMessageBox.showerror("Unsupported type",
                     "%s is not a source module" % name, parent=self.text)
                 return
             if f:
                 f.close()
             if self.flist:
                 self.flist.open(file)
             else:
                 self.io.loadfile(file)


Daniel Haertle

------------------------------------------------------------------------
         Daniel Haertle        haertle@iqe.phys.ethz.ch
      _________________  ___   http://www.nlo.ethz.ch
     /  ____/_   __/  /_/  /   ETH Hoenggerberg - Nonlinear Optics Laboratory
    /  __/_  /  / /  __   /    Institute of Quantum Electronics, HPF E18
   /______/ /__/ /__/ /__/     8093 Zuerich   -   Switzerland
                               Tel +41 1 63 32338    Fax +41 1 63 31056
------------------------------------------------------------------------