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

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2009年 2月 26日 (木) 04:27:47 JST


-------------------------
REMOTE_ADDR = 74.15.84.244
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-dynmc
-------------------------
@@ -40,21 +40,9 @@
  <menuitem name="FileOpen" action="Open"/>
  <menuitem name="FileOpen" action="Open"></menuitem>
 
-The ((*action*)) attribute is is applied to all elements except top-level widgets and separators. When loading the UI file to associate a Gtk::Action object to each element, Gtk::UIManager uses the action attributes. Gtk::Action object holds information about how the item is drawn and what callback function should be called, if any, when the item is activated.
+The ((*action*)) attribute is applied to all elements except top-level widgets and separators. When loading the UI file to associate a Gtk::Action object to each element, Gtk::UIManager uses the action attributes. There exists a relationship between this "action" attribute and Gtk::Action and  Gtk::ActionGroup objects. Most important for us here is how the attributes of Gtk::Action objects (name, stock id, label, accelerator, tool-tip, and callbacks) are initialized and shared with our application. (We will talk about this after we look at the UI files and see the example ruby program using them.)
 
-:Gtk::Action properties:
-    If you look at the code in our example program (uimanager.rb) after our discussion of the ui-files, you will notice that we need to provide a two dimensional array of objects to the Gtk::ActionGroup:
 
-     group.add_actions(entries)
-
-    where each row in ((*entries*)) contains the following objects: 
-    * name,
-    * stock id,
-    * label with mnemonics,
-    * accelerator, 
-    * tool-tip,
-    * callback (Proc object)
-
 Separators can be placed in a menu with the <separator/> tag. You do not need to provide name or action information for separators. Upon encountering <separator/> tag Gtk::UIManager will insert a generic Gtk::SeparatorMenuItem.
 
 In addition to menu bars, you create toolbars in a UI file with the <toolbar> tag:
@@ -79,7 +67,-5 @@
 
 Each toolbar can contain any number of <toolitem> elements. Tool items are specified in the same manner as menu items, with an "action" and an optional "name" attributes. The same names can be used for <toolitem> elements in separate UI files, but names should be uniquely defined if you build both toolbar and menu bar in the same UI file.
 
-However you can use the same "action" for multiple elements. This will cause the elements to be drawn in the same way and to be connected to the same callback proc. For example the same "action" will be used for the "Cut" element in either "menu.ui" and "toolbar.ui" files.
+However you can use the same "action" for multiple elements. This will cause the elements to be drawn in the same way and to be connected to the same callback proc. For example the same "action" will be used for the "Cut" element in either "menu.ui" and "toolbar.ui" files in our example application (uimanager.rb).
 
 In addition to toolbars and menu bars, it is possible to define pop-up menus in a UI file. Notice that there are repeated  actions in all of the above UI files. Repeating actions allows you to define only a single Gtk::Action object for multiple instances of an "action".
 
@@ -98,7 +86,-5 @@
 
 
 :Note:
-    While the toolbar, menu bar and pop-up menu in our example are split into separate UI files, yo can include as many of these widgets as you like in one file. The only requirement is that the whole file content is contained within the <ui> and </ui> tag.
+    While the toolbar, menu bar and pop-up menu in our example are split into separate UI files, you can include as many of these widgets as you like in one file. The only requirement is that the whole file content is contained within the <ui> and </ui> tag.
 
 
 == Loading UI Files
@@ -136,9 +124,-3 @@
  help      = Proc.new { puts "help" }
  about     = Proc.new { puts "about" }
 
- # label,        Stock_id,          Short label, accelerator, tooltip,    callback
+ # name,        stock_id,           label,    accelerator,  tool-tip,   callback
  entries = [
-   ["File",      nil,              "_File",      nil,         nil,        nil],
+   ["File",      nil,              "_File",      nil,         nil,        nil ],
    ["Open",      Gtk::Stock::OPEN,  nil, nil, "Open an existing file", open],
    ["Save",      Gtk::Stock::SAVE,  nil, nil, "Save the document to a file", save],
    ["Quit",      Gtk::Stock::QUIT,  nil, nil, "Quit the application", quit],
@@ -184,6 +172,31 @@
  window.add(vbox)
  window.show_all
  Gtk.main
+
+The first thing you need to do when using Gtk::UIMamager to dynamically load menus and toolbars is to create an array of actions. Though it is possible to manually create every Gtk::Action, Gtk::ToggleAction, or Gtk::RadioAction object, but there is a much easier way with Gtk::ActionGroup#add_actions(entries). The ((*entries*)) argument is a two dimensional array containing rows of Gtk::Action properties. Gtk::Action object holds information about how a menu or toolbar item is drawn and what callback function should be called, if any, when the item is activated.
+
+:Gtk::Action properties:
+    If you look at the code in our example program (uimanager.rb)  you will notice that we need to provide a two dimensional array of objects to the Gtk::ActionGroup. we do this as follows:
+
+     group.add_actions(entries)
+
+    where each row in ((*entries*)) contains the following objects: 
+    * name,
+    * stock id,
+    * label with mnemonics,
+    * accelerator - (a string understood by: Gtk::Accelerator.parse(accelerator))
+    * tool-tip
+    * callback proc object
+
+At this point it would be beneficial to look at the API for Gtk::ActionGroup#add_actions, where the array we just discussed is mentioned explicitly and individual elements explained:
+
+
+--- add_actions(entries)
+
+    This is a convenience method to create a number of actions and add them to the action group. 
+    The "activate" signals of the actions are connected to the procs and their accel paths are set to <Actions>/group-name/action-name.
+    * entries: [[name, stock_id, label, accelerator, tooltip, proc], ... ]: an array of action descriptions
+       * name: The name of the action. 
+       * stock_id: The stock id(the constant value of Gtk::Stock) for the action.
+       * label: The label for the action. This field should typically be marked for translation, see Gtk::ActionGroup#translation_domain=. 
+       * accelerator: The accelerator for the action, in the format understood by Gtk::Accelerator.parse.
+       * tooltip: The tooltip for the action. This field should typically be marked for translation, see Gtk::ActionGroup#translation_domain=. 
+       * proc: The proc object to call when the action is activated. The proc takes 2 parameters. 1st parameter is Gtk::ActionGroup, and 2nd one is Gtk::Action. 
+               (e.g.) prc = Proc.new {|actiongroup, action| ... }
+    * Returns: self
+
+
+
+
+
 
 
 




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