[gnome-devel-docs] tutorials python: comboboxes and toolbars pages and samples



commit d1a5c104879468c2165d74127a7dbb626a275578
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Sat Jul 21 12:53:13 2012 +0100

    tutorials python: comboboxes and toolbars pages and samples

 platform-demos/C/samples/combobox.py             |   20 ++-
 platform-demos/C/samples/combobox_multicolumn.py |   26 ++--
 platform-demos/C/samples/toolbar.py              |   39 ++++-
 platform-demos/C/samples/toolbar_builder.py      |  100 +++++++++++
 platform-demos/C/toolbar.py.page                 |   48 ++++--
 platform-demos/C/toolbar_builder.py.page         |  201 ++++++++++++++++++++++
 platform-demos/Makefile.am                       |    2 +
 7 files changed, 393 insertions(+), 43 deletions(-)
---
diff --git a/platform-demos/C/samples/combobox.py b/platform-demos/C/samples/combobox.py
index 4d81736..b08a89e 100644
--- a/platform-demos/C/samples/combobox.py
+++ b/platform-demos/C/samples/combobox.py
@@ -11,28 +11,30 @@ class MyWindow(Gtk.ApplicationWindow):
 
         # the data in the model, of type string
         listmodel = Gtk.ListStore(str)
-        # there is no insert_with_values in Python, we use append to
+        # append the data in the model
         for i in range(len(distros)):
             listmodel.append(distros[i])
 
         # a combobox to see the data stored in the model
         combobox = Gtk.ComboBox(model=listmodel)
 
-        # a cellrenderer
+        # a cellrenderer to render the text
         cell = Gtk.CellRendererText()
-        # packs the cell into the beginning of the combobox, allocating
-        # (False) no more space than needed
+
+        # pack the cell into the beginning of the combobox, allocating
+        # no more space than needed
         combobox.pack_start(cell, False)
-        # there is no set_attributes() in Python
-        # associates a property ("text") of the cellrenderer (cell) to a column (column 0)
+        # associate a property ("text") of the cellrenderer (cell) to a column (column 0)
         # in the model used by the combobox
         combobox.add_attribute(cell, "text", 0)
-        # the first row is the active one
+
+        # the first row is the active one by default at the beginning
         combobox.set_active(0)
 
-        # when a row is selected, emit a signal
+        # connect the signal emitted when a row is selected to the callback function
         combobox.connect("changed", self.on_changed)
 
+        # add the combobox to the window
         self.add(combobox)
 
     def on_changed(self, combo):
@@ -44,7 +46,7 @@ class MyWindow(Gtk.ApplicationWindow):
 
 class MyApplication(Gtk.Application):
     def __init__(self):
-        Gtk.Application.__init__(self, application_id="org.example.combobox")
+        Gtk.Application.__init__(self)
 
     def do_activate(self):
         win = MyWindow(self)
diff --git a/platform-demos/C/samples/combobox_multicolumn.py b/platform-demos/C/samples/combobox_multicolumn.py
index 2e59fcd..63f2765 100644
--- a/platform-demos/C/samples/combobox_multicolumn.py
+++ b/platform-demos/C/samples/combobox_multicolumn.py
@@ -12,42 +12,44 @@ class MyWindow(Gtk.ApplicationWindow):
         self.set_default_size(200, -1)
         self.set_border_width(10)
 
-        # the data in the model, of type string
+        # the data in the model, of type string on two columns
         listmodel = Gtk.ListStore(str, str)
-        # there is no insert_with_values in Python, we use append
+        # append the data
         for i in range(len(actions)):
             listmodel.append(actions[i])
 
         # a combobox to see the data stored in the model
         combobox = Gtk.ComboBox(model=listmodel)
 
-        # cellrenderers
+        # cellrenderers to render the data
         renderer_pixbuf = Gtk.CellRendererPixbuf()
         renderer_text = Gtk.CellRendererText()
-        # we pack the cell into the beginning of the combobox, allocating
-        # (False) no more space than needed
 
