QScintilla/Shell.py

changeset 6581
8eb6220f2bb7
parent 6580
082d58e2415e
child 6602
331ac8f99cf8
child 6633
c5aab2ede19a
equal deleted inserted replaced
6580:082d58e2415e 6581:8eb6220f2bb7
115 @signal searchStringFound(bool) emitted to indicate the search 115 @signal searchStringFound(bool) emitted to indicate the search
116 result 116 result
117 @signal historyStyleChanged(ShellHistoryStyle) emitted to indicate a 117 @signal historyStyleChanged(ShellHistoryStyle) emitted to indicate a
118 change of the history style 118 change of the history style
119 @signal queueText(str) emitted to queue some text for processing 119 @signal queueText(str) emitted to queue some text for processing
120 @signal virtualEnvironmentChanged(str) emitted to signal the new virtual
121 environment of the shell
120 """ 122 """
121 searchStringFound = pyqtSignal(bool) 123 searchStringFound = pyqtSignal(bool)
122 historyStyleChanged = pyqtSignal(ShellHistoryStyle) 124 historyStyleChanged = pyqtSignal(ShellHistoryStyle)
123 queueText = pyqtSignal(str) 125 queueText = pyqtSignal(str)
126 virtualEnvironmentChanged = pyqtSignal(str)
124 127
125 def __init__(self, dbs, vm, project, windowedVariant, parent=None): 128 def __init__(self, dbs, vm, project, windowedVariant, parent=None):
126 """ 129 """
127 Constructor 130 Constructor
128 131
163 """ using the up and down cursor keys while holding down the""" 166 """ using the up and down cursor keys while holding down the"""
164 """ Ctrl-key. This can be switched to just the up and down""" 167 """ Ctrl-key. This can be switched to just the up and down"""
165 """ cursor keys on the Shell page of the configuration""" 168 """ cursor keys on the Shell page of the configuration"""
166 """ dialog. Pressing these keys after some text has been""" 169 """ dialog. Pressing these keys after some text has been"""
167 """ entered will start an incremental search.</p>""" 170 """ entered will start an incremental search.</p>"""
168 """<p>The shell has some special commands. 'reset' kills the""" 171 """<p>The shell has some special commands. 'restart' kills"""
169 """ shell and starts a new one. 'clear' clears the display""" 172 """ the shell and starts a new one. 'clear' clears the"""
170 """ of the shell window. 'start' is used to switch the shell""" 173 """ display of the shell window. 'start' is used to start a"""
171 """ language and must be followed by a supported language.""" 174 """ shell for a virtual environment and should be followed"""
172 """ Supported languages are listed by the 'languages'""" 175 """ by a virtual environment name. start' without a virtual"""
173 """ command. 'quit' is used to exit the application.These""" 176 """ environment name starts the default shell. Available"""
174 """ commands (except 'languages') are available through the""" 177 """ virtual environments may be listed with the 'envs' or"""
175 """ window menus as well.</p>""" 178 """ 'environments' commands. The active virtual environment"""
179 """ can be questioned by the 'which' command. 'quit' or"""
180 """ 'exit' is used to exit the application. These commands"""
181 """ (except environments', 'envs' and 'which') are available"""
182 """ through the window menus as well.</p>"""
176 """<p>Pressing the Tab key after some text has been entered""" 183 """<p>Pressing the Tab key after some text has been entered"""
177 """ will show a list of possible completions. The relevant""" 184 """ will show a list of possible completions. The relevant"""
178 """ entry may be selected from this list. If only one entry""" 185 """ entry may be selected from this list. If only one entry"""
179 """ is available, this will be inserted automatically.</p>""" 186 """ is available, this will be inserted automatically.</p>"""
180 )) 187 ))
190 """ using the up and down cursor keys while holding down the""" 197 """ using the up and down cursor keys while holding down the"""
191 """ Ctrl-key. This can be switched to just the up and down""" 198 """ Ctrl-key. This can be switched to just the up and down"""
192 """ cursor keys on the Shell page of the configuration""" 199 """ cursor keys on the Shell page of the configuration"""
193 """ dialog. Pressing these keys after some text has been""" 200 """ dialog. Pressing these keys after some text has been"""
194 """ entered will start an incremental search.</p>""" 201 """ entered will start an incremental search.</p>"""
195 """<p>The shell has some special commands. 'reset' kills the""" 202 """<p>The shell has some special commands. 'restart' kills"""
196 """ shell and starts a new one. 'clear' clears the display""" 203 """ the shell and starts a new one. 'clear' clears the"""
197 """ of the shell window. 'start' is used to switch the shell""" 204 """ display of the shell window. 'start' is used to start a"""
198 """ language and must be followed by a supported language.""" 205 """ shell for a virtual environment and should be followed"""
199 """ Supported languages are listed by the 'languages'""" 206 """ by a virtual environment name. start' without a virtual"""
200 """ command. These commands (except 'languages') are""" 207 """ environment name starts the default shell. Available"""
201 """ available through the context menu as well.</p>""" 208 """ virtual environments may be listed with the 'envs' or"""
209 """ 'environments' commands. The active virtual environment"""
210 """ can be questioned by the 'which' command. These commands"""
211 """ (except environments' and 'envs') are available through"""
212 """ the context menu as well.</p>"""
202 """<p>Pressing the Tab key after some text has been entered""" 213 """<p>Pressing the Tab key after some text has been entered"""
203 """ will show a list of possible completions. The relevant""" 214 """ will show a list of possible completions. The relevant"""
204 """ entry may be selected from this list. If only one entry""" 215 """ entry may be selected from this list. If only one entry"""
205 """ is available, this will be inserted automatically.</p>""" 216 """ is available, this will be inserted automatically.</p>"""
206 """<p>In passive debugging mode the shell is only available""" 217 """<p>In passive debugging mode the shell is only available"""
296 307
297 self.menu.addSeparator() 308 self.menu.addSeparator()
298 self.menu.addAction(self.tr('Find'), self.__find) 309 self.menu.addAction(self.tr('Find'), self.__find)
299 self.menu.addSeparator() 310 self.menu.addSeparator()
300 self.menu.addAction(self.tr('Clear'), self.clear) 311 self.menu.addAction(self.tr('Clear'), self.clear)
301 self.menu.addAction(self.tr('Reset'), self.__reset) 312 self.menu.addAction(self.tr('Restart'), self.doRestart)
302 self.menu.addAction( 313 self.menu.addAction(
303 self.tr('Reset and Clear'), self.__resetAndClear) 314 self.tr('Restart and Clear'), self.doClearRestart)
304 self.menu.addSeparator() 315 self.menu.addSeparator()
305 self.menu.addMenu(self.lmenu) 316 self.menu.addMenu(self.lmenu)
317 self.menu.addAction(self.tr('Active Name'), self.__showVenvName)
306 self.menu.addSeparator() 318 self.menu.addSeparator()
307 self.menu.addAction(self.tr("Configure..."), self.__configure) 319 self.menu.addAction(self.tr("Configure..."), self.__configure)
308 320
309 self.__bindLexer() 321 self.__bindLexer()
310 self.__setTextDisplay() 322 self.__setTextDisplay()
625 if self.clientType not in self.__historyLists: 637 if self.clientType not in self.__historyLists:
626 # load history list 638 # load history list
627 self.loadHistory(self.clientType) 639 self.loadHistory(self.clientType)
628 self.__history = self.__historyLists[self.clientType] 640 self.__history = self.__historyLists[self.clientType]
629 self.__setHistoryIndex() 641 self.__setHistoryIndex()
642
643 self.virtualEnvironmentChanged.emit(venvName)
644 Preferences.setShell("LastVirtualEnvironment", venvName)
630 645
631 def __setHistoryIndex(self, index=None): 646 def __setHistoryIndex(self, index=None):
632 """ 647 """
633 Private method to set the initial history index. 648 Private method to set the initial history index.
634 649
817 .format(version, platform, dbgclient)) 832 .format(version, platform, dbgclient))
818 else: 833 else:
819 self.__write(version) 834 self.__write(version)
820 if venvName: 835 if venvName:
821 self.__write("\n[{0}]".format(venvName)) 836 self.__write("\n[{0}]".format(venvName))
837
838 self.virtualEnvironmentChanged.emit(venvName)
839 Preferences.setShell("LastVirtualEnvironment", venvName)
822 self.__write('\n') 840 self.__write('\n')
823 841
824 self.__write(sys.ps1) 842 self.__write(sys.ps1)
825 843
826 def __writePrompt(self): 844 def __writePrompt(self):
1766 self.__getBanner() 1784 self.__getBanner()
1767 if not self.passive: 1785 if not self.passive:
1768 return 1786 return
1769 else: 1787 else:
1770 cmd = '' 1788 cmd = ''
1771 elif cmd == 'reset': 1789 elif cmd in ['reset', 'restart']:
1772 self.dbs.startClient(False, venvName=self.__currentVenv) 1790 self.dbs.startClient(False, venvName=self.__currentVenv)
1773 if self.passive: 1791 if self.passive:
1774 return 1792 return
1775 else: 1793 else:
1776 cmd = '' 1794 cmd = ''
1777 elif cmd in ["quit", "quit()"] and self.__windowed: 1795 elif cmd in ['envs', 'environments']:
1796 venvs = e5App().getObject("VirtualEnvManager")\
1797 .getVirtualenvNames()
1798 s = self.tr('Available Virtual Environments:\n{0}\n').format(
1799 '\n'.join("- {0}".format(venv) for venv in sorted(venvs))
1800 )
1801 self.__write(s)
1802 self.__clientStatement(False)
1803 return
1804 elif cmd == 'which':
1805 s = self.tr("Current Virtual Environment: '{0}'\n").format(
1806 self.__currentVenv)
1807 self.__write(s)
1808 self.__clientStatement(False)
1809 return
1810 elif cmd in ["quit", "quit()", "exit", "exit()"] and \
1811 self.__windowed:
1778 # call main window quit() 1812 # call main window quit()
1779 self.vm.quit() 1813 self.vm.quit()
1780 return 1814 return
1781 1815
1782 self.dbs.remoteStatement(cmd) 1816 self.dbs.remoteStatement(cmd)
1794 self.inRawMode = False 1828 self.inRawMode = False
1795 self.echoInput = True 1829 self.echoInput = True
1796 1830
1797 self.dbs.remoteRawInput(cmd) 1831 self.dbs.remoteRawInput(cmd)
1798 1832
1833 def __showVenvName(self):
1834 """
1835 Private method to show the name of the active virtual environment.
1836 """
1837 s = "\n" + self.tr("Current Virtual Environment: '{0}'\n").format(
1838 self.__currentVenv)
1839 self.__write(s)
1840 self.__clientStatement(False)
1841
1799 def __useHistory(self): 1842 def __useHistory(self):
1800 """ 1843 """
1801 Private method to display a command from the history. 1844 Private method to display a command from the history.
1802 """ 1845 """
1803 if self.__isHistoryIndexValid(): 1846 if self.__isHistoryIndexValid():
1902 Public slot to clear the display. 1945 Public slot to clear the display.
1903 """ 1946 """
1904 # Display the banner. 1947 # Display the banner.
1905 self.__getBanner() 1948 self.__getBanner()
1906 1949
1907 def __resetAndClear(self): 1950 def doClearRestart(self):
1908 """ 1951 """
1909 Private slot to handle the 'reset and clear' context menu entry. 1952 Public slot to handle the 'restart and clear' context menu entry.
1910 """ 1953 """
1911 self.__reset() 1954 self.doRestart()
1912 self.clear() 1955 self.clear()
1913 1956
1914 def __reset(self): 1957 def doRestart(self):
1915 """ 1958 """
1916 Private slot to handle the 'reset' context menu entry. 1959 Public slot to handle the 'restart' context menu entry.
1917 """ 1960 """
1918 self.dbs.startClient(False) 1961 self.dbs.startClient(False, venvName=self.__currentVenv)
1919 1962
1920 def __startDebugClient(self, action): 1963 def __startDebugClient(self, action):
1921 """ 1964 """
1922 Private slot to start a debug client according to the action 1965 Private slot to start a debug client according to the action
1923 triggered. 1966 triggered.

eric ide

mercurial