fhttpy/modules/events.py

30 lines
746 B
Python
Raw Normal View History

2022-02-14 21:43:12 +00:00
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