diff options
author | Guido van Rossum <guido@python.org> | 1999-06-10 15:19:14 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-06-10 15:19:14 (GMT) |
commit | 4431b0f243dda169c37ba748d4539998874fdcf7 (patch) | |
tree | 77c9b366d217502449c0f33917815266247fb29e /Tools/idle/ClassBrowser.py | |
parent | 7a6212872212fb74d9217150d969a6e3c1fc3fa9 (diff) | |
download | cpython-4431b0f243dda169c37ba748d4539998874fdcf7.zip cpython-4431b0f243dda169c37ba748d4539998874fdcf7.tar.gz cpython-4431b0f243dda169c37ba748d4539998874fdcf7.tar.bz2 |
Adapt to the new pyclbr's support of listing top-level functions. If
this functionality is not present (e.g. when used with a vintage
Python 1.5.2 installation) top-level functions are not listed.
(Hmm... Any distribution of IDLE 0.5 should probably include a copy
of the new pyclbr.py!)
Diffstat (limited to 'Tools/idle/ClassBrowser.py')
-rw-r--r-- | Tools/idle/ClassBrowser.py | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/Tools/idle/ClassBrowser.py b/Tools/idle/ClassBrowser.py index 0cf978e..0cdd645 100644 --- a/Tools/idle/ClassBrowser.py +++ b/Tools/idle/ClassBrowser.py @@ -8,10 +8,6 @@ XXX TO DO: - show function argument list? (have to do pattern matching on source) - should the classes and methods lists also be in the module's menu bar? - add base classes to class browser tree -- make methodless classes inexpandable -- make classless modules inexpandable - - """ import os @@ -19,6 +15,14 @@ import sys import string import pyclbr +# XXX Patch pyclbr with dummies if it's vintage Python 1.5.2: +if not hasattr(pyclbr, "readmodule_ex"): + pyclbr.readmodule_ex = pyclbr.readmodule +if not hasattr(pyclbr, "Function"): + class Function(pyclbr.Class): + pass + pyclbr.Function = Function + import PyShell from WindowList import ListedToplevel from TreeWidget import TreeNode, TreeItem, ScrolledCanvas @@ -92,7 +96,7 @@ class ModuleBrowserTreeItem(TreeItem): if os.path.normcase(ext) != ".py": return [] try: - dict = pyclbr.readmodule(name, [dir] + sys.path) + dict = pyclbr.readmodule_ex(name, [dir] + sys.path) except ImportError, msg: return [] items = [] @@ -125,23 +129,34 @@ class ClassBrowserTreeItem(TreeItem): self.name = name self.classes = classes self.file = file + try: + self.cl = self.classes[self.name] + except (IndexError, KeyError): + self.cl = None + self.isfunction = isinstance(self.cl, pyclbr.Function) def GetText(self): - return "class " + self.name + if self.isfunction: + return "def " + self.name + "(...)" + else: + return "class " + self.name - def IsExpandable(self): - try: - cl = self.classes[self.name] - except (IndexError, KeyError): - return 0 + def GetIconName(self): + if self.isfunction: + return "python" else: - return not not cl.methods + return "folder" + + def IsExpandable(self): + if self.cl: + return not not self.cl.methods def GetSubList(self): + if not self.cl: + return [] sublist = [] for name in self.listmethods(): - item = MethodBrowserTreeItem( - name, self.classes[self.name], self.file) + item = MethodBrowserTreeItem(name, self.cl, self.file) sublist.append(item) return sublist @@ -149,29 +164,15 @@ class ClassBrowserTreeItem(TreeItem): if not os.path.exists(self.file): return edit = PyShell.flist.open(self.file) - if self.classes.has_key(self.name): - cl = self.classes[self.name] - else: - name = self.name - i = string.find(name, '(') - if i < 0: - return - name = name[:i] - if not self.classes.has_key(name): - return - cl = self.classes[name] - if not hasattr(cl, 'lineno'): - return - lineno = cl.lineno - edit.gotoline(lineno) + if hasattr(self.cl, 'lineno'): + lineno = self.cl.lineno + edit.gotoline(lineno) def listmethods(self): - try: - cl = self.classes[self.name] - except (IndexError, KeyError): + if not self.cl: return [] items = [] - for name, lineno in cl.methods.items(): + for name, lineno in self.cl.methods.items(): items.append((lineno, name)) items.sort() list = [] |