select: listen to multiple events at once

This commit is contained in:
Jeremy Penner 2011-09-21 17:40:54 -04:00
parent c96f0e8698
commit 9bde1fdb76

View file

@ -34,6 +34,33 @@ class Event(TPrs):
if ev in tok.mpevDgoob and tok.mpevDgoob[ev](value): if ev in tok.mpevDgoob and tok.mpevDgoob[ev](value):
raise Event.OobBreakException() raise Event.OobBreakException()
@classmethod
def select(cls, tok, *rgev):
for ev in rgev:
ev.rgtk.append(tok)
chNotify = tok.chEv
fOob = False
while True:
evRcv, value = chNotify.receive()
if evRcv in tok.mpevDgoob:
if tok.mpevDgoob[ev](value):
fOob = True
break
else:
break
for ev in rgev:
if ev != evRcv:
ev.rgtk.remove(tok)
if fOob:
raise Event.OobBreakException()
return evRcv, value
@classmethod
def selectDg(cls, tok, *rgev_dg):
rgev, rgdg = zip(*rgev_dg)
ev, value = cls.select(tok, *rgev)
rgdg[rgev.index(ev)](value)
def fire(self, value = None): def fire(self, value = None):
self.stkValue.append(value) self.stkValue.append(value)
self.game.queueEv.append(self) self.game.queueEv.append(self)