summaryrefslogtreecommitdiffstats
path: root/Mac/Contrib/PyIDE-src/IDELib/Widgets/ModuleBrowser.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1998-08-18 14:59:10 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1998-08-18 14:59:10 (GMT)
commitcb5704e6a8f4a97d9fc5554df83fa88d058287b9 (patch)
treea2b6032cccb6d4ba130b07fa415d64d613d76e0c /Mac/Contrib/PyIDE-src/IDELib/Widgets/ModuleBrowser.py
parent7cc5735ef26a60df9d1bc3554c1912f951a90308 (diff)
downloadcpython-cb5704e6a8f4a97d9fc5554df83fa88d058287b9.zip
cpython-cb5704e6a8f4a97d9fc5554df83fa88d058287b9.tar.gz
cpython-cb5704e6a8f4a97d9fc5554df83fa88d058287b9.tar.bz2
Initial revision
Diffstat (limited to 'Mac/Contrib/PyIDE-src/IDELib/Widgets/ModuleBrowser.py')
-rw-r--r--Mac/Contrib/PyIDE-src/IDELib/Widgets/ModuleBrowser.py164
1 files changed, 164 insertions, 0 deletions
diff --git a/Mac/Contrib/PyIDE-src/IDELib/Widgets/ModuleBrowser.py b/Mac/Contrib/PyIDE-src/IDELib/Widgets/ModuleBrowser.py
new file mode 100644
index 0000000..67685b8
--- /dev/null
+++ b/Mac/Contrib/PyIDE-src/IDELib/Widgets/ModuleBrowser.py
@@ -0,0 +1,164 @@
+import W
+import sys
+
+__version__ = "0.2"
+__author__ = "jvr"
+
+class _modulebrowser:
+
+ def __init__(self):
+ self.editmodules = []
+ self.modules = []
+ self.window = W.Window((194, 1000), "Module Browser", minsize = (194, 160), maxsize = (340, 20000))
+
+ self.window.openbutton = W.Button((10, 8, 80, 16), "Open", self.openbuttonhit)
+ self.window.browsebutton = W.Button((100, 8, 80, 16), "BrowseŠ", self.browsebuttonhit)
+ self.window.reloadbutton = W.Button((10, 32, 80, 16), "Reload", self.reloadbuttonhit)
+ self.window.openotherbutton = W.Button((100, 32, 80, 16), "Open otherŠ", self.openother)
+
+ self.window.openbutton.enable(0)
+ self.window.reloadbutton.enable(0)
+ self.window.browsebutton.enable(0)
+ self.window.setdefaultbutton(self.window.browsebutton)
+
+ self.window.bind("cmdr", self.window.reloadbutton.push)
+ self.window.bind("cmdb", self.window.browsebutton.push)
+
+ self.window.bind("<activate>", self.activate)
+ self.window.bind("<close>", self.close)
+
+ self.window.list = W.List((-1, 56, 1, -14), [], self.listhit)
+
+ self.window.open()
+ self.checkbuttons()
+
+ def close(self):
+ global _browser
+ _browser = None
+
+ def activate(self, onoff):
+ if onoff:
+ self.makelist()
+
+ def listhit(self, isdbl):
+ self.checkbuttons()
+ if isdbl:
+ if self.window._defaultbutton:
+ self.window._defaultbutton.push()
+
+ def checkbuttons(self):
+ sel = self.window.list.getselection()
+ if sel:
+ for i in sel:
+ if self.editmodules[i]:
+ self.window.openbutton.enable(1)
+ self.window.reloadbutton.enable(1)
+ self.window.setdefaultbutton(self.window.openbutton)
+ break
+ else:
+ self.window.openbutton.enable(0)
+ self.window.reloadbutton.enable(0)
+ self.window.setdefaultbutton(self.window.browsebutton)
+ self.window.browsebutton.enable(1)
+ else:
+ #self.window.setdefaultbutton(self.window.browsebutton)
+ self.window.openbutton.enable(0)
+ self.window.reloadbutton.enable(0)
+ self.window.browsebutton.enable(0)
+
+ def openbuttonhit(self):
+ import imp
+ sel = self.window.list.getselection()
+ W.SetCursor("watch")
+ for i in sel:
+ modname = self.window.list[i]
+ try:
+ self.openscript(sys.modules[modname].__file__, modname)
+ except IOError:
+ try:
+ file, path, description = imp.find_module(modname)
+ except ImportError:
+ W.SetCursor("arrow")
+ W.Message("Canıt find file for module ³%s²."
+ % modname)
+ else:
+ self.openscript(path, modname)
+
+ def openscript(self, path, modname):
+ if path[-3:] == '.py':
+ W.getapplication().openscript(path)
+ else:
+ W.Message("Canıt edit ³%s²; it might be a shared library or a .pyc file."
+ % modname)
+
+ def openother(self):
+ import imp
+ import EasyDialogs
+
+ modname = EasyDialogs.AskString("Open module:")
+ if modname:
+ try:
+ file, path, description = imp.find_module(modname)
+ except ImportError:
+ if modname in sys.builtin_module_names:
+ alerttext = "³%s² is a builtin module, which you canıt edit." % modname
+ else:
+ alerttext = "No module named ³%s²." % modname
+ raise W.AlertError, alerttext
+ self.openscript(path, modname)
+
+ def reloadbuttonhit(self):
+ sel = self.window.list.getselection()
+ W.SetCursor("watch")
+ for i in sel:
+ m = sys.modules[self.window.list[i]]
+ reload(m)
+
+ def browsebuttonhit(self):
+ sel = self.window.list.getselection()
+ if not sel:
+ return
+ import PyBrowser
+ for i in sel:
+ PyBrowser.Browser(sys.modules[self.window.list[i]])
+
+ def makelist(self):
+ editmodules, modules = getmoduleslist()
+ if modules == self.modules:
+ return
+ self.editmodules, self.modules = editmodules, modules
+ self.window.list.setdrawingmode(0)
+ sel = self.window.list.getselectedobjects()
+ self.window.list.set(self.modules)
+ self.window.list.setselectedobjects(sel)
+ self.window.list.setdrawingmode(1)
+
+
+def getmoduleslist():
+ import PyBrowser # for caselesssort function
+ modules = sys.modules.keys()
+ modules = PyBrowser.caselesssort(modules)
+ editmodules = []
+ sysmodules = sys.modules
+ modulesappend = editmodules.append
+ for m in modules:
+ module = sysmodules[m]
+ try:
+ if sysmodules[m].__file__[-3:] == '.py':
+ modulesappend(1)
+ else:
+ modulesappend(0)
+ except AttributeError:
+ modulesappend(0)
+ return editmodules, modules
+
+
+
+_browser = None
+
+def ModuleBrowser():
+ global _browser
+ if _browser is not None:
+ _browser.window.select()
+ else:
+ _browser = _modulebrowser()