QScintilla/Shell.py

changeset 6581
8eb6220f2bb7
parent 6580
082d58e2415e
child 6602
331ac8f99cf8
child 6633
c5aab2ede19a
--- a/QScintilla/Shell.py	Sun Nov 04 12:38:32 2018 +0100
+++ b/QScintilla/Shell.py	Sun Nov 04 17:20:11 2018 +0100
@@ -117,10 +117,13 @@
     @signal historyStyleChanged(ShellHistoryStyle) emitted to indicate a
         change of the history style
     @signal queueText(str) emitted to queue some text for processing
+    @signal virtualEnvironmentChanged(str) emitted to signal the new virtual
+        environment of the shell
     """
     searchStringFound = pyqtSignal(bool)
     historyStyleChanged = pyqtSignal(ShellHistoryStyle)
     queueText = pyqtSignal(str)
+    virtualEnvironmentChanged = pyqtSignal(str)
     
     def __init__(self, dbs, vm, project, windowedVariant, parent=None):
         """
@@ -165,14 +168,18 @@
                 """ 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. 'reset' kills the"""
-                """ shell and starts a new one. 'clear' clears the display"""
-                """ of the shell window. 'start' is used to switch the shell"""
-                """ language and must be followed by a supported language."""
-                """ Supported languages are listed by the 'languages'"""
-                """ command. 'quit' is used to exit the application.These"""
-                """ commands (except 'languages') are available through the"""
-                """ window menus as well.</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"""
+                """ 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>"""
                 """<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"""
@@ -192,13 +199,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. 'reset' kills the"""
-                """ shell and starts a new one. 'clear' clears the display"""
-                """ of the shell window. 'start' is used to switch the shell"""
-                """ language and must be followed by a supported language."""
-                """ Supported languages are listed by the 'languages'"""
-                """ command. These commands (except 'languages') are"""
-                """ available through the context menu as well.</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"""
+                """ 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>"""
                 """<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"""
@@ -298,11 +309,12 @@
             self.menu.addAction(self.tr('Find'), self.__find)
             self.menu.addSeparator()
             self.menu.addAction(self.tr('Clear'), self.clear)
-            self.menu.addAction(self.tr('Reset'), self.__reset)
+            self.menu.addAction(self.tr('Restart'), self.doRestart)
             self.menu.addAction(
-                self.tr('Reset and Clear'), self.__resetAndClear)
+                self.tr('Restart and Clear'), self.doClearRestart)
             self.menu.addSeparator()
             self.menu.addMenu(self.lmenu)
+            self.menu.addAction(self.tr('Active Name'), self.__showVenvName)
             self.menu.addSeparator()
             self.menu.addAction(self.tr("Configure..."), self.__configure)
         
@@ -627,6 +639,9 @@
                 self.loadHistory(self.clientType)
             self.__history = self.__historyLists[self.clientType]
             self.__setHistoryIndex()
+        
+        self.virtualEnvironmentChanged.emit(venvName)
+        Preferences.setShell("LastVirtualEnvironment", venvName)
     
     def __setHistoryIndex(self, index=None):
         """
@@ -819,6 +834,9 @@
                 self.__write(version)
             if venvName:
                 self.__write("\n[{0}]".format(venvName))
+            
+            self.virtualEnvironmentChanged.emit(venvName)
+            Preferences.setShell("LastVirtualEnvironment", venvName)
         self.__write('\n')
         
         self.__write(sys.ps1)
@@ -1768,13 +1786,29 @@
                     return
                 else:
                     cmd = ''
-            elif cmd == 'reset':
+            elif cmd in ['reset', 'restart']:
                 self.dbs.startClient(False, venvName=self.__currentVenv)
                 if self.passive:
                     return
                 else:
                     cmd = ''
-            elif cmd in ["quit", "quit()"] and self.__windowed:
+            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
@@ -1796,6 +1830,15 @@
             
             self.dbs.remoteRawInput(cmd)
     
+    def __showVenvName(self):
+        """
+        Private method to show the name of the active virtual environment.
+        """
+        s = "\n" + self.tr("Current Virtual Environment: '{0}'\n").format(
+            self.__currentVenv)
+        self.__write(s)
+        self.__clientStatement(False)
+    
     def __useHistory(self):
         """
         Private method to display a command from the history.
@@ -1904,18 +1947,18 @@
         # Display the banner.
         self.__getBanner()
         
-    def __resetAndClear(self):
+    def doClearRestart(self):
         """
-        Private slot to handle the 'reset and clear' context menu entry.
+        Public slot to handle the 'restart and clear' context menu entry.
         """
-        self.__reset()
+        self.doRestart()
         self.clear()
         
-    def __reset(self):
+    def doRestart(self):
         """
-        Private slot to handle the 'reset' context menu entry.
+        Public slot to handle the 'restart' context menu entry.
         """
-        self.dbs.startClient(False)
+        self.dbs.startClient(False, venvName=self.__currentVenv)
         
     def __startDebugClient(self, action):
         """

eric ide

mercurial