[gnome-devel-docs] tutorials python: grid widget rewritten



commit 74bd36df7b44993a6f78173c19023dd4ce23a9c6
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Thu Aug 2 02:47:51 2012 +0100

    tutorials python: grid widget rewritten

 platform-demos/C/grid.py.page          |   55 +++++++++++++++++++++++---------
 platform-demos/C/media/grid_simple.png |  Bin 0 -> 3809 bytes
 platform-demos/C/samples/grid.py       |   35 +++++++++++++-------
 platform-demos/Makefile.am             |    1 +
 4 files changed, 63 insertions(+), 28 deletions(-)
---
diff --git a/platform-demos/C/grid.py.page b/platform-demos/C/grid.py.page
index 981c5da..518fe6c 100644
--- a/platform-demos/C/grid.py.page
+++ b/platform-demos/C/grid.py.page
@@ -6,7 +6,7 @@
   <info>
 	  <link type="guide" xref="beginner.py#layout"/>
 	  <link type="seealso" xref="button.py"/>
-    <revision version="0.1" date="2012-02-21" status="stub"/>
+    <revision version="0.2" date="2012-08-01" status="stub"/>
 
     <credit type="author copyright">
       <name>Tiffany Antopolski</name>
@@ -14,23 +14,48 @@
       <years>2012</years>
     </credit>
 
+    <credit type="author copyright">
+      <name>Marta Maria Casetti</name>
+      <email>mmcasetti gmail com</email>
+      <years>2012</years>
+    </credit>
+
     <desc>Pack widgets in rows and columns</desc>
   </info>
 
   <title>Grid widget</title>
 
-  <media type="image" mime="image/png" src="media/grid.png"/>
-  <p>A button widget connected to a progress bar.</p>
-
-      <code mime="text/javascript" style="numbered">
-<xi:include href="samples/grid.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/GtkApplication.html";>Gtk.Application</link></p></item>
-  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplicationWindow.html";>Gtk.ApplicationWindow</link></p></item>
-  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkGrid.html";>Gtk.Grid</link></p></item>
-  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkProgressBar.html";>Gtk.ProgressBar</link></p></item>
-</list>
+  <media type="image" mime="image/png" src="media/grid_simple.png"/>
+  <p>Some labels in a grid.</p>
+
+  <links type="section" />
+
+  <section id="code">
+    <title>Code used to generate this example</title>
+    <code mime="text/python" style="numbered"><xi:include href="samples/grid.py" parse="text"><xi:fallback/></xi:include></code>
+  </section>
+
+  <section id="methods">
+    <title>Useful methods for a Grid widget</title>
+
+    <list>
+      <item><p>To attach a widget <code>child</code> in position <code>left, top</code> in a slot of given <code>width, height</code> use <code>attach(child, top, left, width, height)</code>. If a widget <code>sibling<code> is already in place, we can also use <code>attach_next_to(child, sibling, side, width, height)</code>, where <code>side</code> is one of <code>Gtk.PositionType.LEFT, Gtk.PositionType.RIGHT, Gtk.PositionType.TOP, Gtk.PositionType.BOTTOM</p>.</item>
+      <item><p><code>insert_row(position)</code> and <code>insert_column(position)</code> do exactly what they say; children which are attached at or below this position are moved one row down, and children which span across this position are grown to span the new row. <code>insert_next_to(sibling, side)</code> inserts a row or column at the specified position. The new row or column is placed next to <code>sibling</code>, on the side determined by <code>side</code>; if side is <code>Gtk.PositionType.TOP</code> or <code>Gtk.PositionType.BOTTOM</code>, a row is inserted, if side is <code>Gtk.PositionType.LEFT</code> of <code>Gtk.PositionType.RIGHT</code>, a column is inserted.</p></item>
+      <item><p><code>set_row_homogeneous(True)</code> and <code>set_column_homogeneous(True)</code> ensure that (respectively) every row or every column has the same width or height.</p></item>
+      <item><p><code>set_row_spacing(spacing)</code> and <code>set_column_spacing(spacing)</code> force a spacing between (respectively) rows or columns. The value of <code>spacing</code> can be between <code>0</code>, which is the default value, and <code>32767</code></p></item>
+    </list>
+
+  </section>
+
+  <section id="methods">
+    <title>API References</title>
+    <p>In this sample we used the following:</p>
+    <list>
+      <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkApplication.html";>Gtk.Application</link></p></item>
+      <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkApplicationWindow.html";>Gtk.ApplicationWindow</link></p></item>
+      <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkLabel.html";>Gtk.Label</link></p></item>
+      <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkImage.html";>Gtk.Image</link></p></item>
+      <item><p><link href="http://developer.gnome.org/gtk3/unstable/GtkGrid.html";>Gtk.Grid</link></p></item>
+    </list>
+  </section>
 </page>
diff --git a/platform-demos/C/media/grid_simple.png b/platform-demos/C/media/grid_simple.png
new file mode 100644
index 0000000..22fd8bc
Binary files /dev/null and b/platform-demos/C/media/grid_simple.png differ
diff --git a/platform-demos/C/samples/grid.py b/platform-demos/C/samples/grid.py
index 206fc75..70a7217 100644
--- a/platform-demos/C/samples/grid.py
+++ b/platform-demos/C/samples/grid.py
@@ -1,31 +1,40 @@
 from gi.repository import Gtk
 import sys
 
-class GridWindow(Gtk.ApplicationWindow):
+class MyWindow(Gtk.ApplicationWindow):
     def __init__(self, app):
         Gtk.Window.__init__(self, title="Grid Example", application=app)
 
+        # three labels
+        label_top_left = Gtk.Label(label="This is Top Left")
+        label_top_right = Gtk.Label(label="This is Top Right")
+        label_bottom = Gtk.Label(label="This is Bottom")
+
+        # a grid
         grid = Gtk.Grid()
-        button = Gtk.Button(label="Button")
 
-        self.add(grid)
-        grid.attach(button, 1, 1, 1, 1)
-        self.progress_bar = Gtk.ProgressBar()
-        grid.attach_next_to(self.progress_bar, button, 3, 1, 1)
+        # some space between the columns of the grid
+        grid.set_column_spacing(20)
 
-        button.connect("clicked", self.button_clicked_cb)
+        # in the grid:
+        # attach the first label in the top left corner
+        grid.attach(label_top_left, 0, 0, 1, 1)
+        # attach the second label
+        grid.attach(label_top_right, 1, 0, 1, 1)
+        # attach the third label below the first label
+        grid.attach_next_to(label_bottom, label_top_left, Gtk.PositionType.BOTTOM, 2, 1)
 
-    def button_clicked_cb(self, widget):
-        self.progress_bar.pulse()
+        # add the grid to the window
+        self.add(grid)
 
-class GridApplication(Gtk.Application):
+class MyApplication(Gtk.Application):
     def __init__(self):
-        Gtk.Application.__init__(self, application_id="org.gtk.example.grid")
+        Gtk.Application.__init__(self)
 
     def do_activate(self):
-        win = GridWindow(self)
+        win = MyWindow(self)
         win.show_all()
 
-app = GridApplication()
+app = MyApplication()
 exit_status = app.run(sys.argv)
 sys.exit(exit_status)
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index 5882c0a..a700895 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -169,6 +169,7 @@ DOC_FIGURES = \
 	media/gmenu.py.png			\
 	media/gmenu.vala.png			\
 	media/grid.png				\
+	media/grid_simple.png				\
 	media/guitar-tuner.png			\
 	media/guitar-tuner-glade.png		\
 	media/guitar-tuner-pipeline.png		\



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