Skip to content
Snippets Groups Projects
Commit 7e6a9574 authored by Nicolas Mansard's avatar Nicolas Mansard
Browse files

Added the ALWAYS timer in attime.

parent fbcb0c47
No related branches found
No related tags found
No related merge requests found
class attimeAlways:
None
ALWAYS = attimeAlways()
class attimeStop:
None
STOP = attimeStop()
class Calendar:
def __init__(self):
self.events=dict()
self.ping = list()
#self.periodic=list()
def __repr__(self):
res=''
# for iter in sort(self.events.keys()):
for iter,funpairs in sorted( self.events.iteritems() ):
res += str(iter)+": \n"
# funpairs=self.events[iter]
for funpair in funpairs:
if funpair[1]=='': res+=funpair[0]+'\n'
else: res += str(funpair[1])+'\n'
return res
def stop(self,*args): self.registerEvents(STOP,*args)
def registerEvent( self,iter,pairfundoc ):
#if iter==ALWAYS:
# self.periodic.append(pairfundoc)
# return
if iter==STOP:
self.events[ALWAYS].remove(pairfundoc)
if not iter in self.events.keys(): self.events[iter] = list()
self.events[iter].append(pairfundoc)
......@@ -22,7 +36,8 @@ class Calendar:
3 entry types are possible: 1. only the functor. 2. a pair
(functor,doc). 3. a list of pairs (functor,doc).
'''
if len(funs)==2 and callable(funs[0]) and isinstance( funs[1],str ): self.registerEvent(iter, ( funs[0],funs[1] ) )
if len(funs)==2 and callable(funs[0]) and isinstance( funs[1],str ):
self.registerEvent(iter, ( funs[0],funs[1] ) )
else:
for fun in funs:
if isinstance( fun,tuple ):
......@@ -36,7 +51,10 @@ class Calendar:
def callPing(self):
for f in self.ping: f()
def run(self,iter,*args):
if iter in self.events.keys():
if ALWAYS in self.events:
for fun,doc in self.events[ALWAYS]:
fun(*args)
if iter in self.events:
self.callPing()
for fun,doc in self.events[iter]:
intro = "At time "+str(iter)+": "
......@@ -60,10 +78,10 @@ class Calendar:
calendarRef=self
fun=None
def __init__(selfdeco,functer):
if functer.__doc__!=None:
if len(functer.__doc__)>0:
selfdeco.__doc__ = functer.__doc__
selfdeco.__doc__ += " (will be run at time "+str(selfdeco.iterRef)+")"
if functer.__doc__==None: functer.__doc__ = "No doc fun"
if len(functer.__doc__)>0:
selfdeco.__doc__ = functer.__doc__
selfdeco.__doc__ += " (will be run at time "+str(selfdeco.iterRef)+")"
selfdeco.fun=functer
selfdeco.calendarRef.registerEvents(selfdeco.iterRef,functer,functer.__doc__)
def __call__(selfdeco,*args):
......@@ -74,3 +92,7 @@ class Calendar:
for i in range(t+1): self.run(i)
attime=Calendar()
sigset = ( lambda s,v : s.__class__.value.__set__(s,v) )
refset = ( lambda mt,v : mt.__class__.ref.__set__(mt,v) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment