generalize to allow multiple event managers in an application

This commit is contained in:
David Rose 2003-02-26 22:28:30 +00:00
parent a71af97bf4
commit 13fa64c33a

View File

@ -8,7 +8,7 @@ class EventManager:
notify = None notify = None
def __init__(self): def __init__(self, eventQueue = None):
""" """
Create a C++ event queue and handler Create a C++ event queue and handler
""" """
@ -16,15 +16,24 @@ class EventManager:
if (EventManager.notify == None): if (EventManager.notify == None):
EventManager.notify = directNotify.newCategory("EventManager") EventManager.notify = directNotify.newCategory("EventManager")
if eventQueue != None:
self.eventQueue = eventQueue
else:
self.eventQueue = EventQueue.getGlobalEventQueue() self.eventQueue = EventQueue.getGlobalEventQueue()
self.eventHandler = EventHandler(self.eventQueue) self.eventHandler = EventHandler(self.eventQueue)
def eventLoop(self, task): def doEvents(self):
""" """
Process all the events on the C++ event queue Process all the events on the C++ event queue
""" """
while (not self.eventQueue.isQueueEmpty()): while (not self.eventQueue.isQueueEmpty()):
self.processEvent(self.eventQueue.dequeueEvent()) self.processEvent(self.eventQueue.dequeueEvent())
def eventLoopTask(self, task):
"""
Process all the events on the C++ event queue
"""
self.doEvents()
return Task.cont return Task.cont
def parseEventParameter(self, eventParameter): def parseEventParameter(self, eventParameter):
@ -73,7 +82,7 @@ class EventManager:
def restart(self): def restart(self):
taskMgr.add(self.eventLoop, 'eventManager') taskMgr.add(self.eventLoopTask, 'eventManager')
def shutdown(self): def shutdown(self):
taskMgr.remove('eventManager') taskMgr.remove('eventManager')