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



commit f0a1c90c57466293b84f31dcb49a5d4365ba71d0
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Mon May 28 21:30:52 2012 +0100

    tutorials python: a better spinbutton example

 platform-demos/C/media/spinbutton.png  |  Bin 6172 -> 5222 bytes
 platform-demos/C/samples/spinbutton.py |   25 +++++++++++--------------
 platform-demos/C/spinbutton.py.page    |    3 +--
 3 files changed, 12 insertions(+), 16 deletions(-)
---
diff --git a/platform-demos/C/media/spinbutton.png b/platform-demos/C/media/spinbutton.png
index 500b5a5..514c530 100644
Binary files a/platform-demos/C/media/spinbutton.png and b/platform-demos/C/media/spinbutton.png differ
diff --git a/platform-demos/C/samples/spinbutton.py b/platform-demos/C/samples/spinbutton.py
index 568ff91..f4d59d3 100644
--- a/platform-demos/C/samples/spinbutton.py
+++ b/platform-demos/C/samples/spinbutton.py
@@ -4,7 +4,8 @@ import sys
 class MyWindow(Gtk.ApplicationWindow):
     def __init__(self, app):
         Gtk.Window.__init__(self, title="SpinButton Example", application=app)
-        self.set_default_size(200, 150)
+        self.set_default_size(210, 70)
+        self.set_border_width(5)
 
         # an adjustment (initial value, min value, max value,
         # step increment - press cursor keys or +/- buttons to see!,
@@ -14,32 +15,28 @@ class MyWindow(Gtk.ApplicationWindow):
 
         # a spin button for integers (digits=0)
         spin = Gtk.SpinButton(adjustment=ad, climb_rate=1, digits=0)
+        # as wide as possible
+        spin.set_hexpand(True)
 
         spin.connect("value-changed", self.spin_selected)
 
-        # 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")
-        # a new message onto the statusbar's stack
-        statusbar.push(context_id, "Give me a number...")
+        # a label
+        label = Gtk.Label()
+        label.set_text("Choose a number")
 
         # a grid to attach the widgets
         grid = Gtk.Grid()
-        grid.set_row_homogeneous(True)
         grid.attach(spin, 1, 1, 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.spin = spin
 
-    # the signal of the spinbutton is signaled to the statusbar
-    # onto which we push a new status
+    # the signal of the spinbutton is signaled to the label the text of which is changed
     def spin_selected(self, event):
-        self.bar.push(self.id,
-                      "The number you selected is " + str(self.spin.get_value_as_int()) + ".")
+        self.label.set_text("The number you selected is " + str(self.spin.get_value_as_int()) + ".")
         return True
 
 class MyApplication(Gtk.Application):
diff --git a/platform-demos/C/spinbutton.py.page b/platform-demos/C/spinbutton.py.page
index 9b6f47d..3782a01 100644
--- a/platform-demos/C/spinbutton.py.page
+++ b/platform-demos/C/spinbutton.py.page
@@ -5,8 +5,7 @@
   <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"/>
+    <revision version="0.1" date="2012-05-28" status="draft"/>
 
     <credit type="author copyright">
       <name>Marta Maria Casetti</name>



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