E5XML/XMLMessageDialog.py

Fri, 31 Dec 2010 15:50:33 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 31 Dec 2010 15:50:33 +0100
branch
5_0_x
changeset 792
a13346916170
parent 110
c9a969db1469
permissions
-rw-r--r--

Updated copyright notice.

# -*- coding: utf-8 -*-

# Copyright (c) 2004 - 2011 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to display XML parse messages.
"""

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from .Ui_XMLMessageDialog import Ui_XMLMessageDialog


class XMLMessageDialog(QDialog, Ui_XMLMessageDialog):
    """
    Class implementing a dialog to display XML parse messages.
    """
    def __init__(self, msgs, parent = None):
        """
        Constructor
        
        @param msgs list of tuples of (message type, system id,
            line no, column no, message)
        @param parent parent object of the dialog (QWidget)
        """
        QDialog.__init__(self,parent)
        self.setupUi(self)
        
        for type, sysId, line, column, msg in msgs:
            if type == "F":
                color = QColor(Qt.red)
                self.__appendText(self.trUtf8("Fatal Error"), color)
            elif type == "E":
                color = QColor(Qt.blue)
                self.__appendText(self.trUtf8("Error"), color)
            elif type == "W":
                color = QColor(Qt.black)
                self.__appendText(self.trUtf8("Warning"), color)
            
            self.__appendText(sysId, color)
            self.__appendText(self.trUtf8("Line: {0}, Column: {1}")
                .format(line, column), color)
            self.__appendText(msg, color)
            
            self.__appendText("------", QColor(Qt.black))
        
        tc = self.messages.textCursor()
        tc.movePosition(QTextCursor.Start)
        self.messages.setTextCursor(tc)
        self.messages.ensureCursorVisible()

    def __appendText(self, txt, color):
        """
        Private method to append text to the end of the messages pane.
        
        @param txt text to insert (string)
        @param color text color to be used (QColor)
        """
        if txt is not None:
            tc = self.messages.textCursor()
            tc.movePosition(QTextCursor.End)
            self.messages.setTextCursor(tc)
            self.messages.setTextColor(color)
            self.messages.insertPlainText(txt)
            self.messages.insertPlainText("\n")

eric ide

mercurial