import wx """ Animator """ class Anim(object): """ Myltiple instances of these get added to an instance of Animator. """ def __init__(self, count, stepFunc, args=[]): self.stepF = stepFunc self.count = count # how meny time to step self.args = args # arguments to step function class Animator(object): """ @win - usualy app @rate - integer ms @syncFunc - a parameter less function calld every tick of the counter. """ def __init__(self, win, rate, syncFunc): self.win = win self.rate = rate self.runList = [] #run all these every tick self.syncF = syncFunc self.id = wx.NewId() self.timer = wx.Timer(win, self.id) self.win.Bind(wx.EVT_TIMER, self.Update, id=self.id) def Add(self, steps, func, args=[]): item = Anim(steps, func, args) self.runList.append(item) def Update(self, evt): wx.CallAfter(self.Next) def Next(self): """ """ print 'Next' sync = False for next in self.runList: next.count -= 1 print next.count if next.count > 0: next.stepF(*next.args) sync = True if sync: print 'sync' self.syncF() # call sync after all step functions else: print 'stop' self.timer.Stop() #self.win.Unbind(wx.EVT_TIMER, id=self.id) def Start(self): print self.rate self.timer.Start(self.rate) # ~ test code loaded into py.shell ~ counter = 100 def step(txt): global counter counter -= 1 print txt def sync(): print 'sync' an = Animator(app,500,sync) an.Add(5, step, ['test A']) an.Add(10, step, ['test B']) an.Start()