1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2004 - 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to display XML parse messages. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import * |
|
11 from PyQt4.QtGui import * |
|
12 |
|
13 from .Ui_XMLMessageDialog import Ui_XMLMessageDialog |
|
14 |
|
15 |
|
16 class XMLMessageDialog(QDialog, Ui_XMLMessageDialog): |
|
17 """ |
|
18 Class implementing a dialog to display XML parse messages. |
|
19 """ |
|
20 def __init__(self, msgs, parent = None): |
|
21 """ |
|
22 Constructor |
|
23 |
|
24 @param msgs list of tuples of (message type, system id, |
|
25 line no, column no, message) |
|
26 @param parent parent object of the dialog (QWidget) |
|
27 """ |
|
28 QDialog.__init__(self,parent) |
|
29 self.setupUi(self) |
|
30 |
|
31 for type, sysId, line, column, msg in msgs: |
|
32 if type == "F": |
|
33 color = QColor(Qt.red) |
|
34 self.__appendText(self.trUtf8("Fatal Error"), color) |
|
35 elif type == "E": |
|
36 color = QColor(Qt.blue) |
|
37 self.__appendText(self.trUtf8("Error"), color) |
|
38 elif type == "W": |
|
39 color = QColor(Qt.black) |
|
40 self.__appendText(self.trUtf8("Warning"), color) |
|
41 |
|
42 self.__appendText(sysId, color) |
|
43 self.__appendText(self.trUtf8("Line: {0}, Column: {1}") |
|
44 .format(line, column), color) |
|
45 self.__appendText(msg, color) |
|
46 |
|
47 self.__appendText("------", QColor(Qt.black)) |
|
48 |
|
49 tc = self.messages.textCursor() |
|
50 tc.movePosition(QTextCursor.Start) |
|
51 self.messages.setTextCursor(tc) |
|
52 self.messages.ensureCursorVisible() |
|
53 |
|
54 def __appendText(self, txt, color): |
|
55 """ |
|
56 Private method to append text to the end of the messages pane. |
|
57 |
|
58 @param txt text to insert (string) |
|
59 @param color text color to be used (QColor) |
|
60 """ |
|
61 if txt is not None: |
|
62 tc = self.messages.textCursor() |
|
63 tc.movePosition(QTextCursor.End) |
|
64 self.messages.setTextCursor(tc) |
|
65 self.messages.setTextColor(color) |
|
66 self.messages.insertPlainText(txt) |
|
67 self.messages.insertPlainText("\n") |
|