9 |
9 |
10 import sys |
10 import sys |
11 import os |
11 import os |
12 import re |
12 import re |
13 |
13 |
14 from PyQt4.QtCore import QSignalMapper, QTimer, QByteArray, QProcess, Qt, QEvent |
14 from PyQt4.QtCore import pyqtSignal, QSignalMapper, QTimer, QByteArray, QProcess, Qt, \ |
15 from PyQt4.QtGui import QDialog, QInputDialog, QApplication, QMenu, QPalette, QFont |
15 QEvent |
|
16 from PyQt4.QtGui import QDialog, QInputDialog, QApplication, QMenu, QPalette, QFont, \ |
|
17 QWidget, QHBoxLayout, QShortcut |
16 from PyQt4.Qsci import QsciScintilla |
18 from PyQt4.Qsci import QsciScintilla |
17 |
19 |
18 from E5Gui.E5Application import e5App |
20 from E5Gui.E5Application import e5App |
19 |
21 |
20 from . import Lexers |
22 from . import Lexers |
22 |
24 |
23 import Preferences |
25 import Preferences |
24 import Utilities |
26 import Utilities |
25 |
27 |
26 import UI.PixmapCache |
28 import UI.PixmapCache |
|
29 from UI.SearchWidget import SearchWidget |
27 |
30 |
28 from .ShellHistoryDialog import ShellHistoryDialog |
31 from .ShellHistoryDialog import ShellHistoryDialog |
|
32 |
|
33 |
|
34 class TerminalAssembly(QWidget): |
|
35 """ |
|
36 Class implementing the containing widget for the terminal. |
|
37 """ |
|
38 def __init__(self, vm, parent=None): |
|
39 """ |
|
40 Constructor |
|
41 |
|
42 @param vm reference to the viewmanager object |
|
43 @param parent reference to the parent widget (QWidget) |
|
44 """ |
|
45 super().__init__(parent) |
|
46 |
|
47 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) |
|
48 |
|
49 self.__terminal = Terminal(vm, self) |
|
50 self.__searchWidget = SearchWidget(self.__terminal, self) |
|
51 self.__searchWidget.hide() |
|
52 |
|
53 self.__layout = QHBoxLayout(self) |
|
54 self.__layout.setContentsMargins(1, 1, 1, 1) |
|
55 self.__layout.addWidget(self.__terminal) |
|
56 self.__layout.addWidget(self.__searchWidget) |
|
57 |
|
58 self.__searchWidget.searchNext.connect(self.__terminal.searchNext) |
|
59 self.__searchWidget.searchPrevious.connect(self.__terminal.searchPrev) |
|
60 self.__terminal.searchStringFound.connect(self.__searchWidget.searchStringFound) |
|
61 |
|
62 def showFind(self, txt=""): |
|
63 """ |
|
64 Public method to display the search widget. |
|
65 |
|
66 @param txt text to be shown in the combo (string) |
|
67 """ |
|
68 self.__searchWidget.showFind(txt) |
|
69 |
|
70 def terminal(self): |
|
71 """ |
|
72 Public method to get a reference to the terminal widget. |
|
73 |
|
74 @return reference to the terminal widget (Terminal) |
|
75 """ |
|
76 return self.__terminal |
29 |
77 |
30 |
78 |
31 class Terminal(QsciScintillaCompat): |
79 class Terminal(QsciScintillaCompat): |
32 """ |
80 """ |
33 Class implementing a simple terminal based on QScintilla. |
81 Class implementing a simple terminal based on QScintilla. |
34 |
82 |
35 A user can enter commands that are executed by a shell process. |
83 A user can enter commands that are executed by a shell process. |
|
84 |
|
85 @signal searchStringFound(found) emitted to indicate the search result (boolean) |
36 """ |
86 """ |
|
87 searchStringFound = pyqtSignal(bool) |
|
88 |
37 def __init__(self, vm, parent=None): |
89 def __init__(self, vm, parent=None): |
38 """ |
90 """ |
39 Constructor |
91 Constructor |
40 |
92 |
41 @param vm reference to the viewmanager object |
93 @param vm reference to the viewmanager object |
106 # Create a little context menu |
160 # Create a little context menu |
107 self.menu = QMenu(self) |
161 self.menu = QMenu(self) |
108 self.menu.addAction(self.trUtf8('Cut'), self.cut) |
162 self.menu.addAction(self.trUtf8('Cut'), self.cut) |
109 self.menu.addAction(self.trUtf8('Copy'), self.copy) |
163 self.menu.addAction(self.trUtf8('Copy'), self.copy) |
110 self.menu.addAction(self.trUtf8('Paste'), self.paste) |
164 self.menu.addAction(self.trUtf8('Paste'), self.paste) |
|
165 self.menu.addSeparator() |
|
166 self.menu.addAction(self.trUtf8('Find'), self.__find) |
|
167 self.menu.addSeparator() |
111 self.menu.addMenu(self.hmenu) |
168 self.menu.addMenu(self.hmenu) |
112 self.menu.addSeparator() |
169 self.menu.addSeparator() |
113 self.menu.addAction(self.trUtf8('Clear'), self.clear) |
170 self.menu.addAction(self.trUtf8('Clear'), self.clear) |
114 self.__startAct = self.menu.addAction(self.trUtf8("Start"), self.__startShell) |
171 self.__startAct = self.menu.addAction(self.trUtf8("Start"), self.__startShell) |
115 self.__stopAct = self.menu.addAction(self.trUtf8("Stop"), self.__stopShell) |
172 self.__stopAct = self.menu.addAction(self.trUtf8("Stop"), self.__stopShell) |
954 """ |
1011 """ |
955 if not self.__actionsAdded: |
1012 if not self.__actionsAdded: |
956 self.addActions(self.vm.editorActGrp.actions()) |
1013 self.addActions(self.vm.editorActGrp.actions()) |
957 self.addActions(self.vm.copyActGrp.actions()) |
1014 self.addActions(self.vm.copyActGrp.actions()) |
958 self.addActions(self.vm.viewActGrp.actions()) |
1015 self.addActions(self.vm.viewActGrp.actions()) |
|
1016 self.__searchShortcut = QShortcut(self.vm.searchAct.shortcut(), self, |
|
1017 self.__find, self.__find) |
|
1018 self.__searchNextShortcut = QShortcut(self.vm.searchNextAct.shortcut(), self, |
|
1019 self.__searchNext, self.__searchNext) |
|
1020 self.__searchPrevShortcut = QShortcut(self.vm.searchPrevAct.shortcut(), self, |
|
1021 self.__searchPrev, self.__searchPrev) |
959 |
1022 |
960 try: |
1023 try: |
961 self.vm.editActGrp.setEnabled(False) |
1024 self.vm.editActGrp.setEnabled(False) |
962 self.vm.editorActGrp.setEnabled(True) |
1025 self.vm.editorActGrp.setEnabled(True) |
963 self.vm.copyActGrp.setEnabled(True) |
1026 self.vm.copyActGrp.setEnabled(True) |
1001 def __configure(self): |
1064 def __configure(self): |
1002 """ |
1065 """ |
1003 Private method to open the configuration dialog. |
1066 Private method to open the configuration dialog. |
1004 """ |
1067 """ |
1005 e5App().getObject("UserInterface").showPreferences("terminalPage") |
1068 e5App().getObject("UserInterface").showPreferences("terminalPage") |
|
1069 |
|
1070 def __find(self): |
|
1071 """ |
|
1072 Private slot to show the find widget. |
|
1073 """ |
|
1074 txt = self.selectedText() |
|
1075 self.__mainWindow.showFind(txt) |
|
1076 |
|
1077 def __searchNext(self): |
|
1078 """ |
|
1079 Private method to search for the next occurrence. |
|
1080 """ |
|
1081 if self.__lastSearch: |
|
1082 self.searchNext(*self.__lastSearch) |
|
1083 |
|
1084 def searchNext(self, txt, caseSensitive, wholeWord): |
|
1085 """ |
|
1086 Public method to search the next occurrence of the given text. |
|
1087 """ |
|
1088 self.__lastSearch = (txt, caseSensitive, wholeWord) |
|
1089 ok = self.findFirst(txt, False, caseSensitive, wholeWord, False, forward=True) |
|
1090 self.searchStringFound.emit(ok) |
|
1091 |
|
1092 def __searchPrev(self): |
|
1093 """ |
|
1094 Private method to search for the next occurrence. |
|
1095 """ |
|
1096 if self.__lastSearch: |
|
1097 self.searchPrev(*self.__lastSearch) |
|
1098 |
|
1099 def searchPrev(self, txt, caseSensitive, wholeWord): |
|
1100 """ |
|
1101 Public method to search the previous occurrence of the given text. |
|
1102 """ |
|
1103 self.__lastSearch = (txt, caseSensitive, wholeWord) |
|
1104 if self.hasSelectedText(): |
|
1105 line, index = self.getSelection()[:2] |
|
1106 else: |
|
1107 line, index = -1, -1 |
|
1108 ok = self.findFirst(txt, False, caseSensitive, wholeWord, False, forward=False, |
|
1109 line=line, index=index) |
|
1110 self.searchStringFound.emit(ok) |