QScintilla/Editor.py

changeset 3062
9de9373da5bb
parent 3059
16c93928cfc5
child 3067
8fd7ae10de2b
equal deleted inserted replaced
3059:16c93928cfc5 3062:9de9373da5bb
1032 self.indicMarginMenu.addAction( 1032 self.indicMarginMenu.addAction(
1033 self.trUtf8('Clear syntax error'), self.clearSyntaxError) 1033 self.trUtf8('Clear syntax error'), self.clearSyntaxError)
1034 self.indicMarginMenu.addSeparator() 1034 self.indicMarginMenu.addSeparator()
1035 self.marginMenuActs["NextWarningMarker"] = \ 1035 self.marginMenuActs["NextWarningMarker"] = \
1036 self.indicMarginMenu.addAction( 1036 self.indicMarginMenu.addAction(
1037 self.trUtf8("Next warning"), self.nextFlakesWarning) 1037 self.trUtf8("Next warning"), self.nextWarning)
1038 self.marginMenuActs["PreviousWarningMarker"] = \ 1038 self.marginMenuActs["PreviousWarningMarker"] = \
1039 self.indicMarginMenu.addAction( 1039 self.indicMarginMenu.addAction(
1040 self.trUtf8("Previous warning"), self.previousFlakesWarning) 1040 self.trUtf8("Previous warning"), self.previousWarning)
1041 self.marginMenuActs["ShowWarning"] = \ 1041 self.marginMenuActs["ShowWarning"] = \
1042 self.indicMarginMenu.addAction( 1042 self.indicMarginMenu.addAction(
1043 self.trUtf8('Show warning message'), self.__showFlakesWarning) 1043 self.trUtf8('Show warning message'), self.__showWarning)
1044 self.marginMenuActs["ClearWarnings"] = \ 1044 self.marginMenuActs["ClearWarnings"] = \
1045 self.indicMarginMenu.addAction( 1045 self.indicMarginMenu.addAction(
1046 self.trUtf8('Clear warnings'), self.clearFlakesWarnings) 1046 self.trUtf8('Clear warnings'), self.clearWarnings)
1047 self.indicMarginMenu.addSeparator() 1047 self.indicMarginMenu.addSeparator()
1048 self.marginMenuActs["NextCoverageMarker"] = \ 1048 self.marginMenuActs["NextCoverageMarker"] = \
1049 self.indicMarginMenu.addAction( 1049 self.indicMarginMenu.addAction(
1050 self.trUtf8('Next uncovered line'), self.nextUncovered) 1050 self.trUtf8('Next uncovered line'), self.nextUncovered)
1051 self.marginMenuActs["PreviousCoverageMarker"] = \ 1051 self.marginMenuActs["PreviousCoverageMarker"] = \
1089 self.trUtf8('Show syntax error message'), self.__showSyntaxError) 1089 self.trUtf8('Show syntax error message'), self.__showSyntaxError)
1090 self.marginMenuActs["ClearSyntaxError"] = self.marginMenu.addAction( 1090 self.marginMenuActs["ClearSyntaxError"] = self.marginMenu.addAction(
1091 self.trUtf8('Clear syntax error'), self.clearSyntaxError) 1091 self.trUtf8('Clear syntax error'), self.clearSyntaxError)
1092 self.marginMenu.addSeparator() 1092 self.marginMenu.addSeparator()
1093 self.marginMenuActs["NextWarningMarker"] = self.marginMenu.addAction( 1093 self.marginMenuActs["NextWarningMarker"] = self.marginMenu.addAction(
1094 self.trUtf8("Next warning"), self.nextFlakesWarning) 1094 self.trUtf8("Next warning"), self.nextWarning)
1095 self.marginMenuActs["PreviousWarningMarker"] = \ 1095 self.marginMenuActs["PreviousWarningMarker"] = \
1096 self.marginMenu.addAction( 1096 self.marginMenu.addAction(
1097 self.trUtf8("Previous warning"), self.previousFlakesWarning) 1097 self.trUtf8("Previous warning"), self.previousWarning)
1098 self.marginMenuActs["ShowWarning"] = self.marginMenu.addAction( 1098 self.marginMenuActs["ShowWarning"] = self.marginMenu.addAction(
1099 self.trUtf8('Show warning message'), self.__showFlakesWarning) 1099 self.trUtf8('Show warning message'), self.__showWarning)
1100 self.marginMenuActs["ClearWarnings"] = self.marginMenu.addAction( 1100 self.marginMenuActs["ClearWarnings"] = self.marginMenu.addAction(
1101 self.trUtf8('Clear warnings'), self.clearFlakesWarnings) 1101 self.trUtf8('Clear warnings'), self.clearWarnings)
1102 self.marginMenu.addSeparator() 1102 self.marginMenu.addSeparator()
1103 self.marginMenuActs["Breakpoint"] = self.marginMenu.addAction( 1103 self.marginMenuActs["Breakpoint"] = self.marginMenu.addAction(
1104 self.trUtf8('Toggle breakpoint'), self.menuToggleBreakpoint) 1104 self.trUtf8('Toggle breakpoint'), self.menuToggleBreakpoint)
1105 self.marginMenuActs["TempBreakpoint"] = self.marginMenu.addAction( 1105 self.marginMenuActs["TempBreakpoint"] = self.marginMenu.addAction(
1106 self.trUtf8('Toggle temporary breakpoint'), 1106 self.trUtf8('Toggle temporary breakpoint'),
3038 self.__toggleBreakpoint(line + 1) 3038 self.__toggleBreakpoint(line + 1)
3039 elif modifiers & Qt.KeyboardModifiers(Qt.ControlModifier): 3039 elif modifiers & Qt.KeyboardModifiers(Qt.ControlModifier):
3040 if self.markersAtLine(line) & (1 << self.syntaxerror): 3040 if self.markersAtLine(line) & (1 << self.syntaxerror):
3041 self.__showSyntaxError(line) 3041 self.__showSyntaxError(line)
3042 elif self.markersAtLine(line) & (1 << self.warning): 3042 elif self.markersAtLine(line) & (1 << self.warning):
3043 self.__showFlakesWarning(line) 3043 self.__showWarning(line)
3044 else: 3044 else:
3045 if self.marginMenuActs["LMBbreakpoints"].isChecked(): 3045 if self.marginMenuActs["LMBbreakpoints"].isChecked():
3046 self.__toggleBreakpoint(line + 1) 3046 self.__toggleBreakpoint(line + 1)
3047 else: 3047 else:
3048 self.toggleBookmark(line + 1) 3048 self.toggleBookmark(line + 1)
3053 self.__toggleBreakpoint(line + 1) 3053 self.__toggleBreakpoint(line + 1)
3054 elif margin == self.__indicMargin: 3054 elif margin == self.__indicMargin:
3055 if self.markersAtLine(line) & (1 << self.syntaxerror): 3055 if self.markersAtLine(line) & (1 << self.syntaxerror):
3056 self.__showSyntaxError(line) 3056 self.__showSyntaxError(line)
3057 elif self.markersAtLine(line) & (1 << self.warning): 3057 elif self.markersAtLine(line) & (1 << self.warning):
3058 self.__showFlakesWarning(line) 3058 self.__showWarning(line)
3059 3059
3060 def handleMonospacedEnable(self): 3060 def handleMonospacedEnable(self):
3061 """ 3061 """
3062 Private slot to handle the Use Monospaced Font context menu entry. 3062 Private slot to handle the Use Monospaced Font context menu entry.
3063 """ 3063 """
4970 4970
4971 _fn, lineno, message = warning.getMessageData() 4971 _fn, lineno, message = warning.getMessageData()
4972 if "__IGNORE_WARNING__" not in \ 4972 if "__IGNORE_WARNING__" not in \
4973 Utilities.extractLineFlags( 4973 Utilities.extractLineFlags(
4974 self.text(lineno - 1).strip()): 4974 self.text(lineno - 1).strip()):
4975 self.toggleFlakesWarning( 4975 self.toggleWarning(
4976 lineno, True, message) 4976 lineno, True, message)
4977 except SyntaxError as err: 4977 except SyntaxError as err:
4978 if err.text.strip(): 4978 if err.text.strip():
4979 msg = err.text.strip() 4979 msg = err.text.strip()
4980 else: 4980 else:
4989 if syntaxError: 4989 if syntaxError:
4990 self.toggleSyntaxError( 4990 self.toggleSyntaxError(
4991 int(errorline), int(errorindex), True, _error) 4991 int(errorline), int(errorindex), True, _error)
4992 else: 4992 else:
4993 for warning in warnings: 4993 for warning in warnings:
4994 self.toggleFlakesWarning( 4994 self.toggleWarning(
4995 int(warning[1]), True, warning[2]) 4995 int(warning[1]), True, warning[2])
4996 4996
4997 def __initOnlineSyntaxCheck(self): 4997 def __initOnlineSyntaxCheck(self):
4998 """ 4998 """
4999 Private slot to initialize the online syntax check. 4999 Private slot to initialize the online syntax check.
5372 self, 5372 self,
5373 self.trUtf8("Syntax Error"), 5373 self.trUtf8("Syntax Error"),
5374 self.trUtf8("No syntax error message available.")) 5374 self.trUtf8("No syntax error message available."))
5375 5375
5376 ########################################################################### 5376 ###########################################################################
5377 ## Flakes warning handling methods below 5377 ## Warning handling methods below
5378 ########################################################################### 5378 ###########################################################################
5379 5379
5380 def toggleFlakesWarning(self, line, warning, msg="", 5380 def toggleWarning(self, line, warning, msg="", warningType=WarningCode):
5381 warningType=WarningCode): 5381 """
5382 """ 5382 Public method to toggle a warning indicator.
5383 Public method to toggle a flakes warning indicator. 5383
5384 5384 Note: This method is used to set pyflakes and code style warnings.
5385 Note: This method is used to set code style warnings as well. 5385
5386 5386 @param line line number of the warning
5387 @param line line number of the flakes warning
5388 @param warning flag indicating if the warning marker should be 5387 @param warning flag indicating if the warning marker should be
5389 set or deleted (boolean) 5388 set or deleted (boolean)
5390 @param msg warning message (string) 5389 @param msg warning message (string)
5391 @keyparam warningType type of warning message (integer) 5390 @keyparam warningType type of warning message (integer)
5392 """ 5391 """
5393 if line == 0: 5392 if line == 0:
5394 line = 1 5393 line = 1
5395 # hack to show a warning marker, if line is reported to be 0 5394 # hack to show a warning marker, if line is reported to be 0
5396 if warning: 5395 if warning:
5397 # set/ammend a new warning marker 5396 # set/amend a new warning marker
5398 warn = (msg, warningType) 5397 warn = (msg, warningType)
5399 markers = self.markersAtLine(line - 1) 5398 markers = self.markersAtLine(line - 1)
5400 if not (markers & (1 << self.warning)): 5399 if not (markers & (1 << self.warning)):
5401 handle = self.markerAdd(line - 1, self.warning) 5400 handle = self.markerAdd(line - 1, self.warning)
5402 self.warnings[handle] = [warn] 5401 self.warnings[handle] = [warn]
5413 self.markerDeleteHandle(handle) 5412 self.markerDeleteHandle(handle)
5414 self.syntaxerrorToggled.emit(self) 5413 self.syntaxerrorToggled.emit(self)
5415 5414
5416 self.__setAnnotation(line - 1) 5415 self.__setAnnotation(line - 1)
5417 5416
5418 def getFlakesWarnings(self): 5417 def getWarnings(self):
5419 """ 5418 """
5420 Public method to retrieve the flakes warning markers. 5419 Public method to retrieve the warning markers.
5421 5420
5422 @return sorted list of all lines containing a flakes warning 5421 @return sorted list of all lines containing a warning
5423 (list of integer) 5422 (list of integer)
5424 """ 5423 """
5425 fwlist = [] 5424 fwlist = []
5426 for handle in list(self.warnings.keys()): 5425 for handle in list(self.warnings.keys()):
5427 fwlist.append(self.markerLine(handle) + 1) 5426 fwlist.append(self.markerLine(handle) + 1)
5428 5427
5429 fwlist.sort() 5428 fwlist.sort()
5430 return fwlist 5429 return fwlist
5431 5430
5432 def hasFlakesWarnings(self): 5431 def hasWarnings(self):
5433 """ 5432 """
5434 Public method to check for the presence of flakes warnings. 5433 Public method to check for the presence of warnings.
5435 5434
5436 @return flag indicating the presence of flakes warnings (boolean) 5435 @return flag indicating the presence of warnings (boolean)
5437 """ 5436 """
5438 return len(self.warnings) > 0 5437 return len(self.warnings) > 0
5439 5438
5440 def nextFlakesWarning(self): 5439 def nextWarning(self):
5441 """ 5440 """
5442 Public slot to handle the 'Next warning' context menu action. 5441 Public slot to handle the 'Next warning' context menu action.
5443 """ 5442 """
5444 line, index = self.getCursorPosition() 5443 line, index = self.getCursorPosition()
5445 if line == self.lines() - 1: 5444 if line == self.lines() - 1:
5452 fwline = self.markerFindNext(0, 1 << self.warning) 5451 fwline = self.markerFindNext(0, 1 << self.warning)
5453 if fwline >= 0: 5452 if fwline >= 0:
5454 self.setCursorPosition(fwline, 0) 5453 self.setCursorPosition(fwline, 0)
5455 self.ensureLineVisible(fwline) 5454 self.ensureLineVisible(fwline)
5456 5455
5457 def previousFlakesWarning(self): 5456 def previousWarning(self):
5458 """ 5457 """
5459 Public slot to handle the 'Previous warning' context menu action. 5458 Public slot to handle the 'Previous warning' context menu action.
5460 """ 5459 """
5461 line, index = self.getCursorPosition() 5460 line, index = self.getCursorPosition()
5462 if line == 0: 5461 if line == 0:
5472 self.setCursorPosition(fwline, 0) 5471 self.setCursorPosition(fwline, 0)
5473 self.ensureLineVisible(fwline) 5472 self.ensureLineVisible(fwline)
5474 5473
5475 def clearFlakesWarnings(self): 5474 def clearFlakesWarnings(self):
5476 """ 5475 """
5477 Public slot to handle the 'Clear all warnings' context menu action. 5476 Public slot to clear all pyflakes warnings.
5477 """
5478 self.__clearTypedWarning(Editor.WarningCode)
5479
5480 def clearStyleWarnings(self):
5481 """
5482 Public slot to clear all style warnings.
5483 """
5484 self.__clearTypedWarning(Editor.WarningStyle)
5485
5486 def __clearTypedWarning(self, warningKind):
5487 """
5488 Public method to clear warnings of a specific kind.
5489
5490 @param warningKind kind of warning to clear (Editor.WarningCode,
5491 Editor.WarningStyle)
5492 """
5493 assert warningKind in [Editor.WarningCode, Editor.WarningStyle]
5494
5495 for handle in list(self.warnings.keys()):
5496 warnings = []
5497 for msg, warningType in self.warnings[handle]:
5498 if warningType == warningKind:
5499 continue
5500
5501 warnings.append((msg, warningType))
5502
5503 if warnings:
5504 self.warnings[handle] = warnings
5505 self.__setAnnotation(self.markerLine(handle))
5506 else:
5507 del self.warnings[handle]
5508 self.__setAnnotation(self.markerLine(handle))
5509 self.markerDeleteHandle(handle)
5510 self.syntaxerrorToggled.emit(self)
5511
5512 def clearWarnings(self):
5513 """
5514 Public slot to clear all warnings.
5478 """ 5515 """
5479 for handle in self.warnings: 5516 for handle in self.warnings:
5480 self.warnings[handle] = [] 5517 self.warnings[handle] = []
5481 self.__setAnnotation(self.markerLine(handle)) 5518 self.__setAnnotation(self.markerLine(handle))
5482 self.markerDeleteHandle(handle) 5519 self.markerDeleteHandle(handle)
5483 self.warnings = {} 5520 self.warnings = {}
5484 self.syntaxerrorToggled.emit(self) 5521 self.syntaxerrorToggled.emit(self)
5485 5522
5486 def __showFlakesWarning(self, line=-1): 5523 def __showWarning(self, line=-1):
5487 """ 5524 """
5488 Private slot to handle the 'Show warning' context menu action. 5525 Private slot to handle the 'Show warning' context menu action.
5489 5526
5490 @param line line number to show the flakes warning for (integer) 5527 @param line line number to show the warning for (integer)
5491 """ 5528 """
5492 if line == -1: 5529 if line == -1:
5493 line = self.line 5530 line = self.line
5494 5531
5495 for handle in list(self.warnings.keys()): 5532 for handle in list(self.warnings.keys()):
5555 warningAnnotations = [] 5592 warningAnnotations = []
5556 errorAnnotations = [] 5593 errorAnnotations = []
5557 styleAnnotations = [] 5594 styleAnnotations = []
5558 5595
5559 # step 1: do warnings 5596 # step 1: do warnings
5560 for handle in list(self.warnings.keys()): 5597 for handle in self.warnings.keys():
5561 if self.markerLine(handle) == line: 5598 if self.markerLine(handle) == line:
5562 for msg, warningType in self.warnings[handle]: 5599 for msg, warningType in self.warnings[handle]:
5563 if warningType == self.WarningStyle: 5600 if warningType == self.WarningStyle:
5564 styleAnnotations.append( 5601 styleAnnotations.append(
5565 self.trUtf8("Style: {0}").format(msg)) 5602 self.trUtf8("Style: {0}").format(msg))
5566 else: 5603 else:
5567 warningAnnotations.append( 5604 warningAnnotations.append(
5568 self.trUtf8("Warning: {0}").format(msg)) 5605 self.trUtf8("Warning: {0}").format(msg))
5569 5606
5570 # step 2: do syntax errors 5607 # step 2: do syntax errors
5571 for handle in list(self.syntaxerrors.keys()): 5608 for handle in self.syntaxerrors.keys():
5572 if self.markerLine(handle) == line: 5609 if self.markerLine(handle) == line:
5573 for msg, _ in self.syntaxerrors[handle]: 5610 for msg, _ in self.syntaxerrors[handle]:
5574 errorAnnotations.append( 5611 errorAnnotations.append(
5575 self.trUtf8("Error: {0}").format(msg)) 5612 self.trUtf8("Error: {0}").format(msg))
5576 5613
6057 6094
6058 # clear syntax error markers 6095 # clear syntax error markers
6059 self.clearSyntaxError() 6096 self.clearSyntaxError()
6060 6097
6061 # clear flakes warning markers 6098 # clear flakes warning markers
6062 self.clearFlakesWarnings() 6099 self.clearWarnings()
6063 6100
6064 # clear breakpoint markers 6101 # clear breakpoint markers
6065 for handle in list(self.breaks.keys()): 6102 for handle in list(self.breaks.keys()):
6066 self.markerDeleteHandle(handle) 6103 self.markerDeleteHandle(handle)
6067 self.breaks = {} 6104 self.breaks = {}

eric ide

mercurial