Beispiel #1
0
    def onFSChanged( self, addedPythonFiles, deletedPythonFiles ):
        " Triggered when some files appeared or disappeared "

        needUpdate = False
        itemsToDelete = []
        for path in deletedPythonFiles:
            for item in self.rootItem.childItems:
                if os.path.realpath( path ) == \
                   os.path.realpath( item.getPath() ):
                    itemsToDelete.append( item )

        for item in itemsToDelete:
            needUpdate = True
            self.removeTreeItem( item )

        for path in addedPythonFiles:
            try:
                info = self.globalData.briefModinfoCache.get( path )
            except:
                # It could be that a file was created and deleted straight
                # away. In this case the cache will generate an exception.
                continue
            for funcObj in info.functions:
                needUpdate = True
                newItem = TreeViewFunctionItem( self.rootItem, funcObj )
                newItem.appendData( [ basename( path ), funcObj.line ] )
                newItem.setPath( path )
                self.addTreeItem( self.rootItem, newItem )
        return needUpdate
Beispiel #2
0
 def __populateModel( self ):
     " Populates the project browser model "
     self.clear()
     project = self.globalData.project
     cache = self.globalData.briefModinfoCache
     for fname in project.filesList:
         if detectFileType( fname ) in [ PythonFileType, Python3FileType ]:
             info = cache.get( fname )
             for func in info.functions:
                 item = TreeViewFunctionItem( self.rootItem, func )
                 item.appendData( [ basename( fname ), func.line ] )
                 item.setPath( fname )
                 self.rootItem.appendChild( item )
     return
Beispiel #3
0
    def onFileUpdated( self, fileName ):
        " Triggered when a file was updated "

        # Here: python file which belongs to the project
        info = self.globalData.briefModinfoCache.get( fileName )

        existingFunctions = []
        itemsToRemove = []
        needUpdate = False

        # For all root items
        path = os.path.realpath( fileName )
        for treeItem in self.rootItem.childItems:
            if os.path.realpath( treeItem.getPath() ) != path:
                continue

            # Item belongs to the modified file
            name = treeItem.sourceObj.name
            found = False
            for func in info.functions:
                if func.name == name:
                    found = True
                    existingFunctions.append( name )
                    treeItem.updateData( func )
                    treeItem.setData( 2, func.line )
                    self.signalItemUpdated( treeItem )
                    self.updateSingleFuncItem( treeItem, func )
                    break
            if not found:
                itemsToRemove.append( treeItem )

        for item in itemsToRemove:
            needUpdate = True
            self.removeTreeItem( item )

        # Add those which have been introduced
        for item in info.functions:
            if not item.name in existingFunctions:
                needUpdate = True
                newItem = TreeViewFunctionItem( self.rootItem, item )
                newItem.appendData( [ basename( fileName ), item.line ] )
                newItem.setPath( fileName )
                self.addTreeItem( self.rootItem, newItem )

        return needUpdate
    def updateFunctionsItem( self, treeItem, functionsObj ):
        " Updates functions item "
        if not treeItem.populated:
            return

        existingFunctions = []
        itemsToRemove = []
        for functionItem in treeItem.childItems:
            name = functionItem.sourceObj.name
            found = False
            for func in functionsObj:
                if func.name == name:
                    found = True
                    existingFunctions.append( name )
                    if cmpFunctionDisplayName( functionItem.sourceObj,
                                               func ):
                        functionItem.updateData( func )
                        functionItem.setData( 2, func.line )
                    else:
                        # Appearence changed
                        functionItem.updateData( func )
                        functionItem.setData( 2, func.line )
                        self.signalItemUpdated( functionItem )
                    self.updateSingleFuncItem( functionItem, func )
                    break
            if not found:
                itemsToRemove.append( functionItem )

        for item in itemsToRemove:
            self.removeTreeItem( item )

        # Add those which have been introduced
        for func in functionsObj:
            if func.name not in existingFunctions:
                newItem = TreeViewFunctionItem( treeItem, func )
                if treeItem.columnCount() > 1:
                    newItem.appendData( [ treeItem.data( 1 ), func.line ] )
                    newItem.setPath( self.findParentPath( treeItem ) )
                self.addTreeItem( treeItem, newItem )
        return
Beispiel #5
0
    def updateFunctionsItem(self, treeItem, functionsObj):
        " Updates functions item "
        if not treeItem.populated:
            return

        existingFunctions = []
        itemsToRemove = []
        for functionItem in treeItem.childItems:
            name = functionItem.sourceObj.name
            found = False
            for func in functionsObj:
                if func.name == name:
                    found = True
                    existingFunctions.append(name)
                    if cmpFunctionDisplayName(functionItem.sourceObj, func):
                        functionItem.updateData(func)
                        functionItem.setData(2, func.line)
                    else:
                        # Appearence changed
                        functionItem.updateData(func)
                        functionItem.setData(2, func.line)
                        self.signalItemUpdated(functionItem)
                    self.updateSingleFuncItem(functionItem, func)
                    break
            if not found:
                itemsToRemove.append(functionItem)

        for item in itemsToRemove:
            self.removeTreeItem(item)

        # Add those which have been introduced
        for func in functionsObj:
            if func.name not in existingFunctions:
                newItem = TreeViewFunctionItem(treeItem, func)
                if treeItem.columnCount() > 1:
                    newItem.appendData([treeItem.data(1), func.line])
                    newItem.setPath(self.findParentPath(treeItem))
                self.addTreeItem(treeItem, newItem)
        return