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

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2012年 10月 26日 (金) 04:29:30 JST


-------------------------
REMOTE_ADDR = 184.145.49.94
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-statb
-------------------------
@@ -3,7 +3,7 @@
 
 == Status Bar Hints
 
-Usually placed along the bottom of the window, the Gtk::StatusBar widget can be used to give the user further information about what is going on in the application. A status bar can also be very useful with menus, because you can provide more information to the user about the functionality of the menu item that the mouse cursor is hovering over.
+Usually placed along the bottom of the window, the Gtk::Statusbar widget can be used to give the user further information about what is going on in the application. A status bar can also be very useful with menus, because you can provide more information to the user about the functionality of the menu item that the mouse cursor is hovering over.
 
 === The Status Bar Widget
 
@@ -11,7 +11,7 @@
 
 === Status Bar Context and Message Identifiers
 
-A new status bar widget is created with Gtk::StatusBar.new. Newly created status bar will have empty message stack. Before you are able add or remove a message to or from the new status bar's stack, you must retrieve a context identifier ((*(context_id)*)) with Gtk::StatusBar#get_context_id(context_description). The API documentation may help you see how this associations are related:
+A new status bar widget is created with Gtk::Statusbar.new. Newly created status bar will have empty message stack. Before you are able add or remove a message to or from the new status bar's stack, you must retrieve a context identifier ((*(context_id)*)) with Gtk::Statusbar#get_context_id(context_description). The API documentation may help you see how this associations are related:
 
 --- get_context_id(context_description)
 
@@ -32,7 +32,7 @@
 
 --- pop(context_id)
 
-    Removes the message at the top of a Gtk::StatusBar's stack.
+    Removes the message at the top of a Gtk::Statusbar's stack.
     * context_id : a context identifier.  
     * Returns: self
 
@@ -57,7 +57,9 @@
 {{br}}
 ((*statbhints.rb*))
 
+
  #!/usr/bin/env ruby
+ 
  require 'gtk2'
  
  def statusbar_hint(menui, event, statusbar, hints)
@@ -67,6 +69,10 @@
    else
      statusbar.pop(cntxt_id)
    end
+   return  # Mandatory, if used together with another signal handler that
+           # needs to update screen activity, like browsing menu choices! 
  end
  
  # Create the poup menu with three items and a separator.
@@ -74,10 +78,14 @@
  # user.
  def create_popup_menu(menu, progb, sbar)
    pulse  = Gtk::MenuItem.new("Pulse Progress")
-   separator = Gtk::HSeparator.new
+   separator = Gtk::MenuItem.new
    fill   = Gtk::MenuItem.new("Set as Complete")
    clear  = Gtk::MenuItem.new("_Clear Progress")
-   
+ 
    pulse.name = "pulse"
    fill.name  = "fill"
    clear.name = "clear"
@@ -88,10 +92,14 @@
    }
  
    menu.append(pulse)
-   # menu.append(separator) # <--- should probably work, but it doesn't
+   menu.append(separator)
    menu.append(fill)
    menu.append(clear)
-   
+ 
    pulse.signal_connect('enter_notify_event') { |w, e| statusbar_hint(w, e, sbar, smsgs) }
    fill.signal_connect('enter_notify_event')  { |w, e| statusbar_hint(w, e, sbar, smsgs) }
    clear.signal_connect('enter_notify_event') { |w, e| statusbar_hint(w, e, sbar, smsgs) }
@@ -104,11 +108,10 @@
    fill.signal_connect('activate')  { |w| fill_activated(w, progb) }
    clear.signal_connect('activate') { |w| clear_activated(w, progb) }
  
-   # We do not need this method since there is no detach in our program.
-   # Also the API documentation is rather vague about its usage
-   
- #  menu.attach_to_widget(progb) {|attach_widgt, mnu| puts "detaching" }
-   
    menu.show_all
  end
  
@@ -130,11 +129,9 @@
    progbar.text = "Reset to Zero"
  end
  
- window = Gtk::Window.new(Gtk::Window::TOPLEVEL)
+ window = Gtk::Window.new("Ruby: Status Bar Hints")
  window.resizable = true
- window.title = "Ruby: Status Bar Hints"
  window.border_width = 10
- window.signal_connect('delete_event') { Gtk.main_quit }
+ window.signal_connect('destroy') { Gtk.main_quit }
  window.set_size_request(250, -1)
  
  # Create all of the necessary widgets and initialize the popup menu.
@@ -142,19 +140,15 @@
  eventbox = Gtk::EventBox.new
  progress = Gtk::ProgressBar.new
  progress.text = "Nothing yet happened"
- # progress.pulse              # <-- comment this out and see the diff.
+ progress.pulse
  progress.pulse_step = 0.05
  statusbar = Gtk::Statusbar.new
  
  create_popup_menu(menu, progress, statusbar)
- 
- # gtk_event_box_set_above_child (GTK_EVENT_BOX (eventbox), FALSE);
  
  eventbox = Gtk::EventBox.new
  eventbox.events = Gdk::Event::BUTTON_PRESS_MASK
  eventbox.signal_connect('button_press_event') do |w, event|
    if event.event_type == Gdk::Event::BUTTON_PRESS
-     if event.button == 3   # left mouse button
+     if event.button == 3   # right mouse button
        menu.popup(nil, nil, event.button, event.time)
      end
    end
@@ -169,6 +165,8 @@
  eventbox.realize
  window.show_all
  Gtk.main
+
+
+
+
+
+
 
 
 When implementing status bar hints, you first need to figure out what signals are necessary. We want to be able to add a message to the status bar when the mouse cursor moves over the menu item, and remove it when the cursor leaves. For this scenario the ((*enter-notify-event*)) and ((*leave-notify-event*)) seem like a reasonable choice.




ruby-gnome2-cvs メーリングリストの案内
Back to archive index