Browser tree for Python module. Uses TreeItem as the basis for the structure of the tree. Used by both browsers.
| 142 | |
| 143 | |
| 144 | class ModuleBrowserTreeItem(TreeItem): |
| 145 | """Browser tree for Python module. |
| 146 | |
| 147 | Uses TreeItem as the basis for the structure of the tree. |
| 148 | Used by both browsers. |
| 149 | """ |
| 150 | |
| 151 | def __init__(self, file): |
| 152 | """Create a TreeItem for the file. |
| 153 | |
| 154 | Args: |
| 155 | file: Full path and module name. |
| 156 | """ |
| 157 | self.file = file |
| 158 | |
| 159 | def GetText(self): |
| 160 | "Return the module name as the text string to display." |
| 161 | return os.path.basename(self.file) |
| 162 | |
| 163 | def GetIconName(self): |
| 164 | "Return the name of the icon to display." |
| 165 | return "python" |
| 166 | |
| 167 | def GetSubList(self): |
| 168 | "Return ChildBrowserTreeItems for children." |
| 169 | return [ChildBrowserTreeItem(obj) for obj in self.listchildren()] |
| 170 | |
| 171 | def OnDoubleClick(self): |
| 172 | "Open a module in an editor window when double clicked." |
| 173 | if not is_browseable_extension(self.file): |
| 174 | return |
| 175 | if not os.path.exists(self.file): |
| 176 | return |
| 177 | file_open(self.file) |
| 178 | |
| 179 | def IsExpandable(self): |
| 180 | "Return True if Python file." |
| 181 | return is_browseable_extension(self.file) |
| 182 | |
| 183 | def listchildren(self): |
| 184 | "Return sequenced classes and functions in the module." |
| 185 | if not is_browseable_extension(self.file): |
| 186 | return [] |
| 187 | dir, base = os.path.split(self.file) |
| 188 | name, _ = os.path.splitext(base) |
| 189 | try: |
| 190 | tree = pyclbr.readmodule_ex(name, [dir] + sys.path) |
| 191 | except ImportError: |
| 192 | return [] |
| 193 | return transform_children(tree, name) |
| 194 | |
| 195 | |
| 196 | class ChildBrowserTreeItem(TreeItem): |
no outgoing calls
no test coverage detected
searching dependent graphs…