Skip to content

Instantly share code, notes, and snippets.

@toshia
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toshia/05d5ee302f49677e9d34 to your computer and use it in GitHub Desktop.
Save toshia/05d5ee302f49677e9d34 to your computer and use it in GitHub Desktop.
Ruby2.1.3p242、gtk2 2.2.2では動かないけど2.2.0では動くカウントアップタイマー
# coding: utf-8
#require 'bundler/setup'
require 'gtk2'
window = Gtk::Window.new
w_text = Gtk::Label.new("...")
w_btn = Gtk::Button.new("click")
counter = 0
window.add(Gtk::VBox.new.add(w_text).add(w_btn))
window.set_size_request(320,320)
window.signal_connect(:destroy){ Gtk.main_quit }
w_btn.signal_connect(:clicked){
# w_text.set_text("...")
# counter = 0
true
}
window.show_all
Thread.new do
loop do
sleep 1
counter += 1
w_text.set_text(counter.to_s)
## 最初はこちらのコードで検証してました
# Gtk.idle_add_priority(GLib::PRIORITY_LOW) do
# counter += 1
# w_text.set_text(counter.to_s)
# false
# end
end
end
Gtk.main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment