Ruby GTK Pixbuf timed image change

一曲冷凌霜 提交于 2019-12-06 08:24:27

use GLib.timeout_add () or GLib.timeout_add_seconds (). Return False if you don't want to use it anymore.read GLib documentation, Section: Main Event Loop

This is a solution:

  def start_button__clicked(but)
    @thread = Thread.new { 
      loop do 
        next_button__clicked
        sleep(2) 
      end 
  end

  def stop_button__clicked(but)
    @thread.kill
  end

This is how I would do it in visual ruby. Its basically the same.

You'd just have a form with a button named "start_button" and "stop_button" etc.

the following code is an implementation:

GLib::Timeout.add(1000) do
  pics.nuImage if pics.time
  true
end

pics.window.signal_connect("key_press_event") do |_window, event|
  case event.keyval
  when Gdk::Keyval::GDK_KEY_space
    pics.time = !pics.time
  end
end

more details: http://ruby-gnome2.sourceforge.jp/hiki.cgi?GLib%3A%3ATimeout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!