tags:

views:

384

answers:

2

I need to perform some actions periodically on my GTK Ruby program and i am looking for the working example of using gobject.timeout_add() function.

A: 

I have found this solution, but I am not sure:

class MainWin 
   def initialize() 
     @window = Gtk::Window::new 
     .... 
     periodic 
   end 

   def periodic 
     do_something 
     Glib::Timeout.add(100) { periodic } 
   end
 end
demas
+1  A: 

Hi, here is a short example showing a timeout each second that prints the message foo. The true at the end of the timeout block means that you don't want to remove the timeout. Return false when you want the timeout to stop firing.

require 'glib2'

GLib::Timeout.add(1000) do 
  puts "foo"      
  true
end

mainloop = GLib::MainLoop.new
mainloop.run
m5h
Thanks. The true at the end of block is that I needed.
demas