-        # first the image, then the text
-        # it does not matter in which order they are in the model,
+        # we pack the cell into the beginning of the combobox, allocating
+        # no more space than needed;
+        # first the image, then the text;
+        # note that it does not matter in which order they are in the model,
         # the visualization is decided by the order of the cellrenderers
         combobox.pack_start(renderer_pixbuf, False)
         combobox.pack_start(renderer_text, False)
 
-        # there is no set_attributes() in Python
-        # associates a property of the cellrenderer to a column in the model
+        # associate a property of the cellrenderer to a column in the model
         # used by the combobox
         combobox.add_attribute(renderer_text, "text", 0)
         combobox.add_attribute(renderer_pixbuf, "stock_id", 1)
-        # the first row is the active one
+
+        # the first row is the active one at the beginning
         combobox.set_active(0)
 
-        # when a row is selected, emit a signal
+        # connect the signal emitted when a row is selected to the callback function
         combobox.connect("changed", self.on_changed)
 
+        # add the combobox to the window
         self.add(combobox)
 
     def on_changed(self, combo):
         # if the row selected is not the first one, write on the terminal
+        # the value of the first column in the model
         if combo.get_active() != 0:
 			print "You chose " + str(actions[combo.get_active()][0]) +"\n"
         return True
@@ -55,7 +57,7 @@ class MyWindow(Gtk.ApplicationWindow):
 
 class MyApplication(Gtk.Application):
     def __init__(self):
-        Gtk.Application.__init__(self, application_id="org.example.combobox_multicolumn")
+        Gtk.Application.__init__(self)
 
     def do_activate(self):
         win = MyWindow(self)
diff --git a/platform-demos/C/samples/toolbar.py b/platform-demos/C/samples/toolbar.py
index a225d55..c673d7e 100644
--- a/platform-demos/C/samples/toolbar.py
+++ b/platform-demos/C/samples/toolbar.py
@@ -8,32 +8,44 @@ class MyWindow(Gtk.ApplicationWindow):
         Gtk.Window.__init__(self, title="Toolbar Example", application=app)
         self.set_default_size(400, 200)
 
-        # a grid to attach the toolbar created in the method create_toolbar (see below)
+        # a grid to attach the toolbar
         grid = Gtk.Grid()
+
+        # a toolbar created in the method create_toolbar (see below)
         toolbar = self.create_toolbar()
+        # with extra horizontal space
         toolbar.set_hexpand(True)
+        # show the toolbar
         toolbar.show()
+
+        # attach the toolbar to the grid
         grid.attach(toolbar, 0, 0, 1, 1)
+
+        # add the grid to the window
         self.add(grid)
 
         # create the actions that control the window and connect their signal to a
-        # callback method (see below)
+        # callback method (see below):
+
+        # undo
         undo_action = Gio.SimpleAction.new("undo", None)
         undo_action.connect("activate", self.undo_callback)
         self.add_action(undo_action)
 
+        # fullscreen
         fullscreen_action = Gio.SimpleAction.new("fullscreen", None)
         fullscreen_action.connect("activate", self.fullscreen_callback)
         self.add_action(fullscreen_action)
 
-
+    # a method to create the toolbar
     def create_toolbar(self):
+        # a toolbar
         toolbar = Gtk.Toolbar()
 
-        # set this as the primary toolbar of the application
+        # which is the primary toolbar of the application
         toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
 
-        # create a button with a stock image
+        # create a button for the "new" action, with a stock image
         new_button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_NEW)
         # label is shown
         new_button.set_is_important(True)
@@ -45,28 +57,34 @@ class MyWindow(Gtk.ApplicationWindow):
         # The action controls the application (app)
         new_button.set_action_name("app.new")
 
+        # button for the "open" action
         open_button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_OPEN)
         open_button.set_is_important(True)
         toolbar.insert(open_button, 1)
         open_button.show()
         open_button.set_action_name("app.open")
 
+        # button for the "undo" action
         undo_button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_UNDO)
         undo_button.set_is_important(True)
         toolbar.insert(undo_button, 2)
         undo_button.show()
         undo_button.set_action_name("win.undo")
 
