eric6/QScintilla/Shell.py

branch
maintenance
changeset 8176
31965986ecd1
parent 8142
43248bafe9b2
parent 8169
139bd30c52c2
child 8273
698ae46f40a4
diff -r e01ae92db699 -r 31965986ecd1 eric6/QScintilla/Shell.py
--- a/eric6/QScintilla/Shell.py	Sat Mar 06 10:00:52 2021 +0100
+++ b/eric6/QScintilla/Shell.py	Sun Mar 28 15:00:11 2021 +0200
@@ -58,8 +58,8 @@
         
         from UI.SearchWidget import SearchWidget
         self.__searchWidget = SearchWidget(self.__shell, self, horizontal)
-        self.__searchWidget.setSizePolicy(QSizePolicy.Fixed,
-                                          QSizePolicy.Preferred)
+        self.__searchWidget.setSizePolicy(QSizePolicy.Policy.Fixed,
+                                          QSizePolicy.Policy.Preferred)
         self.__searchWidget.hide()
         
         if horizontal:
@@ -165,18 +165,19 @@
                 """ cursor keys on the Shell page of the configuration"""
                 """ dialog. Pressing these keys after some text has been"""
                 """ entered will start an incremental search.</p>"""
-                """<p>The shell has some special commands. 'restart' kills"""
-                """ the shell and starts a new one. 'clear' clears the"""
-                """ display of the shell window. 'start' is used to start a"""
+                """<p>The shell has some special commands. '%restart' kills"""
+                """ the shell and starts a new one. '%clear' clears the"""
+                """ display of the shell window. '%start' is used to start a"""
                 """ shell for a virtual environment and should be followed"""
-                """ by a virtual environment name. start' without a virtual"""
-                """ environment name starts the default shell. Available"""
-                """ virtual environments may be listed with the 'envs' or"""
-                """ 'environments' commands. The active virtual environment"""
-                """ can be questioned by the 'which' command. 'quit' or"""
-                """ 'exit' is used to exit the application. These commands"""
-                """ (except environments', 'envs' and 'which') are available"""
-                """ through the window menus as well.</p>"""
+                """ by a virtual environment name. '%start' without a"""
+                """ virtual environment name starts the default shell."""
+                """ Available virtual environments may be listed with the"""
+                """ '%envs' or '%environments' commands. The active virtual"""
+                """ environment can be questioned by the '%which' command."""
+                """ '%quit' or '%exit' is used to exit the application."""
+                """ These commands (except '%environments', '%envs' and"""
+                """ '%which') are available through the window menus as"""
+                """ well.</p>"""
                 """<p>Pressing the Tab key after some text has been entered"""
                 """ will show a list of possible completions. The relevant"""
                 """ entry may be selected from this list. If only one entry"""
@@ -196,17 +197,17 @@
                 """ cursor keys on the Shell page of the configuration"""
                 """ dialog. Pressing these keys after some text has been"""
                 """ entered will start an incremental search.</p>"""
-                """<p>The shell has some special commands. 'restart' kills"""
-                """ the shell and starts a new one. 'clear' clears the"""
-                """ display of the shell window. 'start' is used to start a"""
+                """<p>The shell has some special commands. '%restart' kills"""
+                """ the shell and starts a new one. '%clear' clears the"""
+                """ display of the shell window. '%start' is used to start a"""
                 """ shell for a virtual environment and should be followed"""
-                """ by a virtual environment name. start' without a virtual"""
-                """ environment name starts the default shell. Available"""
-                """ virtual environments may be listed with the 'envs' or"""
-                """ 'environments' commands. The active virtual environment"""
-                """ can be questioned by the 'which' command. These commands"""
-                """ (except environments' and 'envs') are available through"""
-                """ the context menu as well.</p>"""
+                """ by a virtual environment name. '%start' without a"""
+                """ virtual environment name starts the default shell."""
+                """ Available virtual environments may be listed with the"""
+                """ '%envs' or '%environments' commands. The active virtual"""
+                """ environment can be questioned by the '%which' command."""
+                """ These commands (except '%environments' and '%envs') are"""
+                """ available through the context menu as well.</p>"""
                 """<p>Pressing the Tab key after some text has been entered"""
                 """ will show a list of possible completions. The relevant"""
                 """ entry may be selected from this list. If only one entry"""
