[ruby-gnome2-doc-cvs] [Ruby-GNOME2 Project Website] update - tut-gtk2-mnstbs-popup

アーカイブの一覧に戻る

ruby-****@sourc***** ruby-****@sourc*****
2012年 10月 23日 (火) 07:46:27 JST


-------------------------
REMOTE_ADDR = 184.145.49.94
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-popup
-------------------------
@@ -21,7 +21,28 @@
 
 For most widgets you will need to create your own pop-up menu. In this section you are going to learn how to supply a pop-up menu to a Gtk::ProgressBar widget. You can see the pop-up menu we are going to implement in the picture on the right.
 
-In the example three pop-up menu items are used to pulse the progress bar, set it as 100 percent complete, and to clear it. You will notice that the progress bar is contained in an event box. This is because like a Gtk::Label, which we made click-able way back in this tutorial, is not capable of intercepting GDK events by itself. Let's look at the program: 
+In the example three pop-up menu items are used to pulse the progress bar, set it as 100 percent complete, and to clear it. You will notice that the progress bar is contained in an event box. This is because the Gtk::ProgressBar widget, just like the Gtk::Label, which in chapter 3 in section called ((<Event Boxes|tut-gtk2-contwidg-eventbox>)) we made click-able, is not capable of intercepting GDK events by itself. 
+
+{{image_right("dialog-warning.png")}}
+:Surprise - Progress Bar in Ruby, can be made event sensitive?!
+
+    API documentation for Gtk::Widget#event= tells us that for the widgets which do not have Gtk::Widget::NO_WINDOW flag set, you should be able to specify which events you wish the widget would respond to by using either Gtk::Widget#event= or Gtk::Widget#add_events(events) instance methods. The following code segment:
+
+     # Gtk::Widget#flags reveals Gtk::Widget#GtkWidgetFlags
+     if progress.flags & Gtk::Widget::NO_WINDOW
+       puts "#{progress.class} does not contain Gdk::Window"
+     end
+
+    will confirm that Gtg::ProgressBar is a widget which does not provide its own Gdk::Window (see: GTK::Widget#GtkWidgetFlags). Nevertheless, as of Ruby 1.9.3 (October 2012), the following still works:
+
+     progress.add_events(Gdk::Event::BUTTON_PRESS_MASK)
+     progress.signal_connect("button_press_event") do |widget, event|
+       if (event.button == 3)
+         menu.popup(nil, nil, event.button, event.time)
+       end	
+     end
+
+In our example program we chose the traditional approach reflecting the fact that for widgets incapable of responding to desired events we supply the Even Box. Let's look at the program: 
 
 
 {{br}}




ruby-gnome2-cvs メーリングリストの案内
アーカイブの一覧に戻る