[gnome-devel-docs] tutorials python: a better scale example



commit b5fc72553ffa7ed7b5c8f1d53dc8e8929aa374e2
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Mon May 28 21:13:14 2012 +0100

    tutorials python: a better scale example

 platform-demos/C/media/scale.png  |  Bin 7697 -> 9431 bytes
 platform-demos/C/samples/scale.py |   29 +++++++++++++++--------------
 platform-demos/C/scale.py.page    |    1 -
 3 files changed, 15 insertions(+), 15 deletions(-)
---
diff --git a/platform-demos/C/media/scale.png b/platform-demos/C/media/scale.png
index 30e6826..8e1448c 100644
Binary files a/platform-demos/C/media/scale.png and b/platform-demos/C/media/scale.png differ
diff --git a/platform-demos/C/samples/scale.py b/platform-demos/C/samples/scale.py
index 86f1e05..aa2c242 100644
--- a/platform-demos/C/samples/scale.py
+++ b/platform-demos/C/samples/scale.py
@@ -5,6 +5,7 @@ class MyWindow(Gtk.ApplicationWindow):
     def __init__(self, app):
         Gtk.Window.__init__(self, title="Scale Example", application=app)
         self.set_default_size(400, 300)
+        self.set_border_width(5)
 
         # two adjustments (initial value, min value, max value,
         # step increment - press cursor keys to see!,
@@ -16,42 +17,42 @@ class MyWindow(Gtk.ApplicationWindow):
         # an horizontal scale
         h_scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=ad1)
         h_scale.set_digits(0)
+        # that can expand horizontally if there is space in the grid (see below)
+        h_scale.set_hexpand(True)
+        # that is aligned at the top of the space allowed in the grid (see below)
+        h_scale.set_valign(Gtk.Align.START)
 
         h_scale.connect("value-changed", self.scale_moved)
 
         # a vertical scale
         v_scale = Gtk.Scale(orientation=Gtk.Orientation.VERTICAL, adjustment=ad2)
+        # that can expand vertically if there is space in the grid (see below)
+        v_scale.set_vexpand(True)
 
         v_scale.connect("value-changed", self.scale_moved)
 
-        # the statusbar (the context_id is not shown in the UI but it is needed)
-        statusbar = Gtk.Statusbar()
-        context_id = statusbar.get_context_id("example")
-        # pushed a new message onto the statusbar's stack
-        statusbar.push(context_id, "Move around the scales...")
+        # a label
+        label = Gtk.Label()
+        label.set_text("Move around the scales...")
 
         # a grid to attach the widgets
         grid = Gtk.Grid()
         grid.set_column_spacing(10)
         grid.set_column_homogeneous(True)
-        grid.set_row_homogeneous(True)
         grid.attach(h_scale, 1, 1, 1, 1)
         grid.attach_next_to(v_scale, h_scale, Gtk.PositionType.RIGHT, 1, 1)
-        grid.attach(statusbar, 1, 2, 2, 1)
+        grid.attach(label, 1, 2, 2, 1)
 
         self.add(grid)
 
-        self.bar = statusbar
-        self.id = context_id
+        self.label = label
         self.scale1 = h_scale
         self.scale2 = v_scale
 
-    # any signal from the scales is signaled to the statusbar
-    # onto which we push a new status
+    # any signal from the scales is signaled to the label the text of which is changed
     def scale_moved(self, event):
-        self.bar.push(self.id,
-                      "Horizontal scale is " + str(int(self.scale1.get_value())) +
-                      "; vertical scale is " + str(self.scale2.get_value()) + ".")
+        self.label.set_text("Horizontal scale is " + str(int(self.scale1.get_value())) +
+                            "; vertical scale is " + str(self.scale2.get_value()) + ".")
         return True
 
 class MyApplication(Gtk.Application):
diff --git a/platform-demos/C/scale.py.page b/platform-demos/C/scale.py.page
index 8e0d0a8..766557f 100644
--- a/platform-demos/C/scale.py.page
+++ b/platform-demos/C/scale.py.page
@@ -5,7 +5,6 @@
   <info>
     <link type="guide" xref="beginner.py#entry"/>
     <link type="seealso" xref="grid.py"/>
-    <link type="seealso" xref="statusbar.py"/>
     <revision version="0.1" date="2012-05-25" status="draft"/>
 
     <credit type="author copyright">



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