def __onTabChanged(self, index): """Triggered when another tab becomes active""" # If the timer is still active that means the tab was switched before # the handler had a chance to work. Therefore update the previous tab # first if so. if self.__updateTimer.isActive(): self.__updateTimer.stop() self.__updateView() # Now, switch the pyflakes browser to the new tab if index == -1: widget = self.__editorsManager.currentWidget() else: widget = self.__editorsManager.getWidgetByIndex(index) if widget is None: self.__currentUUID = None self.setAnalysisNotAvailable(self.__uiLabel, self.__ccLabel) return if widget.getType() not in [ MainWindowTabWidgetBase.PlainTextEditor, MainWindowTabWidgetBase.VCSAnnotateViewer ]: self.__currentUUID = None self.setAnalysisNotAvailable(self.__uiLabel, self.__ccLabel) return # This is text editor, detect the file type if not isPythonMime(widget.getMime()): self.__currentUUID = None self.setAnalysisNotAvailable(self.__uiLabel, self.__ccLabel) return # This is a python file, check if we already have the parsed info in # the cache uuid = widget.getUUID() self.__currentUUID = uuid if uuid in self.__flakesResults: # We have it, change the icon and the tooltip correspondingly results = self.__flakesResults[uuid].messages ccResults = self.__flakesResults[uuid].ccMessages self.setAnalysisResults(self.__uiLabel, results, self.__ccLabel, ccResults, None) return # It is first time we are here, create a new editor = widget.getEditor() editor.textChanged.connect(self.__onBufferChanged) editor.cursorPositionChanged.connect(self.__cursorPositionChanged) results, ccResults = getBufferErrors(editor.text) attributes = PyflakesAttributes() attributes.messages = results attributes.ccMessages = ccResults attributes.changed = False self.__flakesResults[uuid] = attributes self.__currentUUID = uuid self.setAnalysisResults(self.__uiLabel, results, self.__ccLabel, ccResults, editor)
def __updateView(self): """Updates the view when a file is changed""" self.__updateTimer.stop() if self.__currentUUID is None: return widget = self.__editorsManager.getWidgetByUUID(self.__currentUUID) if widget is None: return if not self.__flakesResults[self.__currentUUID].changed: return editor = widget.getEditor() results = getBufferErrors(editor.text) self.__flakesResults[self.__currentUUID].messages = results self.__flakesResults[self.__currentUUID].changed = False self.setFlakesResults(self.__uiLabel, results, editor)