--- a/eric6/QScintilla/Editor.py Sat Mar 06 10:00:52 2021 +0100 +++ b/eric6/QScintilla/Editor.py Sun Mar 28 15:00:11 2021 +0200 @@ -194,7 +194,7 @@ @exception OSError raised to indicate an issue accessing the file """ super(Editor, self).__init__(parent) - self.setAttribute(Qt.WA_KeyCompression) + self.setAttribute(Qt.WidgetAttribute.WA_KeyCompression) self.setUtf8(True) self.dbs = dbs @@ -334,8 +334,10 @@ # define the line markers if Preferences.getEditor("LineMarkersBackground"): - self.currentline = self.markerDefine(QsciScintilla.Background) - self.errorline = self.markerDefine(QsciScintilla.Background) + self.currentline = self.markerDefine( + QsciScintilla.MarkerSymbol.Background) + self.errorline = self.markerDefine( + QsciScintilla.MarkerSymbol.Background) self.__setLineMarkerColours() else: self.currentline = self.markerDefine( @@ -471,7 +473,7 @@ self.resize(sh) # Make sure tabbing through a QWorkspace works. - self.setFocusPolicy(Qt.StrongFocus) + self.setFocusPolicy(Qt.FocusPolicy.StrongFocus) self.__updateReadOnly(True) @@ -557,7 +559,7 @@ self.project.projectPropertiesChanged.connect( self.__projectPropertiesChanged) - self.grabGesture(Qt.PinchGesture) + self.grabGesture(Qt.GestureType.PinchGesture) self.SCN_ZOOM.connect(self.__markerMap.update) self.__markerMap.update() @@ -1811,7 +1813,10 @@ self.SCN_STYLENEEDED.connect(self.__styleNeeded) # get the font for style 0 and set it as the default font - key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language()) + if pyname and pyname.startswith("Pygments|"): + key = 'Scintilla/Guessed/style0/font' + else: + key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language()) fdesc = Preferences.Prefs.settings.value(key) if fdesc is not None: font = QFont(fdesc[0], int(fdesc[1])) @@ -2514,7 +2519,7 @@ (self.fileName, ln), (cond, temp, enabled, ignorecount), self.condHistory, self, modal=True) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: cond, temp, enabled, ignorecount = dlg.getData() self.breakpointModel.setBreakPointByIndex( index, self.fileName, ln, @@ -2702,12 +2707,14 @@ Public slot to print the text. """ from .Printer import Printer - printer = Printer(mode=QPrinter.HighResolution) + printer = Printer(mode=QPrinter.PrinterMode.HighResolution) sb = e5App().getObject("UserInterface").statusBar() printDialog = QPrintDialog(printer, self) if self.hasSelectedText(): - printDialog.setOption(QAbstractPrintDialog.PrintSelection, True) - if printDialog.exec() == QDialog.Accepted: + printDialog.setOption( + QAbstractPrintDialog.PrintDialogOption.PrintSelection, + True) + if printDialog.exec() == QDialog.DialogCode.Accepted: sb.showMessage(self.tr('Printing...')) QApplication.processEvents() fn = self.getFileName() @@ -2715,7 +2722,10 @@ printer.setDocName(os.path.basename(fn)) else: printer.setDocName(self.noName) - if printDialog.printRange() == QAbstractPrintDialog.Selection: + if ( + printDialog.printRange() == + QAbstractPrintDialog.PrintRange.Selection + ): # get the selection fromLine, fromIndex, toLine, toIndex = self.getSelection() if toIndex == 0: @@ -2740,7 +2750,7 @@ from PyQt5.QtPrintSupport import QPrintPreviewDialog from .Printer import Printer - printer = Printer(mode=QPrinter.HighResolution) + printer = Printer(mode=QPrinter.PrinterMode.HighResolution) fn = self.getFileName() if fn is not None: printer.setDocName(os.path.basename(fn)) @@ -2878,7 +2888,7 @@ @return create pixmap (QPixmap) """ pixmap = QPixmap(size, size) - pixmap.fill(Qt.transparent) + pixmap.fill(Qt.GlobalColor.transparent) painter = QPainter(pixmap) painter.fillRect(size - 4, 0, 4, size, Preferences.getEditorColour(key)) @@ -4371,8 +4381,10 @@ # set the line marker colours or pixmap if Preferences.getEditor("LineMarkersBackground"): - self.markerDefine(QsciScintilla.Background, self.currentline) - self.markerDefine(QsciScintilla.Background, self.errorline) + self.markerDefine(QsciScintilla.MarkerSymbol.Background, + self.currentline) + self.markerDefine(QsciScintilla.MarkerSymbol.Background, + self.errorline) self.__setLineMarkerColours() else: self.markerDefine( @@ -4549,7 +4561,8 @@ Preferences.getEditorColour("FoldMarkersBackground")) else: self.setMarginWidth(self.__foldMargin, 0) - self.setFolding(QsciScintilla.NoFoldStyle, self.__foldMargin) + self.setFolding(QsciScintilla.FoldStyle.NoFoldStyle, + self.__foldMargin) def __resizeLinenoMargin(self): """ @@ -4586,7 +4599,8 @@ self.setIndentationGuidesForegroundColor( Preferences.getEditorColour("IndentationGuidesForeground")) if Preferences.getEditor("ShowWhitespace"): - self.setWhitespaceVisibility(QsciScintilla.WsVisible) + self.setWhitespaceVisibility( + QsciScintilla.WhitespaceVisibility.WsVisible) try: self.setWhitespaceForegroundColor( Preferences.getEditorColour("WhitespaceForeground")) @@ -4598,13 +4612,14 @@ # QScintilla before 2.5 doesn't support this pass else: - self.setWhitespaceVisibility(QsciScintilla.WsInvisible) + self.setWhitespaceVisibility( + QsciScintilla.WhitespaceVisibility.WsInvisible) self.setEolVisibility(Preferences.getEditor("ShowEOL")) self.setAutoIndent(Preferences.getEditor("AutoIndentation")) if Preferences.getEditor("BraceHighlighting"): - self.setBraceMatching(QsciScintilla.SloppyBraceMatch) - else: - self.setBraceMatching(QsciScintilla.NoBraceMatch) + self.setBraceMatching(QsciScintilla.BraceMatch.SloppyBraceMatch) + else: + self.setBraceMatching(QsciScintilla.BraceMatch.NoBraceMatch) self.setMatchedBraceForegroundColor( Preferences.getEditorColour("MatchingBrace")) self.setMatchedBraceBackgroundColor( @@ -4618,7 +4633,7 @@ Preferences.getEditorColour("SelectionBackground")) else: self.setSelectionBackgroundColor( - QApplication.palette().color(QPalette.Highlight)) + QApplication.palette().color(QPalette.ColorRole.Highlight)) if Preferences.getEditor("ColourizeSelText"): self.resetSelectionForegroundColor() elif Preferences.getEditor("CustomSelectionColours"): @@ -4626,7 +4641,8 @@ Preferences.getEditorColour("SelectionForeground")) else: self.setSelectionForegroundColor( - QApplication.palette().color(QPalette.HighlightedText)) + QApplication.palette().color( + QPalette.ColorRole.HighlightedText)) self.setSelectionToEol(Preferences.getEditor("ExtendSelectionToEol")) self.setCaretForegroundColor( Preferences.getEditorColour("CaretForeground")) @@ -4682,9 +4698,11 @@ try: if Preferences.getEditor("AnnotationsEnabled"): - self.setAnnotationDisplay(QsciScintilla.AnnotationBoxed) + self.setAnnotationDisplay( + QsciScintilla.AnnotationDisplay.AnnotationBoxed) else: - self.setAnnotationDisplay(QsciScintilla.AnnotationHidden) + self.setAnnotationDisplay( + QsciScintilla.AnnotationDisplay.AnnotationHidden) except AttributeError: pass self.__setAnnotationStyles() @@ -4696,6 +4714,9 @@ self.setVirtualSpaceOptions( Preferences.getEditor("VirtualSpaceOptions")) + # to avoid errors due to line endings by pasting + self.SendScintilla(QsciScintilla.SCI_SETPASTECONVERTENDINGS, True) + self.__markerMap.setEnabled(True) def __setEolMode(self): @@ -4738,12 +4759,20 @@ self.setAutoCompletionShowSingle( Preferences.getEditor("AutoCompletionShowSingle")) autoCompletionSource = Preferences.getEditor("AutoCompletionSource") - if autoCompletionSource == QsciScintilla.AcsDocument: - self.setAutoCompletionSource(QsciScintilla.AcsDocument) - elif autoCompletionSource == QsciScintilla.AcsAPIs: - self.setAutoCompletionSource(QsciScintilla.AcsAPIs) - else: - self.setAutoCompletionSource(QsciScintilla.AcsAll) + if ( + autoCompletionSource == + QsciScintilla.AutoCompletionSource.AcsDocument + ): + self.setAutoCompletionSource( + QsciScintilla.AutoCompletionSource.AcsDocument) + elif ( + autoCompletionSource == QsciScintilla.AutoCompletionSource.AcsAPIs + ): + self.setAutoCompletionSource( + QsciScintilla.AutoCompletionSource.AcsAPIs) + else: + self.setAutoCompletionSource( + QsciScintilla.AutoCompletionSource.AcsAll) self.maxLines = Preferences.getEditor("AutoCompletionMaxLines") self.maxChars = Preferences.getEditor("AutoCompletionMaxChars") @@ -4767,17 +4796,21 @@ pass if Preferences.getEditor("CallTipsEnabled"): - if calltipsStyle == QsciScintilla.CallTipsNoContext: - self.setCallTipsStyle(QsciScintilla.CallTipsNoContext) + if calltipsStyle == QsciScintilla.CallTipsStyle.CallTipsNoContext: + self.setCallTipsStyle( + QsciScintilla.CallTipsStyle.CallTipsNoContext) elif ( - calltipsStyle == QsciScintilla.CallTipsNoAutoCompletionContext + calltipsStyle == + QsciScintilla.CallTipsStyle.CallTipsNoAutoCompletionContext ): self.setCallTipsStyle( - QsciScintilla.CallTipsNoAutoCompletionContext) + QsciScintilla.CallTipsStyle + .CallTipsNoAutoCompletionContext) else: - self.setCallTipsStyle(QsciScintilla.CallTipsContext) - else: - self.setCallTipsStyle(QsciScintilla.CallTipsNone) + self.setCallTipsStyle( + QsciScintilla.CallTipsStyle.CallTipsContext) + else: + self.setCallTipsStyle(QsciScintilla.CallTipsStyle.CallTipsNone) ########################################################################### ## Autocompletion handling methods below @@ -4801,11 +4834,11 @@ return acs = Preferences.getEditor("AutoCompletionSource") - if acs == QsciScintilla.AcsDocument: + if acs == QsciScintilla.AutoCompletionSource.AcsDocument: self.autoCompleteFromDocument() - elif acs == QsciScintilla.AcsAPIs: + elif acs == QsciScintilla.AutoCompletionSource.AcsAPIs: self.autoCompleteFromAPIs() - elif acs == QsciScintilla.AcsAll: + elif acs == QsciScintilla.AutoCompletionSource.AcsAll: self.autoCompleteFromAll() else: E5MessageBox.information( @@ -4825,12 +4858,21 @@ if enable: autoCompletionSource = Preferences.getEditor( "AutoCompletionSource") - if autoCompletionSource == QsciScintilla.AcsDocument: - self.setAutoCompletionSource(QsciScintilla.AcsDocument) - elif autoCompletionSource == QsciScintilla.AcsAPIs: - self.setAutoCompletionSource(QsciScintilla.AcsAPIs) + if ( + autoCompletionSource == + QsciScintilla.AutoCompletionSource.AcsDocument + ): + self.setAutoCompletionSource( + QsciScintilla.AutoCompletionSource.AcsDocument) + elif ( + autoCompletionSource == + QsciScintilla.AutoCompletionSource.AcsAPIs + ): + self.setAutoCompletionSource( + QsciScintilla.AutoCompletionSource.AcsAPIs) else: - self.setAutoCompletionSource(QsciScintilla.AcsAll) + self.setAutoCompletionSource( + QsciScintilla.AutoCompletionSource.AcsAll) def __toggleAutoCompletionEnable(self): """ @@ -4872,7 +4914,8 @@ self.__acTimer.stop() if ( - self.callTipsStyle() != QsciScintilla.CallTipsNone and + self.callTipsStyle() != + QsciScintilla.CallTipsStyle.CallTipsNone and self.lexer_ is not None and chr(charNumber) in '()' ): self.callTip() @@ -5007,7 +5050,10 @@ self.__autoComplete(auto, context) elif not auto: self.autoCompleteQScintilla() - elif self.autoCompletionSource() != QsciScintilla.AcsNone: + elif ( + self.autoCompletionSource() != + QsciScintilla.AutoCompletionSource.AcsNone + ): self.autoCompleteQScintilla() def __getAcText(self): @@ -5521,7 +5567,7 @@ self.menuActs["MonospacedFont"].setEnabled(self.lexer_ is None) splitOrientation = self.vm.getSplitOrientation() - if splitOrientation == Qt.Horizontal: + if splitOrientation == Qt.Orientation.Horizontal: self.menuActs["NewSplit"].setIcon( UI.PixmapCache.getIcon("splitHorizontal")) else: @@ -6907,7 +6953,7 @@ self, self.tr("Macro Recording"), self.tr("Enter name of the macro:"), - QLineEdit.Normal) + QLineEdit.EchoMode.Normal) if ok and name: self.macros[name] = self.curMacro @@ -7115,10 +7161,13 @@ @type QEvent """ if ( - evt.type() == QEvent.WindowStateChange and + evt.type() == QEvent.Type.WindowStateChange and bool(self.fileName) ): - if self.windowState() == Qt.WindowStates(Qt.WindowMinimized): + if ( + self.windowState() == Qt.WindowStates( + Qt.WindowState.WindowMinimized) + ): cap = os.path.basename(self.fileName) else: cap = self.fileName @@ -7157,7 +7206,7 @@ @type QWheelEvent """ delta = evt.angleDelta().y() - if evt.modifiers() & Qt.ControlModifier: + if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: if delta < 0: self.zoomOut() elif delta > 0: @@ -7165,7 +7214,7 @@ evt.accept() return - if evt.modifiers() & Qt.ShiftModifier: + if evt.modifiers() & Qt.KeyboardModifier.ShiftModifier: if delta < 0: self.gotoMethodClass(False) elif delta > 0: @@ -7184,7 +7233,7 @@ @return flag indicating, if the event was handled @rtype bool """ - if evt.type() == QEvent.Gesture: + if evt.type() == QEvent.Type.Gesture: self.gestureEvent(evt) return True @@ -7197,12 +7246,12 @@ @param evt reference to the gesture event @type QGestureEvent """ - pinch = evt.gesture(Qt.PinchGesture) + pinch = evt.gesture(Qt.GestureType.PinchGesture) if pinch: - if pinch.state() == Qt.GestureStarted: + if pinch.state() == Qt.GestureState.GestureStarted: zoom = (self.getZoom() + 10) / 10.0 pinch.setTotalScaleFactor(zoom) - elif pinch.state() == Qt.GestureUpdated: + elif pinch.state() == Qt.GestureState.GestureUpdated: zoom = int(pinch.totalScaleFactor() * 10) - 10 if zoom <= -9: zoom = -9 @@ -7505,7 +7554,7 @@ self, self.tr("Add aliased file resource"), self.tr("Alias for file <b>{0}</b>:").format(relFile), - QLineEdit.Normal, + QLineEdit.EchoMode.Normal, relFile) if ok and alias: line, index = self.getCursorPosition() @@ -7520,7 +7569,7 @@ """ from Project.AddLanguageDialog import AddLanguageDialog dlg = AddLanguageDialog(self) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: lang = dlg.getSelectedLanguage() line, index = self.getCursorPosition() self.insert('<qresource lang="{0}">\n</qresource>\n'.format(lang)) @@ -7677,6 +7726,14 @@ for t in templateNames]) return + elif cmd == QsciScintilla.SCI_DELETEBACK: + line, index = self.getCursorPosition() + text = self.text(line)[index - 1:index + 1] + matchingPairs = ['()', '[]', '{}', '<>', "''", '""'] + # __IGNORE_WARNING_M613__ + if text in matchingPairs: + self.delete() + super(Editor, self).editorCommand(cmd) def __applyTemplate(self, templateName, language): @@ -7820,7 +7877,7 @@ if Preferences.getEditor("AutoSpellCheckingEnabled"): try: self.SCN_CHARADDED.connect( - self.__spellCharAdded, Qt.UniqueConnection) + self.__spellCharAdded, Qt.ConnectionType.UniqueConnection) except TypeError: pass self.spell.checkDocumentIncrementally() @@ -8051,7 +8108,7 @@ hashStr = str( QCryptographicHash.hash( Utilities.encode(self.__savedText, self.encoding)[0], - QCryptographicHash.Sha1).toHex(), + QCryptographicHash.Algorithm.Sha1).toHex(), encoding="utf-8") self.__send(Editor.StartEditToken, hashStr) @@ -8148,7 +8205,7 @@ hashStr = str( QCryptographicHash.hash( Utilities.encode(self.text(), self.encoding)[0], - QCryptographicHash.Sha1).toHex(), + QCryptographicHash.Algorithm.Sha1).toHex(), encoding="utf-8") if hashStr != argsString: # text is different to the remote site, request to sync it @@ -8231,7 +8288,7 @@ hashStr = str( QCryptographicHash.hash( Utilities.encode(self.__savedText, self.encoding)[0], - QCryptographicHash.Sha1).toHex(), + QCryptographicHash.Algorithm.Sha1).toHex(), encoding="utf-8") if hashStr == argsString: @@ -8331,7 +8388,7 @@ from .SortOptionsDialog import SortOptionsDialog dlg = SortOptionsDialog() - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: ascending, alnum, caseSensitive = dlg.getData() origStartLine, origStartIndex, origEndLine, origEndIndex = ( self.getRectangularSelection() @@ -8417,7 +8474,7 @@ super(Editor, self).mouseReleaseEvent(evt) if ( - button != Qt.NoButton and + button != Qt.MouseButton.NoButton and Preferences.getEditor("MouseClickHandlersEnabled") and key in self.__mouseClickHandlers ): @@ -8609,11 +8666,11 @@ if option == "EOLMode": value = config["end_of_line"] if value == "lf": - value = QsciScintilla.EolUnix + value = QsciScintilla.EolMode.EolUnix elif value == "crlf": - value = QsciScintilla.EolWindows + value = QsciScintilla.EolMode.EolWindows elif value == "cr": - value = QsciScintilla.EolMac + value = QsciScintilla.EolMode.EolMac else: value = None elif option == "DefaultEncoding":