|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2006 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the log viewer widget and the log widget. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import * |
|
11 from PyQt4.QtGui import * |
|
12 |
|
13 from E4Gui.E4TabWidget import E4TabWidget |
|
14 |
|
15 from E4Gui.E4Application import e4App |
|
16 |
|
17 import UI.PixmapCache |
|
18 import Preferences |
|
19 |
|
20 class LogViewer(QTextEdit): |
|
21 """ |
|
22 Class providing a specialized text edit for displaying logging information. |
|
23 """ |
|
24 def __init__(self, parent = None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param parent reference to the parent widget (QWidget) |
|
29 """ |
|
30 QTextEdit.__init__(self, parent) |
|
31 self.setAcceptRichText(False) |
|
32 self.setLineWrapMode(QTextEdit.NoWrap) |
|
33 self.setReadOnly(True) |
|
34 |
|
35 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) |
|
36 |
|
37 # create the context menu |
|
38 self.__menu = QMenu(self) |
|
39 self.__menu.addAction(self.trUtf8('Clear'), self.clear) |
|
40 self.__menu.addAction(self.trUtf8('Copy'), self.copy) |
|
41 self.__menu.addSeparator() |
|
42 self.__menu.addAction(self.trUtf8('Select All'), self.selectAll) |
|
43 self.__menu.addSeparator() |
|
44 self.__menu.addAction(self.trUtf8("Configure..."), self.__configure) |
|
45 |
|
46 self.setContextMenuPolicy(Qt.CustomContextMenu) |
|
47 self.connect(self, SIGNAL("customContextMenuRequested(const QPoint &)"), |
|
48 self.__handleShowContextMenu) |
|
49 |
|
50 self.cNormalFormat = self.currentCharFormat() |
|
51 self.cErrorFormat = self.currentCharFormat() |
|
52 self.cErrorFormat.setForeground(QBrush(Preferences.getUI("LogStdErrColour"))) |
|
53 |
|
54 def __handleShowContextMenu(self, coord): |
|
55 """ |
|
56 Private slot to show the context menu. |
|
57 |
|
58 @param coord the position of the mouse pointer (QPoint) |
|
59 """ |
|
60 coord = self.mapToGlobal(coord) |
|
61 self.__menu.popup(coord) |
|
62 |
|
63 def __appendText(self, txt, error = False): |
|
64 """ |
|
65 Public method to append text to the end. |
|
66 |
|
67 @param txt text to insert (string) |
|
68 @param error flag indicating to insert error text (boolean) |
|
69 """ |
|
70 tc = self.textCursor() |
|
71 tc.movePosition(QTextCursor.End) |
|
72 self.setTextCursor(tc) |
|
73 if error: |
|
74 self.setCurrentCharFormat(self.cErrorFormat) |
|
75 else: |
|
76 self.setCurrentCharFormat(self.cNormalFormat) |
|
77 self.insertPlainText(txt) |
|
78 self.ensureCursorVisible() |
|
79 |
|
80 def appendToStdout(self, txt): |
|
81 """ |
|
82 Public slot to appand text to the "stdout" tab. |
|
83 |
|
84 @param txt text to be appended (string) |
|
85 """ |
|
86 self.__appendText(txt, error = False) |
|
87 QApplication.processEvents() |
|
88 |
|
89 def appendToStderr(self, txt): |
|
90 """ |
|
91 Public slot to appand text to the "stderr" tab. |
|
92 |
|
93 @param txt text to be appended (string) |
|
94 """ |
|
95 self.__appendText(txt, error = True) |
|
96 QApplication.processEvents() |
|
97 |
|
98 def preferencesChanged(self): |
|
99 """ |
|
100 Public slot to handle a change of the preferences. |
|
101 """ |
|
102 self.cErrorFormat.setForeground(QBrush(Preferences.getUI("LogStdErrColour"))) |
|
103 |
|
104 def __configure(self): |
|
105 """ |
|
106 Private method to open the configuration dialog. |
|
107 """ |
|
108 e4App().getObject("UserInterface").showPreferences("interfacePage") |