QScintilla/Shell.py

branch
maintenance
changeset 6602
331ac8f99cf8
parent 6487
d3ca83d691e7
parent 6581
8eb6220f2bb7
child 6646
51eefa621de4
equal deleted inserted replaced
6570:06e7d2941ead 6602:331ac8f99cf8
39 39
40 class ShellAssembly(QWidget): 40 class ShellAssembly(QWidget):
41 """ 41 """
42 Class implementing the containing widget for the shell. 42 Class implementing the containing widget for the shell.
43 """ 43 """
44 def __init__(self, dbs, vm, horizontal=True, parent=None): 44 def __init__(self, dbs, vm, project, horizontal=True, parent=None):
45 """ 45 """
46 Constructor 46 Constructor
47 47
48 @param dbs reference to the debug server object 48 @param dbs reference to the debug server object
49 @type DebugServer
49 @param vm reference to the viewmanager object 50 @param vm reference to the viewmanager object
50 @param horizontal flag indicating a horizontal layout (boolean) 51 @type ViewManager
51 @param parent parent widget (QWidget) 52 @param project reference to the project object
53 @type Project
54 @param horizontal flag indicating a horizontal layout
55 @type bool
56 @param parent parent widget
57 @type QWidget
52 """ 58 """
53 super(ShellAssembly, self).__init__(parent) 59 super(ShellAssembly, self).__init__(parent)
54 60
55 self.__shell = Shell(dbs, vm, False, self) 61 self.__shell = Shell(dbs, vm, project, False, self)
56 62
57 from UI.SearchWidget import SearchWidget 63 from UI.SearchWidget import SearchWidget
58 self.__searchWidget = SearchWidget(self.__shell, self, horizontal) 64 self.__searchWidget = SearchWidget(self.__shell, self, horizontal)
59 self.__searchWidget.setSizePolicy(QSizePolicy.Fixed, 65 self.__searchWidget.setSizePolicy(QSizePolicy.Fixed,
60 QSizePolicy.Preferred) 66 QSizePolicy.Preferred)
109 @signal searchStringFound(bool) emitted to indicate the search 115 @signal searchStringFound(bool) emitted to indicate the search
110 result 116 result
111 @signal historyStyleChanged(ShellHistoryStyle) emitted to indicate a 117 @signal historyStyleChanged(ShellHistoryStyle) emitted to indicate a
112 change of the history style 118 change of the history style
113 @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
114 """ 122 """
115 searchStringFound = pyqtSignal(bool) 123 searchStringFound = pyqtSignal(bool)
116 historyStyleChanged = pyqtSignal(ShellHistoryStyle) 124 historyStyleChanged = pyqtSignal(ShellHistoryStyle)
117 queueText = pyqtSignal(str) 125 queueText = pyqtSignal(str)
118 126 virtualEnvironmentChanged = pyqtSignal(str)
119 def __init__(self, dbs, vm, windowedVariant, parent=None): 127
128 def __init__(self, dbs, vm, project, windowedVariant, parent=None):
120 """ 129 """
121 Constructor 130 Constructor
122 131
123 @param dbs reference to the debug server object 132 @param dbs reference to the debug server object
133 @type DebugServer
124 @param vm reference to the viewmanager object 134 @param vm reference to the viewmanager object
135 @type ViewManager
136 @param project reference to the project object
137 @type Project
125 @param windowedVariant flag indicating the shell window variant 138 @param windowedVariant flag indicating the shell window variant
126 (boolean) 139 @type bool
127 @param parent parent widget (QWidget) 140 @param parent parent widget
141 @type QWidget
128 """ 142 """
129 super(Shell, self).__init__(parent) 143 super(Shell, self).__init__(parent)
130 self.setUtf8(True) 144 self.setUtf8(True)
131 145
132 self.vm = vm 146 self.vm = vm
133 self.__mainWindow = parent 147 self.__mainWindow = parent
134 self.__lastSearch = () 148 self.__lastSearch = ()
135 self.__windowed = windowedVariant 149 self.__windowed = windowedVariant
150 self.__currentVenv = ""
136 151
137 self.linesepRegExp = r"\r\n|\n|\r" 152 self.linesepRegExp = r"\r\n|\n|\r"
138 153
139 self.passive = ((not self.__windowed) and 154 self.passive = ((not self.__windowed) and
140 Preferences.getDebugger("PassiveDbgEnabled")) 155 Preferences.getDebugger("PassiveDbgEnabled"))
151 """ using the up and down cursor keys while holding down the""" 166 """ using the up and down cursor keys while holding down the"""
152 """ 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"""
153 """ cursor keys on the Shell page of the configuration""" 168 """ cursor keys on the Shell page of the configuration"""
154 """ dialog. Pressing these keys after some text has been""" 169 """ dialog. Pressing these keys after some text has been"""
155 """ entered will start an incremental search.</p>""" 170 """ entered will start an incremental search.</p>"""
156 """<p>The shell has some special commands. 'reset' kills the""" 171 """<p>The shell has some special commands. 'restart' kills"""
157 """ shell and starts a new one. 'clear' clears the display""" 172 """ the shell and starts a new one. 'clear' clears the"""
158 """ of the shell window. 'start' is used to switch the shell""" 173 """ display of the shell window. 'start' is used to start a"""
159 """ language and must be followed by a supported language.""" 174 """ shell for a virtual environment and should be followed"""
160 """ Supported languages are listed by the 'languages'""" 175 """ by a virtual environment name. start' without a virtual"""
161 """ command. 'quit' is used to exit the application.These""" 176 """ environment name starts the default shell. Available"""
162 """ commands (except 'languages') are available through the""" 177 """ virtual environments may be listed with the 'envs' or"""
163 """ 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>"""
164 """<p>Pressing the Tab key after some text has been entered""" 183 """<p>Pressing the Tab key after some text has been entered"""
165 """ will show a list of possible completions. The relevant""" 184 """ will show a list of possible completions. The relevant"""
166 """ entry may be selected from this list. If only one entry""" 185 """ entry may be selected from this list. If only one entry"""
167 """ is available, this will be inserted automatically.</p>""" 186 """ is available, this will be inserted automatically.</p>"""
168 )) 187 ))
178 """ using the up and down cursor keys while holding down the""" 197 """ using the up and down cursor keys while holding down the"""
179 """ 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"""
180 """ cursor keys on the Shell page of the configuration""" 199 """ cursor keys on the Shell page of the configuration"""
181 """ dialog. Pressing these keys after some text has been""" 200 """ dialog. Pressing these keys after some text has been"""
182 """ entered will start an incremental search.</p>""" 201 """ entered will start an incremental search.</p>"""
183 """<p>The shell has some special commands. 'reset' kills the""" 202 """<p>The shell has some special commands. 'restart' kills"""
184 """ shell and starts a new one. 'clear' clears the display""" 203 """ the shell and starts a new one. 'clear' clears the"""
185 """ of the shell window. 'start' is used to switch the shell""" 204 """ display of the shell window. 'start' is used to start a"""
186 """ language and must be followed by a supported language.""" 205 """ shell for a virtual environment and should be followed"""
187 """ Supported languages are listed by the 'languages'""" 206 """ by a virtual environment name. start' without a virtual"""
188 """ command. These commands (except 'languages') are""" 207 """ environment name starts the default shell. Available"""
189 """ 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>"""
190 """<p>Pressing the Tab key after some text has been entered""" 213 """<p>Pressing the Tab key after some text has been entered"""
191 """ will show a list of possible completions. The relevant""" 214 """ will show a list of possible completions. The relevant"""
192 """ entry may be selected from this list. If only one entry""" 215 """ entry may be selected from this list. If only one entry"""
193 """ is available, this will be inserted automatically.</p>""" 216 """ is available, this will be inserted automatically.</p>"""
194 """<p>In passive debugging mode the shell is only available""" 217 """<p>In passive debugging mode the shell is only available"""
264 self.__getBanner() 287 self.__getBanner()
265 288
266 if not self.__windowed: 289 if not self.__windowed:
267 # Create a little language context menu 290 # Create a little language context menu
268 self.lmenu = QMenu(self.tr('Start')) 291 self.lmenu = QMenu(self.tr('Start'))
269 self.lmenu.aboutToShow.connect(self.__showLanguageMenu) 292 self.lmenu.aboutToShow.connect(self.__showStartMenu)
270 self.lmenu.triggered.connect(self.__startDebugClient) 293 self.lmenu.triggered.connect(self.__startDebugClient)
271 294
272 # Create the history context menu 295 # Create the history context menu
273 self.hmenu = QMenu(self.tr('History')) 296 self.hmenu = QMenu(self.tr('History'))
274 self.hmenu.addAction(self.tr('Select entry'), self.selectHistory) 297 self.hmenu.addAction(self.tr('Select entry'), self.selectHistory)
284 307
285 self.menu.addSeparator() 308 self.menu.addSeparator()
286 self.menu.addAction(self.tr('Find'), self.__find) 309 self.menu.addAction(self.tr('Find'), self.__find)
287 self.menu.addSeparator() 310 self.menu.addSeparator()
288 self.menu.addAction(self.tr('Clear'), self.clear) 311 self.menu.addAction(self.tr('Clear'), self.clear)
289 self.menu.addAction(self.tr('Reset'), self.__reset) 312 self.menu.addAction(self.tr('Restart'), self.doRestart)
290 self.menu.addAction( 313 self.menu.addAction(
291 self.tr('Reset and Clear'), self.__resetAndClear) 314 self.tr('Restart and Clear'), self.doClearRestart)
292 self.menu.addSeparator() 315 self.menu.addSeparator()
293 self.menu.addMenu(self.lmenu) 316 self.menu.addMenu(self.lmenu)
317 self.menu.addAction(self.tr('Active Name'), self.__showVenvName)
294 self.menu.addSeparator() 318 self.menu.addSeparator()
295 self.menu.addAction(self.tr("Configure..."), self.__configure) 319 self.menu.addAction(self.tr("Configure..."), self.__configure)
296 320
297 self.__bindLexer() 321 self.__bindLexer()
298 self.__setTextDisplay() 322 self.__setTextDisplay()
349 373
350 self.__queuedText = '' 374 self.__queuedText = ''
351 self.__blockTextProcessing = False 375 self.__blockTextProcessing = False
352 self.queueText.connect(self.__concatenateText, Qt.QueuedConnection) 376 self.queueText.connect(self.__concatenateText, Qt.QueuedConnection)
353 377
378 self.__project = project
379 if self.__project:
380 self.__project.projectOpened.connect(self.__projectOpened)
381 self.__project.projectClosed.connect(self.__projectClosed)
382
354 self.grabGesture(Qt.PinchGesture) 383 self.grabGesture(Qt.PinchGesture)
355 384
356 def __showLanguageMenu(self): 385 def __showStartMenu(self):
357 """ 386 """
358 Private slot to prepare the language submenu. 387 Private slot to prepare the start submenu.
359 """ 388 """
360 self.lmenu.clear() 389 self.lmenu.clear()
361 clientLanguages = self.dbs.getSupportedLanguages(shellOnly=True) 390 venvManager = e5App().getObject("VirtualEnvManager")
362 for language in sorted(clientLanguages): 391 for venvName in sorted(venvManager.getVirtualenvNames()):
363 act = self.lmenu.addAction(language) 392 self.lmenu.addAction(venvName)
364 act.setData(language) 393 if self.__project.isOpen():
394 self.lmenu.addSeparator()
395 self.lmenu.addAction(self.tr("Project"))
365 396
366 def __resizeLinenoMargin(self): 397 def __resizeLinenoMargin(self):
367 """ 398 """
368 Private slot to resize the line numbers margin. 399 Private slot to resize the line numbers margin.
369 """ 400 """
577 self.echoInput = True 608 self.echoInput = True
578 self.clientCapabilities = 0 609 self.clientCapabilities = 0
579 self.inCommandExecution = False 610 self.inCommandExecution = False
580 self.interruptCommandExecution = False 611 self.interruptCommandExecution = False
581 612
582 def __clientCapabilities(self, cap, clType): 613 def __clientCapabilities(self, cap, clType, venvName):
583 """ 614 """
584 Private slot to handle the reporting of the clients capabilities. 615 Private slot to handle the reporting of the clients capabilities.
585 616
586 @param cap client capabilities (integer) 617 @param cap client capabilities
587 @param clType type of the debug client (string) 618 @type int
619 @param clType type of the debug client
620 @type str
621 @param venvName name of the virtual environment
622 @type str
588 """ 623 """
589 self.clientCapabilities = cap 624 self.clientCapabilities = cap
625 self.__currentVenv = venvName
590 if clType != self.clientType: 626 if clType != self.clientType:
591 self.clientType = clType 627 self.clientType = clType
592 self.__bindLexer(self.clientType) 628 self.__bindLexer(self.clientType)
593 self.__setTextDisplay() 629 self.__setTextDisplay()
594 self.__setMargin0() 630 self.__setMargin0()
601 if self.clientType not in self.__historyLists: 637 if self.clientType not in self.__historyLists:
602 # load history list 638 # load history list
603 self.loadHistory(self.clientType) 639 self.loadHistory(self.clientType)
604 self.__history = self.__historyLists[self.clientType] 640 self.__history = self.__historyLists[self.clientType]
605 self.__setHistoryIndex() 641 self.__setHistoryIndex()
642
643 self.virtualEnvironmentChanged.emit(venvName)
644 Preferences.setShell("LastVirtualEnvironment", venvName)
606 645
607 def __setHistoryIndex(self, index=None): 646 def __setHistoryIndex(self, index=None):
608 """ 647 """
609 Private method to set the initial history index. 648 Private method to set the initial history index.
610 649
765 if self.passive: 804 if self.passive:
766 self.__writeBanner('', '', '') 805 self.__writeBanner('', '', '')
767 else: 806 else:
768 self.dbs.remoteBanner() 807 self.dbs.remoteBanner()
769 808
770 def __writeBanner(self, version, platform, dbgclient): 809 def __writeBanner(self, version, platform, dbgclient, venvName):
771 """ 810 """
772 Private method to write a banner with info from the debug client. 811 Private method to write a banner with info from the debug client.
773 812
774 @param version interpreter version string (string) 813 @param version interpreter version string
775 @param platform platform of the remote interpreter (string) 814 @type str
776 @param dbgclient debug client variant used (string) 815 @param platform platform of the remote interpreter
816 @type str
817 @param dbgclient debug client variant used
818 @type str
819 @param venvName name of the virtual environment
820 @type str
777 """ 821 """
778 super(Shell, self).clear() 822 super(Shell, self).clear()
779 if self.passive and not self.dbs.isConnected(): 823 if self.passive and not self.dbs.isConnected():
780 self.__write(self.tr('Passive Debug Mode')) 824 self.__write(self.tr('Passive Debug Mode'))
781 self.__write(self.tr('\nNot connected')) 825 self.__write(self.tr('\nNot connected'))
782 else: 826 else:
827 self.__currentVenv = venvName
783 version = version.replace("#", self.tr("No.")) 828 version = version.replace("#", self.tr("No."))
784 if platform != "" and dbgclient != "": 829 if platform != "" and dbgclient != "":
785 self.__write( 830 self.__write(
786 self.tr('{0} on {1}, {2}') 831 self.tr('{0} on {1}, {2}')
787 .format(version, platform, dbgclient)) 832 .format(version, platform, dbgclient))
788 else: 833 else:
789 self.__write(version) 834 self.__write(version)
835 if venvName:
836 self.__write("\n[{0}]".format(venvName))
837
838 self.virtualEnvironmentChanged.emit(venvName)
839 Preferences.setShell("LastVirtualEnvironment", venvName)
790 self.__write('\n') 840 self.__write('\n')
791 841
792 self.__write(sys.ps1) 842 self.__write(sys.ps1)
793 843
794 def __writePrompt(self): 844 def __writePrompt(self):
795 """ 845 """
796 Private method to write the prompt. 846 Private method to write the prompt using a write queue.
797 """ 847 """
798 self.__write(self.inContinue and sys.ps2 or sys.ps1) 848 self.queueText.emit(self.inContinue and sys.ps2 or sys.ps1)
799 # little trick to get the cursor position registered within QScintilla 849
800 self.SendScintilla(QsciScintilla.SCI_CHARLEFT)
801 self.SendScintilla(QsciScintilla.SCI_CHARRIGHT)
802
803 def __clientStatement(self, more): 850 def __clientStatement(self, more):
804 """ 851 """
805 Private method to handle the response from the debugger client. 852 Private method to handle the response from the debugger client.
806 853
807 @param more flag indicating that more user input is required (boolean) 854 @param more flag indicating that more user input is required (boolean)
808 """ 855 """
809 if not self.inRawMode: 856 if not self.inRawMode:
810 self.inContinue = more 857 self.inContinue = more
811 self.__writePrompt() 858 self.__writePrompt()
812 self.inCommandExecution = False 859 self.inCommandExecution = False
813 860
814 def __clientException(self, exceptionType, exceptionMessage, stackTrace): 861 def __clientException(self, exceptionType, exceptionMessage, stackTrace):
815 """ 862 """
816 Private method to handle an exception of the client. 863 Private method to handle an exception of the client.
817 864
818 @param exceptionType type of exception raised (string) 865 @param exceptionType type of exception raised (string)
932 # Finally process the accumulated text 979 # Finally process the accumulated text
933 self.__write(self.__queuedText) 980 self.__write(self.__queuedText)
934 981
935 self.__queuedText = '' 982 self.__queuedText = ''
936 self.__blockTextProcessing = False 983 self.__blockTextProcessing = False
984
985 # little trick to get the cursor position registered within QScintilla
986 self.SendScintilla(QsciScintilla.SCI_CHARLEFT)
987 self.SendScintilla(QsciScintilla.SCI_CHARRIGHT)
937 988
938 def __write(self, s): 989 def __write(self, s):
939 """ 990 """
940 Private method to display some text without queuing. 991 Private method to display some text without queuing.
941 992
1708 cmd != self.__history[self.__histidx - 1]: 1759 cmd != self.__history[self.__histidx - 1]:
1709 self.__setHistoryIndex(index=-1) 1760 self.__setHistoryIndex(index=-1)
1710 else: 1761 else:
1711 self.__setHistoryIndex(historyIndex) 1762 self.__setHistoryIndex(historyIndex)
1712 1763
1713 if cmd.startswith('start '): 1764 if cmd == 'start' or cmd.startswith('start '):
1714 if not self.passive: 1765 if not self.passive:
1715 cmdList = cmd.split(None, 1) 1766 cmdList = cmd.split(None, 1)
1716 if len(cmdList) < 2: 1767 if len(cmdList) < 2:
1717 self.dbs.startClient(False) # same as reset 1768 self.dbs.startClient(False) # start default backend
1718 else: 1769 else:
1719 clientLanguages = self.dbs.getSupportedLanguages( 1770 venvName = cmdList[1]
1720 shellOnly=True) 1771 if venvName == self.tr("Project"):
1721 language = cmdList[1] 1772 if self.__project.isOpen():
1722 if language not in clientLanguages: 1773 self.dbs.startClient(False, forProject=True)
1723 language = cmdList[1].capitalize() 1774 else:
1724 if language not in clientLanguages: 1775 self.dbs.startClient(
1725 language = "" 1776 False, venvName=self.__currentVenv)
1726 if language: 1777 # same as reset
1727 self.dbs.startClient(False, language)
1728 else: 1778 else:
1729 # language not supported or typo 1779 self.dbs.startClient(False, venvName=venvName)
1730 self.__write( 1780 self.__getBanner()
1731 self.tr( 1781 return
1732 'Shell language "{0}" not supported.\n')
1733 .format(cmdList[1]))
1734 self.__clientStatement(False)
1735 return
1736 cmd = ''
1737 elif cmd == 'languages':
1738 s = '{0}\n'.format(', '.join(sorted(
1739 self.dbs.getSupportedLanguages(shellOnly=True))))
1740 self.__write(s)
1741 self.__clientStatement(False)
1742 return
1743 elif cmd == 'clear': 1782 elif cmd == 'clear':
1744 # Display the banner. 1783 # Display the banner.
1745 self.__getBanner() 1784 self.__getBanner()
1746 if not self.passive: 1785 if not self.passive:
1747 return 1786 return
1748 else: 1787 else:
1749 cmd = '' 1788 cmd = ''
1750 elif cmd == 'reset': 1789 elif cmd in ['reset', 'restart']:
1751 self.dbs.startClient(False) 1790 self.dbs.startClient(False, venvName=self.__currentVenv)
1752 if self.passive: 1791 if self.passive:
1753 return 1792 return
1754 else: 1793 else:
1755 cmd = '' 1794 cmd = ''
1756 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:
1757 # call main window quit() 1812 # call main window quit()
1758 self.vm.quit() 1813 self.vm.quit()
1759 return 1814 return
1760 1815
1761 self.dbs.remoteStatement(cmd) 1816 self.dbs.remoteStatement(cmd)
1773 self.inRawMode = False 1828 self.inRawMode = False
1774 self.echoInput = True 1829 self.echoInput = True
1775 1830
1776 self.dbs.remoteRawInput(cmd) 1831 self.dbs.remoteRawInput(cmd)
1777 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
1778 def __useHistory(self): 1842 def __useHistory(self):
1779 """ 1843 """
1780 Private method to display a command from the history. 1844 Private method to display a command from the history.
1781 """ 1845 """
1782 if self.__isHistoryIndexValid(): 1846 if self.__isHistoryIndexValid():
1881 Public slot to clear the display. 1945 Public slot to clear the display.
1882 """ 1946 """
1883 # Display the banner. 1947 # Display the banner.
1884 self.__getBanner() 1948 self.__getBanner()
1885 1949
1886 def __resetAndClear(self): 1950 def doClearRestart(self):
1887 """ 1951 """
1888 Private slot to handle the 'reset and clear' context menu entry. 1952 Public slot to handle the 'restart and clear' context menu entry.
1889 """ 1953 """
1890 self.__reset() 1954 self.doRestart()
1891 self.clear() 1955 self.clear()
1892 1956
1893 def __reset(self): 1957 def doRestart(self):
1894 """ 1958 """
1895 Private slot to handle the 'reset' context menu entry. 1959 Public slot to handle the 'restart' context menu entry.
1896 """ 1960 """
1897 self.dbs.startClient(False) 1961 self.dbs.startClient(False, venvName=self.__currentVenv)
1898 1962
1899 def __startDebugClient(self, action): 1963 def __startDebugClient(self, action):
1900 """ 1964 """
1901 Private slot to start a debug client according to the action 1965 Private slot to start a debug client according to the action
1902 triggered. 1966 triggered.
1903 1967
1904 @param action context menu action that was triggered (QAction) 1968 @param action context menu action that was triggered (QAction)
1905 """ 1969 """
1906 language = action.data() 1970 venvName = action.text()
1907 self.dbs.startClient(False, language) 1971 if venvName == self.tr("Project"):
1972 self.dbs.startClient(False, forProject=True)
1973 else:
1974 self.dbs.startClient(False, venvName=venvName)
1908 self.__getBanner() 1975 self.__getBanner()
1909 1976
1910 def handlePreferencesChanged(self): 1977 def handlePreferencesChanged(self):
1911 """ 1978 """
1912 Public slot to handle the preferencesChanged signal. 1979 Public slot to handle the preferencesChanged signal.
2141 Private method to search for the next occurrence. 2208 Private method to search for the next occurrence.
2142 """ 2209 """
2143 if self.__lastSearch: 2210 if self.__lastSearch:
2144 self.searchNext(*self.__lastSearch) 2211 self.searchNext(*self.__lastSearch)
2145 2212
2146 def searchNext(self, txt, caseSensitive, wholeWord): 2213 def searchNext(self, txt, caseSensitive, wholeWord, regexp):
2147 """ 2214 """
2148 Public method to search the next occurrence of the given text. 2215 Public method to search the next occurrence of the given text.
2149 2216
2150 @param txt text to search for (string) 2217 @param txt text to search for
2218 @type str
2151 @param caseSensitive flag indicating to perform a case sensitive 2219 @param caseSensitive flag indicating to perform a case sensitive
2152 search (boolean) 2220 search
2221 @type bool
2153 @param wholeWord flag indicating to search for whole words 2222 @param wholeWord flag indicating to search for whole words
2154 only (boolean) 2223 only
2155 """ 2224 @type bool
2156 self.__lastSearch = (txt, caseSensitive, wholeWord) 2225 @param regexp flag indicating a regular expression search
2226 @type bool
2227 """
2228 self.__lastSearch = (txt, caseSensitive, wholeWord, regexp)
2157 ok = self.findFirst( 2229 ok = self.findFirst(
2158 txt, False, caseSensitive, wholeWord, True, forward=True) 2230 txt, regexp, caseSensitive, wholeWord, True, forward=True,
2231 posix=regexp)
2159 self.searchStringFound.emit(ok) 2232 self.searchStringFound.emit(ok)
2160 2233
2161 def __searchPrev(self): 2234 def __searchPrev(self):
2162 """ 2235 """
2163 Private method to search for the next occurrence. 2236 Private method to search for the next occurrence.
2164 """ 2237 """
2165 if self.__lastSearch: 2238 if self.__lastSearch:
2166 self.searchPrev(*self.__lastSearch) 2239 self.searchPrev(*self.__lastSearch)
2167 2240
2168 def searchPrev(self, txt, caseSensitive, wholeWord): 2241 def searchPrev(self, txt, caseSensitive, wholeWord, regexp):
2169 """ 2242 """
2170 Public method to search the previous occurrence of the given text. 2243 Public method to search the previous occurrence of the given text.
2171 2244
2172 @param txt text to search for (string) 2245 @param txt text to search for
2246 @type str
2173 @param caseSensitive flag indicating to perform a case sensitive 2247 @param caseSensitive flag indicating to perform a case sensitive
2174 search (boolean) 2248 search
2249 @type bool
2175 @param wholeWord flag indicating to search for whole words 2250 @param wholeWord flag indicating to search for whole words
2176 only (boolean) 2251 only
2177 """ 2252 @type bool
2178 self.__lastSearch = (txt, caseSensitive, wholeWord) 2253 @param regexp flag indicating a regular expression search
2254 @type bool
2255 """
2256 self.__lastSearch = (txt, caseSensitive, wholeWord, regexp)
2179 if self.hasSelectedText(): 2257 if self.hasSelectedText():
2180 line, index = self.getSelection()[:2] 2258 line, index = self.getSelection()[:2]
2181 else: 2259 else:
2182 line, index = -1, -1 2260 line, index = -1, -1
2183 ok = self.findFirst( 2261 ok = self.findFirst(
2184 txt, False, caseSensitive, wholeWord, True, 2262 txt, regexp, caseSensitive, wholeWord, True,
2185 forward=False, line=line, index=index) 2263 forward=False, line=line, index=index, posix=regexp)
2186 self.searchStringFound.emit(ok) 2264 self.searchStringFound.emit(ok)
2187 2265
2188 def historyStyle(self): 2266 def historyStyle(self):
2189 """ 2267 """
2190 Public method to get the shell history style. 2268 Public method to get the shell history style.
2200 2278
2201 @return flag indicating if history is enabled 2279 @return flag indicating if history is enabled
2202 @rtype bool 2280 @rtype bool
2203 """ 2281 """
2204 return self.__historyStyle != ShellHistoryStyle.Disabled 2282 return self.__historyStyle != ShellHistoryStyle.Disabled
2283
2284 #################################################################
2285 ## Project Support
2286 #################################################################
2287
2288 def __projectOpened(self):
2289 """
2290 Private slot to start the shell for the opened project.
2291 """
2292 if Preferences.getProject("RestartShellForProject"):
2293 self.dbs.startClient(False, forProject=True)
2294 self.__getBanner()
2295
2296 def __projectClosed(self):
2297 """
2298 Private slot to restart the default shell when the project is closed.
2299 """
2300 if Preferences.getProject("RestartShellForProject"):
2301 self.dbs.startClient(False)
2302 self.__getBanner()

eric ide

mercurial