Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@obelisk68
Last active August 4, 2018 01:24
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 obelisk68/70ac4429c0f736ad215758a483f61034 to your computer and use it in GitHub Desktop.
Save obelisk68/70ac4429c0f736ad215758a483f61034 to your computer and use it in GitHub Desktop.
Ruby/GTK+ でちょっと考えた
require 'gtk2'
class GUI < Gtk::Window
Meth = [:wanwan, :nya]
def initialize(&bk)
super("GUI")
set_width_request(200)
box = Gtk::VBox.new
add(box)
@button1 = Gtk::Button.new("イヌ")
@button2 = Gtk::Button.new("ネコ")
label1 = Gtk::Label.new("吾輩はイヌである")
label2 = Gtk::Label.new("吾輩はネコである")
[@button1, label1, @button2, label2].each do |wd|
box.pack_start(wd, true, true, 5)
end
signal_connect("destroy") {Gtk.main_quit}
@meth = {}
instance_eval(&bk)
[@button1, @button2].zip(Meth).each do |bt|
bt[0].signal_connect("clicked", &@meth[bt[1]])
end
show_all
Gtk.main
end
Meth.each do |name|
define_method(name) {|&bk| @meth[name] = bk}
end
end
GUI.new do
wanwan do
puts "わんわん"
md = Gtk::MessageDialog.new(self, Gtk::Dialog::MODAL,
Gtk::MessageDialog::INFO, Gtk::MessageDialog::BUTTONS_OK, "わんわん")
md.signal_connect("response") {md.destroy}
md.run
end
nya {puts "にゃー"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment