Mercurial > MadButterfly
diff pyink/MBScene.py @ 1147:5cfa73d7e80f
Add the Run button to simulate the animation
author | wycc |
---|---|
date | Fri, 24 Dec 2010 15:00:28 +0800 |
parents | e14ec6d1a661 |
children | 153a87b4edb7 |
line wrap: on
line diff
--- 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)