16 except ImportError: |
16 except ImportError: |
17 from ThirdParty.enum import Enum |
17 from ThirdParty.enum import Enum |
18 |
18 |
19 from PyQt5.QtCore import pyqtSignal, QFileInfo, Qt, QEvent |
19 from PyQt5.QtCore import pyqtSignal, QFileInfo, Qt, QEvent |
20 from PyQt5.QtGui import QClipboard, QPalette, QFont |
20 from PyQt5.QtGui import QClipboard, QPalette, QFont |
21 from PyQt5.QtWidgets import QDialog, QInputDialog, QApplication, QMenu, \ |
21 from PyQt5.QtWidgets import ( |
22 QWidget, QHBoxLayout, QVBoxLayout, QShortcut, QSizePolicy |
22 QDialog, QInputDialog, QApplication, QMenu, QWidget, QHBoxLayout, |
|
23 QVBoxLayout, QShortcut, QSizePolicy |
|
24 ) |
23 from PyQt5.Qsci import QsciScintilla |
25 from PyQt5.Qsci import QsciScintilla |
24 |
26 |
25 from E5Gui.E5Application import e5App |
27 from E5Gui.E5Application import e5App |
26 from E5Gui import E5MessageBox |
28 from E5Gui import E5MessageBox |
27 |
29 |
365 QsciScintilla.SCI_LINEENDEXTEND: self.extendSelectionToEOL, |
367 QsciScintilla.SCI_LINEENDEXTEND: self.extendSelectionToEOL, |
366 |
368 |
367 QsciScintilla.SCI_CANCEL: self.__QScintillaCancel, |
369 QsciScintilla.SCI_CANCEL: self.__QScintillaCancel, |
368 } |
370 } |
369 |
371 |
370 self.__historyNavigateByCursor = \ |
372 self.__historyNavigateByCursor = ( |
371 Preferences.getShell("HistoryNavigateByCursor") |
373 Preferences.getShell("HistoryNavigateByCursor") |
|
374 ) |
372 |
375 |
373 self.__queuedText = '' |
376 self.__queuedText = '' |
374 self.__blockTextProcessing = False |
377 self.__blockTextProcessing = False |
375 self.queueText.connect(self.__concatenateText, Qt.QueuedConnection) |
378 self.queueText.connect(self.__concatenateText, Qt.QueuedConnection) |
376 |
379 |
580 Preferences.getEditorColour("CallTipsBackground")) |
583 Preferences.getEditorColour("CallTipsBackground")) |
581 self.setCallTipsVisible(Preferences.getEditor("CallTipsVisible")) |
584 self.setCallTipsVisible(Preferences.getEditor("CallTipsVisible")) |
582 calltipsStyle = Preferences.getEditor("CallTipsStyle") |
585 calltipsStyle = Preferences.getEditor("CallTipsStyle") |
583 if calltipsStyle == QsciScintilla.CallTipsNoContext: |
586 if calltipsStyle == QsciScintilla.CallTipsNoContext: |
584 self.setCallTipsStyle(QsciScintilla.CallTipsNoContext) |
587 self.setCallTipsStyle(QsciScintilla.CallTipsNoContext) |
585 elif calltipsStyle == \ |
588 elif ( |
586 QsciScintilla.CallTipsNoAutoCompletionContext: |
589 calltipsStyle == |
|
590 QsciScintilla.CallTipsNoAutoCompletionContext |
|
591 ): |
587 self.setCallTipsStyle( |
592 self.setCallTipsStyle( |
588 QsciScintilla.CallTipsNoAutoCompletionContext) |
593 QsciScintilla.CallTipsNoAutoCompletionContext) |
589 else: |
594 else: |
590 self.setCallTipsStyle(QsciScintilla.CallTipsContext) |
595 self.setCallTipsStyle(QsciScintilla.CallTipsContext) |
591 else: |
596 else: |
629 self.__bindLexer(self.clientType) |
634 self.__bindLexer(self.clientType) |
630 self.__setTextDisplay() |
635 self.__setTextDisplay() |
631 self.__setMargin0() |
636 self.__setMargin0() |
632 self.__setAutoCompletion(self.clientType) |
637 self.__setAutoCompletion(self.clientType) |
633 self.__setCallTips(self.clientType) |
638 self.__setCallTips(self.clientType) |
634 self.racEnabled = \ |
639 self.racEnabled = ( |
635 Preferences.getShell("AutoCompletionEnabled") and \ |
640 Preferences.getShell("AutoCompletionEnabled") and |
636 (cap & HasCompleter) > 0 |
641 (cap & HasCompleter) > 0 |
|
642 ) |
637 |
643 |
638 if self.clientType not in self.__historyLists: |
644 if self.clientType not in self.__historyLists: |
639 # load history list |
645 # load history list |
640 self.loadHistory(self.clientType) |
646 self.loadHistory(self.clientType) |
641 self.__history = self.__historyLists[self.clientType] |
647 self.__history = self.__historyLists[self.clientType] |
651 @param index index value to be set |
657 @param index index value to be set |
652 @type int or None |
658 @type int or None |
653 """ |
659 """ |
654 if index is None: |
660 if index is None: |
655 # determine based on history style |
661 # determine based on history style |
656 if self.clientType and \ |
662 if ( |
657 self.__historyStyle == ShellHistoryStyle.WindowsStyle: |
663 self.clientType and |
|
664 self.__historyStyle == ShellHistoryStyle.WindowsStyle |
|
665 ): |
658 idx = int(Preferences.Prefs.settings.value( |
666 idx = int(Preferences.Prefs.settings.value( |
659 "Shell/HistoryIndexes/" + self.clientType, -1)) |
667 "Shell/HistoryIndexes/" + self.clientType, -1)) |
660 if idx >= len(self.__history): |
668 if idx >= len(self.__history): |
661 idx = -1 |
669 idx = -1 |
662 self.__histidx = idx |
670 self.__histidx = idx |
664 self.__histidx = -1 |
672 self.__histidx = -1 |
665 else: |
673 else: |
666 self.__histidx = index |
674 self.__histidx = index |
667 if self.__histidx >= len(self.__history): |
675 if self.__histidx >= len(self.__history): |
668 self.__histidx = -1 |
676 self.__histidx = -1 |
669 if self.clientType and \ |
677 if ( |
670 self.__historyStyle == ShellHistoryStyle.WindowsStyle: |
678 self.clientType and |
|
679 self.__historyStyle == ShellHistoryStyle.WindowsStyle |
|
680 ): |
671 Preferences.Prefs.settings.setValue( |
681 Preferences.Prefs.settings.setValue( |
672 "Shell/HistoryIndexes/" + self.clientType, self.__histidx) |
682 "Shell/HistoryIndexes/" + self.clientType, self.__histidx) |
673 |
683 |
674 def __isHistoryIndexValid(self): |
684 def __isHistoryIndexValid(self): |
675 """ |
685 """ |
867 @param exceptionMessage message given by the exception (string) |
877 @param exceptionMessage message given by the exception (string) |
868 @param stackTrace list of stack entries (list of string) |
878 @param stackTrace list of stack entries (list of string) |
869 """ |
879 """ |
870 self .__clientError() |
880 self .__clientError() |
871 |
881 |
872 if not self.__windowed and \ |
882 if ( |
873 Preferences.getDebugger("ShowExceptionInShell"): |
883 not self.__windowed and |
|
884 Preferences.getDebugger("ShowExceptionInShell") |
|
885 ): |
874 if exceptionType: |
886 if exceptionType: |
875 if stackTrace: |
887 if stackTrace: |
876 self.__write( |
888 self.__write( |
877 self.tr('Exception "{0}"\n{1}\nFile: {2}, Line: {3}\n') |
889 self.tr('Exception "{0}"\n{1}\nFile: {2}, Line: {3}\n') |
878 .format( |
890 .format( |
901 @param characterNo character number of the syntax error position |
913 @param characterNo character number of the syntax error position |
902 (integer) |
914 (integer) |
903 """ |
915 """ |
904 self .__clientError() |
916 self .__clientError() |
905 |
917 |
906 if not self.__windowed and \ |
918 if ( |
907 Preferences.getDebugger("ShowExceptionInShell"): |
919 not self.__windowed and |
|
920 Preferences.getDebugger("ShowExceptionInShell") |
|
921 ): |
908 if message is None: |
922 if message is None: |
909 self.__write(self.tr("Unspecified syntax error.\n")) |
923 self.__write(self.tr("Unspecified syntax error.\n")) |
910 else: |
924 else: |
911 self.__write( |
925 self.__write( |
912 self.tr('Syntax error "{1}" in file {0} at line {2},' |
926 self.tr('Syntax error "{1}" in file {0} at line {2},' |
1298 self.prline, self.prcol = self.getCursorPosition() |
1312 self.prline, self.prcol = self.getCursorPosition() |
1299 if self.echoInput: |
1313 if self.echoInput: |
1300 ac = self.isListActive() |
1314 ac = self.isListActive() |
1301 super(Shell, self).keyPressEvent(ev) |
1315 super(Shell, self).keyPressEvent(ev) |
1302 self.incrementalSearchActive = True |
1316 self.incrementalSearchActive = True |
1303 if ac and \ |
1317 if ac and self.racEnabled: |
1304 self.racEnabled: |
|
1305 self.dbs.remoteCompletion(self.completionText + txt) |
1318 self.dbs.remoteCompletion(self.completionText + txt) |
1306 else: |
1319 else: |
1307 self.__insertTextNoEcho(txt) |
1320 self.__insertTextNoEcho(txt) |
1308 else: |
1321 else: |
1309 ev.ignore() |
1322 ev.ignore() |
1606 if buf.startswith(sys.ps1): |
1619 if buf.startswith(sys.ps1): |
1607 buf = buf.replace(sys.ps1, "") |
1620 buf = buf.replace(sys.ps1, "") |
1608 if buf.startswith(sys.ps2): |
1621 if buf.startswith(sys.ps2): |
1609 buf = buf.replace(sys.ps2, "") |
1622 buf = buf.replace(sys.ps2, "") |
1610 if buf and self.incrementalSearchActive: |
1623 if buf and self.incrementalSearchActive: |
1611 if self.incrementalSearchString and \ |
1624 if ( |
1612 buf.startswith(self.incrementalSearchString): |
1625 self.incrementalSearchString and |
|
1626 buf.startswith(self.incrementalSearchString) |
|
1627 ): |
1613 idx, found = self.__rsearchHistory( |
1628 idx, found = self.__rsearchHistory( |
1614 self.incrementalSearchString, self.__histidx) |
1629 self.incrementalSearchString, self.__histidx) |
1615 if found and idx >= 0: |
1630 if found and idx >= 0: |
1616 self.__setHistoryIndex(index=idx) |
1631 self.__setHistoryIndex(index=idx) |
1617 self.__useHistory() |
1632 self.__useHistory() |
1649 if buf.startswith(sys.ps1): |
1664 if buf.startswith(sys.ps1): |
1650 buf = buf.replace(sys.ps1, "") |
1665 buf = buf.replace(sys.ps1, "") |
1651 if buf.startswith(sys.ps2): |
1666 if buf.startswith(sys.ps2): |
1652 buf = buf.replace(sys.ps2, "") |
1667 buf = buf.replace(sys.ps2, "") |
1653 if buf and self.incrementalSearchActive: |
1668 if buf and self.incrementalSearchActive: |
1654 if self.incrementalSearchString and \ |
1669 if ( |
1655 buf.startswith(self.incrementalSearchString): |
1670 self.incrementalSearchString and |
|
1671 buf.startswith(self.incrementalSearchString) |
|
1672 ): |
1656 idx, found = self.__searchHistory( |
1673 idx, found = self.__searchHistory( |
1657 self.incrementalSearchString, self.__histidx) |
1674 self.incrementalSearchString, self.__histidx) |
1658 if found and idx >= 0: |
1675 if found and idx >= 0: |
1659 self.__setHistoryIndex(index=idx) |
1676 self.__setHistoryIndex(index=idx) |
1660 self.__useHistory() |
1677 self.__useHistory() |
1751 self.__history.append(cmd) |
1768 self.__history.append(cmd) |
1752 if self.__historyStyle == ShellHistoryStyle.LinuxStyle: |
1769 if self.__historyStyle == ShellHistoryStyle.LinuxStyle: |
1753 self.__setHistoryIndex(index=-1) |
1770 self.__setHistoryIndex(index=-1) |
1754 elif self.__historyStyle == ShellHistoryStyle.WindowsStyle: |
1771 elif self.__historyStyle == ShellHistoryStyle.WindowsStyle: |
1755 if historyIndex is None: |
1772 if historyIndex is None: |
1756 if self.__histidx - 1 > 0 and \ |
1773 if ( |
1757 cmd != self.__history[self.__histidx - 1]: |
1774 self.__histidx - 1 > 0 and |
|
1775 cmd != self.__history[self.__histidx - 1] |
|
1776 ): |
1758 self.__setHistoryIndex(index=-1) |
1777 self.__setHistoryIndex(index=-1) |
1759 else: |
1778 else: |
1760 self.__setHistoryIndex(historyIndex) |
1779 self.__setHistoryIndex(historyIndex) |
1761 |
1780 |
1762 if cmd == 'start' or cmd.startswith('start '): |
1781 if cmd == 'start' or cmd.startswith('start '): |
1769 if venvName == self.tr("Project"): |
1788 if venvName == self.tr("Project"): |
1770 if self.__project.isOpen(): |
1789 if self.__project.isOpen(): |
1771 self.dbs.startClient( |
1790 self.dbs.startClient( |
1772 False, forProject=True, |
1791 False, forProject=True, |
1773 workingDir=self.__project.getProjectPath()) |
1792 workingDir=self.__project.getProjectPath()) |
1774 self.__currentWorkingDirectory = \ |
1793 self.__currentWorkingDirectory = ( |
1775 self.__project.getProjectPath() |
1794 self.__project.getProjectPath() |
|
1795 ) |
1776 else: |
1796 else: |
1777 self.dbs.startClient( |
1797 self.dbs.startClient( |
1778 False, venvName=self.__currentVenv, |
1798 False, venvName=self.__currentVenv, |
1779 workingDir=self.__currentWorkingDirectory) |
1799 workingDir=self.__currentWorkingDirectory) |
1780 # same as reset |
1800 # same as reset |
1796 if self.passive: |
1816 if self.passive: |
1797 return |
1817 return |
1798 else: |
1818 else: |
1799 cmd = '' |
1819 cmd = '' |
1800 elif cmd in ['envs', 'environments']: |
1820 elif cmd in ['envs', 'environments']: |
1801 venvs = e5App().getObject("VirtualEnvManager")\ |
1821 venvs = ( |
|
1822 e5App().getObject("VirtualEnvManager") |
1802 .getVirtualenvNames() |
1823 .getVirtualenvNames() |
|
1824 ) |
1803 s = self.tr('Available Virtual Environments:\n{0}\n').format( |
1825 s = self.tr('Available Virtual Environments:\n{0}\n').format( |
1804 '\n'.join("- {0}".format(venv) for venv in sorted(venvs)) |
1826 '\n'.join("- {0}".format(venv) for venv in sorted(venvs)) |
1805 ) |
1827 ) |
1806 self.__write(s) |
1828 self.__write(s) |
1807 self.__clientStatement(False) |
1829 self.__clientStatement(False) |
1810 s = self.tr("Current Virtual Environment: '{0}'\n").format( |
1832 s = self.tr("Current Virtual Environment: '{0}'\n").format( |
1811 self.__currentVenv) |
1833 self.__currentVenv) |
1812 self.__write(s) |
1834 self.__write(s) |
1813 self.__clientStatement(False) |
1835 self.__clientStatement(False) |
1814 return |
1836 return |
1815 elif cmd in ["quit", "quit()", "exit", "exit()"] and \ |
1837 elif ( |
1816 self.__windowed: |
1838 cmd in ["quit", "quit()", "exit", "exit()"] and |
|
1839 self.__windowed |
|
1840 ): |
1817 # call main window quit() |
1841 # call main window quit() |
1818 self.vm.quit() |
1842 self.vm.quit() |
1819 return |
1843 return |
1820 |
1844 |
1821 self.dbs.remoteStatement(cmd) |
1845 self.dbs.remoteStatement(cmd) |
1912 """ |
1938 """ |
1913 if startIdx == -1: |
1939 if startIdx == -1: |
1914 idx = len(self.__history) - 1 |
1940 idx = len(self.__history) - 1 |
1915 else: |
1941 else: |
1916 idx = startIdx - 1 |
1942 idx = startIdx - 1 |
1917 while idx >= 0 and \ |
1943 while ( |
1918 not self.__history[idx].startswith(txt): |
1944 idx >= 0 and |
|
1945 not self.__history[idx].startswith(txt) |
|
1946 ): |
1919 idx -= 1 |
1947 idx -= 1 |
1920 found = idx >= 0 and self.__history[idx].startswith(txt) |
1948 found = idx >= 0 and self.__history[idx].startswith(txt) |
1921 return idx, found |
1949 return idx, found |
1922 |
1950 |
1923 def focusNextPrevChild(self, nextChild): |
1951 def focusNextPrevChild(self, nextChild): |
1974 @param action context menu action that was triggered (QAction) |
2002 @param action context menu action that was triggered (QAction) |
1975 """ |
2003 """ |
1976 venvName = action.text() |
2004 venvName = action.text() |
1977 if venvName == self.tr("Project"): |
2005 if venvName == self.tr("Project"): |
1978 if self.__project.isOpen(): |
2006 if self.__project.isOpen(): |
1979 self.__currentWorkingDirectory = \ |
2007 self.__currentWorkingDirectory = ( |
1980 self.__project.getProjectPath() |
2008 self.__project.getProjectPath() |
|
2009 ) |
1981 self.dbs.startClient(False, forProject=True, |
2010 self.dbs.startClient(False, forProject=True, |
1982 workingDir=self.__currentWorkingDirectory) |
2011 workingDir=self.__currentWorkingDirectory) |
1983 else: |
2012 else: |
1984 self.dbs.startClient(False, venvName=venvName) |
2013 self.dbs.startClient(False, venvName=venvName) |
1985 self.__getBanner() |
2014 self.__getBanner() |
2001 self.__setCallTips() |
2030 self.__setCallTips() |
2002 |
2031 |
2003 # do the history related stuff |
2032 # do the history related stuff |
2004 self.__maxHistoryEntries = Preferences.getShell("MaxHistoryEntries") |
2033 self.__maxHistoryEntries = Preferences.getShell("MaxHistoryEntries") |
2005 for key in list(self.__historyLists.keys()): |
2034 for key in list(self.__historyLists.keys()): |
2006 self.__historyLists[key] = \ |
2035 self.__historyLists[key] = ( |
2007 self.__historyLists[key][-self.__maxHistoryEntries:] |
2036 self.__historyLists[key][-self.__maxHistoryEntries:] |
|
2037 ) |
2008 self.__historyStyle = Preferences.getShell("HistoryStyle") |
2038 self.__historyStyle = Preferences.getShell("HistoryStyle") |
2009 self.__historyWrap = Preferences.getShell("HistoryWrap") |
2039 self.__historyWrap = Preferences.getShell("HistoryWrap") |
2010 self.__setHistoryIndex() |
2040 self.__setHistoryIndex() |
2011 if not self.__windowed: |
2041 if not self.__windowed: |
2012 self.hmenu.menuAction().setEnabled(self.isHistoryEnabled()) |
2042 self.hmenu.menuAction().setEnabled(self.isHistoryEnabled()) |
2013 self.__historyNavigateByCursor = \ |
2043 self.__historyNavigateByCursor = Preferences.getShell( |
2014 Preferences.getShell("HistoryNavigateByCursor") |
2044 "HistoryNavigateByCursor") |
2015 self.historyStyleChanged.emit(self.__historyStyle) |
2045 self.historyStyleChanged.emit(self.__historyStyle) |
2016 |
2046 |
2017 # do stdout /stderr stuff |
2047 # do stdout /stderr stuff |
2018 showStdOutErr = Preferences.getShell("ShowStdOutErr") |
2048 showStdOutErr = Preferences.getShell("ShowStdOutErr") |
2019 if self.__showStdOutErr != showStdOutErr: |
2049 if self.__showStdOutErr != showStdOutErr: |
2067 """ |
2097 """ |
2068 Protected method to handle the drag enter event. |
2098 Protected method to handle the drag enter event. |
2069 |
2099 |
2070 @param event the drag enter event (QDragEnterEvent) |
2100 @param event the drag enter event (QDragEnterEvent) |
2071 """ |
2101 """ |
2072 self.inDragDrop = event.mimeData().hasUrls() or \ |
2102 self.inDragDrop = ( |
|
2103 event.mimeData().hasUrls() or |
2073 event.mimeData().hasText() |
2104 event.mimeData().hasText() |
|
2105 ) |
2074 if self.inDragDrop: |
2106 if self.inDragDrop: |
2075 event.acceptProposedAction() |
2107 event.acceptProposedAction() |
2076 else: |
2108 else: |
2077 super(Shell, self).dragEnterEvent(event) |
2109 super(Shell, self).dragEnterEvent(event) |
2078 |
2110 |