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 classObj in info.classes:
                needUpdate = True
                newItem = TreeViewClassItem( self.rootItem, classObj )
                newItem.appendData( [ basename( path ), classObj.line ] )
                newItem.setPath( path )
                self.addTreeItem( self.rootItem, newItem )
        return needUpdate
    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 classObj in info.classes:
                    item = TreeViewClassItem( self.rootItem, classObj )
                    item.appendData( [ basename( fname ), classObj.line ] )
                    item.setPath( fname )
                    self.rootItem.appendChild( item )
        return
    def onFileUpdated( self, fileName ):
        " Triggered when a file was updated "

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

        existingClasses = []
        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 cls in info.classes:
                if cls.name == name:
                    found = True
                    existingClasses.append( name )
                    treeItem.updateData( cls )
                    treeItem.setData( 2, cls.line )
                    self.signalItemUpdated( treeItem )
                    self.updateSingleClassItem( treeItem, cls )
                    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.classes:
            if not item.name in existingClasses:
                needUpdate = True
                newItem = TreeViewClassItem( self.rootItem, item )
                newItem.appendData( [ basename( fileName ), item.line ] )
                newItem.setPath( fileName )
                self.addTreeItem( self.rootItem, newItem )

        return needUpdate
示例#4
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 classObj in info.classes:
                needUpdate = True
                newItem = TreeViewClassItem(self.rootItem, classObj)
                newItem.appendData([basename(path), classObj.line])
                newItem.setPath(path)
                self.addTreeItem(self.rootItem, newItem)
        return needUpdate
示例#5
0
    def updateClassesItem( self, treeItem, classesObj ):
        " Updates classes item "
        if not treeItem.populated:
            return

        existingClasses = []
        itemsToRemove = []
        for classItem in treeItem.childItems:
            name = classItem.sourceObj.name
            found = False
            for cls in classesObj:
                if cls.name == name:
                    found = True
                    existingClasses.append( name )
                    if cmpClassDisplayName( classItem.sourceObj, cls ):
                        classItem.updateData( cls )
                        classItem.setData( 2, cls.line )
                    else:
                        # Appearence changed
                        classItem.updateData( cls )
                        classItem.setData( 2, cls.line )
                        self.signalItemUpdated( classItem )
                    self.updateSingleClassItem( classItem, cls )
                    break
            if not found:
                itemsToRemove.append( classItem )

        for item in itemsToRemove:
            self.removeTreeItem( item )

        # Add those which have been introduced
        for cls in classesObj:
            if cls.name not in existingClasses:
                newItem = TreeViewClassItem( treeItem, cls )
                if treeItem.columnCount() > 1:
                    newItem.appendData( [ treeItem.data( 1 ), cls.line ] )
                    newItem.setPath( self.findParentPath( treeItem ) )
                self.addTreeItem( treeItem, newItem )
        return
示例#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 classObj in info.classes:
                    item = TreeViewClassItem(self.rootItem, classObj)
                    item.appendData([basename(fname), classObj.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)

        existingClasses = []
        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 cls in info.classes:
                if cls.name == name:
                    found = True
                    existingClasses.append(name)
                    treeItem.updateData(cls)
                    treeItem.setData(2, cls.line)
                    self.signalItemUpdated(treeItem)
                    self.updateSingleClassItem(treeItem, cls)
                    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.classes:
            if not item.name in existingClasses:
                needUpdate = True
                newItem = TreeViewClassItem(self.rootItem, item)
                newItem.appendData([basename(fileName), item.line])
                newItem.setPath(fileName)
                self.addTreeItem(self.rootItem, newItem)

        return needUpdate
示例#8
0
    def updateClassesItem(self, treeItem, classesObj):
        " Updates classes item "
        if not treeItem.populated:
            return

        existingClasses = []
        itemsToRemove = []
        for classItem in treeItem.childItems:
            name = classItem.sourceObj.name
            found = False
            for cls in classesObj:
                if cls.name == name:
                    found = True
                    existingClasses.append(name)
                    if cmpClassDisplayName(classItem.sourceObj, cls):
                        classItem.updateData(cls)
                        classItem.setData(2, cls.line)
                    else:
                        # Appearence changed
                        classItem.updateData(cls)
                        classItem.setData(2, cls.line)
                        self.signalItemUpdated(classItem)
                    self.updateSingleClassItem(classItem, cls)
                    break
            if not found:
                itemsToRemove.append(classItem)

        for item in itemsToRemove:
            self.removeTreeItem(item)

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