-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMessageManager.py
53 lines (45 loc) · 2.38 KB
/
MessageManager.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
# -*- coding:utf-8 -*-
"""
/***************************************************************************
AutoFields
A QGIS plugin
Automatic attribute updates when creating or modifying vector features
-------------------
begin : 2016-05-22
copyright : (C) 2016 by Germán Carrillo (GeoTux)
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* 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 qgis.core import QgsMessageLog
from PyQt4.QtGui import QPushButton
class MessageManager():
def __init__( self, mode='production', iface=None ):
self.mode = mode # 'production' or 'debug'
self.iface = iface
self.levelList = ['info', 'warning', 'critical', 'success']
def show( self, message, type='info', justForDebug=False ):
""" Prints the message to the appropriate output """
if self.mode == 'production':
if not justForDebug:
self.iface.messageBar().pushMessage( "AutoFields", message,
level=self.levelList.index(type), duration=15 )
else: # Print all to console
print "[AutoFields]", message
#QgsMessageLog.instance().logMessage( "AutoFields: "+message,"", QgsMessageLog.WARNING )
def showWithButton( self, message, buttonText, slot, type='info' ):
""" Prints a message with a button.
"""
widget = self.iface.messageBar().createMessage( "AutoFields", message )
button = QPushButton( widget )
button.setText( buttonText )
button.pressed.connect( slot )
widget.layout().addWidget( button )
self.iface.messageBar().pushWidget( widget, level=self.levelList.index(type), duration=15 )