mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-05 02:43:37 +00:00
27 lines
703 B
Python
27 lines
703 B
Python
|
class EventHandler(object):
|
||
|
"""
|
||
|
Class to connect events to event handlers.
|
||
|
"""
|
||
|
|
||
|
def __init__(self):
|
||
|
self.handlers = {}
|
||
|
|
||
|
def connect(self, event_name, handler):
|
||
|
"""
|
||
|
Connect an event handler to an event. Append it to handlers list.
|
||
|
"""
|
||
|
try:
|
||
|
self.handlers[event_name].append(handler)
|
||
|
except KeyError:
|
||
|
self.handlers[event_name] = [handler]
|
||
|
|
||
|
def raiseEvent(self, event_name, *args):
|
||
|
"""
|
||
|
Raiser an event: call each handler for this event_name.
|
||
|
"""
|
||
|
if event_name not in self.handlers:
|
||
|
return
|
||
|
for handler in self.handlers[event_name]:
|
||
|
handler(*args)
|
||
|
|