ruby-****@sourc*****
ruby-****@sourc*****
2012年 1月 21日 (土) 08:40:31 JST
------------------------- REMOTE_ADDR = 184.145.90.60 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dialog-fichoo ------------------------- @@ -58,7 +58,7 @@ #!/usr/bin/env ruby require 'gtk2' - + # Allow the user to enter a new file name and location for # the file and set the button to the text of the location. def button_clicked (parent, btt) @@ -70,29 +70,32 @@ [ Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL ], [ Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT ] ) - dialog.run do |response| - if response == Gtk::Dialog::RESPONSE_ACCEPT - filename = dialog.filename - btt.label = filename + dialog.signal_connect('response') do |w, r| + odg = case r + when Gtk::Dialog::RESPONSE_ACCEPT + filename = dialog.filename + btt.label = filename + "'ACCEPT' (#{r}) button pressed -- filename is {{ #{filename} }}" + when Gtk::Dialog::RESPONSE_CANCEL; "'CANCEL' (#{r}) button pressed" + else; "Undefined response ID; perhaps Close-x? (#{r})" end + puts odg + dialog.destroy end - dialog.destroy + dialog.run end - - window = Gtk::Window.new + + window = Gtk::Window.new("Save a File") window.border_width = 10 window.set_size_request(200, -1) - window.title = "Save a File" - window.signal_connect('delete_event') { false } window.signal_connect('destroy') { Gtk.main_quit } - + button = Gtk::Button.new("Save As ...") button.signal_connect('clicked') { button_clicked(window, button) } - + window.add(button) window.show_all Gtk.main - == Creating a Folder