ruby-****@sourc*****
ruby-****@sourc*****
2012年 1月 22日 (日) 03:54:36 JST
------------------------- REMOTE_ADDR = 184.145.90.60 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dialog-fichoo ------------------------- @@ -108,25 +108,35 @@ #!/usr/bin/env ruby require 'gtk2' - - # Create a new GtkFileChooserDialog that will be used - # to create a new folder. - dialog = Gtk::FileChooserDialog.new( + + # Create a new Gtk::FileChooserDialog used to create a new folder. + def create_folder_btt(parent) + dialog = Gtk::FileChooserDialog.new( "Create a Folder ...", nil, Gtk::FileChooser::ACTION_CREATE_FOLDER, nil, [ Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL ], [ Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK ] - ) - dialog.run do |response| - if response == Gtk::Dialog::RESPONSE_OK - filename = dialog.filename - dir = dialog.current_folder - print "Creating directory - [current:%s]; [new:%s]\n" % [dir, filename] + ) + dialog.run do |response| + if response == Gtk::Dialog::RESPONSE_OK + new = dialog.filename + current = dialog.current_folder + print "Creating directory - \n[current:%s]\n[new:%s]\n" % [current, new] + end end + dialog.destroy end - dialog.destroy + + window = Gtk::Window.new("Creating a folder") + window.border_width = 10 + window.set_size_request(200, -1) + window.signal_connect('destroy') { Gtk.main_quit } + button = Gtk::Button.new("Open create folder dialog") + button.signal_connect('clicked') { create_folder_btt(window) } + window.add(button) + window.show_all Gtk.main