QScintilla/Editor.py

changeset 2905
a1ae4b297bc0
parent 2904
1da821da961e
child 2926
ae7c9d9f3b4a
equal deleted inserted replaced
2904:1da821da961e 2905:a1ae4b297bc0
93 eolChanged = pyqtSignal(str) 93 eolChanged = pyqtSignal(str)
94 encodingChanged = pyqtSignal(str) 94 encodingChanged = pyqtSignal(str)
95 lastEditPositionAvailable = pyqtSignal() 95 lastEditPositionAvailable = pyqtSignal()
96 refreshed = pyqtSignal() 96 refreshed = pyqtSignal()
97 97
98 WarningCode = 1
99 WarningStyle = 2
100
98 # Autocompletion icon definitions 101 # Autocompletion icon definitions
99 ClassID = 1 102 ClassID = 1
100 ClassProtectedID = 2 103 ClassProtectedID = 2
101 ClassPrivateID = 3 104 ClassPrivateID = 3
102 MethodID = 4 105 MethodID = 4
150 # clear some variables 153 # clear some variables
151 self.lastHighlight = None # remember the last highlighted line 154 self.lastHighlight = None # remember the last highlighted line
152 self.lastErrorMarker = None # remember the last error line 155 self.lastErrorMarker = None # remember the last error line
153 self.lastCurrMarker = None # remember the last current line 156 self.lastCurrMarker = None # remember the last current line
154 157
155 self.breaks = {} # key: marker handle, 158 self.breaks = {}
156 # value: (lineno, condition, temporary, 159 # key: marker handle,
157 # enabled, ignorecount) 160 # value: (lineno, condition, temporary,
158 self.bookmarks = [] # bookmarks are just a list of handles to the 161 # enabled, ignorecount)
159 # bookmark markers 162 self.bookmarks = []
160 self.syntaxerrors = {} # key: marker handle 163 # bookmarks are just a list of handles to the
161 # value: list of (error message, error index) 164 # bookmark markers
162 self.warnings = {} # key: marker handle 165 self.syntaxerrors = {}
163 # value: list of warning messages 166 # key: marker handle
167 # value: list of (error message, error index)
168 self.warnings = {}
169 # key: marker handle
170 # value: list of (warning message, warning type)
164 self.notcoveredMarkers = [] # just a list of marker handles 171 self.notcoveredMarkers = [] # just a list of marker handles
165 self.showingNotcoveredMarkers = False 172 self.showingNotcoveredMarkers = False
166 173
167 self.condHistory = [] 174 self.condHistory = []
168 self.lexer_ = None 175 self.lexer_ = None
172 self.apiLanguage = '' 179 self.apiLanguage = ''
173 self.lastModified = 0 180 self.lastModified = 0
174 self.line = -1 181 self.line = -1
175 self.inReopenPrompt = False 182 self.inReopenPrompt = False
176 # true if the prompt to reload a changed source is present 183 # true if the prompt to reload a changed source is present
177 self.inFileRenamed = False # true if we are propagating a rename action 184 self.inFileRenamed = False
178 self.inLanguageChanged = False # true if we are propagating a language change 185 # true if we are propagating a rename action
179 self.inEolChanged = False # true if we are propagating an eol change 186 self.inLanguageChanged = False
180 self.inEncodingChanged = False # true if we are propagating an encoding change 187 # true if we are propagating a language change
181 self.inDragDrop = False # true if we are in drop mode 188 self.inEolChanged = False
182 self.inLinesChanged = False # true if we are propagating a lines changed event 189 # true if we are propagating an eol change
183 self.__hasTaskMarkers = False # no task markers present 190 self.inEncodingChanged = False
191 # true if we are propagating an encoding change
192 self.inDragDrop = False
193 # true if we are in drop mode
194 self.inLinesChanged = False
195 # true if we are propagating a lines changed event
196 self.__hasTaskMarkers = False
197 # no task markers present
184 198
185 self.macros = {} # list of defined macros 199 self.macros = {} # list of defined macros
186 self.curMacro = None 200 self.curMacro = None
187 self.recording = False 201 self.recording = False
188 202
5197 5211
5198 ############################################################################ 5212 ############################################################################
5199 ## Flakes warning handling methods below 5213 ## Flakes warning handling methods below
5200 ############################################################################ 5214 ############################################################################
5201 5215
5202 # TODO: add flag for PEP-8 messages and record this flag in self.warnings 5216 def toggleFlakesWarning(self, line, warning, msg="",
5203 def toggleFlakesWarning(self, line, warning, msg=""): 5217 warningType=WarningCode):
5204 """ 5218 """
5205 Public method to toggle a flakes warning indicator. 5219 Public method to toggle a flakes warning indicator.
5206 5220
5207 Note: This method is used to set PEP 8 warnings as well. 5221 Note: This method is used to set PEP 8 warnings as well.
5208 5222
5209 @param line line number of the flakes warning 5223 @param line line number of the flakes warning
5210 @param warning flag indicating if the warning marker should be 5224 @param warning flag indicating if the warning marker should be
5211 set or deleted (boolean) 5225 set or deleted (boolean)
5212 @param msg warning message (string) 5226 @param msg warning message (string)
5227 @keyparam warningType type of warning message (integer)
5213 """ 5228 """
5214 if line == 0: 5229 if line == 0:
5215 line = 1 5230 line = 1
5216 # hack to show a warning marker, if line is reported to be 0 5231 # hack to show a warning marker, if line is reported to be 0
5217 if warning: 5232 if warning:
5218 # set/ammend a new warning marker 5233 # set/ammend a new warning marker
5234 warn = (msg, warningType)
5219 markers = self.markersAtLine(line - 1) 5235 markers = self.markersAtLine(line - 1)
5220 if not (markers & (1 << self.warning)): 5236 if not (markers & (1 << self.warning)):
5221 handle = self.markerAdd(line - 1, self.warning) 5237 handle = self.markerAdd(line - 1, self.warning)
5222 self.warnings[handle] = [msg] 5238 self.warnings[handle] = [warn]
5223 self.syntaxerrorToggled.emit(self) 5239 self.syntaxerrorToggled.emit(self)
5224 else: 5240 else:
5225 for handle in list(self.warnings.keys()): 5241 for handle in list(self.warnings.keys()):
5226 if self.markerLine(handle) == line - 1 and \ 5242 if self.markerLine(handle) == line - 1 and \
5227 msg not in self.warnings[handle]: 5243 warn not in self.warnings[handle]:
5228 self.warnings[handle].append(msg) 5244 self.warnings[handle].append(warn)
5229 else: 5245 else:
5230 for handle in list(self.warnings.keys()): 5246 for handle in list(self.warnings.keys()):
5231 if self.markerLine(handle) == line - 1: 5247 if self.markerLine(handle) == line - 1:
5232 del self.warnings[handle] 5248 del self.warnings[handle]
5233 self.markerDeleteHandle(handle) 5249 self.markerDeleteHandle(handle)
5312 line = self.line 5328 line = self.line
5313 5329
5314 for handle in list(self.warnings.keys()): 5330 for handle in list(self.warnings.keys()):
5315 if self.markerLine(handle) == line: 5331 if self.markerLine(handle) == line:
5316 E5MessageBox.warning(self, 5332 E5MessageBox.warning(self,
5317 self.trUtf8("py3flakes Warning"), 5333 self.trUtf8("Warning"),
5318 '\n'.join(self.warnings[handle])) 5334 '\n'.join(self.warnings[handle]))
5319 break 5335 break
5320 else: 5336 else:
5321 E5MessageBox.warning(self, 5337 E5MessageBox.warning(self,
5322 self.trUtf8("py3flakes Warning"), 5338 self.trUtf8("Warning"),
5323 self.trUtf8("No py3flakes warning message available.")) 5339 self.trUtf8("No warning messages available."))
5324 5340
5325 ############################################################################ 5341 ############################################################################
5326 ## Annotation handling methods below 5342 ## Annotation handling methods below
5327 ############################################################################ 5343 ############################################################################
5328 5344
5329 # TODO: add additional annotations style (green) for PEP-8 warnings
5330 def __setAnnotationStyles(self): 5345 def __setAnnotationStyles(self):
5331 """ 5346 """
5332 Private slot to define the style used by inline annotations. 5347 Private slot to define the style used by inline annotations.
5333 """ 5348 """
5334 if hasattr(QsciScintilla, "annotate"): 5349 if hasattr(QsciScintilla, "annotate"):
5345 self.annotationErrorStyle, 5360 self.annotationErrorStyle,
5346 Preferences.getEditorColour("AnnotationsErrorForeground")) 5361 Preferences.getEditorColour("AnnotationsErrorForeground"))
5347 self.SendScintilla(QsciScintilla.SCI_STYLESETBACK, 5362 self.SendScintilla(QsciScintilla.SCI_STYLESETBACK,
5348 self.annotationErrorStyle, 5363 self.annotationErrorStyle,
5349 Preferences.getEditorColour("AnnotationsErrorBackground")) 5364 Preferences.getEditorColour("AnnotationsErrorBackground"))
5350 5365
5351 # TODO: show pep-8 warnings in a different color (green) with prefix 'Style:' 5366 self.annotationStyleStyle = self.annotationErrorStyle + 1
5367 self.SendScintilla(QsciScintilla.SCI_STYLESETFORE,
5368 self.annotationStyleStyle,
5369 Preferences.getEditorColour("AnnotationsStyleForeground"))
5370 self.SendScintilla(QsciScintilla.SCI_STYLESETBACK,
5371 self.annotationStyleStyle,
5372 Preferences.getEditorColour("AnnotationsStyleBackground"))
5373
5352 def __setAnnotation(self, line): 5374 def __setAnnotation(self, line):
5353 """ 5375 """
5354 Private method to set the annotations for the given line. 5376 Private method to set the annotations for the given line.
5355 5377
5356 @param line number of the line that needs annotation (integer) 5378 @param line number of the line that needs annotation (integer)
5357 """ 5379 """
5358 if hasattr(QsciScintilla, "annotate"): 5380 if hasattr(QsciScintilla, "annotate"):
5359 warningAnnotations = [] 5381 warningAnnotations = []
5360 errorAnnotations = [] 5382 errorAnnotations = []
5383 styleAnnotations = []
5361 5384
5362 # step 1: do py3flakes warnings 5385 # step 1: do warnings
5363 for handle in list(self.warnings.keys()): 5386 for handle in list(self.warnings.keys()):
5364 if self.markerLine(handle) == line: 5387 if self.markerLine(handle) == line:
5365 for msg in self.warnings[handle]: 5388 for msg, warningType in self.warnings[handle]:
5366 warningAnnotations.append( 5389 if warningType == self.WarningStyle:
5367 self.trUtf8("Warning: {0}").format(msg)) 5390 styleAnnotations.append(
5391 self.trUtf8("Style: {0}").format(msg))
5392 else:
5393 warningAnnotations.append(
5394 self.trUtf8("Warning: {0}").format(msg))
5368 5395
5369 # step 2: do syntax errors 5396 # step 2: do syntax errors
5370 for handle in list(self.syntaxerrors.keys()): 5397 for handle in list(self.syntaxerrors.keys()):
5371 if self.markerLine(handle) == line: 5398 if self.markerLine(handle) == line:
5372 for msg, _ in self.syntaxerrors[handle]: 5399 for msg, _ in self.syntaxerrors[handle]:
5373 errorAnnotations.append( 5400 errorAnnotations.append(
5374 self.trUtf8("Error: {0}").format(msg)) 5401 self.trUtf8("Error: {0}").format(msg))
5375 5402
5376 wLen = len(warningAnnotations) 5403 wLen = len(warningAnnotations)
5377 eLen = len(errorAnnotations) 5404 eLen = len(errorAnnotations)
5405 sLen = len(styleAnnotations)
5378 annotations = [] 5406 annotations = []
5407
5408 if sLen:
5409 annotationStyleTxt = "\n".join(styleAnnotations)
5410 if wLen:
5411 annotationStyleTxt += "\n"
5412 annotations.append(QsciStyledText(annotationStyleTxt,
5413 self.annotationStyleStyle))
5379 5414
5380 if wLen: 5415 if wLen:
5381 annotationWarningTxt = "\n".join(warningAnnotations) 5416 annotationWarningTxt = "\n".join(warningAnnotations)
5382 if eLen: 5417 if eLen:
5383 annotationWarningTxt += "\n" 5418 annotationWarningTxt += "\n"

eric ide

mercurial