src/eric7/QScintilla/Editor.py

branch
eric7-maintenance
changeset 10079
0222a480e93d
parent 10004
983477114d3c
parent 10069
435cc5875135
child 10148
31ba20629af4
equal deleted inserted replaced
10005:097199aec4bd 10079:0222a480e93d
62 62
63 EditorAutoCompletionListID = 1 63 EditorAutoCompletionListID = 1
64 TemplateCompletionListID = 2 64 TemplateCompletionListID = 2
65 ReferencesListID = 3 65 ReferencesListID = 3
66 66
67 ReferenceItem = collections.namedtuple( 67 ReferenceItem = collections.namedtuple( # noqa: U200
68 "ReferenceItem", ["modulePath", "codeLine", "line", "column"] 68 "ReferenceItem", ["modulePath", "codeLine", "line", "column"]
69 ) 69 )
70 70
71 71
72 class Editor(QsciScintillaCompat): 72 class Editor(QsciScintillaCompat):
142 encodingChanged = pyqtSignal(str) 142 encodingChanged = pyqtSignal(str)
143 spellLanguageChanged = pyqtSignal(str) 143 spellLanguageChanged = pyqtSignal(str)
144 lastEditPositionAvailable = pyqtSignal() 144 lastEditPositionAvailable = pyqtSignal()
145 refreshed = pyqtSignal() 145 refreshed = pyqtSignal()
146 settingsRead = pyqtSignal() 146 settingsRead = pyqtSignal()
147 mouseDoubleClick = pyqtSignal(QPoint, int) 147 mouseDoubleClick = pyqtSignal(QPoint, Qt.MouseButton)
148 148
149 WarningCode = 1 149 WarningCode = 1
150 WarningStyle = 2 150 WarningStyle = 2
151 151
152 # Autocompletion icon definitions 152 # Autocompletion icon definitions
2308 """ 2308 """
2309 if self.lastHighlight is not None: 2309 if self.lastHighlight is not None:
2310 lineno = self.markerLine(self.lastHighlight) 2310 lineno = self.markerLine(self.lastHighlight)
2311 self.ensureVisible(lineno + 1) 2311 self.ensureVisible(lineno + 1)
2312 2312
2313 def highlight(self, line=None, error=False, syntaxError=False): 2313 def highlight(self, line=None, error=False, syntaxError=False): # noqa: U100
2314 """ 2314 """
2315 Public method to highlight [or de-highlight] a particular line. 2315 Public method to highlight [or de-highlight] a particular line.
2316 2316
2317 @param line line number to highlight (integer) 2317 @param line line number to highlight (integer)
2318 @param error flag indicating whether the error highlight should be 2318 @param error flag indicating whether the error highlight should be
2355 ## Breakpoint handling methods below 2355 ## Breakpoint handling methods below
2356 ########################################################################### 2356 ###########################################################################
2357 2357
2358 def __modified( 2358 def __modified(
2359 self, 2359 self,
2360 pos, 2360 pos, # noqa: U100
2361 mtype, 2361 mtype,
2362 text, 2362 text, # noqa: U100
2363 length, 2363 length, # noqa: U100
2364 linesAdded, 2364 linesAdded,
2365 line, 2365 line,
2366 foldNow, 2366 foldNow, # noqa: U100
2367 foldPrev, 2367 foldPrev, # noqa: U100
2368 token, 2368 token, # noqa: U100
2369 annotationLinesAdded, 2369 annotationLinesAdded, # noqa: U100
2370 ): 2370 ):
2371 """ 2371 """
2372 Private method to handle changes of the number of lines. 2372 Private method to handle changes of the number of lines.
2373 2373
2374 @param pos start position of change (integer) 2374 @param pos start position of change (integer)
3045 3045
3046 ########################################################################### 3046 ###########################################################################
3047 ## Change tracing methods below 3047 ## Change tracing methods below
3048 ########################################################################### 3048 ###########################################################################
3049 3049
3050 def __createChangeMarkerPixmap(self, key, size=16, width=4): 3050 def __createChangeMarkerPixmap(self, key, size=16):
3051 """ 3051 """
3052 Private method to create a pixmap for the change markers. 3052 Private method to create a pixmap for the change markers.
3053 3053
3054 @param key key of the color to use (string) 3054 @param key key of the color to use (string)
3055 @param size size of the pixmap (integer) 3055 @param size size of the pixmap (integer)
3056 @param width width of the marker line (integer)
3057 @return create pixmap (QPixmap) 3056 @return create pixmap (QPixmap)
3058 """ 3057 """
3059 pixmap = QPixmap(size, size) 3058 pixmap = QPixmap(size, size)
3060 pixmap.fill(Qt.GlobalColor.transparent) 3059 pixmap.fill(Qt.GlobalColor.transparent)
3061 painter = QPainter(pixmap) 3060 painter = QPainter(pixmap)
3327 txt, self.encoding = Utilities.readEncodedFileWithEncoding( 3326 txt, self.encoding = Utilities.readEncodedFileWithEncoding(
3328 fn, encoding 3327 fn, encoding
3329 ) 3328 )
3330 else: 3329 else:
3331 txt, self.encoding = Utilities.readEncodedFile(fn) 3330 txt, self.encoding = Utilities.readEncodedFile(fn)
3332 except (UnicodeDecodeError, OSError) as why: 3331 except (OSError, UnicodeDecodeError) as why:
3333 EricMessageBox.critical( 3332 EricMessageBox.critical(
3334 self.vm, 3333 self.vm,
3335 self.tr("Open File"), 3334 self.tr("Open File"),
3336 self.tr( 3335 self.tr(
3337 "<p>The file <b>{0}</b> could not be opened.</p>" 3336 "<p>The file <b>{0}</b> could not be opened.</p>"
3447 fn, txt, self.encoding, forcedEncoding=editorConfigEncoding 3446 fn, txt, self.encoding, forcedEncoding=editorConfigEncoding
3448 ) 3447 )
3449 if createBackup and perms_valid: 3448 if createBackup and perms_valid:
3450 os.chmod(fn, permissions) 3449 os.chmod(fn, permissions)
3451 return True 3450 return True
3452 except (OSError, Utilities.CodingError, UnicodeError) as why: 3451 except (OSError, UnicodeError, Utilities.CodingError) as why:
3453 EricMessageBox.critical( 3452 EricMessageBox.critical(
3454 self, 3453 self,
3455 self.tr("Save File"), 3454 self.tr("Save File"),
3456 self.tr( 3455 self.tr(
3457 "<p>The file <b>{0}</b> could not be saved.<br/>Reason: {1}</p>" 3456 "<p>The file <b>{0}</b> could not be saved.<br/>Reason: {1}</p>"
3617 self.lastModified = ( 3616 self.lastModified = (
3618 pathlib.Path(fn).stat().st_mtime if pathlib.Path(fn).exists() else 0 3617 pathlib.Path(fn).stat().st_mtime if pathlib.Path(fn).exists() else 0
3619 ) 3618 )
3620 return False 3619 return False
3621 3620
3622 def saveFileAs(self, path=None, toProject=False): 3621 def saveFileAs(self, path=None):
3623 """ 3622 """
3624 Public slot to save a file with a new name. 3623 Public slot to save a file with a new name.
3625 3624
3626 @param path directory to save the file in (string) 3625 @param path directory to save the file in (string)
3627 @param toProject flag indicating a save to project operation
3628 (boolean)
3629 @return tuple of two values (boolean, string) giving a success 3626 @return tuple of two values (boolean, string) giving a success
3630 indicator and the name of the saved file 3627 indicator and the name of the saved file
3631 """ 3628 """
3632 return self.saveFile(True, path) 3629 return self.saveFile(True, path)
3633 3630
3742 QsciScintilla.SCI_FOLDCHILDREN, 3739 QsciScintilla.SCI_FOLDCHILDREN,
3743 line - 1, 3740 line - 1,
3744 QsciScintilla.SC_FOLDACTION_EXPAND, 3741 QsciScintilla.SC_FOLDACTION_EXPAND,
3745 ) 3742 )
3746 3743
3747 def __marginClicked(self, margin, line, modifiers): 3744 def __marginClicked(self, margin, line, modifiers): # noqa: U100
3748 """ 3745 """
3749 Private slot to handle the marginClicked signal. 3746 Private slot to handle the marginClicked signal.
3750 3747
3751 @param margin id of the clicked margin (integer) 3748 @param margin id of the clicked margin (integer)
3752 @param line line number of the click (integer) 3749 @param line line number of the click (integer)
6684 6681
6685 ########################################################################### 6682 ###########################################################################
6686 ## Warning handling methods below 6683 ## Warning handling methods below
6687 ########################################################################### 6684 ###########################################################################
6688 6685
6689 def toggleWarning(self, line, col, warning, msg="", warningType=WarningCode): 6686 def toggleWarning(
6687 self, line, col, warning, msg="", warningType=WarningCode # noqa: U100
6688 ):
6690 """ 6689 """
6691 Public method to toggle a warning indicator. 6690 Public method to toggle a warning indicator.
6692 6691
6693 Note: This method is used to set pyflakes and code style warnings. 6692 Note: This method is used to set pyflakes and code style warnings.
6694 6693
7221 """ 7220 """
7222 super().redo() 7221 super().redo()
7223 self.undoAvailable.emit(self.isUndoAvailable()) 7222 self.undoAvailable.emit(self.isUndoAvailable())
7224 self.redoAvailable.emit(self.isRedoAvailable()) 7223 self.redoAvailable.emit(self.isRedoAvailable())
7225 7224
7226 def close(self, alsoDelete=False): 7225 def close(self):
7227 """ 7226 """
7228 Public method called when the window gets closed. 7227 Public method called when the window gets closed.
7229 7228
7230 This overwritten method redirects the action to our 7229 This overwritten method redirects the action to our
7231 ViewManager.closeEditor, which in turn calls our closeIt 7230 ViewManager.closeEditor, which in turn calls our closeIt
7232 method. 7231 method.
7233 7232
7234 @param alsoDelete ignored
7235 @return flag indicating a successful close of the editor (boolean) 7233 @return flag indicating a successful close of the editor (boolean)
7236 """ 7234 """
7237 return self.vm.closeEditor(self) 7235 return self.vm.closeEditor(self)
7238 7236
7239 def closeIt(self): 7237 def closeIt(self):
8031 templateViewer = ericApp().getObject("TemplateViewer") 8029 templateViewer = ericApp().getObject("TemplateViewer")
8032 except KeyError: 8030 except KeyError:
8033 # template viewer is not active 8031 # template viewer is not active
8034 return 8032 return
8035 8033
8036 if templateViewer.hasTemplate(templateName, self.getLanguage()): 8034 if templateViewer.hasTemplate(templateName, language):
8037 self.extendSelectionWordLeft() 8035 self.extendSelectionWordLeft()
8038 templateViewer.applyNamedTemplate(templateName, self.getLanguage()) 8036 templateViewer.applyNamedTemplate(templateName, language)
8039 8037
8040 ####################################################################### 8038 #######################################################################
8041 ## Project related methods 8039 ## Project related methods
8042 ####################################################################### 8040 #######################################################################
8043 8041

eric ide

mercurial