10 import contextlib |
10 import contextlib |
11 import enum |
11 import enum |
12 import pathlib |
12 import pathlib |
13 import re |
13 import re |
14 import sys |
14 import sys |
|
15 import time |
15 |
16 |
16 from PyQt6.Qsci import QsciScintilla |
17 from PyQt6.Qsci import QsciScintilla |
17 from PyQt6.QtCore import QEvent, QPoint, Qt, pyqtSignal, pyqtSlot |
18 from PyQt6.QtCore import QEvent, QPoint, Qt, pyqtSignal, pyqtSlot |
18 from PyQt6.QtGui import QClipboard, QFont, QPalette, QShortcut |
19 from PyQt6.QtGui import QClipboard, QFont, QPalette, QShortcut |
19 from PyQt6.QtWidgets import ( |
20 from PyQt6.QtWidgets import ( |
386 Private slot to prepare the start submenu. |
387 Private slot to prepare the start submenu. |
387 """ |
388 """ |
388 self.lmenu.clear() |
389 self.lmenu.clear() |
389 venvManager = ericApp().getObject("VirtualEnvManager") |
390 venvManager = ericApp().getObject("VirtualEnvManager") |
390 for venvName in sorted(venvManager.getVirtualenvNames()): |
391 for venvName in sorted(venvManager.getVirtualenvNames()): |
391 self.lmenu.addAction(venvName) |
392 act = self.lmenu.addAction(venvName) |
|
393 act.setData(venvName) |
392 if self.__project.isOpen(): |
394 if self.__project.isOpen(): |
393 self.lmenu.addSeparator() |
395 self.lmenu.addSeparator() |
394 self.lmenu.addAction(self.tr("Project")) |
396 act = self.lmenu.addAction(self.tr("Project")) |
|
397 act.setData("<<project>>") |
|
398 if ericApp().getObject("EricServer").isServerConnected(): |
|
399 self.lmenu.addSeparator() |
|
400 act = self.lmenu.addAction(self.tr("eric-ide Server")) |
|
401 act.setData("<<eric-server>>") |
395 |
402 |
396 def __resizeLinenoMargin(self): |
403 def __resizeLinenoMargin(self): |
397 """ |
404 """ |
398 Private slot to resize the line numbers margin. |
405 Private slot to resize the line numbers margin. |
399 """ |
406 """ |
1923 self.__getBanner() |
1930 self.__getBanner() |
1924 elif cmd == "%clear": |
1931 elif cmd == "%clear": |
1925 # Display the banner. |
1932 # Display the banner. |
1926 self.__getBanner() |
1933 self.__getBanner() |
1927 elif cmd in ["%reset", "%restart"]: |
1934 elif cmd in ["%reset", "%restart"]: |
1928 self.dbs.startClient( |
1935 self.doRestart() |
1929 False, |
|
1930 venvName=self.__currentVenv, |
|
1931 workingDir=self.__currentWorkingDirectory, |
|
1932 ) |
|
1933 elif cmd in ["%envs", "%environments"]: |
1936 elif cmd in ["%envs", "%environments"]: |
1934 venvs = ( |
1937 venvs = ( |
1935 ericApp().getObject("VirtualEnvManager").getVirtualenvNames() |
1938 ericApp().getObject("VirtualEnvManager").getVirtualenvNames() |
1936 ) |
1939 ) |
1937 s = self.tr("Available Virtual Environments:\n{0}\n").format( |
1940 s = self.tr("Available Virtual Environments:\n{0}\n").format( |
1979 self.__write(s) |
1982 self.__write(s) |
1980 self.__clientStatement(False) |
1983 self.__clientStatement(False) |
1981 self.setFocus(Qt.FocusReason.OtherFocusReason) |
1984 self.setFocus(Qt.FocusReason.OtherFocusReason) |
1982 else: |
1985 else: |
1983 self.dbs.remoteStatement(self.__getSelectedDebuggerId(), cmd) |
1986 self.dbs.remoteStatement(self.__getSelectedDebuggerId(), cmd) |
1984 while self.inCommandExecution: |
1987 now = time.monotonic() |
|
1988 while self.inCommandExecution and time.monotonic() - now < 10: |
|
1989 # 10 seconds timeout |
1985 with contextlib.suppress(KeyboardInterrupt): |
1990 with contextlib.suppress(KeyboardInterrupt): |
1986 QApplication.processEvents() |
1991 QApplication.processEvents() |
|
1992 self.inCommandExecution = False |
1987 else: |
1993 else: |
1988 if not self.__echoInput: |
1994 if not self.__echoInput: |
1989 cmd = self.buff |
1995 cmd = self.buff |
1990 self.buff = "" |
1996 self.buff = "" |
1991 elif cmd: |
1997 elif cmd: |
2136 triggered. |
2142 triggered. |
2137 |
2143 |
2138 @param action context menu action that was triggered |
2144 @param action context menu action that was triggered |
2139 @type QAction |
2145 @type QAction |
2140 """ |
2146 """ |
2141 venvName = action.text() |
2147 venvName = action.data() |
2142 if venvName == self.tr("Project"): |
2148 if venvName == "<<project>>": |
2143 if self.__project.isOpen(): |
2149 if self.__project.isOpen(): |
2144 self.__currentWorkingDirectory = self.__project.getProjectPath() |
2150 self.__currentWorkingDirectory = self.__project.getProjectPath() |
2145 self.dbs.startClient( |
2151 self.dbs.startClient( |
2146 False, forProject=True, workingDir=self.__currentWorkingDirectory |
2152 False, forProject=True, workingDir=self.__currentWorkingDirectory |
2147 ) |
2153 ) |
|
2154 elif venvName == "<<eric-server>>": |
|
2155 self.dbs.startClient(False, startRemote=True) |
2148 else: |
2156 else: |
2149 self.dbs.startClient(False, venvName=venvName) |
2157 self.dbs.startClient(False, venvName=venvName) |
2150 self.__getBanner() |
2158 self.__getBanner() |
2151 |
2159 |
2152 def handlePreferencesChanged(self): |
2160 def handlePreferencesChanged(self): |
2614 """ |
2622 """ |
2615 if not self.__shuttingDown and Preferences.getProject("RestartShellForProject"): |
2623 if not self.__shuttingDown and Preferences.getProject("RestartShellForProject"): |
2616 self.dbs.startClient(False) |
2624 self.dbs.startClient(False) |
2617 self.__getBanner() |
2625 self.__getBanner() |
2618 |
2626 |
|
2627 ################################################################# |
|
2628 ## eric-ide Server Support |
|
2629 ################################################################# |
|
2630 |
|
2631 @pyqtSlot(bool) |
|
2632 def remoteConnectionChanged(self, connected): |
|
2633 """ |
|
2634 Public slot handling a change of the connection state to an eric-ide server. |
|
2635 |
|
2636 @param connected flag indicating the connection state |
|
2637 @type bool |
|
2638 """ |
|
2639 if connected: |
|
2640 if Preferences.getEricServer("AutostartShell"): |
|
2641 self.dbs.startClient(False, startRemote=True) |
|
2642 else: |
|
2643 if self.__currentVenv == self.dbs.getEricServerEnvironmentString(): |
|
2644 # start default backend |
|
2645 self.dbs.startClient(False) |
|
2646 self.__getBanner() |
2619 |
2647 |
2620 # |
2648 # |
2621 # eflag: noqa = M601 |
2649 # eflag: noqa = M601 |