[gnome-devel-docs] tutorials python: an example of scales



commit 008e17631580a855a792c32222d0e2851adc8cfd
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Fri May 25 16:21:15 2012 +0100

    tutorials python: an example of scales

 platform-demos/C/media/scale.png  |  Bin 0 -> 7697 bytes
 platform-demos/C/samples/scale.py |   70 +++++++++++++++++++++++++++++++++++++
 platform-demos/C/scale.py.page    |   34 ++++++++++++++++++
 platform-demos/Makefile.am        |    3 ++
 4 files changed, 107 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/media/scale.png b/platform-demos/C/media/scale.png
new file mode 100644
index 0000000..30e6826
Binary files /dev/null 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
new file mode 100644
index 0000000..f4a212b
--- /dev/null
+++ b/platform-demos/C/samples/scale.py
@@ -0,0 +1,70 @@
+from gi.repository import Gtk
+import sys
+
+class MyWindow(Gtk.ApplicationWindow):
+    def __init__(self, app):
+        Gtk.Window.__init__(self, title="Scale Example", application=app)
+        self.set_default_size(400, 300)
+
+        # two adjustments (initial value, min value, max value,
+        # step increment - press cursor keys to see!,
+        # page increment - click around the handle to see!,
+        # page size - not used here)
+        ad1 = Gtk.Adjustment(0, 0, 100, 5, 10, 0)
+        ad2 = Gtk.Adjustment(50, 0, 100, 5, 10, 0)
+
+        # an horizontal scale
+        h_scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=ad1)
+        h_scale.set_digits(0)
+
+        h_scale.connect("value-changed", self.scale_moved)
+
+        # a vertical scale
+        v_scale = Gtk.VScale(adjustment=ad2)
+
+        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 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)
+
+        self.add(grid)
+
+        self.bar = statusbar
+        self.id = context_id
+        self.scale1 = h_scale
+        self.scale2 = v_scale
+
+    # any signal from the keyboard is signaled to the statusbar
+    # onto which we push a new status
+    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()) + ".")
+        return True
+
+class MyApplication(Gtk.Application):
+    def __init__(self):
+        Gtk.Application.__init__(self, application_id="org.example.spinner")
+
+    def do_activate(self):
+        win = MyWindow(self)
+        win.show_all()
+
+    def do_startup(self):
+        Gtk.Application.do_startup(self)
+
+app = MyApplication()
+exit_status = app.run(sys.argv)
+sys.exit(exit_status)
diff --git a/platform-demos/C/scale.py.page b/platform-demos/C/scale.py.page
new file mode 100644
index 0000000..8b33280
--- /dev/null
+++ b/platform-demos/C/scale.py.page
@@ -0,0 +1,34 @@
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="scale.py">
+  <info>
+    <link type="guide" xref="beginner.py#display-widgets"/>
+    <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">
+      <name>Marta Maria Casetti</name>
+      <email>mmcasetti gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A slider widget for selecting a value from a range</desc>
+  </info>
+
+  <title>Scale</title>
+  <media type="image" mime="image/png" src="media/scale.png"/>
+  <p>Slide the scales!</p>
+
+<code mime="text/x-python" style="numbered"><xi:include href="samples/scale.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/GtkScale.html";>GtkScale</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkAdjustment.html";>GtkAdjustment</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/gtk3-Standard-Enumerations.html";>Standard Enumerations</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkStatusbar.html";>GtkStatusbar</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index 2b44a3e..f9b4e63 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -55,6 +55,7 @@ demo_sources = \
 	samples/progressbar.vala		\
 	samples/radiobutton.py			\
 	samples/radiobutton.vala		\
+	samples/scale.py              \
 	samples/spinner.py              \
 	samples/spinner.vala			\
 	samples/statusbar.py			\
@@ -101,6 +102,7 @@ DOC_FIGURES = \
 	media/progressbar.ogv			\
 	media/radiobutton.png			\
 	media/record-collection.png		\
+	media/scale.png			\
 	media/spinner.png			\
 	media/statusbar.png			\
 	media/switch_on.png			\
@@ -181,6 +183,7 @@ DOC_PAGES =				\
 	radiobutton.py.page		\
 	radiobutton.vala.page		\
 	record-collection.js.page	\
+	scale.py.page		        \
 	spinner.py.page		        \
 	spinner.vala.page		\
 	statusbar.py.page		\



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