@@ -374,14 +375,15 @@
         
         self.__queuedText = ''
         self.__blockTextProcessing = False
-        self.queueText.connect(self.__concatenateText, Qt.QueuedConnection)
+        self.queueText.connect(self.__concatenateText,
+                               Qt.ConnectionType.QueuedConnection)
         
         self.__project = project
         if self.__project:
             self.__project.projectOpened.connect(self.__projectOpened)
             self.__project.projectClosed.connect(self.__projectClosed)
         
-        self.grabGesture(Qt.PinchGesture)
+        self.grabGesture(Qt.GestureType.PinchGesture)
     
     def __showStartMenu(self):
         """
@@ -479,7 +481,8 @@
         """
         self.setTabWidth(Preferences.getEditor("TabWidth"))
         if Preferences.getEditor("ShowWhitespace"):
-            self.setWhitespaceVisibility(QsciScintilla.WsVisible)
+            self.setWhitespaceVisibility(
+                QsciScintilla.WhitespaceVisibility.WsVisible)
             try:
                 self.setWhitespaceForegroundColor(
                     Preferences.getEditorColour("WhitespaceForeground"))
@@ -491,12 +494,13 @@
                 # QScintilla before 2.5 doesn't support this
                 pass
         else:
-            self.setWhitespaceVisibility(QsciScintilla.WsInvisible)
+            self.setWhitespaceVisibility(
+                QsciScintilla.WhitespaceVisibility.WsInvisible)
         self.setEolVisibility(Preferences.getEditor("ShowEOL"))
         if Preferences.getEditor("BraceHighlighting"):
-            self.setBraceMatching(QsciScintilla.SloppyBraceMatch)
+            self.setBraceMatching(QsciScintilla.BraceMatch.SloppyBraceMatch)
         else:
-            self.setBraceMatching(QsciScintilla.NoBraceMatch)
+            self.setBraceMatching(QsciScintilla.BraceMatch.NoBraceMatch)
         self.setMatchedBraceForegroundColor(
             Preferences.getEditorColour("MatchingBrace"))
         self.setMatchedBraceBackgroundColor(
@@ -510,7 +514,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"):
@@ -518,7 +522,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"))
@@ -526,9 +531,9 @@
         self.caretWidth = Preferences.getEditor("CaretWidth")
         self.setCaretWidth(self.caretWidth)
         if Preferences.getShell("WrapEnabled"):
-            self.setWrapMode(QsciScintilla.WrapWord)
+            self.setWrapMode(QsciScintilla.WrapMode.WrapWord)
         else:
-            self.setWrapMode(QsciScintilla.WrapNone)
+            self.setWrapMode(QsciScintilla.WrapMode.WrapNone)
         self.useMonospaced = Preferences.getShell("UseMonospacedFont")
         self.__setMonospaced(self.useMonospaced)
         
@@ -586,18 +591,21 @@
                 Preferences.getEditorColour("CallTipsHighlight"))
             self.setCallTipsVisible(Preferences.getEditor("CallTipsVisible"))
             calltipsStyle = Preferences.getEditor("CallTipsStyle")
-            if calltipsStyle == QsciScintilla.CallTipsNoContext:
-                self.setCallTipsStyle(QsciScintilla.CallTipsNoContext)
+            if calltipsStyle == QsciScintilla.CallTipsStyle.CallTipsNoContext:
+                self.setCallTipsStyle(
+                    QsciScintilla.CallTipsStyle.CallTipsNoContext)
             elif (
                 calltipsStyle ==
-                    QsciScintilla.CallTipsNoAutoCompletionContext
+                    QsciScintilla.CallTipsStyle.CallTipsNoAutoCompletionContext
             ):
                 self.setCallTipsStyle(
-                    QsciScintilla.CallTipsNoAutoCompletionContext)
+                    QsciScintilla.CallTipsStyle
+                    .CallTipsNoAutoCompletionContext)
             else:
