22 |
22 |
23 class LogViewer(QWidget): |
23 class LogViewer(QWidget): |
24 """ |
24 """ |
25 Class implementing the containing widget for the log viewer. |
25 Class implementing the containing widget for the log viewer. |
26 """ |
26 """ |
27 def __init__(self, parent=None): |
27 def __init__(self, ui, parent=None): |
28 """ |
28 """ |
29 Constructor |
29 Constructor |
30 |
30 |
|
31 @param ui reference to the main window (UserInterface) |
31 @param parent reference to the parent widget (QWidget) |
32 @param parent reference to the parent widget (QWidget) |
32 """ |
33 """ |
33 super(LogViewer, self).__init__(parent) |
34 super(LogViewer, self).__init__(parent) |
34 |
35 |
35 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) |
36 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) |
|
37 |
|
38 self.__ui = ui |
36 |
39 |
37 self.__logViewer = LogViewerEdit(self) |
40 self.__logViewer = LogViewerEdit(self) |
38 from .SearchWidget import SearchWidget |
41 from .SearchWidget import SearchWidget |
39 self.__searchWidget = SearchWidget(self.__logViewer, self) |
42 self.__searchWidget = SearchWidget(self.__logViewer, self) |
40 self.__searchWidget.hide() |
43 self.__searchWidget.hide() |
53 """ |
56 """ |
54 Public slot to appand text to the "stdout" tab. |
57 Public slot to appand text to the "stdout" tab. |
55 |
58 |
56 @param txt text to be appended (string) |
59 @param txt text to be appended (string) |
57 """ |
60 """ |
58 self.__logViewer.appendToStdout(txt) |
61 added = self.__logViewer.appendToStdout(txt) |
|
62 if added: |
|
63 self.__ui.showLogViewer() |
59 |
64 |
60 def appendToStderr(self, txt): |
65 def appendToStderr(self, txt): |
61 """ |
66 """ |
62 Public slot to appand text to the "stderr" tab. |
67 Public slot to appand text to the "stderr" tab. |
63 |
68 |
64 @param txt text to be appended (string) |
69 @param txt text to be appended (string) |
65 """ |
70 """ |
66 self.__logViewer.appendToStderr(txt) |
71 added = self.__logViewer.appendToStderr(txt) |
|
72 if added: |
|
73 self.__ui.showLogViewer() |
67 |
74 |
68 def preferencesChanged(self): |
75 def preferencesChanged(self): |
69 """ |
76 """ |
70 Public slot to handle a change of the preferences. |
77 Public slot to handle a change of the preferences. |
71 """ |
78 """ |
120 self.cNormalFormat = self.currentCharFormat() |
130 self.cNormalFormat = self.currentCharFormat() |
121 self.cErrorFormat = self.currentCharFormat() |
131 self.cErrorFormat = self.currentCharFormat() |
122 self.cErrorFormat.setForeground( |
132 self.cErrorFormat.setForeground( |
123 QBrush(Preferences.getUI("LogStdErrColour"))) |
133 QBrush(Preferences.getUI("LogStdErrColour"))) |
124 |
134 |
|
135 self.__stdoutFilter = Preferences.getUI("LogViewerStdoutFilter") |
|
136 self.__stderrFilter = Preferences.getUI("LogViewerStderrFilter") |
|
137 self.__stdxxxFilter = Preferences.getUI("LogViewerStdxxxFilter") |
|
138 |
125 def __handleShowContextMenu(self, coord): |
139 def __handleShowContextMenu(self, coord): |
126 """ |
140 """ |
127 Private slot to show the context menu. |
141 Private slot to show the context menu. |
128 |
142 |
129 @param coord the position of the mouse pointer (QPoint) |
143 @param coord the position of the mouse pointer (QPoint) |
130 """ |
144 """ |
131 coord = self.mapToGlobal(coord) |
145 coord = self.mapToGlobal(coord) |
132 self.__menu.popup(coord) |
146 self.__menu.popup(coord) |
133 |
147 |
134 def __appendText(self, txt, error=False): |
148 def __appendText(self, txt, isErrorMessage=False): |
135 """ |
149 """ |
136 Private method to append text to the end. |
150 Private method to append text to the end. |
137 |
151 |
138 @param txt text to insert (string) |
152 @param txt text to insert (string) |
139 @param error flag indicating to insert error text (boolean) |
153 @param isErrorMessage flag indicating to insert error text (boolean) |
140 """ |
154 """ |
141 tc = self.textCursor() |
155 tc = self.textCursor() |
142 tc.movePosition(QTextCursor.End) |
156 tc.movePosition(QTextCursor.End) |
143 self.setTextCursor(tc) |
157 self.setTextCursor(tc) |
144 if error: |
158 if isErrorMessage: |
145 self.setCurrentCharFormat(self.cErrorFormat) |
159 self.setCurrentCharFormat(self.cErrorFormat) |
146 else: |
160 else: |
147 self.setCurrentCharFormat(self.cNormalFormat) |
161 self.setCurrentCharFormat(self.cNormalFormat) |
148 self.insertPlainText(txt) |
162 self.insertPlainText(txt) |
149 self.ensureCursorVisible() |
163 self.ensureCursorVisible() |
150 |
164 |
|
165 def __filterMessage(self, message, isErrorMessage=False): |
|
166 """ |
|
167 Private method to filter messages. |
|
168 |
|
169 @param message message to be checked (string) |
|
170 @param isErrorMessage flag indicating to check an error message |
|
171 (boolean) |
|
172 @return flag indicating that the message should be filtered out |
|
173 (boolean) |
|
174 """ |
|
175 if isErrorMessage: |
|
176 filters = self.__stderrFilter + self.__stdxxxFilter |
|
177 else: |
|
178 filters = self.__stdoutFilter + self.__stdxxxFilter |
|
179 for filter in filters: |
|
180 if filter in message: |
|
181 return True |
|
182 |
|
183 return False |
|
184 |
151 def appendToStdout(self, txt): |
185 def appendToStdout(self, txt): |
152 """ |
186 """ |
153 Public slot to appand text to the "stdout" tab. |
187 Public slot to appand text to the "stdout" tab. |
154 |
188 |
155 @param txt text to be appended (string) |
189 @param txt text to be appended (string) |
156 """ |
190 @return flag indicating text was appended (boolean) |
157 self.__appendText(txt, error=False) |
191 """ |
|
192 if self.__filterMessage(txt, isErrorMessage=False): |
|
193 return False |
|
194 |
|
195 self.__appendText(txt, isErrorMessage=False) |
158 QApplication.processEvents() |
196 QApplication.processEvents() |
|
197 return True |
159 |
198 |
160 def appendToStderr(self, txt): |
199 def appendToStderr(self, txt): |
161 """ |
200 """ |
162 Public slot to appand text to the "stderr" tab. |
201 Public slot to appand text to the "stderr" tab. |
163 |
202 |
164 @param txt text to be appended (string) |
203 @param txt text to be appended (string) |
165 """ |
204 @return flag indicating text was appended (boolean) |
166 self.__appendText(txt, error=True) |
205 """ |
|
206 if self.__filterMessage(txt, isErrorMessage=True): |
|
207 return False |
|
208 |
|
209 self.__appendText(txt, isErrorMessage=True) |
167 QApplication.processEvents() |
210 QApplication.processEvents() |
|
211 return True |
168 |
212 |
169 def preferencesChanged(self): |
213 def preferencesChanged(self): |
170 """ |
214 """ |
171 Public slot to handle a change of the preferences. |
215 Public slot to handle a change of the preferences. |
172 """ |
216 """ |
173 self.cErrorFormat.setForeground( |
217 self.cErrorFormat.setForeground( |
174 QBrush(Preferences.getUI("LogStdErrColour"))) |
218 QBrush(Preferences.getUI("LogStdErrColour"))) |
|
219 |
|
220 self.__stdoutFilter = Preferences.getUI("LogViewerStdoutFilter") |
|
221 self.__stderrFilter = Preferences.getUI("LogViewerStderrFilter") |
|
222 self.__stdxxxFilter = Preferences.getUI("LogViewerStdxxxFilter") |
175 |
223 |
176 def __configure(self): |
224 def __configure(self): |
177 """ |
225 """ |
178 Private method to open the configuration dialog. |
226 Private method to open the configuration dialog. |
179 """ |
227 """ |