E5XML/XMLMessageDialog.py

Fri, 10 Sep 2010 08:54:33 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 10 Sep 2010 08:54:33 +0200
changeset 580
45c38566b001
parent 110
c9a969db1469
child 792
a13346916170
permissions
-rw-r--r--

Implemented the plug-in repository reader.

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

# Copyright (c) 2004 - 2010 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