src/eric7/QScintilla/Editor.py

branch
eric7
changeset 10474
c18ca679259d
parent 10473
f45fd45cb11d
child 10499
71208bcc7d99
equal deleted inserted replaced
10473:f45fd45cb11d 10474:c18ca679259d
88 Keywords = 11 88 Keywords = 11
89 Module = 12 89 Module = 12
90 90
91 FromDocument = 99 91 FromDocument = 99
92 TemplateImage = 100 92 TemplateImage = 100
93
94
95 class EditorWarningKind(enum.Enum):
96 """
97 Class defining the kind of warnings supported by the Editor class.
98 """
99
100 Code = 1
101 Python = 2
102 Style = 3
103 Info = 4
104 Error = 5
93 105
94 106
95 class Editor(QsciScintillaCompat): 107 class Editor(QsciScintillaCompat):
96 """ 108 """
97 Class implementing the editor component of the eric IDE. 109 Class implementing the editor component of the eric IDE.
167 lastEditPositionAvailable = pyqtSignal() 179 lastEditPositionAvailable = pyqtSignal()
168 refreshed = pyqtSignal() 180 refreshed = pyqtSignal()
169 settingsRead = pyqtSignal() 181 settingsRead = pyqtSignal()
170 mouseDoubleClick = pyqtSignal(QPoint, Qt.MouseButton) 182 mouseDoubleClick = pyqtSignal(QPoint, Qt.MouseButton)
171 183
172 # TODO: convert to an enum.Enum
173 WarningCode = 1
174 WarningPython = 2
175 WarningStyle = 3
176 WarningInfo = 4
177 WarningError = 5
178
179 # Cooperation related definitions 184 # Cooperation related definitions
180 Separator = "@@@" 185 Separator = "@@@"
181 186
182 StartEditToken = "START_EDIT" 187 StartEditToken = "START_EDIT"
183 EndEditToken = "END_EDIT" 188 EndEditToken = "END_EDIT"
6762 if error: 6767 if error:
6763 _fn, lineno, col, code, msg = error 6768 _fn, lineno, col, code, msg = error
6764 self.toggleSyntaxError(lineno, col, True, msg) 6769 self.toggleSyntaxError(lineno, col, True, msg)
6765 6770
6766 for _fn, lineno, col, _code, msg in problems.get("py_warnings", []): 6771 for _fn, lineno, col, _code, msg in problems.get("py_warnings", []):
6767 self.toggleWarning(lineno, col, True, msg, warningType=Editor.WarningPython) 6772 self.toggleWarning(
6773 lineno, col, True, msg, warningType=EditorWarningKind.Python
6774 )
6768 6775
6769 for _fn, lineno, col, _code, msg in problems.get("warnings", []): 6776 for _fn, lineno, col, _code, msg in problems.get("warnings", []):
6770 self.toggleWarning(lineno, col, True, msg, warningType=Editor.WarningCode) 6777 self.toggleWarning(
6778 lineno, col, True, msg, warningType=EditorWarningKind.Code
6779 )
6771 6780
6772 self.updateVerticalScrollBar() 6781 self.updateVerticalScrollBar()
6773 6782
6774 @pyqtSlot() 6783 @pyqtSlot()
6775 def __initOnlineSyntaxCheck(self): 6784 def __initOnlineSyntaxCheck(self):
7220 ########################################################################### 7229 ###########################################################################
7221 ## Warning handling methods below 7230 ## Warning handling methods below
7222 ########################################################################### 7231 ###########################################################################
7223 7232
7224 def toggleWarning( 7233 def toggleWarning(
7225 self, line, col, setWarning, msg="", warningType=WarningCode # noqa: U100 7234 self,
7235 line,
7236 col, # noqa: U100
7237 setWarning,
7238 msg="",
7239 warningType=EditorWarningKind.Code,
7226 ): 7240 ):
7227 """ 7241 """
7228 Public method to toggle a warning indicator. 7242 Public method to toggle a warning indicator.
7229 7243
7230 Note: This method is used to set pyflakes and code style warnings. 7244 Note: This method is used to set pyflakes and code style warnings.
7237 set or deleted 7251 set or deleted
7238 @type bool 7252 @type bool
7239 @param msg warning message 7253 @param msg warning message
7240 @type str 7254 @type str
7241 @param warningType type of warning message 7255 @param warningType type of warning message
7242 @type int 7256 @type EditorWarningKind
7243 """ 7257 """
7244 if line == 0: 7258 if line == 0:
7245 line = 1 7259 line = 1
7246 # hack to show a warning marker, if line is reported to be 0 7260 # hack to show a warning marker, if line is reported to be 0
7247 7261
7341 @pyqtSlot() 7355 @pyqtSlot()
7342 def clearFlakesWarnings(self): 7356 def clearFlakesWarnings(self):
7343 """ 7357 """
7344 Public slot to clear all pyflakes warnings. 7358 Public slot to clear all pyflakes warnings.
7345 """ 7359 """
7346 self.__clearTypedWarning(Editor.WarningCode) 7360 self.__clearTypedWarning(EditorWarningKind.Code)
7347 self.__clearTypedWarning(Editor.WarningPython) 7361 self.__clearTypedWarning(EditorWarningKind.Python)
7348 7362
7349 @pyqtSlot() 7363 @pyqtSlot()
7350 def clearStyleWarnings(self): 7364 def clearStyleWarnings(self):
7351 """ 7365 """
7352 Public slot to clear all style warnings. 7366 Public slot to clear all style warnings.
7353 """ 7367 """
7354 self.__clearTypedWarning(Editor.WarningStyle) 7368 self.__clearTypedWarning(EditorWarningKind.Style)
7355 7369
7356 @pyqtSlot() 7370 @pyqtSlot()
7357 def clearInfoWarnings(self): 7371 def clearInfoWarnings(self):
7358 """ 7372 """
7359 Public slot to clear all info warnings. 7373 Public slot to clear all info warnings.
7360 """ 7374 """
7361 self.__clearTypedWarning(Editor.WarningInfo) 7375 self.__clearTypedWarning(EditorWarningKind.Info)
7362 7376
7363 @pyqtSlot() 7377 @pyqtSlot()
7364 def clearErrorWarnings(self): 7378 def clearErrorWarnings(self):
7365 """ 7379 """
7366 Public slot to clear all error warnings. 7380 Public slot to clear all error warnings.
7367 """ 7381 """
7368 self.__clearTypedWarning(Editor.WarningError) 7382 self.__clearTypedWarning(EditorWarningKind.Error)
7369 7383
7370 @pyqtSlot() 7384 @pyqtSlot()
7371 def clearCodeWarnings(self): 7385 def clearCodeWarnings(self):
7372 """ 7386 """
7373 Public slot to clear all code warnings. 7387 Public slot to clear all code warnings.
7374 """ 7388 """
7375 self.__clearTypedWarning(Editor.WarningCode) 7389 self.__clearTypedWarning(EditorWarningKind.Code)
7376 7390
7377 def __clearTypedWarning(self, warningKind): 7391 def __clearTypedWarning(self, warningKind):
7378 """ 7392 """
7379 Private method to clear warnings of a specific kind. 7393 Private method to clear warnings of a specific kind.
7380 7394
7381 @param warningKind kind of warning to clear (Editor.WarningCode, 7395 @param warningKind kind of warning to clear
7382 Editor.WarningPython, Editor.WarningStyle) 7396 @type EditorWarningKind
7383 @type int
7384 """ 7397 """
7385 for handle in list(self._warnings): 7398 for handle in list(self._warnings):
7386 issues = [] 7399 issues = []
7387 for msg, warningType in self._warnings[handle]: 7400 for msg, warningType in self._warnings[handle]:
7388 if warningType == warningKind: 7401 if warningType == warningKind:
7510 7523
7511 # step 1: do warnings 7524 # step 1: do warnings
7512 for handle in self._warnings: 7525 for handle in self._warnings:
7513 if self.markerLine(handle) == line: 7526 if self.markerLine(handle) == line:
7514 for msg, warningType in self._warnings[handle]: 7527 for msg, warningType in self._warnings[handle]:
7515 if warningType == Editor.WarningInfo: 7528 if warningType == EditorWarningKind.Info:
7516 infoAnnotations.append(self.tr("Info: {0}").format(msg)) 7529 infoAnnotations.append(self.tr("Info: {0}").format(msg))
7517 elif warningType == Editor.WarningError: 7530 elif warningType == EditorWarningKind.Error:
7518 errorAnnotations.append(self.tr("Error: {0}").format(msg)) 7531 errorAnnotations.append(self.tr("Error: {0}").format(msg))
7519 elif warningType == Editor.WarningStyle: 7532 elif warningType == EditorWarningKind.Style:
7520 styleAnnotations.append(self.tr("Style: {0}").format(msg)) 7533 styleAnnotations.append(self.tr("Style: {0}").format(msg))
7521 elif warningType == Editor.WarningPython: 7534 elif warningType == EditorWarningKind.Python:
7522 warningAnnotations.append(msg) 7535 warningAnnotations.append(msg)
7523 else: 7536 else:
7524 warningAnnotations.append( 7537 warningAnnotations.append(
7525 self.tr("Warning: {0}").format(msg) 7538 self.tr("Warning: {0}").format(msg)
7526 ) 7539 )

eric ide

mercurial