-
Notifications
You must be signed in to change notification settings - Fork 11
/
error_handler.py
66 lines (56 loc) · 2.56 KB
/
error_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
# ******************************************************************************
#
# Metatools
# ---------------------------------------------------------
# Metadata browser/editor
# Copyright (C) 2011 BV ([email protected])
#
# This source is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This code is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# A copy of the GNU General Public License is available on the World Wide Web
# at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
# to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.
#
# ******************************************************************************
from PyQt4.QtXmlPatterns import QAbstractMessageHandler
class ErrorHandler(QAbstractMessageHandler):
def __init__(self, windowTitle):
QAbstractMessageHandler.__init__(self)
self.windowTitle = windowTitle
self.errorOccured = False
def resetError(self):
self.errorOccured = False
def message(self, msg_type, desc, identifier, loc):
self.handleMessage(msg_type, desc, identifier, loc)
def handleMessage(self, msg_type, desc, identifier, loc):
# QMessageBox.information(None, "Error", desc + " Ident: " + identifier.toString() + " Line: " + QString(str(loc.line())))
from metatoolsviewer import MetatoolsViewer
message_type = {0: "Debug", 1: "Warning", 2: "Critical", 3: "Fatal"}
if msg_type > 1:
self.errorOccured = True
desc.replace("<p>", "")
desc.replace("</p>", "")
desc.replace(
"<body>",
"<head><style>.XQuery-keyword, .XQuery-type {color: red;} infolabel {color: blue; text-weight: bold; text-size: 14px}</style></head><body>",
) # add styles
desc.replace(
"<body>",
"<infolabel>Problem type: </infolabel>%s <br/><infolabel>Problem line: </infolabel>%s <br/><infolabel>Problem description: </infolabel>"
% (message_type[msg_type], loc.line()),
) # add info
dlg = MetatoolsViewer()
dlg.resize(dlg.width(), 200)
dlg.setHtml(desc)
dlg.setWindowTitle(self.windowTitle)
dlg.exec_()