|
8 | 8 | - show function argument list? (have to do pattern matching on source) |
9 | 9 | - should the classes and methods lists also be in the module's menu bar? |
10 | 10 | - add base classes to class browser tree |
11 | | -- make methodless classes inexpandable |
12 | | -- make classless modules inexpandable |
13 | | -
|
14 | | -
|
15 | 11 | """ |
16 | 12 |
|
17 | 13 | import os |
18 | 14 | import sys |
19 | 15 | import string |
20 | 16 | import pyclbr |
21 | 17 |
|
| 18 | +# XXX Patch pyclbr with dummies if it's vintage Python 1.5.2: |
| 19 | +if not hasattr(pyclbr, "readmodule_ex"): |
| 20 | + pyclbr.readmodule_ex = pyclbr.readmodule |
| 21 | +if not hasattr(pyclbr, "Function"): |
| 22 | + class Function(pyclbr.Class): |
| 23 | + pass |
| 24 | + pyclbr.Function = Function |
| 25 | + |
22 | 26 | import PyShell |
23 | 27 | from WindowList import ListedToplevel |
24 | 28 | from TreeWidget import TreeNode, TreeItem, ScrolledCanvas |
@@ -92,7 +96,7 @@ def listclasses(self): |
92 | 96 | if os.path.normcase(ext) != ".py": |
93 | 97 | return [] |
94 | 98 | try: |
95 | | - dict = pyclbr.readmodule(name, [dir] + sys.path) |
| 99 | + dict = pyclbr.readmodule_ex(name, [dir] + sys.path) |
96 | 100 | except ImportError, msg: |
97 | 101 | return [] |
98 | 102 | items = [] |
@@ -125,53 +129,50 @@ def __init__(self, name, classes, file): |
125 | 129 | self.name = name |
126 | 130 | self.classes = classes |
127 | 131 | self.file = file |
| 132 | + try: |
| 133 | + self.cl = self.classes[self.name] |
| 134 | + except (IndexError, KeyError): |
| 135 | + self.cl = None |
| 136 | + self.isfunction = isinstance(self.cl, pyclbr.Function) |
128 | 137 |
|
129 | 138 | def GetText(self): |
130 | | - return "class " + self.name |
| 139 | + if self.isfunction: |
| 140 | + return "def " + self.name + "(...)" |
| 141 | + else: |
| 142 | + return "class " + self.name |
131 | 143 |
|
132 | | - def IsExpandable(self): |
133 | | - try: |
134 | | - cl = self.classes[self.name] |
135 | | - except (IndexError, KeyError): |
136 | | - return 0 |
| 144 | + def GetIconName(self): |
| 145 | + if self.isfunction: |
| 146 | + return "python" |
137 | 147 | else: |
138 | | - return not not cl.methods |
| 148 | + return "folder" |
| 149 | + |
| 150 | + def IsExpandable(self): |
| 151 | + if self.cl: |
| 152 | + return not not self.cl.methods |
139 | 153 |
|
140 | 154 | def GetSubList(self): |
| 155 | + if not self.cl: |
| 156 | + return [] |
141 | 157 | sublist = [] |
142 | 158 | for name in self.listmethods(): |
143 | | - item = MethodBrowserTreeItem( |
144 | | - name, self.classes[self.name], self.file) |
| 159 | + item = MethodBrowserTreeItem(name, self.cl, self.file) |
145 | 160 | sublist.append(item) |
146 | 161 | return sublist |
147 | 162 |
|
148 | 163 | def OnDoubleClick(self): |
149 | 164 | if not os.path.exists(self.file): |
150 | 165 | return |
151 | 166 | edit = PyShell.flist.open(self.file) |
152 | | - if self.classes.has_key(self.name): |
153 | | - cl = self.classes[self.name] |
154 | | - else: |
155 | | - name = self.name |
156 | | - i = string.find(name, '(') |
157 | | - if i < 0: |
158 | | - return |
159 | | - name = name[:i] |
160 | | - if not self.classes.has_key(name): |
161 | | - return |
162 | | - cl = self.classes[name] |
163 | | - if not hasattr(cl, 'lineno'): |
164 | | - return |
165 | | - lineno = cl.lineno |
166 | | - edit.gotoline(lineno) |
| 167 | + if hasattr(self.cl, 'lineno'): |
| 168 | + lineno = self.cl.lineno |
| 169 | + edit.gotoline(lineno) |
167 | 170 |
|
168 | 171 | def listmethods(self): |
169 | | - try: |
170 | | - cl = self.classes[self.name] |
171 | | - except (IndexError, KeyError): |
| 172 | + if not self.cl: |
172 | 173 | return [] |
173 | 174 | items = [] |
174 | | - for name, lineno in cl.methods.items(): |
| 175 | + for name, lineno in self.cl.methods.items(): |
175 | 176 | items.append((lineno, name)) |
176 | 177 | items.sort() |
177 | 178 | list = [] |
|
0 commit comments