[gnome-devel-docs] tutorials python: example of switch button



commit 4ab257c918e3a5e347ffc3c4b498c47afd36bff9
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Thu May 24 12:17:00 2012 +0100

    tutorials python: example of switch button

 platform-demos/C/samples/switch.py |   49 ++++++++++++++++++++++++++++++++++++
 platform-demos/C/switch.py.page    |   37 +++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/samples/switch.py b/platform-demos/C/samples/switch.py
new file mode 100644
index 0000000..54edc34
--- /dev/null
+++ b/platform-demos/C/samples/switch.py
@@ -0,0 +1,49 @@
+from gi.repository import GLib
+from gi.repository import Gtk
+import sys
+
+class MyWindow(Gtk.ApplicationWindow):
+    def __init__(self, app):
+        Gtk.Window.__init__(self, title="Switch Example", application=app)
+        self.set_default_size(300, 100)
+        self.set_border_width(10)
+
+        # a switch, turned on by default, sends the signal notify::active
+        switcher = Gtk.Switch()
+        switcher.set_active(True)
+        switcher.connect("notify::active", self.activate_cb)
+
+        # a label
+        label = Gtk.Label()
+        label.set_text("Title")
+
+        # a grid to allocate the widgets
+        grid = Gtk.Grid()
+        grid.set_column_spacing (10);
+        grid.attach (label, 0, 0, 1, 1);
+        grid.attach (switcher, 1, 0, 1, 1);
+
+        self.add(grid)
+
+    # the switch operates on the title of the window. Since the signal is
+    # notify::active we need the argument 'active'
+    def activate_cb(self, button, active):
+        if button.get_active():
+            self.set_title("Switch Example")
+        else:
+            self.set_title("")
+
+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/switch.py.page b/platform-demos/C/switch.py.page
new file mode 100644
index 0000000..19b00f0
--- /dev/null
+++ b/platform-demos/C/switch.py.page
@@ -0,0 +1,37 @@
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="switch.py">
+  <info>
+    <link type="guide" xref="beginner.py#buttons"/>
+    <link type="seealso" xref="checkbutton.py"/>
+    <link type="seealso" xref="label.py"/>
+    <link type="seealso" xref="grid.py"/>
+
+    <revision version="0.1" date="2012-05-24" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Marta Maria Casetti</name>
+      <email>mmcasetti gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A "light switch" style toggle</desc>
+  </info>
+
+  <title>Switch</title>
+  <media type="image" mime="image/png" style="floatend" src="media/switch_off.png"/>
+  <media type="image" mime="image/png" src="media/switch_on.png"/>
+
+  <p>This Switch makes the title appears and disappear.</p>
+
+<code mime="text/x-python" style="numbered"><xi:include href="samples/switch.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/GtkSwitch.html";>GtkSwitch</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkLabel.html";>GtkLabel</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkGrid.html";>GtkGrid</link></p></item>
+</list>
+</page>



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