def populateClassItem( self, parentItem, repopulate ): " Populates a class item " parentItem.populated = True # Count the number of items count = len( parentItem.sourceObj.decorators ) + \ len( parentItem.sourceObj.functions ) if parentItem.sourceObj.classes: count += 1 if parentItem.sourceObj.classAttributes: count += 1 if parentItem.sourceObj.instanceAttributes: count += 1 if count == 0: return # Insert rows if repopulate: self.beginInsertRows( self.createIndex( parentItem.row(), 0, parentItem ), 0, count - 1 ) for item in parentItem.sourceObj.decorators: node = TreeViewDecoratorItem( parentItem, item ) if parentItem.columnCount() > 1: node.appendData( [ parentItem.data( 1 ), item.line ] ) node.setPath( self.findParentPath( parentItem ) ) self._addItem( node, parentItem ) for item in parentItem.sourceObj.functions: node = TreeViewFunctionItem( parentItem, item ) if parentItem.columnCount() > 1: node.appendData( [ parentItem.data( 1 ), item.line ] ) node.setPath( self.findParentPath( parentItem ) ) self._addItem( node, parentItem ) if parentItem.sourceObj.classes: node = TreeViewClassesItem( parentItem, parentItem.sourceObj ) if parentItem.columnCount() > 1: node.appendData( [ "", "" ] ) self._addItem( node, parentItem ) if parentItem.sourceObj.classAttributes: node = TreeViewStaticAttributesItem( parentItem ) if parentItem.columnCount() > 1: node.appendData( [ "", "" ] ) self._addItem( node, parentItem ) if parentItem.sourceObj.instanceAttributes: node = TreeViewInstanceAttributesItem( parentItem ) if parentItem.columnCount() > 1: node.appendData( [ "", "" ] ) self._addItem( node, parentItem ) if repopulate: self.endInsertRows() return
def populateClassItem(self, parentItem, repopulate): " Populates a class item " parentItem.populated = True # Count the number of items count = len( parentItem.sourceObj.decorators ) + \ len( parentItem.sourceObj.functions ) if parentItem.sourceObj.classes: count += 1 if parentItem.sourceObj.classAttributes: count += 1 if parentItem.sourceObj.instanceAttributes: count += 1 if count == 0: return # Insert rows if repopulate: self.beginInsertRows( self.createIndex(parentItem.row(), 0, parentItem), 0, count - 1) for item in parentItem.sourceObj.decorators: node = TreeViewDecoratorItem(parentItem, item) if parentItem.columnCount() > 1: node.appendData([parentItem.data(1), item.line]) node.setPath(self.findParentPath(parentItem)) self._addItem(node, parentItem) for item in parentItem.sourceObj.functions: node = TreeViewFunctionItem(parentItem, item) if parentItem.columnCount() > 1: node.appendData([parentItem.data(1), item.line]) node.setPath(self.findParentPath(parentItem)) self._addItem(node, parentItem) if parentItem.sourceObj.classes: node = TreeViewClassesItem(parentItem, parentItem.sourceObj) if parentItem.columnCount() > 1: node.appendData(["", ""]) self._addItem(node, parentItem) if parentItem.sourceObj.classAttributes: node = TreeViewStaticAttributesItem(parentItem) if parentItem.columnCount() > 1: node.appendData(["", ""]) self._addItem(node, parentItem) if parentItem.sourceObj.instanceAttributes: node = TreeViewInstanceAttributesItem(parentItem) if parentItem.columnCount() > 1: node.appendData(["", ""]) self._addItem(node, parentItem) if repopulate: self.endInsertRows() return
def updateSingleFuncItem( self, treeItem, funcObj ): " Updates single function item " if not treeItem.populated: return # It may have decor, classes and other functions existingDecors = [] hadFunctions = False hadClasses = False itemsToRemove = [] for funcChildItem in treeItem.childItems: if funcChildItem.itemType == DecoratorItemType: name = funcChildItem.sourceObj.name found = False for decor in funcObj.decorators: if decor.name == name: found = True existingDecors.append( name ) if cmpDecoratorDisplayName( funcChildItem.sourceObj, decor ): funcChildItem.updateData( decor ) funcChildItem.setData( 2, decor.line ) else: # Appearence changed funcChildItem.updateData( decor ) funcChildItem.setData( 2, decor.line ) self.signalItemUpdated( funcChildItem ) break if not found: itemsToRemove.append( funcChildItem ) continue elif funcChildItem.itemType == FunctionsItemType: hadFunctions = True if not funcObj.functions: itemsToRemove.append( funcChildItem ) else: funcChildItem.updateData( funcObj ) self.updateFunctionsItem( funcChildItem, funcObj.functions ) continue elif funcChildItem.itemType == ClassesItemType: hadClasses = True if not funcObj.classes: itemsToRemove.append( funcChildItem ) else: funcChildItem.updateData( funcObj ) self.updateClassesItem( funcChildItem, funcObj.classes ) continue for item in itemsToRemove: self.removeTreeItem( item ) # Add those which have been introduced for decor in funcObj.decorators: if decor.name not in existingDecors: newItem = TreeViewDecoratorItem( treeItem, decor ) if treeItem.columnCount() > 1: newItem.appendData( [ treeItem.data( 1 ), decor.line ] ) newItem.setPath( self.findParentPath( treeItem ) ) self.addTreeItem( treeItem, newItem ) if not hadFunctions and funcObj.functions: newItem = TreeViewFunctionsItem( treeItem, funcObj ) if treeItem.columnCount() > 1: newItem.appendData( [ "", "" ] ) self.addTreeItem( treeItem, newItem ) if not hadClasses and funcObj.classes: newItem = TreeViewClassesItem( treeItem, funcObj ) if treeItem.columnCount() > 1: newItem.appendData( [ "", "" ] ) self.addTreeItem( treeItem, newItem ) return
def updateSingleClassItem( self, treeItem, classObj ): " Updates single class item " if not treeItem.populated: return # There might be decorators, classes, methods, static attributes and # instance attributes existingDecors = [] existingMethods = [] hadStaticAttributes = False hadInstanceAttributes = False hadClasses = False itemsToRemove = [] for classChildItem in treeItem.childItems: if classChildItem.itemType == DecoratorItemType: name = classChildItem.sourceObj.name found = False for decor in classObj.decorators: if decor.name == name: found = True existingDecors.append( name ) if cmpDecoratorDisplayName( classChildItem.sourceObj, decor ): classChildItem.updateData( decor ) classChildItem.setData( 2, decor.line ) else: # Appearence changed classChildItem.updateData( decor ) classChildItem.setData( 2, decor.line ) self.signalItemUpdated( classChildItem ) break if not found: itemsToRemove.append( classChildItem ) continue elif classChildItem.itemType == ClassesItemType: hadClasses = True if not classObj.classes: itemsToRemove.append( classChildItem ) else: classChildItem.updateData( classObj ) self.updateClassesItem( classChildItem, classObj.classes ) continue elif classChildItem.itemType == FunctionItemType: name = classChildItem.sourceObj.name found = False for method in classObj.functions: if method.name == name: found = True existingMethods.append( name ) if cmpFunctionDisplayName( classChildItem.sourceObj, method ): classChildItem.updateData( method ) classChildItem.setData( 2, method.line ) else: # Appearence changed classChildItem.updateData( method ) classChildItem.setData( 2, method.line ) self.signalItemUpdated( classChildItem ) self.updateSingleFuncItem( classChildItem, method ) break if not found: itemsToRemove.append( classChildItem ) continue elif classChildItem.itemType == StaticAttributesItemType: hadStaticAttributes = True if not classObj.classAttributes: itemsToRemove.append( classChildItem ) else: self.updateAttrItem( classChildItem, classObj.classAttributes ) continue elif classChildItem.itemType == InstanceAttributesItemType: hadInstanceAttributes = True if not classObj.instanceAttributes: itemsToRemove.append( classChildItem ) else: self.updateAttrItem( classChildItem, classObj.instanceAttributes ) continue for item in itemsToRemove: self.removeTreeItem( item ) # Add those which have been introduced for decor in classObj.decorators: if decor.name not in existingDecors: newItem = TreeViewDecoratorItem( treeItem, decor ) if treeItem.columnCount() > 1: newItem.appendData( [ treeItem.data( 1 ), decor.line ] ) newItem.setPath( self.findParentPath( treeItem ) ) self.addTreeItem( treeItem, newItem ) for method in classObj.functions: if method.name not in existingMethods: newItem = TreeViewFunctionItem( treeItem, method ) if treeItem.columnCount() > 1: newItem.appendData( [ treeItem.data( 1 ), method.line ] ) newItem.setPath( self.findParentPath( treeItem ) ) self.addTreeItem( treeItem, newItem ) if not hadClasses and classObj.classes: newItem = TreeViewClassesItem( treeItem, classObj ) if treeItem.columnCount() > 1: newItem.appendData( [ "", "" ] ) self.addTreeItem( treeItem, newItem ) if not hadStaticAttributes and \ classObj.classAttributes: newItem = TreeViewStaticAttributesItem( treeItem ) if treeItem.columnCount() > 1: newItem.appendData( [ "", "" ] ) self.addTreeItem( treeItem, newItem ) if not hadInstanceAttributes and \ classObj.instanceAttributes: newItem = TreeViewInstanceAttributesItem( treeItem ) if treeItem.columnCount() > 1: newItem.appendData( [ "", "" ] ) self.addTreeItem( treeItem, newItem ) return
def updateSingleFuncItem(self, treeItem, funcObj): " Updates single function item " if not treeItem.populated: return # It may have decor, classes and other functions existingDecors = [] hadFunctions = False hadClasses = False itemsToRemove = [] for funcChildItem in treeItem.childItems: if funcChildItem.itemType == DecoratorItemType: name = funcChildItem.sourceObj.name found = False for decor in funcObj.decorators: if decor.name == name: found = True existingDecors.append(name) if cmpDecoratorDisplayName(funcChildItem.sourceObj, decor): funcChildItem.updateData(decor) funcChildItem.setData(2, decor.line) else: # Appearence changed funcChildItem.updateData(decor) funcChildItem.setData(2, decor.line) self.signalItemUpdated(funcChildItem) break if not found: itemsToRemove.append(funcChildItem) continue elif funcChildItem.itemType == FunctionsItemType: hadFunctions = True if not funcObj.functions: itemsToRemove.append(funcChildItem) else: funcChildItem.updateData(funcObj) self.updateFunctionsItem(funcChildItem, funcObj.functions) continue elif funcChildItem.itemType == ClassesItemType: hadClasses = True if not funcObj.classes: itemsToRemove.append(funcChildItem) else: funcChildItem.updateData(funcObj) self.updateClassesItem(funcChildItem, funcObj.classes) continue for item in itemsToRemove: self.removeTreeItem(item) # Add those which have been introduced for decor in funcObj.decorators: if decor.name not in existingDecors: newItem = TreeViewDecoratorItem(treeItem, decor) if treeItem.columnCount() > 1: newItem.appendData([treeItem.data(1), decor.line]) newItem.setPath(self.findParentPath(treeItem)) self.addTreeItem(treeItem, newItem) if not hadFunctions and funcObj.functions: newItem = TreeViewFunctionsItem(treeItem, funcObj) if treeItem.columnCount() > 1: newItem.appendData(["", ""]) self.addTreeItem(treeItem, newItem) if not hadClasses and funcObj.classes: newItem = TreeViewClassesItem(treeItem, funcObj) if treeItem.columnCount() > 1: newItem.appendData(["", ""]) self.addTreeItem(treeItem, newItem) return
def updateSingleClassItem(self, treeItem, classObj): " Updates single class item " if not treeItem.populated: return # There might be decorators, classes, methods, static attributes and # instance attributes existingDecors = [] existingMethods = [] hadStaticAttributes = False hadInstanceAttributes = False hadClasses = False itemsToRemove = [] for classChildItem in treeItem.childItems: if classChildItem.itemType == DecoratorItemType: name = classChildItem.sourceObj.name found = False for decor in classObj.decorators: if decor.name == name: found = True existingDecors.append(name) if cmpDecoratorDisplayName(classChildItem.sourceObj, decor): classChildItem.updateData(decor) classChildItem.setData(2, decor.line) else: # Appearence changed classChildItem.updateData(decor) classChildItem.setData(2, decor.line) self.signalItemUpdated(classChildItem) break if not found: itemsToRemove.append(classChildItem) continue elif classChildItem.itemType == ClassesItemType: hadClasses = True if not classObj.classes: itemsToRemove.append(classChildItem) else: classChildItem.updateData(classObj) self.updateClassesItem(classChildItem, classObj.classes) continue elif classChildItem.itemType == FunctionItemType: name = classChildItem.sourceObj.name found = False for method in classObj.functions: if method.name == name: found = True existingMethods.append(name) if cmpFunctionDisplayName(classChildItem.sourceObj, method): classChildItem.updateData(method) classChildItem.setData(2, method.line) else: # Appearence changed classChildItem.updateData(method) classChildItem.setData(2, method.line) self.signalItemUpdated(classChildItem) self.updateSingleFuncItem(classChildItem, method) break if not found: itemsToRemove.append(classChildItem) continue elif classChildItem.itemType == StaticAttributesItemType: hadStaticAttributes = True if not classObj.classAttributes: itemsToRemove.append(classChildItem) else: self.updateAttrItem(classChildItem, classObj.classAttributes) continue elif classChildItem.itemType == InstanceAttributesItemType: hadInstanceAttributes = True if not classObj.instanceAttributes: itemsToRemove.append(classChildItem) else: self.updateAttrItem(classChildItem, classObj.instanceAttributes) continue for item in itemsToRemove: self.removeTreeItem(item) # Add those which have been introduced for decor in classObj.decorators: if decor.name not in existingDecors: newItem = TreeViewDecoratorItem(treeItem, decor) if treeItem.columnCount() > 1: newItem.appendData([treeItem.data(1), decor.line]) newItem.setPath(self.findParentPath(treeItem)) self.addTreeItem(treeItem, newItem) for method in classObj.functions: if method.name not in existingMethods: newItem = TreeViewFunctionItem(treeItem, method) if treeItem.columnCount() > 1: newItem.appendData([treeItem.data(1), method.line]) newItem.setPath(self.findParentPath(treeItem)) self.addTreeItem(treeItem, newItem) if not hadClasses and classObj.classes: newItem = TreeViewClassesItem(treeItem, classObj) if treeItem.columnCount() > 1: newItem.appendData(["", ""]) self.addTreeItem(treeItem, newItem) if not hadStaticAttributes and \ classObj.classAttributes: newItem = TreeViewStaticAttributesItem(treeItem) if treeItem.columnCount() > 1: newItem.appendData(["", ""]) self.addTreeItem(treeItem, newItem) if not hadInstanceAttributes and \ classObj.instanceAttributes: newItem = TreeViewInstanceAttributesItem(treeItem) if treeItem.columnCount() > 1: newItem.appendData(["", ""]) self.addTreeItem(treeItem, newItem) return