forked from geometalab/ArcGISConnector-QGIS-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
event_handling.py
46 lines (33 loc) · 1.12 KB
/
event_handling.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
from builtins import object
# EVENT TYPES (Static variables / Enum...)
# Defines the event types that exist in the plugin
from PyQt5.QtCore import QObject
LOGIN_SUCCESS = 'Login Success'
# Publisher of events, typically a controller object.
# Apparently inheritance doesn't work in Python 2 so just
# disregard this until
class Publisher(QObject):
event = None
def __init__(self):
QObject.__init__(self)
self.event = Event()
# Add handler to our events
def addEventHandler(self, handler):
self.event.add(handler)
# Events for event handling, especially routing between views.
# 'Handler' is typically the main plugin object, but can be more than one.
class Event(object):
def __init__(self):
self.handlers = []
def add(self, handler):
self.handlers.append(handler)
return self
def remove(self, handler):
self.handlers.remove(handler)
return self
def fire(self, sender, earg=None):
for handler in self.handlers:
handler(sender, earg)
__iadd__ = add
__isub__ = remove
__call__ = fire