eric6/QScintilla/Editor.py

changeset 8143
2c730d5fd177
parent 8131
f2129bb79269
child 8158
16a34a0167ba
--- a/eric6/QScintilla/Editor.py	Mon Mar 01 17:48:43 2021 +0100
+++ b/eric6/QScintilla/Editor.py	Tue Mar 02 17:17:09 2021 +0100
@@ -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()
@@ -2514,7 +2516,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 +2704,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 +2719,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 +2747,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 +2885,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 +4378,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 +4558,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 +4596,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 +4609,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 +4630,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 +4638,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 +4695,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()
@@ -4738,12 +4753,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 +4790,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 +4828,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 +4852,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 +4908,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 +5044,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 +5561,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 +6947,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 +7155,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 +7200,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 +7208,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 +7227,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 +7240,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 +7548,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 +7563,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))
@@ -7820,7 +7863,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 +8094,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 +8191,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 +8274,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 +8374,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 +8460,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 +8652,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":

eric ide

mercurial