def SetItems(parentItem, fictiveObjects, level): level += 1 for object in fictiveObjects: type = object.type if type not in showTypes and type != "nameismain": continue # Construct text if type == "import": text = "→ %s (%s)" % (object.name, object.text) elif type == "todo": text = object.name elif type == "nameismain": text = object.text elif type == "class": text = object.name elif type == "def": text = object.name + "()" elif type == "attribute": text = "- " + object.name elif type in ("cell", "##", "#%%", "# %%"): type = "cell" text = "## " + object.name + " " * 120 else: text = "%s %s" % (type, object.name) # Create item thisItem = QtWidgets.QTreeWidgetItem(parentItem, [text]) color = QtGui.QColor(colours[object.type]) thisItem.setForeground(0, QtGui.QBrush(color)) font = thisItem.font(0) font.setBold(True) if type == "cell": font.setUnderline(True) thisItem.setFont(0, font) thisItem.linenr = object.linenr # Is this the current item? if ln and object.linenr <= ln and object.linenr2 > ln: selectedItem[0] = thisItem # Any children that we should display? if object.children: SetItems(thisItem, object.children, level) # Set visibility thisItem.setExpanded(bool(level < showLevel))
def onEditorsCurrentChanged(self): """Notify that the file is being parsed and make sure that not the structure of a previously selected file is shown.""" # Get editor and clear list editor = pyzo.editors.getCurrentEditor() self._tree.clear() if editor is None: # Set editor id self._currentEditorId = 0 if editor is not None: # Set editor id self._currentEditorId = id(editor) # Notify text = translate("pyzoSourceStructure", "Parsing ") + editor._name + " ..." QtWidgets.QTreeWidgetItem(self._tree, [text]) # Try getting the structure right now self.updateStructure()