|
6 | 6 | (or recheck on window popup) |
7 | 7 | - add popup menu with more options (e.g. doc strings, base classes, imports) |
8 | 8 | - add base classes to class browser tree |
9 | | -- finish removing limitation to x.py files (ModuleBrowserTreeItem) |
10 | 9 | """ |
11 | 10 |
|
12 | 11 | import os |
|
16 | 15 | from idlelib.config import idleConf |
17 | 16 | from idlelib import pyshell |
18 | 17 | from idlelib.tree import TreeNode, TreeItem, ScrolledCanvas |
| 18 | +from idlelib.util import py_extensions |
19 | 19 | from idlelib.window import ListedToplevel |
20 | 20 |
|
21 | 21 |
|
22 | 22 | file_open = None # Method...Item and Class...Item use this. |
23 | 23 | # Normally pyshell.flist.open, but there is no pyshell.flist for htest. |
24 | 24 |
|
| 25 | +# The browser depends on pyclbr and importlib which do not support .pyi files. |
| 26 | +browseable_extension_blocklist = ('.pyi',) |
| 27 | + |
| 28 | + |
| 29 | +def is_browseable_extension(path): |
| 30 | + _, ext = os.path.splitext(path) |
| 31 | + ext = os.path.normcase(ext) |
| 32 | + return ext in py_extensions and ext not in browseable_extension_blocklist |
| 33 | + |
25 | 34 |
|
26 | 35 | def transform_children(child_dict, modname=None): |
27 | 36 | """Transform a child dictionary to an ordered sequence of objects. |
@@ -76,8 +85,8 @@ def __init__(self, master, path, *, _htest=False, _utest=False): |
76 | 85 |
|
77 | 86 | Instance variables: |
78 | 87 | name: Module name. |
79 | | - file: Full path and module with .py extension. Used in |
80 | | - creating ModuleBrowserTreeItem as the rootnode for |
| 88 | + file: Full path and module with supported extension. |
| 89 | + Used in creating ModuleBrowserTreeItem as the rootnode for |
81 | 90 | the tree and subsequently in the children. |
82 | 91 | """ |
83 | 92 | self.master = master |
@@ -161,22 +170,22 @@ def GetSubList(self): |
161 | 170 |
|
162 | 171 | def OnDoubleClick(self): |
163 | 172 | "Open a module in an editor window when double clicked." |
164 | | - if os.path.normcase(self.file[-3:]) != ".py": |
| 173 | + if not is_browseable_extension(self.file): |
165 | 174 | return |
166 | 175 | if not os.path.exists(self.file): |
167 | 176 | return |
168 | 177 | file_open(self.file) |
169 | 178 |
|
170 | 179 | def IsExpandable(self): |
171 | | - "Return True if Python (.py) file." |
172 | | - return os.path.normcase(self.file[-3:]) == ".py" |
| 180 | + "Return True if Python file." |
| 181 | + return is_browseable_extension(self.file) |
173 | 182 |
|
174 | 183 | def listchildren(self): |
175 | 184 | "Return sequenced classes and functions in the module." |
176 | | - dir, base = os.path.split(self.file) |
177 | | - name, ext = os.path.splitext(base) |
178 | | - if os.path.normcase(ext) != ".py": |
| 185 | + if not is_browseable_extension(self.file): |
179 | 186 | return [] |
| 187 | + dir, base = os.path.split(self.file) |
| 188 | + name, _ = os.path.splitext(base) |
180 | 189 | try: |
181 | 190 | tree = pyclbr.readmodule_ex(name, [dir] + sys.path) |
182 | 191 | except ImportError: |
|
0 commit comments