-                self.setCallTipsStyle(QsciScintilla.CallTipsContext)
+                self.setCallTipsStyle(
+                    QsciScintilla.CallTipsStyle.CallTipsContext)
         else:
-            self.setCallTipsStyle(QsciScintilla.CallTipsNone)
+            self.setCallTipsStyle(QsciScintilla.CallTipsStyle.CallTipsNone)
         
     def setDebuggerUI(self, ui):
         """
@@ -786,7 +794,7 @@
         """
         from .ShellHistoryDialog import ShellHistoryDialog
         dlg = ShellHistoryDialog(self.__history, self.vm, self)
-        if dlg.exec() == QDialog.Accepted:
+        if dlg.exec() == QDialog.DialogCode.Accepted:
             self.__historyLists[self.clientType], idx = dlg.getHistory()
             self.__history = self.__historyLists[self.clientType]
             self.__setHistoryIndex(index=idx)
@@ -1232,8 +1240,8 @@
         @param event the mouse press event (QMouseEvent)
         """
         self.setFocus()
-        if event.button() == Qt.MidButton:
-            lines = QApplication.clipboard().text(QClipboard.Selection)
+        if event.button() == Qt.MouseButton.MidButton:
+            lines = QApplication.clipboard().text(QClipboard.Mode.Selection)
             self.paste(lines)
         else:
             super(Shell, self).mousePressEvent(event)
@@ -1244,7 +1252,7 @@
         
         @param evt reference to the wheel event (QWheelEvent)
         """
-        if evt.modifiers() & Qt.ControlModifier:
+        if evt.modifiers() & Qt.KeyboardModifier.ControlModifier:
             delta = evt.angleDelta().y()
             if delta < 0:
                 self.zoomOut()
