[Sugar-devel] Fw: Help Request - Python Timer

Art Hunkins abhunkin at uncg.edu
Tue Feb 1 21:29:04 EST 2011


Still having trouble with a timer in Python.

Can anyone come up with a couple of lines of Python code that will let me 
know when an already-playing csd has finished, so I can call something else?

(I assume it will call the Csound Python API; and, FWIW, csndsugui is 
available.)

Art Hunkins

----- Original Message ----- 
From: "Art Hunkins" <abhunkin at uncg.edu>
To: <Sugar-devel at lists.sugarlabs.org>
Sent: Tuesday, January 25, 2011 8:58 PM
Subject: Help Request - Python Timer


> 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