+        # button for the "fullscreen/leave fullscreen" action
         self.fullscreen_button = Gtk.ToolButton.new_from_stock(Gtk.STOCK_FULLSCREEN)
         self.fullscreen_button.set_is_important(True)
         toolbar.insert(self.fullscreen_button, 3)
         self.fullscreen_button.set_action_name("win.fullscreen")
 
+        # return the complete toolbar
         return toolbar
 
+    # callback method for undo
     def undo_callback(self, action, parameter):
         print "You clicked \"Undo\"."
 
+    # callback method for fullscreen / leave fullscreen
     def fullscreen_callback(self, action, parameter):
         # check if the state is the same as Gdk.WindowState.FULLSCREEN, which is a bit flag
         is_fullscreen = self.get_window().get_state() & Gdk.WindowState.FULLSCREEN != 0
@@ -79,7 +97,7 @@ class MyWindow(Gtk.ApplicationWindow):
 
 class MyApplication(Gtk.Application):
     def __init__(self):
-        Gtk.Application.__init__(self, application_id="org.example.toolbar")
+        Gtk.Application.__init__(self)
 
     def do_activate(self):
         win = MyWindow(self)
@@ -88,19 +106,24 @@ class MyApplication(Gtk.Application):
     def do_startup(self):
         Gtk.Application.do_startup(self)
 
-        # actions that control the application...
+        # create the actions that control the window and connect their signal to a
+        # callback method (see below):
+
+        # new
         new_action = Gio.SimpleAction.new("new", None)
         new_action.connect("activate", self.new_callback)
         app.add_action(new_action)
 
+        # open
         open_action = Gio.SimpleAction.new("open", None)
         open_action.connect("activate", self.open_callback)
         app.add_action(open_action)
 
-    # ... and their callback methods
+    # callback method for new
     def new_callback(self, action, parameter):
         print "You clicked \"New\"."
 
+    # callback method for open
     def open_callback(self, action, parameter):
         print "You clicked \"Open\"."
 
diff --git a/platform-demos/C/samples/toolbar_builder.py b/platform-demos/C/samples/toolbar_builder.py
new file mode 100644
index 0000000..1984315
--- /dev/null
+++ b/platform-demos/C/samples/toolbar_builder.py
@@ -0,0 +1,100 @@
+from gi.repository import Gtk
+from gi.repository import Gdk
+from gi.repository import Gio
+import sys
+
+class MyWindow(Gtk.ApplicationWindow):
+    def __init__(self, app):
+        Gtk.Window.__init__(self, title="Toolbar Example", application=app)
+        self.set_default_size(400, 200)
+
+        # a grid to attach the toolbar (see below)
+        grid = Gtk.Grid()
+        self.add(grid)
+        # we have to show the grid (and therefore the toolbar) with show(),
+        # as show_all() would show also the buttons in the toolbar that we want to
+        # be hidden (such as the leave_fullscreen button)
+        grid.show()
+
+        # a builder to add the UI designed with Glade to the grid:
+        builder = Gtk.Builder()
+        # get the file (if it is there)
+        try:
+            builder.add_from_file("toolbar_builder.ui")
+        except:
+            print "file not found"
+            sys.exit()
+        # and attach it to the grid
+        grid.attach(builder.get_object("toolbar"), 0, 0, 1, 1)
+
+        # two buttons that will be used later in a method
+        self.fullscreen_button = builder.get_object("fullscreen_button")
+        self.leave_fullscreen_button = builder.get_object("leave_fullscreen_button")
+
+        # create the actions that control the window, connect their signal to a
+        # callback method (see below), add the action to the window:
+
+        # undo
+        undo_action = Gio.SimpleAction.new("undo", None)
+        undo_action.connect("activate", self.undo_callback)
+        self.add_action(undo_action)
+
+        # and fullscreen
+        fullscreen_action = Gio.SimpleAction.new("fullscreen", None)
+        fullscreen_action.connect("activate", self.fullscreen_callback)
+        self.add_action(fullscreen_action)
+
+    # callback for undo
+    def undo_callback(self, action, parameter):
+        print "You clicked \"Undo\"."
+
+    # callback for fullscreen
+    def fullscreen_callback(self, action, parameter):
+        # check if the state is the same as Gdk.WindowState.FULLSCREEN, which is a bit flag
+        is_fullscreen = self.get_window().get_state() & Gdk.WindowState.FULLSCREEN != 0
+        if is_fullscreen:
+            self.unfullscreen()
+            self.leave_fullscreen_button.hide()
+            self.fullscreen_button.show()
+        else:
+            self.fullscreen()
+            self.fullscreen_button.hide()
+            self.leave_fullscreen_button.show()
+
+class MyApplication(Gtk.Application):
+    def __init__(self):
+        Gtk.Application.__init__(self)
+
+    def do_activate(self):
+        win = MyWindow(self)
+        # show the window - with show() not show_all() because that would show also
+        # the leave_fullscreen button
+        win.show()
+
+    def do_startup(self):
+        Gtk.Application.do_startup(self)
+
+        # actions that control the application: create, connect their signal to a
+        # callback method (see below), add the action to the application
+
+        # new
+        new_action = Gio.SimpleAction.new("new", None)
+        new_action.connect("activate", self.new_callback)
+        app.add_action(new_action)
+
+        # open
+        open_action = Gio.SimpleAction.new("open", None)
+        open_action.connect("activate", self.open_callback)
+        app.add_action(open_action)
+
+    # callback for new
+    def new_callback(self, action, parameter):
+        print "You clicked \"New\"."
+
+    # callback for open
+    def open_callback(self, action, parameter):
+        print "You clicked \"Open\"."
+
+app = MyApplication()
+exit_status = app.run(sys.argv)
+sys.exit(exit_status)
diff --git a/platform-demos/C/toolbar.py.page b/platform-demos/C/toolbar.py.page
index 3314c17..b6562b6 100644
--- a/platform-demos/C/toolbar.py.page
+++ b/platform-demos/C/toolbar.py.page
@@ -22,19 +22,39 @@
   <media type="image" mime="image/png" src="media/toolbar.png"/>
   <p>An example of toolbar with buttons (from stock icons).</p>
 
