Tk delay

J

Jesse Jurman

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...
 
J

Jesse Jurman

Jesse said:
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.
 
M

Michael Fellinger

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'
 
H

Hidetoshi NAGAI

From: Jesse Jurman <[email protected]>
Subject: Re: Tk delay
Date: Sun, 4 Apr 2010 03:40:47 +0900
Message-ID: said:
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,
 
J

Jesse Jurman

Michael said:
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"}'
 
M

Michael Fellinger

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"}'

tick = lambda{
puts "hi"
Tk.after(5000, &tick)
}
Tk.after(5000, &tick)
 
H

Hidetoshi NAGAI

From: Jesse Jurman <[email protected]>
Subject: Re: Tk delay
Date: Mon, 5 Apr 2010 09:52:20 +0900
Message-ID: said:
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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top