ruby-****@sourc*****
ruby-****@sourc*****
2012年 11月 5日 (月) 10:48:57 JST
------------------------- REMOTE_ADDR = 184.145.95.170 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-mnui ------------------------- @@ -472,3 +472,70 @@ radio_mi2 = Gtk::RadioMenuItem.new(radio_mi1, "_Click me instead!", true) radio_mi3 = Gtk::RadioMenuItem.new(radio_mi1, "No! Click _me!", true) radio_mi4 = Gtk::RadioMenuItem.new(radio_mi1, "_No! Click me instead!", true) + + + +{{br}} + +{{image_right("misc_menu_items.png")}} + +On the image here on the right, you can see the the UI of the following working program example including the menu items we have not yet seen. + +Let's look at the listing: + +{{br}} +((*other-menu-items.rb*)) + + #!/usr/bin/env ruby + require 'gtk2' + + menu = Gtk::Menu.new + + radio_mi1 = Gtk::RadioMenuItem.new("_I want to be clicked!", true) + radio_mi2 = Gtk::RadioMenuItem.new(radio_mi1, "_Click me instead!", true) + radio_mi3 = Gtk::RadioMenuItem.new(radio_mi1, "No! Click _me!", true) + radio_mi4 = Gtk::RadioMenuItem.new(radio_mi1, "_No! Click me instead!", true) + radio_mi2.active = true + menu = Gtk::Menu.new + menu.append(radio_mi1) + menu.append(radio_mi2) + menu.append(radio_mi3) + menu.append(radio_mi4) + + ckbtt_mi1 = Gtk::CheckMenuItem.new("Check #1", true) + ckbtt_mi2 = Gtk::CheckMenuItem.new("Check #2", true) + # ckbtt_mi1.inconsistent = true # does not work as expected!? + ckbtt_mi2.active = true + menu.append(Gtk::SeparatorMenuItem.new) + menu.append(ckbtt_mi1) + menu.append(ckbtt_mi2) + + imgbtt_mi1 = Gtk::ImageMenuItem.new(Gtk::Stock::CLEAR, accel_group = nil) + imgbtt_mi2 = Gtk::ImageMenuItem.new(Gtk::Stock::HOME, accel_group = nil) + menu.append(Gtk::SeparatorMenuItem.new) + menu.append(imgbtt_mi1) + menu.append(imgbtt_mi2) + + menu.show + menu.show_all + + window = Gtk::Window.new("Other Menu Items") + + # Make window sensitive to Right-mouse-click, to open the pop-up menu. + window.add_events(Gdk::Event::BUTTON_PRESS_MASK) + window.signal_connect("button_press_event") do |widget, event| + menu.popup(nil, nil, event.button, event.time) if (event.button == 3) + end + + # Make window sensitive to <Shift+F10> accelerator keys. These + # accelerator keys generate the 'popup-menu' signal for window, + # which opens the popup-menu. + window.signal_connect("popup_menu") do |w| + menu.popup(nil, nil, 0, Gdk::Event::CURRENT_TIME) + end + + window.set_default_size(250, 100).show_all + window.signal_connect('destroy') { Gtk.main_quit } + window.add(Gtk::Label.new("'Right-click' me to see menus")) + window.show_all + Gtk.main