QScintilla/Shell.py

changeset 6576
ea60ea85067a
parent 6573
ccac2d1f6858
child 6578
2fb729cca297
equal deleted inserted replaced
6575:40a11619ee77 6576:ea60ea85067a
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)
114 """ 120 """
115 searchStringFound = pyqtSignal(bool) 121 searchStringFound = pyqtSignal(bool)
116 historyStyleChanged = pyqtSignal(ShellHistoryStyle) 122 historyStyleChanged = pyqtSignal(ShellHistoryStyle)
117 queueText = pyqtSignal(str) 123 queueText = pyqtSignal(str)
118 124
119 def __init__(self, dbs, vm, windowedVariant, parent=None): 125 def __init__(self, dbs, vm, project, windowedVariant, parent=None):
120 """ 126 """
121 Constructor 127 Constructor
122 128
123 @param dbs reference to the debug server object 129 @param dbs reference to the debug server object
130 @type DebugServer
124 @param vm reference to the viewmanager object 131 @param vm reference to the viewmanager object
132 @type ViewManager
133 @param project reference to the project object
134 @type Project
125 @param windowedVariant flag indicating the shell window variant 135 @param windowedVariant flag indicating the shell window variant
126 (boolean) 136 @type bool
127 @param parent parent widget (QWidget) 137 @param parent parent widget
138 @type QWidget
128 """ 139 """
129 super(Shell, self).__init__(parent) 140 super(Shell, self).__init__(parent)
130 self.setUtf8(True) 141 self.setUtf8(True)
131 142
132 self.vm = vm 143 self.vm = vm
133 self.__mainWindow = parent 144 self.__mainWindow = parent
134 self.__lastSearch = () 145 self.__lastSearch = ()
135 self.__windowed = windowedVariant 146 self.__windowed = windowedVariant
147 self.__currentVenv = ""
136 148
137 self.linesepRegExp = r"\r\n|\n|\r" 149 self.linesepRegExp = r"\r\n|\n|\r"
138 150
139 self.passive = ((not self.__windowed) and 151 self.passive = ((not self.__windowed) and
140 Preferences.getDebugger("PassiveDbgEnabled")) 152 Preferences.getDebugger("PassiveDbgEnabled"))
264 self.__getBanner() 276 self.__getBanner()
265 277
266 if not self.__windowed: 278 if not self.__windowed:
267 # Create a little language context menu 279 # Create a little language context menu
268 self.lmenu = QMenu(self.tr('Start')) 280 self.lmenu = QMenu(self.tr('Start'))
269 self.lmenu.aboutToShow.connect(self.__showLanguageMenu) 281 self.lmenu.aboutToShow.connect(self.__showStartMenu)
270 self.lmenu.triggered.connect(self.__startDebugClient) 282 self.lmenu.triggered.connect(self.__startDebugClient)
271 283
272 # Create the history context menu 284 # Create the history context menu
273 self.hmenu = QMenu(self.tr('History')) 285 self.hmenu = QMenu(self.tr('History'))
274 self.hmenu.addAction(self.tr('Select entry'), self.selectHistory) 286 self.hmenu.addAction(self.tr('Select entry'), self.selectHistory)
349 361
350 self.__queuedText = '' 362 self.__queuedText = ''
351 self.__blockTextProcessing = False 363 self.__blockTextProcessing = False
352 self.queueText.connect(self.__concatenateText, Qt.QueuedConnection) 364 self.queueText.connect(self.__concatenateText, Qt.QueuedConnection)
353 365
366 self.__project = project
367 if self.__project:
368 self.__project.projectOpened.connect(self.__projectOpened)
369 self.__project.projectClosed.connect(self.__projectClosed)
370
354 self.grabGesture(Qt.PinchGesture) 371 self.grabGesture(Qt.PinchGesture)
355 372
356 def __showLanguageMenu(self): 373 def __showStartMenu(self):
357 """ 374 """
358 Private slot to prepare the language submenu. 375 Private slot to prepare the start submenu.
359 """ 376 """
360 self.lmenu.clear() 377 self.lmenu.clear()
361 clientLanguages = self.dbs.getSupportedLanguages(shellOnly=True) 378 venvManager = e5App().getObject("VirtualEnvManager")
362 for language in sorted(clientLanguages): 379 for venvName in sorted(venvManager.getVirtualenvNames()):
363 act = self.lmenu.addAction(language) 380 self.lmenu.addAction(venvName)
364 act.setData(language) 381 if self.__project.isOpen():
382 self.lmenu.addSeparator()
383 self.lmenu.addAction(self.tr("Project"))
365 384
366 def __resizeLinenoMargin(self): 385 def __resizeLinenoMargin(self):
367 """ 386 """
368 Private slot to resize the line numbers margin. 387 Private slot to resize the line numbers margin.
369 """ 388 """
577 self.echoInput = True 596 self.echoInput = True
578 self.clientCapabilities = 0 597 self.clientCapabilities = 0
579 self.inCommandExecution = False 598 self.inCommandExecution = False
580 self.interruptCommandExecution = False 599 self.interruptCommandExecution = False
581 600
582 def __clientCapabilities(self, cap, clType): 601 def __clientCapabilities(self, cap, clType, venvName):
583 """ 602 """
584 Private slot to handle the reporting of the clients capabilities. 603 Private slot to handle the reporting of the clients capabilities.
585 604
586 @param cap client capabilities (integer) 605 @param cap client capabilities
587 @param clType type of the debug client (string) 606 @type int
607 @param clType type of the debug client
608 @type str
609 @param venvName name of the virtual environment
610 @type str
588 """ 611 """
589 self.clientCapabilities = cap 612 self.clientCapabilities = cap
613 self.__currentVenv = venvName
590 if clType != self.clientType: 614 if clType != self.clientType:
591 self.clientType = clType 615 self.clientType = clType
592 self.__bindLexer(self.clientType) 616 self.__bindLexer(self.clientType)
593 self.__setTextDisplay() 617 self.__setTextDisplay()
594 self.__setMargin0() 618 self.__setMargin0()
765 if self.passive: 789 if self.passive:
766 self.__writeBanner('', '', '') 790 self.__writeBanner('', '', '')
767 else: 791 else:
768 self.dbs.remoteBanner() 792 self.dbs.remoteBanner()
769 793
770 def __writeBanner(self, version, platform, dbgclient): 794 def __writeBanner(self, version, platform, dbgclient, venvName):
771 """ 795 """
772 Private method to write a banner with info from the debug client. 796 Private method to write a banner with info from the debug client.
773 797
774 @param version interpreter version string (string) 798 @param version interpreter version string
775 @param platform platform of the remote interpreter (string) 799 @type str
776 @param dbgclient debug client variant used (string) 800 @param platform platform of the remote interpreter
801 @type str
802 @param dbgclient debug client variant used
803 @type str
804 @param venvName name of the virtual environment
805 @type str
777 """ 806 """
778 super(Shell, self).clear() 807 super(Shell, self).clear()
779 if self.passive and not self.dbs.isConnected(): 808 if self.passive and not self.dbs.isConnected():
780 self.__write(self.tr('Passive Debug Mode')) 809 self.__write(self.tr('Passive Debug Mode'))
781 self.__write(self.tr('\nNot connected')) 810 self.__write(self.tr('\nNot connected'))
782 else: 811 else:
812 self.__currentVenv = venvName
783 version = version.replace("#", self.tr("No.")) 813 version = version.replace("#", self.tr("No."))
784 if platform != "" and dbgclient != "": 814 if platform != "" and dbgclient != "":
785 self.__write( 815 self.__write(
786 self.tr('{0} on {1}, {2}') 816 self.tr('{0} on {1}, {2}')
787 .format(version, platform, dbgclient)) 817 .format(version, platform, dbgclient))
788 else: 818 else:
789 self.__write(version) 819 self.__write(version)
820 if venvName:
821 self.__write("\n[{0}]".format(venvName))
790 self.__write('\n') 822 self.__write('\n')
791 823
792 self.__write(sys.ps1) 824 self.__write(sys.ps1)
793 825
794 def __writePrompt(self): 826 def __writePrompt(self):
1708 cmd != self.__history[self.__histidx - 1]: 1740 cmd != self.__history[self.__histidx - 1]:
1709 self.__setHistoryIndex(index=-1) 1741 self.__setHistoryIndex(index=-1)
1710 else: 1742 else:
1711 self.__setHistoryIndex(historyIndex) 1743 self.__setHistoryIndex(historyIndex)
1712 1744
1713 if cmd.startswith('start '): 1745 if cmd == 'start' or cmd.startswith('start '):
1714 if not self.passive: 1746 if not self.passive:
1715 cmdList = cmd.split(None, 1) 1747 cmdList = cmd.split(None, 1)
1716 if len(cmdList) < 2: 1748 if len(cmdList) < 2:
1717 self.dbs.startClient(False) # same as reset 1749 self.dbs.startClient(False) # start default backend
1718 else: 1750 else:
1719 clientLanguages = self.dbs.getSupportedLanguages( 1751 venvName = cmdList[1]
1720 shellOnly=True) 1752 if venvName == self.tr("Project"):
1721 language = cmdList[1] 1753 if self.__project.isOpen():
1722 if language not in clientLanguages: 1754 self.dbs.startClient(False, forProject=True)
1723 language = cmdList[1].capitalize() 1755 else:
1724 if language not in clientLanguages: 1756 self.dbs.startClient(
1725 language = "" 1757 False, venvName=self.__currentVenv)
1726 if language: 1758 # same as reset
1727 self.dbs.startClient(False, language)
1728 else: 1759 else:
1729 # language not supported or typo 1760 self.dbs.startClient(False, venvName=venvName)
1730 self.__write( 1761 self.__getBanner()
1731 self.tr( 1762 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': 1763 elif cmd == 'clear':
1744 # Display the banner. 1764 # Display the banner.
1745 self.__getBanner() 1765 self.__getBanner()
1746 if not self.passive: 1766 if not self.passive:
1747 return 1767 return
1748 else: 1768 else:
1749 cmd = '' 1769 cmd = ''
1750 elif cmd == 'reset': 1770 elif cmd == 'reset':
1751 self.dbs.startClient(False) 1771 self.dbs.startClient(False, venvName=self.__currentVenv)
1752 if self.passive: 1772 if self.passive:
1753 return 1773 return
1754 else: 1774 else:
1755 cmd = '' 1775 cmd = ''
1756 elif cmd in ["quit", "quit()"] and self.__windowed: 1776 elif cmd in ["quit", "quit()"] and self.__windowed:
1901 Private slot to start a debug client according to the action 1921 Private slot to start a debug client according to the action
1902 triggered. 1922 triggered.
1903 1923
1904 @param action context menu action that was triggered (QAction) 1924 @param action context menu action that was triggered (QAction)
1905 """ 1925 """
1906 language = action.data() 1926 venvName = action.text()
1907 self.dbs.startClient(False, language) 1927 if venvName == self.tr("Project"):
1928 self.dbs.startClient(False, forProject=True)
1929 else:
1930 self.dbs.startClient(False, venvName=venvName)
1908 self.__getBanner() 1931 self.__getBanner()
1909 1932
1910 def handlePreferencesChanged(self): 1933 def handlePreferencesChanged(self):
1911 """ 1934 """
1912 Public slot to handle the preferencesChanged signal. 1935 Public slot to handle the preferencesChanged signal.
2211 2234
2212 @return flag indicating if history is enabled 2235 @return flag indicating if history is enabled
2213 @rtype bool 2236 @rtype bool
2214 """ 2237 """
2215 return self.__historyStyle != ShellHistoryStyle.Disabled 2238 return self.__historyStyle != ShellHistoryStyle.Disabled
2239
2240 #################################################################
2241 ## Project Support
2242 #################################################################
2243
2244 def __projectOpened(self):
2245 """
2246 Private slot to start the shell for the opened project.
2247 """
2248 if Preferences.getProject("RestartShellForProject"):
2249 self.dbs.startClient(False, forProject=True)
2250 self.__getBanner()
2251
2252 def __projectClosed(self):
2253 """
2254 Private slot to restart the default shell when the project is closed.
2255 """
2256 if Preferences.getProject("RestartShellForProject"):
2257 self.dbs.startClient(False)
2258 self.__getBanner()

eric ide

mercurial