30 lines
746 B
Python
30 lines
746 B
Python
|
global eventHandlers
|
||
|
eventHandlers = {}
|
||
|
|
||
|
global addEventHandler
|
||
|
def addEventHandler(event,handler):
|
||
|
if not event in eventHandlers: eventHandlers[event] = []
|
||
|
try:
|
||
|
eventHandlers[event].remove(handler)
|
||
|
except:
|
||
|
pass
|
||
|
eventHandlers[event].append(handler)
|
||
|
|
||
|
global removeEventHandler
|
||
|
def removeEventHandler(event,handler):
|
||
|
if not event in eventHandlers: return
|
||
|
try:
|
||
|
eventHandlers[event].remove(handler)
|
||
|
except:
|
||
|
pass
|
||
|
if len(eventHandlers[event]) == 0:
|
||
|
del eventHandlers[event]
|
||
|
|
||
|
global triggerEvent
|
||
|
def triggerEvent(event,*args,eEnv=False,**kwargs):
|
||
|
if not eEnv: eEnv = {}
|
||
|
if not event in eventHandlers: return
|
||
|
for func in eventHandlers[event]:
|
||
|
result = func(event,eEnv,*args,**kwargs)
|
||
|
if result == False: return False
|
||
|
return True
|