UI/LogView.py

changeset 1823
21d988eaf1bf
parent 1509
c0b5e693b0eb
child 1829
fa72a573967f
equal deleted inserted replaced
1822:6ee4a434e64c 1823:21d988eaf1bf
6 """ 6 """
7 Module implementing the log viewer widget and the log widget. 7 Module implementing the log viewer widget and the log widget.
8 """ 8 """
9 9
10 from PyQt4.QtCore import Qt 10 from PyQt4.QtCore import Qt
11 from PyQt4.QtGui import QTextEdit, QBrush, QApplication, QMenu, QTextCursor 11 from PyQt4.QtGui import QTextEdit, QBrush, QApplication, QMenu, QTextCursor, QWidget, \
12 QHBoxLayout, QTextDocument
12 13
13 from E5Gui.E5Application import e5App 14 from E5Gui.E5Application import e5App
15
16 from .SearchWidget import SearchWidget
14 17
15 import UI.PixmapCache 18 import UI.PixmapCache
16 import Preferences 19 import Preferences
17 20
18 21
19 class LogViewer(QTextEdit): 22 class LogViewer(QWidget):
23 """
24 Class implementing the containing widget for the log viewer.
25 """
26 def __init__(self, parent=None):
27 """
28 Constructor
29
30 @param parent reference to the parent widget (QWidget)
31 """
32 super().__init__(parent)
33
34 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png"))
35
36 self.__logViewer = LogViewerEdit(self)
37 self.__searchWidget = SearchWidget(self.__logViewer, self)
38 self.__searchWidget.hide()
39
40 self.__layout = QHBoxLayout(self)
41 self.__layout.addWidget(self.__logViewer)
42 self.__layout.addWidget(self.__searchWidget)
43
44 self.__searchWidget.searchNext.connect(self.__logViewer.searchNext)
45 self.__searchWidget.searchPrevious.connect(self.__logViewer.searchPrev)
46
47 def appendToStdout(self, txt):
48 """
49 Public slot to appand text to the "stdout" tab.
50
51 @param txt text to be appended (string)
52 """
53 self.__logViewer.appendToStdout(txt)
54
55 def appendToStderr(self, txt):
56 """
57 Public slot to appand text to the "stderr" tab.
58
59 @param txt text to be appended (string)
60 """
61 self.__logViewer.appendToStderr(txt)
62
63 def preferencesChanged(self):
64 """
65 Public slot to handle a change of the preferences.
66 """
67 self.__logViewer.preferencesChanged()
68
69 def showFind(self, txt=""):
70 """
71 Public method to display the search widget.
72
73 @param txt text to be shown in the combo (string)
74 """
75 self.__searchWidget.showFind()
76
77
78 class LogViewerEdit(QTextEdit):
20 """ 79 """
21 Class providing a specialized text edit for displaying logging information. 80 Class providing a specialized text edit for displaying logging information.
22 """ 81 """
23 def __init__(self, parent=None): 82 def __init__(self, parent=None):
24 """ 83 """
29 super().__init__(parent) 88 super().__init__(parent)
30 self.setAcceptRichText(False) 89 self.setAcceptRichText(False)
31 self.setLineWrapMode(QTextEdit.NoWrap) 90 self.setLineWrapMode(QTextEdit.NoWrap)
32 self.setReadOnly(True) 91 self.setReadOnly(True)
33 92
34 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) 93 self.__mainWindow = parent
94 self.__lastSearch = ()
35 95
36 # create the context menu 96 # create the context menu
37 self.__menu = QMenu(self) 97 self.__menu = QMenu(self)
38 self.__menu.addAction(self.trUtf8('Clear'), self.clear) 98 self.__menu.addAction(self.trUtf8('Clear'), self.clear)
39 self.__menu.addAction(self.trUtf8('Copy'), self.copy) 99 self.__menu.addAction(self.trUtf8('Copy'), self.copy)
100 self.__menu.addSeparator()
101 self.__menu.addAction(self.trUtf8('Find'), self.__find)
40 self.__menu.addSeparator() 102 self.__menu.addSeparator()
41 self.__menu.addAction(self.trUtf8('Select All'), self.selectAll) 103 self.__menu.addAction(self.trUtf8('Select All'), self.selectAll)
42 self.__menu.addSeparator() 104 self.__menu.addSeparator()
43 self.__menu.addAction(self.trUtf8("Configure..."), self.__configure) 105 self.__menu.addAction(self.trUtf8("Configure..."), self.__configure)
44 106
102 def __configure(self): 164 def __configure(self):
103 """ 165 """
104 Private method to open the configuration dialog. 166 Private method to open the configuration dialog.
105 """ 167 """
106 e5App().getObject("UserInterface").showPreferences("interfacePage") 168 e5App().getObject("UserInterface").showPreferences("interfacePage")
169
170 def __find(self):
171 """
172 Private slot to show the find widget.
173 """
174 txt = self.textCursor().selectedText()
175 self.__mainWindow.showFind(txt)
176
177 def searchNext(self, txt, caseSensitive, wholeWord):
178 """
179 Public method to search the next occurrence of the given text.
180 """
181 self.__lastSearch = (txt, caseSensitive, wholeWord)
182 flags = QTextDocument.FindFlags()
183 if caseSensitive:
184 flags |= QTextDocument.FindCaseSensitively
185 if wholeWord:
186 flags |= QTextDocument.FindWholeWords
187 self.find(txt, flags)
188
189 def searchPrev(self, txt, caseSensitive, wholeWord):
190 """
191 Public method to search the previous occurrence of the given text.
192 """
193 self.__lastSearch = (txt, caseSensitive, wholeWord)
194 flags = QTextDocument.FindFlags(QTextDocument.FindBackward)
195 if caseSensitive:
196 flags |= QTextDocument.FindCaseSensitively
197 if wholeWord:
198 flags |= QTextDocument.FindWholeWords
199 self.find(txt, flags)
200
201 def keyPressEvent(self, evt):
202 """
203 Protected method handling key press events.
204
205 @param evt key press event (QKeyEvent)
206 """
207 if evt.modifiers() == Qt.ControlModifier:
208 if evt.key() == Qt.Key_F:
209 self.__find()
210 evt.accept()
211 return
212 elif evt.key() == Qt.Key_C:
213 self.copy()
214 evt.accept()
215 return
216 elif evt.key() == Qt.Key_A:
217 self.selectAll()
218 evt.accept()
219 return
220 elif evt.modifiers() == Qt.NoModifier:
221 if evt.key() == Qt.Key_F3 and self.__lastSearch:
222 self.searchNext(*self.__lastSearch)
223 evt.accept()
224 return
225 elif evt.modifiers() == Qt.ShiftModifier and self.__lastSearch:
226 if evt.key() == Qt.Key_F3 and self.__lastSearch:
227 self.searchPrev(*self.__lastSearch)
228 evt.accept()
229 return

eric ide

mercurial