mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
first rev
This commit is contained in:
parent
716f0f9c20
commit
72dc12698d
39
direct/src/showbase/BulletinBoardWatcher.py
Executable file
39
direct/src/showbase/BulletinBoardWatcher.py
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
from direct.directnotify import DirectNotifyGlobal
|
||||||
|
from direct.showbase.PythonUtil import Functor
|
||||||
|
from direct.showbase import DirectObject
|
||||||
|
|
||||||
|
class BulletinBoardWatcher(DirectObject.DirectObject):
|
||||||
|
"""This class allows you to wait for N posts to be made to the bulletin
|
||||||
|
board, and give you a notification when all posts have been made. Values
|
||||||
|
of posts are not examined."""
|
||||||
|
notify = DirectNotifyGlobal.directNotify.newCategory('BulletinBoardWatcher')
|
||||||
|
|
||||||
|
def __init__(self, name, postNames, callback):
|
||||||
|
self.notify.debug('__init__: %s, %s, %s' % (name, postNames, callback))
|
||||||
|
self.name = name
|
||||||
|
self.postNames = postNames
|
||||||
|
self.callback = callback
|
||||||
|
self.waitingOn = {}
|
||||||
|
for name in postNames:
|
||||||
|
if not bboard.has(name):
|
||||||
|
eventName = bboard.getEventName(name)
|
||||||
|
self.acceptOnce(eventName, Functor(self.handlePost, eventName))
|
||||||
|
self.waitingOn[eventName] = None
|
||||||
|
self.checkDone()
|
||||||
|
|
||||||
|
def destroy(self):
|
||||||
|
self.ignoreAll()
|
||||||
|
|
||||||
|
def isDone(self):
|
||||||
|
return len(self.waitingOn) == 0
|
||||||
|
|
||||||
|
def checkDone(self):
|
||||||
|
if self.isDone():
|
||||||
|
self.notify.debug('%s: done' % self.name)
|
||||||
|
self.callback()
|
||||||
|
|
||||||
|
def handlePost(self, eventName):
|
||||||
|
self.notify.debug('%s: handlePost(%s)' % (self.name, eventName))
|
||||||
|
assert eventName in self.waitingOn
|
||||||
|
del self.waitingOn[eventName]
|
||||||
|
self.checkDone()
|
Loading…
x
Reference in New Issue
Block a user