mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
generalize to allow multiple event managers in an application
This commit is contained in:
parent
a71af97bf4
commit
13fa64c33a
@ -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")
|
||||||
|
|
||||||
self.eventQueue = EventQueue.getGlobalEventQueue()
|
if eventQueue != None:
|
||||||
|
self.eventQueue = eventQueue
|
||||||
|
else:
|
||||||
|
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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user