开发者

gobject.timeout_add example

I need to perform some actions periodically on my GTK Ruby program and i am looking for the working example of using gobjec开发者_运维百科t.timeout_add() function.


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