QScintilla/Shell.py

branch
maintenance
changeset 6395
613e37fabd96
parent 6319
df201b9fbad4
parent 6387
a168b5f26a14
child 6487
d3ca83d691e7
equal deleted inserted replaced
6320:4c45d163c6ac 6395:613e37fabd96
18 from ThirdParty.enum import Enum 18 from ThirdParty.enum import Enum
19 19
20 from PyQt5.QtCore import pyqtSignal, QFileInfo, Qt, QEvent 20 from PyQt5.QtCore import pyqtSignal, QFileInfo, Qt, QEvent
21 from PyQt5.QtGui import QClipboard, QPalette, QFont 21 from PyQt5.QtGui import QClipboard, QPalette, QFont
22 from PyQt5.QtWidgets import QDialog, QInputDialog, QApplication, QMenu, \ 22 from PyQt5.QtWidgets import QDialog, QInputDialog, QApplication, QMenu, \
23 QWidget, QHBoxLayout, QVBoxLayout, QShortcut 23 QWidget, QHBoxLayout, QVBoxLayout, QShortcut, QSizePolicy
24 from PyQt5.Qsci import QsciScintilla 24 from PyQt5.Qsci import QsciScintilla
25 25
26 from E5Gui.E5Application import e5App 26 from E5Gui.E5Application import e5App
27 from E5Gui import E5MessageBox 27 from E5Gui import E5MessageBox
28 28
54 54
55 self.__shell = Shell(dbs, vm, False, self) 55 self.__shell = Shell(dbs, vm, False, self)
56 56
57 from UI.SearchWidget import SearchWidget 57 from UI.SearchWidget import SearchWidget
58 self.__searchWidget = SearchWidget(self.__shell, self, horizontal) 58 self.__searchWidget = SearchWidget(self.__shell, self, horizontal)
59 self.__searchWidget.setSizePolicy(QSizePolicy.Fixed,
60 QSizePolicy.Preferred)
59 self.__searchWidget.hide() 61 self.__searchWidget.hide()
60 62
61 if horizontal: 63 if horizontal:
62 self.__layout = QHBoxLayout(self) 64 self.__layout = QHBoxLayout(self)
63 else: 65 else:
106 108
107 @signal searchStringFound(bool) emitted to indicate the search 109 @signal searchStringFound(bool) emitted to indicate the search
108 result 110 result
109 @signal historyStyleChanged(ShellHistoryStyle) emitted to indicate a 111 @signal historyStyleChanged(ShellHistoryStyle) emitted to indicate a
110 change of the history style 112 change of the history style
113 @signal queueText(str) emitted to queue some text for processing
111 """ 114 """
112 searchStringFound = pyqtSignal(bool) 115 searchStringFound = pyqtSignal(bool)
113 historyStyleChanged = pyqtSignal(ShellHistoryStyle) 116 historyStyleChanged = pyqtSignal(ShellHistoryStyle)
117 queueText = pyqtSignal(str)
114 118
115 def __init__(self, dbs, vm, windowedVariant, parent=None): 119 def __init__(self, dbs, vm, windowedVariant, parent=None):
116 """ 120 """
117 Constructor 121 Constructor
118 122
341 } 345 }
342 346
343 self.__historyNavigateByCursor = \ 347 self.__historyNavigateByCursor = \
344 Preferences.getShell("HistoryNavigateByCursor") 348 Preferences.getShell("HistoryNavigateByCursor")
345 349
350 self.__queuedText = ''
351 self.__blockTextProcessing = False
352 self.queueText.connect(self.__concatenateText, Qt.QueuedConnection)
353
346 self.grabGesture(Qt.PinchGesture) 354 self.grabGesture(Qt.PinchGesture)
347 355
348 def __showLanguageMenu(self): 356 def __showLanguageMenu(self):
349 """ 357 """
350 Private slot to prepare the language submenu. 358 Private slot to prepare the language submenu.
902 """ 910 """
903 Private method to display some text. 911 Private method to display some text.
904 912
905 @param s text to be displayed (string) 913 @param s text to be displayed (string)
906 """ 914 """
915 self.queueText.emit(s)
916
917 def __concatenateText(self, text):
918 """
919 Private slot to get all available text and process it in one step.
920
921 @param text text to be appended
922 @type str
923 """
924 self.__queuedText += text
925 if self.__blockTextProcessing:
926 return
927
928 self.__blockTextProcessing = True
929 # Get all text which is still waiting for output
930 QApplication.processEvents()
931
932 # Finally process the accumulated text
907 line, col = self.__getEndPos() 933 line, col = self.__getEndPos()
908 self.setCursorPosition(line, col) 934 self.setCursorPosition(line, col)
909 self.insert(Utilities.filterAnsiSequences(s)) 935 self.insert(Utilities.filterAnsiSequences(self.__queuedText))
910 self.prline, self.prcol = self.getCursorPosition() 936 self.prline, self.prcol = self.getCursorPosition()
911 self.ensureCursorVisible() 937 self.ensureCursorVisible()
912 self.ensureLineVisible(self.prline) 938 self.ensureLineVisible(self.prline)
913 939
940 self.__queuedText = ''
941 self.__blockTextProcessing = False
942
914 def __writeStdOut(self, s): 943 def __writeStdOut(self, s):
915 """ 944 """
916 Private method to display some text with StdOut label. 945 Private method to display some text with StdOut label.
917 946
918 @param s text to be displayed (string) 947 @param s text to be displayed (string)
1862 1891
1863 @param action context menu action that was triggered (QAction) 1892 @param action context menu action that was triggered (QAction)
1864 """ 1893 """
1865 language = action.data() 1894 language = action.data()
1866 self.dbs.startClient(False, language) 1895 self.dbs.startClient(False, language)
1896 self.__getBanner()
1867 1897
1868 def handlePreferencesChanged(self): 1898 def handlePreferencesChanged(self):
1869 """ 1899 """
1870 Public slot to handle the preferencesChanged signal. 1900 Public slot to handle the preferencesChanged signal.
1871 """ 1901 """
2018 """ 2048 """
2019 if not self.__actionsAdded: 2049 if not self.__actionsAdded:
2020 self.addActions(self.vm.editorActGrp.actions()) 2050 self.addActions(self.vm.editorActGrp.actions())
2021 self.addActions(self.vm.copyActGrp.actions()) 2051 self.addActions(self.vm.copyActGrp.actions())
2022 self.addActions(self.vm.viewActGrp.actions()) 2052 self.addActions(self.vm.viewActGrp.actions())
2023 self.__searchShortcut = QShortcut( 2053 if not self.__windowed:
2024 self.vm.searchAct.shortcut(), self, 2054 self.__searchShortcut = QShortcut(
2025 self.__find, self.__find) 2055 self.vm.searchAct.shortcut(), self,
2026 self.__searchNextShortcut = QShortcut( 2056 self.__find, self.__find)
2027 self.vm.searchNextAct.shortcut(), self, 2057 self.__searchNextShortcut = QShortcut(
2028 self.__searchNext, self.__searchNext) 2058 self.vm.searchNextAct.shortcut(), self,
2029 self.__searchPrevShortcut = QShortcut( 2059 self.__searchNext, self.__searchNext)
2030 self.vm.searchPrevAct.shortcut(), self, 2060 self.__searchPrevShortcut = QShortcut(
2031 self.__searchPrev, self.__searchPrev) 2061 self.vm.searchPrevAct.shortcut(), self,
2062 self.__searchPrev, self.__searchPrev)
2032 2063
2033 try: 2064 try:
2034 self.vm.editActGrp.setEnabled(False) 2065 self.vm.editActGrp.setEnabled(False)
2035 self.vm.editorActGrp.setEnabled(True) 2066 self.vm.editorActGrp.setEnabled(True)
2036 self.vm.copyActGrp.setEnabled(True) 2067 self.vm.copyActGrp.setEnabled(True)
2037 self.vm.viewActGrp.setEnabled(True) 2068 self.vm.viewActGrp.setEnabled(True)
2038 self.vm.searchActGrp.setEnabled(False) 2069 self.vm.searchActGrp.setEnabled(False)
2039 except AttributeError: 2070 except AttributeError:
2040 pass 2071 pass
2041 self.__searchShortcut.setEnabled(True) 2072 if not self.__windowed:
2042 self.__searchNextShortcut.setEnabled(True) 2073 self.__searchShortcut.setEnabled(True)
2043 self.__searchPrevShortcut.setEnabled(True) 2074 self.__searchNextShortcut.setEnabled(True)
2075 self.__searchPrevShortcut.setEnabled(True)
2044 self.setCaretWidth(self.caretWidth) 2076 self.setCaretWidth(self.caretWidth)
2045 self.setCursorFlashTime(QApplication.cursorFlashTime()) 2077 self.setCursorFlashTime(QApplication.cursorFlashTime())
2046 2078
2047 super(Shell, self).focusInEvent(event) 2079 super(Shell, self).focusInEvent(event)
2048 2080
2054 """ 2086 """
2055 try: 2087 try:
2056 self.vm.editorActGrp.setEnabled(False) 2088 self.vm.editorActGrp.setEnabled(False)
2057 except AttributeError: 2089 except AttributeError:
2058 pass 2090 pass
2059 self.__searchShortcut.setEnabled(False) 2091 if not self.__windowed:
2060 self.__searchNextShortcut.setEnabled(False) 2092 self.__searchShortcut.setEnabled(False)
2061 self.__searchPrevShortcut.setEnabled(False) 2093 self.__searchNextShortcut.setEnabled(False)
2094 self.__searchPrevShortcut.setEnabled(False)
2062 self.setCaretWidth(0) 2095 self.setCaretWidth(0)
2063 super(Shell, self).focusOutEvent(event) 2096 super(Shell, self).focusOutEvent(event)
2064 2097
2065 def insert(self, txt): 2098 def insert(self, txt):
2066 """ 2099 """
2108 @param wholeWord flag indicating to search for whole words 2141 @param wholeWord flag indicating to search for whole words
2109 only (boolean) 2142 only (boolean)
2110 """ 2143 """
2111 self.__lastSearch = (txt, caseSensitive, wholeWord) 2144 self.__lastSearch = (txt, caseSensitive, wholeWord)
2112 ok = self.findFirst( 2145 ok = self.findFirst(
2113 txt, False, caseSensitive, wholeWord, False, forward=True) 2146 txt, False, caseSensitive, wholeWord, True, forward=True)
2114 self.searchStringFound.emit(ok) 2147 self.searchStringFound.emit(ok)
2115 2148
2116 def __searchPrev(self): 2149 def __searchPrev(self):
2117 """ 2150 """
2118 Private method to search for the next occurrence. 2151 Private method to search for the next occurrence.
2134 if self.hasSelectedText(): 2167 if self.hasSelectedText():
2135 line, index = self.getSelection()[:2] 2168 line, index = self.getSelection()[:2]
2136 else: 2169 else:
2137 line, index = -1, -1 2170 line, index = -1, -1
2138 ok = self.findFirst( 2171 ok = self.findFirst(
2139 txt, False, caseSensitive, wholeWord, False, 2172 txt, False, caseSensitive, wholeWord, True,
2140 forward=False, line=line, index=index) 2173 forward=False, line=line, index=index)
2141 self.searchStringFound.emit(ok) 2174 self.searchStringFound.emit(ok)
2142 2175
2143 def historyStyle(self): 2176 def historyStyle(self):
2144 """ 2177 """

eric ide

mercurial