eric6/QScintilla/Shell.py

changeset 8265
0090cfa83159
parent 8243
cc717c2ae956
child 8273
698ae46f40a4
child 8485
bb395ec2a6af
equal deleted inserted replaced
8264:f95dde35d0ab 8265:0090cfa83159
8 """ 8 """
9 9
10 import sys 10 import sys
11 import re 11 import re
12 import contextlib 12 import contextlib
13 13 import enum
14 from enum import Enum
15 14
16 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QFileInfo, Qt, QEvent 15 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QFileInfo, Qt, QEvent
17 from PyQt5.QtGui import QClipboard, QPalette, QFont 16 from PyQt5.QtGui import QClipboard, QPalette, QFont
18 from PyQt5.QtWidgets import ( 17 from PyQt5.QtWidgets import (
19 QDialog, QInputDialog, QApplication, QMenu, QWidget, QHBoxLayout, 18 QDialog, QInputDialog, QApplication, QMenu, QWidget, QHBoxLayout,
91 @return reference to the shell widget (Shell) 90 @return reference to the shell widget (Shell)
92 """ 91 """
93 return self.__shell 92 return self.__shell
94 93
95 94
96 class ShellHistoryStyle(Enum): 95 class ShellHistoryStyle(enum.Enum):
97 """ 96 """
98 Class defining the shell history styles. 97 Class defining the shell history styles.
99 """ 98 """
100 Disabled = 0 99 DISABLED = 0
101 LinuxStyle = 1 100 LINUXSTYLE = 1
102 WindowsStyle = 2 101 WINDOWSSTYLE = 2
103 102
104 103
105 class Shell(QsciScintillaCompat): 104 class Shell(QsciScintillaCompat):
106 """ 105 """
107 Class implementing a graphical Python shell. 106 Class implementing a graphical Python shell.
241 dbs.clientSyntaxError.connect(self.__clientSyntaxError) 240 dbs.clientSyntaxError.connect(self.__clientSyntaxError)
242 dbs.clientSignal.connect(self.__clientSignal) 241 dbs.clientSignal.connect(self.__clientSignal)
243 dbs.mainClientExit.connect(self.__writePrompt) 242 dbs.mainClientExit.connect(self.__writePrompt)
244 self.dbs = dbs 243 self.dbs = dbs
245 244
246 self.__debugUI = None 245 # will register a method to get the debugger ID to work with
246 self.__getSelectedDebuggerId = None
247 247
248 # Make sure we have prompts. 248 # Make sure we have prompts.
249 if self.passive: 249 if self.passive:
250 sys.ps1 = self.tr("Passive >>> ") 250 sys.ps1 = self.tr("Passive >>> ")
251 else: 251 else:
610 Public method to set the debugger UI. 610 Public method to set the debugger UI.
611 611
612 @param ui reference to the debugger UI object (DebugUI) 612 @param ui reference to the debugger UI object (DebugUI)
613 """ 613 """
614 ui.exceptionInterrupt.connect(self.__writePrompt) 614 ui.exceptionInterrupt.connect(self.__writePrompt)
615 self.__debugUI = ui 615 self.registerDebuggerIdMethod(ui.getSelectedDebuggerId)
616
617 def registerDebuggerIdMethod(self, method):
618 """
619 Public method to register a method to get the debugger ID to send data
620 to.
621
622 @param method reference to the method
623 @type function
624 """
625 self.__getSelectedDebuggerId = method
616 626
617 def __initialise(self): 627 def __initialise(self):
618 """ 628 """
619 Private method to get ready for a new remote interpreter. 629 Private method to get ready for a new remote interpreter.
620 """ 630 """
671 """ 681 """
672 if index is None: 682 if index is None:
673 # determine based on history style 683 # determine based on history style
674 if ( 684 if (
675 self.clientType and 685 self.clientType and
676 self.__historyStyle == ShellHistoryStyle.WindowsStyle 686 self.__historyStyle == ShellHistoryStyle.WINDOWSSTYLE
677 ): 687 ):
678 idx = int(Preferences.Prefs.settings.value( 688 idx = int(Preferences.Prefs.settings.value(
679 "Shell/HistoryIndexes/" + self.clientType, -1)) 689 "Shell/HistoryIndexes/" + self.clientType, -1))
680 if idx >= len(self.__history): 690 if idx >= len(self.__history):
681 idx = -1 691 idx = -1
686 self.__histidx = index 696 self.__histidx = index
687 if self.__histidx >= len(self.__history): 697 if self.__histidx >= len(self.__history):
688 self.__histidx = -1 698 self.__histidx = -1
689 if ( 699 if (
690 self.clientType and 700 self.clientType and
691 self.__historyStyle == ShellHistoryStyle.WindowsStyle 701 self.__historyStyle == ShellHistoryStyle.WINDOWSSTYLE
692 ): 702 ):
693 Preferences.Prefs.settings.setValue( 703 Preferences.Prefs.settings.setValue(
694 "Shell/HistoryIndexes/" + self.clientType, self.__histidx) 704 "Shell/HistoryIndexes/" + self.clientType, self.__histidx)
695 705
696 def __isHistoryIndexValid(self): 706 def __isHistoryIndexValid(self):
1336 ac = self.isListActive() 1346 ac = self.isListActive()
1337 super().keyPressEvent(ev) 1347 super().keyPressEvent(ev)
1338 self.incrementalSearchActive = True 1348 self.incrementalSearchActive = True
1339 if ac and self.racEnabled: 1349 if ac and self.racEnabled:
1340 self.dbs.remoteCompletion( 1350 self.dbs.remoteCompletion(
1341 self.__debugUI.getSelectedDebuggerId(), 1351 self.__getSelectedDebuggerId(),
1342 self.completionText + txt 1352 self.completionText + txt
1343 ) 1353 )
1344 else: 1354 else:
1345 self.__insertTextNoEcho(txt) 1355 self.__insertTextNoEcho(txt)
1346 else: 1356 else:
1371 buf = buf.replace(sys.ps2, "") 1381 buf = buf.replace(sys.ps2, "")
1372 if self.inContinue and not buf[:index - len(sys.ps2)].strip(): 1382 if self.inContinue and not buf[:index - len(sys.ps2)].strip():
1373 self.SendScintilla(cmd) 1383 self.SendScintilla(cmd)
1374 elif self.racEnabled: 1384 elif self.racEnabled:
1375 self.dbs.remoteCompletion( 1385 self.dbs.remoteCompletion(
1376 self.__debugUI.getSelectedDebuggerId(), 1386 self.__getSelectedDebuggerId(),
1377 buf 1387 buf
1378 ) 1388 )
1379 1389
1380 def __QScintillaLeftDeleteCommand(self, method): 1390 def __QScintillaLeftDeleteCommand(self, method):
1381 """ 1391 """
1402 method() 1412 method()
1403 db = 1 1413 db = 1
1404 if db and ac and self.racEnabled and self.completionText: 1414 if db and ac and self.racEnabled and self.completionText:
1405 delta = len(self.text(line)) - oldLength 1415 delta = len(self.text(line)) - oldLength
1406 self.dbs.remoteCompletion( 1416 self.dbs.remoteCompletion(
1407 self.__debugUI.getSelectedDebuggerId(), 1417 self.__getSelectedDebuggerId(),
1408 self.completionText[:delta] 1418 self.completionText[:delta]
1409 ) 1419 )
1410 1420
1411 def __QScintillaDeleteBack(self): 1421 def __QScintillaDeleteBack(self):
1412 """ 1422 """
1795 if cmd != "" and ( 1805 if cmd != "" and (
1796 len(self.__history) == 0 or self.__history[-1] != cmd): 1806 len(self.__history) == 0 or self.__history[-1] != cmd):
1797 if len(self.__history) == self.__maxHistoryEntries: 1807 if len(self.__history) == self.__maxHistoryEntries:
1798 del self.__history[0] 1808 del self.__history[0]
1799 self.__history.append(cmd) 1809 self.__history.append(cmd)
1800 if self.__historyStyle == ShellHistoryStyle.LinuxStyle: 1810 if self.__historyStyle == ShellHistoryStyle.LINUXSTYLE:
1801 self.__setHistoryIndex(index=-1) 1811 self.__setHistoryIndex(index=-1)
1802 elif self.__historyStyle == ShellHistoryStyle.WindowsStyle: 1812 elif self.__historyStyle == ShellHistoryStyle.WINDOWSSTYLE:
1803 if historyIndex is None: 1813 if historyIndex is None:
1804 if ( 1814 if (
1805 self.__histidx - 1 > 0 and 1815 self.__histidx - 1 > 0 and
1806 cmd != self.__history[self.__histidx - 1] 1816 cmd != self.__history[self.__histidx - 1]
1807 ): 1817 ):
1885 # call main window quit() 1895 # call main window quit()
1886 self.vm.quit() 1896 self.vm.quit()
1887 return 1897 return
1888 else: 1898 else:
1889 self.dbs.remoteStatement( 1899 self.dbs.remoteStatement(
1890 self.__debugUI.getSelectedDebuggerId(), cmd) 1900 self.__getSelectedDebuggerId(), cmd)
1891 while self.inCommandExecution: 1901 while self.inCommandExecution:
1892 with contextlib.suppress(KeyboardInterrupt): 1902 with contextlib.suppress(KeyboardInterrupt):
1893 QApplication.processEvents() 1903 QApplication.processEvents()
1894 else: 1904 else:
1895 if not self.__echoInput: 1905 if not self.__echoInput:
2362 Public method to check, if the history is enabled. 2372 Public method to check, if the history is enabled.
2363 2373
2364 @return flag indicating if history is enabled 2374 @return flag indicating if history is enabled
2365 @rtype bool 2375 @rtype bool
2366 """ 2376 """
2367 return self.__historyStyle != ShellHistoryStyle.Disabled 2377 return self.__historyStyle != ShellHistoryStyle.DISABLED
2368 2378
2369 ################################################################# 2379 #################################################################
2370 ## Project Support 2380 ## Project Support
2371 ################################################################# 2381 #################################################################
2372 2382

eric ide

mercurial