-<code mime="text/x-python" style="numbered"><xi:include href="samples/toolbar.py" parse="text"><xi:fallback/></xi:include></code>
-
-<p>
-  In this sample we used the following:
-</p>
-<list>
-  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkToolbar.html";>GtkToolbar</link></p></item>
-  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkToolButton.html";>GtkToolButton</link></p></item>
-  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkToolItem.html";>GtkToolItem</link></p></item>
-  <item><p><link href="http://developer.gnome.org/gtk3/3.4/gtk3-Stock-Items.html";>Stock Items</link></p></item>
-  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkActionable.html";>GtkActionable</link></p></item>
-  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWidget.html";>GtkWidget</link></p></item>
-  <item><p><link href="http://developer.gnome.org/gdk3/3.4/gdk3-Event-Structures.html";>Event Structures</link></p></item>
-</list>
+  <links type="section" />
 
+  <section id="code">
+    <title>Code used to generate this example</title>
+
+    <code mime="text/x-python" style="numbered"><xi:include href="samples/toolbar.py" parse="text"><xi:fallback/></xi:include></code>
+  </section>
+
+  <section id="methods">
+    <title>Useful methods for a Toolbar widget</title>
+
+    <list>
+      <item><p>Use <code>insert(tool_item, position)</code> to insert the <code>tool_item</code> at <code>position</code>. If <code>position</code> is negative, the item is appended at the end of the toolbar.</p></item>
+      <item><p><code>get_item_index(tool_item)</code> retrieves the position of <code>tool_item</code> on the toolbar.</p></item>
+      <item><p><code>get_n_items()</code> returns the number of items on the toolbar; <code>get_nth_item(position)</code> returns the item in position <code>position</code>.</p></item>
+      <item>If the toolbar does not have room for all the menu items, and <code>set_show_arrow(True)</code>, the items that do not have room are shown through an overflow menu.</item>
+      <item><code>set_icon_size(icon_size)</code> sets the size of icons in the toolbar; <code>icon_size</code> can be one of <code>Gtk.IconSize.INVALID, Gtk.IconSize.MENU, Gtk.IconSize.SMALL_TOOLBAR, Gtk.IconSize.LARGE_TOOLBAR, Gtk.IconSize.BUTTON, Gtk.IconSize.DND, Gtk.IconSize.DIALOG</code>. This should be used only for special-purpose toolbars, normal application toolbars should respect user preferences for the size of icons. <code>unset_icon_size()</code> unsets the preferences set with <code>set_icon_size(icon_size)</code>, so that user preferences will be used to determine the icon size.</item>
+      <item><p><code>set_style(style)</code>, where <code>style</code> is one of <code>Gtk.ToolbarStyle.ICONS, Gtk.ToolbarStyle.TEXT, Gtk.ToolbarStyle.BOTH, Gtk.ToolbarStyle.BOTH_HORIZ</code>, sets if the toolbar shows only icons, only text, or both (vertically stacked or alongside each other). To let user preferences determine the toolbar style, and unset a toolbar style so set, use <code>unset_style()</code>.</p></item>
+    </list>
+
+  </section>
+
+  <section id="reference">
+    <title>API References</title>
+    <p>In this sample we used the following:</p>
+    <list>
+      <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkToolbar.html";>GtkToolbar</link></p></item>
+      <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkToolButton.html";>GtkToolButton</link></p></item>
+      <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkToolItem.html";>GtkToolItem</link></p></item>
+      <item><p><link href="http://developer.gnome.org/gtk3/3.4/gtk3-Stock-Items.html";>Stock Items</link></p></item>
+      <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkActionable.html";>GtkActionable</link></p></item>
+      <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWidget.html";>GtkWidget</link></p></item>
+      <item><p><link href="http://developer.gnome.org/gdk3/3.4/gdk3-Event-Structures.html#GdkEventWindowState";>Event Structures</link></p></item>
+    </list>
+  </section>
 </page>
