[Sugar-devel] Help Request - Python Timer

Art Hunkins abhunkin at uncg.edu
Tue Jan 25 20:58:05 EST 2011


I'd like help to create a timer in my activity.

The following code works fine. A callback button alternately selects START 
and STOP options in playcsd() (only crucial lines of code are included):

import csndsugui
from timeit import Timer

self.p = False

def playcsd(self, widget):
   if self.p == False:
     self.p = True
     self.but.child.set_label("STOP !")
   else:
     self.p = False
     self.but.child.set_label("START !")

self.but = self.w.cbbutton(self.b7, self.playcsd, "START !")


I need to add timer code that will call playcsd() after a specified time 
period (here, 30 seconds), as an option to pressing the callback button. I 
thought the following added code should work, but it doesn't. No errors are 
reported, but the desired switch to START (call to playcsd() with self.p == 
True) doesn't happen either. (The code follows immediately the last line 
above):

if self.p == True:
   self.t = Timer(30.0, self.playcsd(self.but))
   self.t = start()


Art Hunkins 



More information about the Sugar-devel mailing list