[gnome-devel-docs] tutorials python: radiobutton example



commit 9a29cefa35639be8a23a40760ba7b0303a0d6362
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Wed May 23 15:59:14 2012 +0100

    tutorials python: radiobutton example

 platform-demos/C/radiobutton.py.page    |   34 ++++++++++++++++++
 platform-demos/C/samples/radiobutton.py |   59 +++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/radiobutton.py.page b/platform-demos/C/radiobutton.py.page
new file mode 100644
index 0000000..b842490
--- /dev/null
+++ b/platform-demos/C/radiobutton.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="radiobutton.py">
+  <info>
+    <link type="guide" xref="beginner.py#buttons"/>
+    <link type="seealso" xref="togglebutton.py"/>
+    <link type="seealso" xref="grid.py"/>
+
+    <revision version="0.1" date="2012-05-09" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Marta Maria Casetti</name>
+      <email>mmcasetti gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>Mutually exclusive buttons.</desc>
+  </info>
+
+  <title>RadioButton</title>
+  <media type="image" mime="image/png" src="media/radiobutton.png"/>
+  <p>Three RadioButtons. You can see in the terminal if they are turned off or on.</p>
+
+<code mime="text/x-python" style="numbered"><xi:include href="samples/radiobutton.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/GtkWindow.html";>GtkWindow</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkGrid.html";>GtkGrid</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkRadioButton.html";>GtkRadioButton</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/samples/radiobutton.py b/platform-demos/C/samples/radiobutton.py
new file mode 100644
index 0000000..0c21793
--- /dev/null
+++ b/platform-demos/C/samples/radiobutton.py
@@ -0,0 +1,59 @@
+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="RadioButton Example", application=app)
+        self.set_default_size(250, 100)
+        self.set_border_width(20)
+
+        # a new checkbutton with a label, connected with the callback
+        button1 = Gtk.RadioButton.new(None)
+        button1.set_label("Button 1")
+        button1.connect("toggled", self.toggled_cb)
+
+        # another way to create a button - in the same group as button1
+        button2 = Gtk.RadioButton.new_from_widget(button1)
+        button2.set_label("Button 2")
+        button2.connect("toggled", self.toggled_cb)
+        button2.set_active(False)
+
+        # yet another way
+        button3 = Gtk.RadioButton.new_with_label_from_widget(button1, "Button 3")
+        button3.connect("toggled", self.toggled_cb)
+        button3.set_active(False)
+
+        # DO NOT use new_with_label, it gives a segmentation fault
+
+        # a grid to place the buttons
+        grid = Gtk.Grid.new()
+        grid.attach(button1, 0, 0, 1, 1);
+        grid.attach(button2, 0, 1, 1, 1);
+        grid.attach(button3, 0, 2, 1, 1);
+
+        self.add(grid)
+
+    def toggled_cb(self, button):
+        state = "unknown"
+        if button.get_active():
+            state = "on"
+        else:
+            state = "off"
+        print button.get_label() + " was turned " + state + "\n"
+
+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()
+
+    def do_startup(self):
+        Gtk.Application.do_startup(self)
+
+app = MyApplication()
+exit_status = app.run(sys.argv)
+sys.exit(exit_status)



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