ruby-****@sourc*****
ruby-****@sourc*****
2012年 10月 28日 (日) 08:20:32 JST
------------------------- REMOTE_ADDR = 74.14.158.59 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-statb ------------------------- @@ -1,6 +1,63 @@ = Menus and Toolbars {{link "tut-gtk2-mnstbs-popup", "tut-gtk2-mnstbs", "tut-gtk", "tut-gtk2-mnstbs-mnui"}} + + +== Status Bar + +Status bar is a widget used to provide information about the application status for the time its user interface is active and displayed to the user. It appears at the bottom of the application window. To start this chapter we will add status bar to our earlier rather simple programs from chapter 3, segment called '((<Tables|tut-gtk2-contwidg-tables>))', to demonstrate how to write a minimal status bar implementation. The program originally demonstrated the use of a Gtk::Table object, into which we placed two labels and an entry widget. The table was then added as the top widget to the main window. We wish to associate the entry object in the table with the status bar, and whenever user moves a cursor into the entry field display the message "Entering text" in the status bar, and removing this message if the user moves mouse cursor out of the entry field. + +To add a status bar widget we need to create a vertical box, and place the table with entry object and the labels above the newly created status bar in it. Finally we need to connect the Gtk::Widget's ((*'enter_notify_event'*))and((*'leave_notify_event'*))signal handlers to the entry object. Let's look at the example program: + +((*simple-statusbar.rb*)) + + #!/usr/bin/env ruby + require 'gtk2' + + table = Gtk::Table.new(rows=2, columns=2, homogeneous=true) + label1 = Gtk::Label.new("Enter the name here ...") + label2 = Gtk::Label.new("Name: ") + name = Gtk::Entry.new + + ## -- Status bar -------------------------------- (start #1) ---------------------- + def show_entry_on_sb(sbar, event) + cid = sbar.get_context_id("StatBarTest") + event.event_type == Gdk::Event::ENTER_NOTIFY + ? sbar.push(cid, "Entering text") : sbar.pop(cid) + return + end + statusbar = Gtk::Statusbar.new + name.signal_connect('enter_notify_event') { |w, e| show_entry_on_sb(statusbar, e) } + name.signal_connect('leave_notify_event') { |w, e| show_entry_on_sb(statusbar, e) } + ## -- Status bar -------------------------------- (end #1) ------------------------ + + table.attach_defaults(label1, left=0, right=2, top=0, bottom=1) + table.attach_defaults(label2, left=0, right=1, top=1, bottom=2) + table.attach_defaults(name, left=1, right=2, top=1, bottom=2) + table.row_spacings = 20 + table.column_spacings = 5 + + vbox = Gtk::VBox.new(false, 5) + vbox.pack_start_defaults(table) + + ## -- Status bar -------------------------------- (start #2) ----- + vbox.pack_start_defaults(statusbar) + ## -- Status bar -------------------------------- (end #2) ------- + + window = Gtk::Window.new("Simpe Status Bar") + window.border_width = 10 + window.set_size_request(250, -1) + window.signal_connect('destroy') { Gtk.main_quit } + window.add(vbox) + window.show_all + Gtk.main + +The above introduction covered the pure mechanics of setting up the status bar, and set the grounds for more detailed study of related issues, which follow. + +{{br}} + + + == Status Bar Hints Usually placed along the bottom of the window, the Gtk::Statusbar widget is used to display the current state in which your application is at any point in time. In addition to this it can also be used to give the user further information about what is going on in the application. This is what we here refer to as instantaneous or temporary((*'status bar hints'.*)) They most often manifest themselves as temporary messages associated to individual menu items explaining their actions, whereby they provide more information to the user about the functionality of the menu item that the mouse cursor is hovering over.