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
精彩评论