예제 #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 globalObj in info.globals:
                needUpdate = True
                newItem = TreeViewGlobalItem( self.rootItem, globalObj )
                newItem.appendData( [ basename( path ), globalObj.line ] )
                newItem.setPath( path )
                self.addTreeItem( self.rootItem, newItem )
        return needUpdate
예제 #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 globalObj in info.globals:
                    item = TreeViewGlobalItem( self.rootItem, globalObj )
                    item.appendData( [ basename( fname ), globalObj.line ] )
                    item.setPath( fname )
                    self.rootItem.appendChild( item )
        return
예제 #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 )

        existingGlobals = []
        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.data( 0 )
            found = False
            for glob in info.globals:
                if glob.name == name:
                    found = True
                    existingGlobals.append( name )
                    if treeItem.data( 2 ) != glob.line:
                        # Appearance has changed
                        treeItem.updateData( glob )
                        treeItem.setData( 2, glob.line )
                        self.signalItemUpdated( treeItem )
                    else:
                        treeItem.updateData( glob )

            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.globals:
            if not item.name in existingGlobals:
                needUpdate = True
                newItem = TreeViewGlobalItem( self.rootItem, item )
                newItem.appendData( [ basename( fileName ), item.line ] )
                newItem.setPath( fileName )
                self.addTreeItem( self.rootItem, newItem )

        return needUpdate
예제 #4
0
    def __updateGlobalsItem(self, treeItem, globalsObj):
        " Updates globals item "
        if not treeItem.populated:
            return

        existingGlobals = []
        itemsToRemove = []
        for globalItem in treeItem.childItems:
            name = globalItem.data(0)
            found = False
            for glob in globalsObj:
                if glob.name == name:
                    found = True
                    existingGlobals.append(name)
                    globalItem.updateData(glob)
                    # No need to send the update signal because the name is
                    # still the same
                    break
            if not found:
                # Disappeared item
                itemsToRemove.append(globalItem)

        for item in itemsToRemove:
            self.__removeTreeItem(item)

        # Add those which have been introduced
        for glob in globalsObj:
            if not glob.name in existingGlobals:
                newItem = TreeViewGlobalItem(treeItem, glob)
                self.__addTreeItem(treeItem, newItem)

        return
예제 #5
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 globalObj in info.globals:
                needUpdate = True
                newItem = TreeViewGlobalItem(self.rootItem, globalObj)
                newItem.appendData([basename(path), globalObj.line])
                newItem.setPath(path)
                self.addTreeItem(self.rootItem, newItem)
        return needUpdate
예제 #6
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 globalObj in info.globals:
                    item = TreeViewGlobalItem(self.rootItem, globalObj)
                    item.appendData([basename(fname), globalObj.line])
                    item.setPath(fname)
                    self.rootItem.appendChild(item)
        return
예제 #7
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)

        existingGlobals = []
        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.data(0)
            found = False
            for glob in info.globals:
                if glob.name == name:
                    found = True
                    existingGlobals.append(name)
                    if treeItem.data(2) != glob.line:
                        # Appearance has changed
                        treeItem.updateData(glob)
                        treeItem.setData(2, glob.line)
                        self.signalItemUpdated(treeItem)
                    else:
                        treeItem.updateData(glob)

            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.globals:
            if not item.name in existingGlobals:
                needUpdate = True
                newItem = TreeViewGlobalItem(self.rootItem, item)
                newItem.appendData([basename(fileName), item.line])
                newItem.setPath(fileName)
                self.addTreeItem(self.rootItem, newItem)

        return needUpdate