Tk delay

I am somewhat new to Ruby and Tk, I have made a couple of simple
programs, but now I’m working on a Music Automation Program… like for
a Radio Station… something that will play song after song, infinitely.
Right now I need a means to delay the next song for the number of
seconds that the current song is playing. I’ve heard of a Tk::after
method, but I am having trouble understanding how it works.

Any help, links, or examples would be greatly appreciated…

Jesse J. wrote:

Right now I need a means to delay the next song for the number of
seconds that the current song is playing.

I’m using the Snack audio toolkit for ruby, so I already know how long
the song is… I don’t need to constantly check if the song is
playing… I just need to have a block of code run after a set number of
seconds.

On Sun, Apr 4, 2010 at 3:40 AM, Jesse J. [email protected]
wrote:

Jesse J. wrote:

Right now I need a means to delay the next song for the number of
seconds that the current song is playing.

I’m using the Snack audio toolkit for ruby, so I already know how long
the song is… I don’t need to constantly check if the song is
playing… I just need to have a block of code run after a set number of
seconds.

In stdlib Tk:
ruby -rtk -e ‘Tk.after(5000){ puts “hi” }; Tk.mainloop’

In ffi-tk:
ruby -rffi-tk -e ‘Tk::After.ms(5000){ puts “hi” }; Tk.mainloop’

From: Jesse J. [email protected]
Subject: Re: Tk delay
Date: Sun, 4 Apr 2010 03:40:47 +0900
Message-ID: [email protected]

I’m using the Snack audio toolkit for ruby, so I already know how long
the song is… I don’t need to constantly check if the song is
playing… I just need to have a block of code run after a set number of
seconds.

Snack toolkit can call a callback procedure at end of the sound.
Isn’t it enough for your purpose?

I don’t know Snack for Ruby (rbsnack) library.
Even if rbsnack doesn’t support such callback,
you can call the feature of Tcl/Tk from Ruby/Tk
(if your Tcl/Tk can load Snack, and your Ruby/Tk loads the Tcl/Tk’s
libs).

For example,

Michael F. wrote:

On Sun, Apr 4, 2010 at 3:40 AM, Jesse J. [email protected]
wrote:

Jesse J. wrote:

Right now I need a means to delay the next song for the number of
seconds that the current song is playing.

I’m using the Snack audio toolkit for ruby, so I already know how long
the song is… I don’t need to constantly check if the song is
playing… I just need to have a block of code run after a set number of
seconds.

In stdlib Tk:
ruby -rtk -e ‘Tk.after(5000){ puts “hi” }; Tk.mainloop’

In ffi-tk:
ruby -rffi-tk -e ‘Tk::After.ms(5000){ puts “hi” }; Tk.mainloop’

Thanks, this works… but I can’t get it to loop! I’m going to try using
this with a TkTimer widget… but is there perchance a loop option in
this widget as well? Something like TkTimer’s loop?
i.e. ‘TkTimer.start(5000, -1){puts “hi”}’

From: Jesse J. [email protected]
Subject: Re: Tk delay
Date: Mon, 5 Apr 2010 09:52:20 +0900
Message-ID: [email protected]

Thanks, this works… but I can’t get it to loop! I’m going to try using
this with a TkTimer widget… but is there perchance a loop option in
this widget as well? Something like TkTimer’s loop?
i.e. ‘TkTimer.start(5000, -1){puts “hi”}’

interval argument of TkTimer can accept a proc object.
The proc is called when decide the interval time for the next call.
So, the proc must return a milisecond value of integer.

For example,

On Mon, Apr 5, 2010 at 9:52 AM, Jesse J. [email protected]
wrote:

playing… I just need to have a block of code run after a set number of
this widget as well? Something like TkTimer’s loop?
i.e. ‘TkTimer.start(5000, -1){puts “hi”}’

tick = lambda{
puts “hi”
Tk.after(5000, &tick)
}
Tk.after(5000, &tick)

Michael F. wrote:

On Mon, Apr 5, 2010 at 9:52 AM, Jesse J. [email protected]
wrote:

playing… I just need to have a block of code run after a set number of
this widget as well? Something like TkTimer’s loop?
i.e. ‘TkTimer.start(5000, -1){puts “hi”}’

tick = lambda{
puts “hi”
Tk.after(5000, &tick)
}
Tk.after(5000, &tick)

Thanks! Works perfectly!