[gnome-devel-docs] tutorials python: example of spinbutton
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] tutorials python: example of spinbutton
- Date: Sat, 26 May 2012 15:16:00 +0000 (UTC)
commit 991cb51f055836f4344fae34f8fac2cbf8f1aab0
Author: Marta Maria Casetti <mmcasetti gmail com>
Date: Fri May 25 18:00:40 2012 +0100
tutorials python: example of spinbutton
platform-demos/C/media/spinbutton.png | Bin 0 -> 6172 bytes
platform-demos/C/samples/spinbutton.py | 58 ++++++++++++++++++++++++++++++++
platform-demos/C/spinbutton.py.page | 32 +++++++++++++++++
platform-demos/Makefile.am | 3 ++
4 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/media/spinbutton.png b/platform-demos/C/media/spinbutton.png
new file mode 100644
index 0000000..500b5a5
Binary files /dev/null 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
new file mode 100644
index 0000000..568ff91
--- /dev/null
+++ b/platform-demos/C/samples/spinbutton.py
@@ -0,0 +1,58 @@
+from gi.repository import Gtk
+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)
+
+ # an adjustment (initial value, min value, max value,
+ # step increment - press cursor keys or +/- buttons to see!,
+ # page increment - not used here,
+ # page size - not used here)
+ ad = Gtk.Adjustment(0, 0, 100, 1, 10, 0)
+
+ # a spin button for integers (digits=0)
+ spin = Gtk.SpinButton(adjustment=ad, climb_rate=1, digits=0)
+
+ 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 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)
+
+ self.add(grid)
+
+ self.bar = statusbar
+ self.id = context_id
+ self.spin = spin
+
+ # the signal of the spinbutton is signaled to the statusbar
+ # onto which we push a new status
+ def spin_selected(self, event):
+ self.bar.push(self.id,
+ "The number you selected is " + str(self.spin.get_value_as_int()) + ".")
+ 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/spinbutton.py.page b/platform-demos/C/spinbutton.py.page
new file mode 100644
index 0000000..9b6f47d
--- /dev/null
+++ b/platform-demos/C/spinbutton.py.page
@@ -0,0 +1,32 @@
+<page xmlns="http://projectmallard.org/1.0/"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ type="guide" style="task"
+ id="spinbutton.py">
+ <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">
+ <name>Marta Maria Casetti</name>
+ <email>mmcasetti gmail com</email>
+ <years>2012</years>
+ </credit>
+
+ <desc>Retrieve an integer or floating-point number from the user.</desc>
+ </info>
+
+ <title>SpinButton</title>
+ <media type="image" mime="image/png" src="media/spinbutton.png"/>
+ <p>Choose a number, by entering it or by clicking on the -/+ buttons!</p>
+
+<code mime="text/x-python" style="numbered"><xi:include href="samples/spinbutton.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/GtkSpinButton.html">GtkSpinButton</link></p></item>
+ <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkAdjustment.html">GtkAdjustment</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/Makefile.am b/platform-demos/Makefile.am
index f9b4e63..e366c80 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -56,6 +56,7 @@ demo_sources = \
samples/radiobutton.py \
samples/radiobutton.vala \
samples/scale.py \
+ samples/spinbutton.py \
samples/spinner.py \
samples/spinner.vala \
samples/statusbar.py \
@@ -103,6 +104,7 @@ DOC_FIGURES = \
media/radiobutton.png \
media/record-collection.png \
media/scale.png \
+ media/spinbutton.png \
media/spinner.png \
media/statusbar.png \
media/switch_on.png \
@@ -184,6 +186,7 @@ DOC_PAGES = \
radiobutton.vala.page \
record-collection.js.page \
scale.py.page \
+ spinbutton.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]