[gnome-devel-docs] tutorials python: example of togglebutton with a spinner



commit 8b58dee96aba5049a623ebdc6a56bb38c429a5d8
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Wed May 23 17:02:56 2012 +0100

    tutorials python: example of togglebutton with a spinner

 platform-demos/C/samples/checkbutton.py  |    8 ++--
 platform-demos/C/samples/togglebutton.py |   52 ++++++++++++++++++++++++++++++
 platform-demos/C/togglebutton.py.page    |   33 +++++++++++++++++++
 3 files changed, 89 insertions(+), 4 deletions(-)
---
diff --git a/platform-demos/C/samples/checkbutton.py b/platform-demos/C/samples/checkbutton.py
index 8df66c9..e82f918 100644
--- a/platform-demos/C/samples/checkbutton.py
+++ b/platform-demos/C/samples/checkbutton.py
@@ -8,13 +8,13 @@ class MyWindow(Gtk.ApplicationWindow):
         Gtk.Window.__init__(self, title="CheckButton Example", application=app)
         self.set_default_size(300, 100)
         self.set_border_width(10)
-        
+
         # a new checkbutton with a label, connected with the callback
         button = Gtk.CheckButton.new_with_label("Show Title")
         button.connect("toggled", self.toggled_cb)
         # default: is active
         button.set_active(True)
-        
+
         self.add(button)
 
     # the button operates on the window
@@ -23,11 +23,11 @@ class MyWindow(Gtk.ApplicationWindow):
             self.set_title("CheckButton Example")
         else:
             self.set_title("")
-            
+
 class MyApplication(Gtk.Application):
     def __init__(self):
         Gtk.Application.__init__(self, application_id="org.gtk.example.grid")
-        
+
     def do_activate(self):
         win = MyWindow(self)
         win.show_all()
diff --git a/platform-demos/C/samples/togglebutton.py b/platform-demos/C/samples/togglebutton.py
new file mode 100644
index 0000000..531672f
--- /dev/null
+++ b/platform-demos/C/samples/togglebutton.py
@@ -0,0 +1,52 @@
+from gi.repository import GLib
+from gi.repository import Gtk
+from gi.repository import Gio
+import sys
+
+class MyWindow(Gtk.ApplicationWindow):
+    def __init__(self, app):
+        Gtk.Window.__init__(self, title="ToggleButton Example", application=app)
+        self.set_default_size(300, 300)
+        self.set_border_width(30)
+
+        # a spinner animation, with extra horizontal and vertical space
+        spinner = Gtk.Spinner()
+        spinner.set_hexpand(True)
+        spinner.set_vexpand(True)
+        # we keep a reference to the spinner inside the class (we need it later)
+        self.spinner = spinner
+
+        # a togglebutton
+        button = Gtk.ToggleButton.new_with_label("Start/Stop")
+        button.connect("toggled", self.toggled_cb)
+
+        # a grid to allocate the widgets
+        grid = Gtk.Grid()
+        grid.set_row_homogeneous(False);
+        grid.set_row_spacing(15);
+        grid.attach(spinner, 0, 0, 1, 1);
+        grid.attach(button, 0, 1, 1, 1);
+
+        self.add(grid)
+
+    # the button operates on the window
+    def toggled_cb(self, button):
+        if button.get_active():
+            self.spinner.start()
+        else:
+            self.spinner.stop()
+
+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/togglebutton.py.page b/platform-demos/C/togglebutton.py.page
new file mode 100644
index 0000000..ba3d3ec
--- /dev/null
+++ b/platform-demos/C/togglebutton.py.page
@@ -0,0 +1,33 @@
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="togglebutton.py">
+  <info>
+    <link type="guide" xref="beginner.py#buttons"/>
+    <link type="seealso" xref="grid.py"/>
+
+    <revision version="0.1" date="2012-05-23" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Marta Maria Casetti</name>
+      <email>mmcasetti gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A button which retains state</desc>
+  </info>
+
+  <title>ToggleButton</title>
+  <media type="image" mime="image/png" src="media/togglebutton.png"/>
+  <p>When this ToggleButton is in an active state, the spinner spins.</p>
+
+<code mime="text/x-python" style="numbered"><xi:include href="samples/togglebutton.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/GtkToggleButton.html";>GtkToggleButton</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkWidget.html";>GtkWidget</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkSpinner.html";>GtkSpinner</link></p></item>
+</list>
+</page>



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