@@ -1262,7 +1270,7 @@
         @param evt reference to the event (QEvent)
         @return flag indicating, if the event was handled (boolean)
         """
-        if evt.type() == QEvent.Gesture:
+        if evt.type() == QEvent.Type.Gesture:
             self.gestureEvent(evt)
             return True
         
@@ -1274,12 +1282,12 @@
         
         @param evt reference to the gesture event (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
@@ -1803,77 +1811,90 @@
                     else:
                         self.__setHistoryIndex(historyIndex)
             
-            if cmd == 'start' or cmd.startswith('start '):
-                if not self.passive:
-                    cmdList = cmd.split(None, 1)
-                    if len(cmdList) < 2:
-                        self.dbs.startClient(False)  # start default backend
+            if cmd.startswith("%"):
+                if cmd == '%start' or cmd.startswith('%start '):
+                    if not self.passive:
+                        cmdList = cmd.split(None, 1)
+                        if len(cmdList) < 2:
+                            self.dbs.startClient(False)
+                            # start default backend
+                        else:
+                            venvName = cmdList[1]
+                            if venvName == self.tr("Project"):
+                                if self.__project.isOpen():
+                                    self.dbs.startClient(
+                                        False,
+                                        forProject=True,
+                                        workingDir=self.__project
+                                        .getProjectPath()
+                                    )
+                                    self.__currentWorkingDirectory = (
+                                        self.__project.getProjectPath()
+                                    )
+                                else:
+                                    self.dbs.startClient(
+                                        False,
+                                        venvName=self.__currentVenv,
+                                        workingDir=self
+                                        .__currentWorkingDirectory
+                                    )
+                                    # same as reset
+                            else:
+                                self.dbs.startClient(False, venvName=venvName)
+                                self.__currentWorkingDirectory = ""
+                        self.__getBanner()
+                        return
+                elif cmd == '%clear':
+                    # Display the banner.
+                    self.__getBanner()
+                    if not self.passive:
+                        return
                     else:
-                        venvName = cmdList[1]
-                        if venvName == self.tr("Project"):
-                            if self.__project.isOpen():
-                                self.dbs.startClient(
-                                    False, forProject=True,
-                                    workingDir=self.__project.getProjectPath())
-                                self.__currentWorkingDirectory = (
-                                    self.__project.getProjectPath()
-                                )
-                            else:
-                                self.dbs.startClient(
-                                    False, venvName=self.__currentVenv,
-                                    workingDir=self.__currentWorkingDirectory)
-                                # same as reset
-                        else:
-                            self.dbs.startClient(False, venvName=venvName)
-                            self.__currentWorkingDirectory = ""
-                    self.__getBanner()
-                    return
-            elif cmd == 'clear':
-                # Display the banner.
-                self.__getBanner()
-                if not self.passive:
+                        cmd = ''
+                elif cmd in ['%reset', '%restart']:
+                    self.dbs.startClient(
+                        False, venvName=self.__currentVenv,
+                        workingDir=self.__currentWorkingDirectory)
+                    if self.passive:
+                        return
+                    else:
+                        cmd = ''
+                elif cmd in ['%envs', '%environments']:
+                    venvs = (
+                        e5App().getObject("VirtualEnvManager")
+                        .getVirtualenvNames()
+                    )
+                    s = (
+                        self.tr('Available Virtual Environments:\n{0}\n')
+                        .format('\n'.join(
+                            "- {0}".format(venv)
+                            for venv in sorted(venvs)
+                        ))
+                    )
+                    self.__write(s)
+                    self.__clientStatement(False)
                     return
-                else:
-                    cmd = ''
-            elif cmd in ['reset', 'restart']:
-                self.dbs.startClient(False, venvName=self.__currentVenv,
-                                     workingDir=self.__currentWorkingDirectory)
-                if self.passive:
+                elif cmd == '%which':
+                    s = self.tr("Current Virtual Environment: '{0}'\n").format(
+                        self.__currentVenv)
+                    self.__write(s)
+                    self.__clientStatement(False)
                     return
-                else:
-                    cmd = ''
-            elif cmd in ['envs', 'environments']:
-                venvs = (
-                    e5App().getObject("VirtualEnvManager")
-                    .getVirtualenvNames()
-                )
-                s = self.tr('Available Virtual Environments:\n{0}\n').format(
-                    '\n'.join("- {0}".format(venv) for venv in sorted(venvs))
-                )
-                self.__write(s)
-                self.__clientStatement(False)
-                return
-            elif cmd == 'which':
-                s = self.tr("Current Virtual Environment: '{0}'\n").format(
-                    self.__currentVenv)
-                self.__write(s)
-                self.__clientStatement(False)
-                return
-            elif (
-                cmd in ["quit", "quit()", "exit", "exit()"] and
-                self.__windowed
-            ):
-                # call main window quit()
-                self.vm.quit()
-                return
-            
-            self.dbs.remoteStatement(self.__debugUI.getSelectedDebuggerId(),
-                                     cmd)
-            while self.inCommandExecution:
-                try:
-                    QApplication.processEvents()
-                except KeyboardInterrupt:
-                    pass
+                elif (
+                    cmd in ["%quit", "%quit()", "%exit", "%exit()"] and
+                    self.__windowed
+                ):
+                    # call main window quit()
+                    self.vm.quit()
+                    return
+            else:
+                self.dbs.remoteStatement(
+                    self.__debugUI.getSelectedDebuggerId(), cmd)
+                while self.inCommandExecution:
+                    try:
+                        QApplication.processEvents()
+                    except KeyboardInterrupt:
+                        pass
         else:
             if not self.__echoInput:
                 cmd = self.buff
@@ -2380,3 +2401,6 @@
         if Preferences.getProject("RestartShellForProject"):
             self.dbs.startClient(False)
             self.__getBanner()
+
+#
+# eflag: noqa = M601

eric ide

mercurial