diff --git a/platform-demos/C/toolbar_builder.py.page b/platform-demos/C/toolbar_builder.py.page
new file mode 100644
index 0000000..98a34cb
--- /dev/null
+++ b/platform-demos/C/toolbar_builder.py.page
@@ -0,0 +1,201 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="toolbar_builder.py">
+  <info>
+    <link type="guide" xref="beginner.py#menu-combo-toolbar"/>
+    <link type="seealso" xref="toolbar.py"/>
+    <link type="seealso" xref="grid.py"/>
+    <revision version="0.1" date="2012-07-17" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Tiffany Antopolski</name>
+      <email>tiffany antopolski gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <credit type="author copyright edit">
+      <name>Marta Maria Casetti</name>
+      <email>mmcasetti gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <credit type="author copyright">
+      <name>Sebastian P&#246;lsterl</name>
+      <email>sebp k-d-w org</email>
+      <years>2011</years>
+    </credit>
+
+    <desc>A bar of buttons and other widgets</desc>
+  </info>
+
+  <title>Toolbar created using Glade</title>
+
+  <media type="image" mime="image/png" src="media/toolbar.png"/>
+  <p>This example is similar to <link xref="toolbar.py"/>, except we use Glade to create the toolbar in an XML .ui file.</p>
+
+<links type="sections" />
+
+<section id="glade">
+<title>Creating the toolbar with Glade</title>
+  <p>
+  To create the toolbar using the <link href="http://glade.gnome.org/";>Glade Interface Designer</link>:
+  </p>
+  <steps>
+    <item><p>Open Glade, and save the file as <file>toolbar_builder.ui</file></p>
+          <p><media type="image" src="media/glade_ui.png" width="900">
+              Screenshot of Glade ui
+           </media></p>
+    </item>
+
+    <item><p>Under <gui>Containers</gui> on the left hand side, right click on the toolbar icon and select <gui>Add widget as toplevel</gui>.</p>
+          <p><media type="image" src="media/glade_select_toolbar.png">
+           Screenshot of toolbar icon in Glade ui
+          </media></p>
+    </item>
+
+    <item><p>Under the <gui>General</gui> tab on the bottom right, change the <gui>Name</gui> to <input>toolbar</input> and <gui>Show Arrow</gui> to <gui>No</gui>.</p>
+          <p><media type="image" src="media/glade_toolbar_general.png">
+             Screenshot of General tab
+          </media></p>
+    </item>
+
+    <item><p>Under the <gui>Common</gui> tab, set <gui>Horizontal Expand</gui> to <gui>Yes</gui>.</p>
+         <p><media type="image" src="media/glade_toolbar_common.png">
+              Screenshot of Common tab
+          </media></p>
+     </item>
+
+     <item><p>Right click on the toolbar in the top right and select <gui>Edit</gui>.  The <gui>Tool Bar Editor</gui> window will appear.</p>
+         <p><media type="image" src="media/glade_toolbar_edit.png">
+             Screenshot of where to right click to edit toolbar.
+          </media></p>
+   </item>
+
+   <item><p>We want to add 5 ToolButtons: New, Open, Undo, Fullscreen and Leave Fullscreen.  First, we will add the New ToolButton.
+     </p>
+     <steps>
+       <item><p>Under <gui>Hierarchy</gui> tab, click <gui>Add</gui>.</p></item>
+       <item><p>Change the name of the ToolItem to <input>new_button</input>.</p></item>
+       <item><p>Scroll down and set <gui>Is important</gui> to <gui>Yes</gui>.  This will cause the label of the ToolButton to be shown, when you view the toolbar.</p></item>
+       <item><p>Enter the <gui>action name</gui>: <input>app.new</input>.</p></item>
+       <item><p>Change the <gui>Label</gui> to <input>New</input>.</p></item>
+       <item><p>Select the <gui>New</gui> Stock Id from the drop down menu, or type <input>gtk-new</input>.</p></item>
+     </steps>
+     <p>
+    Repeat the above steps for the remaining ToolButtons, with the following properties:
+  </p>
+  <table frame="all" rules="rows">
+    <thead>
+      <tr>
+        <td><p>Name</p></td>
+        <td><p>Is important</p></td>
+        <td><p>action name</p></td>
+        <td><p>Label</p></td>
+        <td><p>Stock Id</p></td>
+      </tr>
+    </thead>
+    <tbody>
+    <tr>
+      <td><p>open_button</p></td>
+      <td><p>Yes</p></td>
+      <td><p>app.open</p></td>
+      <td><p>Open</p></td>
+      <td><p>gtk-open</p></td>
+    </tr>
+    <tr>
+      <td><p>undo_button</p></td>
+      <td><p>Yes</p></td>
+      <td><p>win.undo</p></td>
+      <td><p>Undo</p></td>
+      <td><p>gtk-undo</p></td>
+    </tr>
+    <tr>
+      <td><p>fullscreen_button</p></td>
+      <td><p>Yes</p></td>
+      <td><p>win.fullscreen</p></td>
+      <td><p>Fullscreen</p></td>
+      <td><p>gtk-fullscreen</p></td>
+    </tr>
+    <tr>
+      <td><p>leave_fullscreen_button</p></td>
+      <td><p>Yes</p></td>
+      <td><p>win.fullscreen</p></td>
+      <td><p>Leave Fullscreen</p></td>
+      <td><p>gtk-leave-fullscreen</p></td>
+    </tr>
+    </tbody>
+</table>
+          <media type="image" src="media/glade_toolbar_editor.png">
+
+          </media>
+    </item>
+
+    <item><p>Close the <gui>Tool Bar Editor</gui>.</p>
+   </item>
+
+   <item><p>When our program will first start, we do not want the <gui>Leave Fullscreen</gui> ToolButton to be visible, since the application will not be in fullscreen mode.  You can set this in the <gui>Common</gui> tab, by clicking the <gui>Visible</gui> property to <gui>No</gui>.  The ToolButton will still appear in the interface designer, but will behave correctly when the file is loaded into your program code. Note that the method <code>show_all()</code> would override this setting - so in the code we have to use <code>show()</code> separately on all the elements.</p>
+          <p><media type="image" src="media/glade_visible_no.png">
+                 Setting the visible property to No
+          </media></p>
+   </item>
+
+    <item><p>Save your work, and close Glade.</p>
+   </item>
+
+   <item><p>The XML file created by Glade is shown below. This is the description of the toolbar.  At the time of this writing, the option to add the class Gtk.STYLE_CLASS_PRIMARY_TOOLBAR in the Glade Interface did not exist.  We can manually add this to the XML file.  To do this, add the following XML code at line 9 of <file>toolbar_builder.ui</file>:</p>
+   <code><![CDATA[
+  <style>
+     <class name="primary-toolbar"/>
+  </style>
+  ]]></code>
+  <p>If you do not add this, the program will still work fine.  The resulting toolbar will however look slightly different then the screenshot at the top of this page.</p>
+   </item>
+</steps>
+  <code mime="text" style="numbered"><xi:include href="samples/toolbar_builder.ui" parse="text"><xi:fallback/></xi:include></code>
+
+</section>
+
+<section id="code">
+<title>Code used to generate this example</title>
+
+  <p>We now create the code below, which adds the toolbar from the file we just created.</p>
+<code mime="text/x-python" style="numbered"><xi:include href="samples/toolbar_builder.python" parse="text"><xi:fallback/></xi:include></code>
+
+</section>
+
+<section id="methods">
+<title>Useful methods for Gtk.Builder</title>
+<p>For the useful methods for a Toolbar widget, see <link xref="toolbar.py" /></p>
+
+<p>Gtk.Builder builds an interface from an XML UI definition.</p>
+
+<list>
+<item><p><code>add_from_file(filename)</code> loads and parses the given file and merges it with the current contents of the Gtk.Builder.</p></item>
+<item><p><code>add_from_string(string)</code> parses the given string and merges it with the current contents of the Gtk.Builder.</p></item>
+<item><p><code>add_objects_from_file(filename, object_ids)</code> is the same as <code>add_from_file()</code>, but it loads only the objects with the ids given in the <code>object_id</code>s list.</p></item>
+<item><p><code>add_objects_from_string(filename, object_ids)</code>  is the same as <code>add_from_string()</code>, but it loads only the objects with the ids given in the <code>object_id</code>s list.</p></item>
+<item><p><code>get_object(object_id)</code> retrieves the widget with the id <code>object_id</code> from the loaded objects in the builder.</p></item>
+<item><p><code>get_objects()</code> returns all loaded objects.</p></item>
+<item><p><code>connect_signals(handler_object)</code> connects the signals to the methods given in the <code>handler_object</code>. This can be any object which contains keys or attributes that are called like the signal handler names given in the interface description, e.g. a class or a dict.</p></item>
+</list>
+
+</section>
+
+<section id="references">
+<title>API References</title>
+<p>
+  In this sample we used the following:
+</p>
+<list>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkGrid.html";>GtkGrid</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkBuilder.html";>GtkBuilder</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWidget.html";>GtkWidget</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gdk3/3.4/gdk3-Event-Structures.html#GdkEventWindowState";>Event Structures</link></p></item>
+  <item><p><link href="http://python-gtk-3-tutorial.readthedocs.org/en/latest/builder.html";>The Python Gtk+ 3 Tutorial - Glade and Gtk.Builder</link></p></item>
+</list>
+
+</section>
+
+</page>
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index c0f356a..29e62fd 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -128,6 +128,7 @@ demo_sources = \
 	samples/toolbar.js			\
 	samples/toolbar.py			\
 	samples/toolbar.vala			\
+	samples/toolbar_builder.py		\
 	samples/toolbar_builder.ui		\
 	samples/toolbar_builder.vala		\
 	samples/treeview_advanced_liststore.py	\
@@ -350,6 +351,7 @@ DOC_PAGES =				\
 	toolbar.js.page			\
 	toolbar.py.page			\
 	toolbar.vala.page		\
+	toolbar_builder.py.page	\
 	toolbar_builder.vala.page	\
 	treeview_advanced_liststore.py.page	\
 	treeview_cellrenderertoggle.py.page	\



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]