-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdderror.py
More file actions
67 lines (61 loc) · 2.6 KB
/
dderror.py
File metadata and controls
67 lines (61 loc) · 2.6 KB
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
67
# -*- coding: utf-8 -*-
"""
dderror
-----------------------------------
Error classes
"""
"""
/***************************************************************************
DataDrivenInputMask
A QGIS plugin
Applies a data-driven input mask to any PostGIS-Layer
-------------------
begin : 2012-06-21
copyright : (C) 2012 by Bernhard Strรถbl / Kommunale Immobilien Jena
email : bernhard.stroebl@jena.de
***************************************************************************/
/***************************************************************************
* *
* This program 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. *
* *
***************************************************************************/
"""
from builtins import object
from qgis.PyQt import QtWidgets
from qgis.gui import QgsMessageBar
from qgis.core import QgsMessageLog, Qgis
class DdError(object):
'''General error'''
def __init__(self, value, fatal = False, iface = None, showInLog = False):
self.value = value
if fatal:
raise FatalError(value)
else:
if showInLog:
QgsMessageLog.logMessage("DdError: " + value, level=Qgis.Critical)
else:
if iface:
iface.messageBar().pushMessage("DdError",
value, Qgis.Critical, duration = 10)
else:
QtWidgets.QMessageBox.warning(None, "DdError", value)
def __str__(self):
return repr(self.value)
class DbError(object):
'''error querying the DB'''
def __init__(self, query, fatal = True):
self.query = query
QtWidgets.QMessageBox.warning(None, "DBError", QtWidgets.QApplication.translate("DBError", "Database Error:") + \
"%(error)s \n %(query)s" % {"error": query.lastError().text(), "query": query.lastQuery()})
if fatal:
raise FatalError("DBError exiting")
def __str__(self):
return repr(self.query.lastError())
class FatalError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)