# HG changeset patch # User wycc # Date 1293174028 -28800 # Node ID 5cfa73d7e80f07a47a10f130f72c5429cd9f1b5c # Parent e14ec6d1a66170e92b9614866042222bf6eeb367 Add the Run button to simulate the animation diff -r e14ec6d1a661 -r 5cfa73d7e80f pyink/MBScene.py --- a/pyink/MBScene.py Fri Dec 24 14:44:07 2010 +0800 +++ b/pyink/MBScene.py Fri Dec 24 15:00:28 2010 +0800 @@ -136,6 +136,8 @@ self.tween=None self.document = None self.dom = None + self.framerate=12 + self.maxframe=0 pass def show_selection(self,w,obj): @@ -199,13 +201,15 @@ traceback.print_exc() continue try: - end = s.getAttribute("end") + end = int(s.getAttribute("end")) if end == None: end = start pass except: end = start pass + if end > self.maxframe: + self.maxframe = end try: typ = s.getAttribute('type') if typ == None: @@ -796,10 +800,23 @@ hbox.pack_start(self.editDone,expand=False,fill=False) self.editDone.connect('clicked', self.changeObjectLabel) - def doRun(self): + def doRun(self,arg): """ Execute the current animation till the last frame. """ + if self.btnRun.get_label() == "Run": + self.btnRun.set_label("Stop") + self.last_update = glib.timeout_add(1000/self.framerate,self.doRunNext) + else: + self.btnRun.set_label("Run") + glib.source_remove(self.last_update) + + def doRunNext(self): + if self.current >= self.maxframe: + self.current = 0 + print self.current,self.maxframe + self.setCurrentScene(self.current+1) + self.last_update = glib.timeout_add(1000/self.framerate,self.doRunNext) def addButtons(self,hbox): @@ -820,6 +837,7 @@ hbox.pack_start(btn,expand=False,fill=False) btn=gtk.Button('Run') btn.connect('clicked', self.doRun) + self.btnRun = btn hbox.pack_start(btn,expand=False,fill=False) self.addNameEditor(hbox) self.addTweenTypeSelector(hbox)