E4XML/XMLMessageDialog.py

Mon, 28 Dec 2009 16:03:33 +0000

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 28 Dec 2009 16:03:33 +0000
changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
permissions
-rw-r--r--

Started porting eric4 to Python3

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

# Copyright (c) 2004 - 2009 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 (QString)
        @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