[gnome-devel-docs] tutorials python: example of colorbutton in python



commit 4d8e5e3f97fad2d3710ebc8c48c5583559e4a7bc
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Sun Jun 3 17:02:45 2012 +0100

    tutorials python: example of colorbutton in python

 platform-demos/C/colorbutton.py.page    |   32 ++++++++++++++++++
 platform-demos/C/media/colorbutton.png  |  Bin 0 -> 3866 bytes
 platform-demos/C/samples/colorbutton.py |   54 +++++++++++++++++++++++++++++++
 platform-demos/Makefile.am              |    3 ++
 4 files changed, 89 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/colorbutton.py.page b/platform-demos/C/colorbutton.py.page
new file mode 100644
index 0000000..7ba0fac
--- /dev/null
+++ b/platform-demos/C/colorbutton.py.page
@@ -0,0 +1,32 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="colorbutton.py">
+  <info>
+    <link type="guide" xref="beginner.py#color-selectors"/>
+    <revision version="0.1" date="2012-06-03" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Marta Maria Casetti</name>
+      <email>mmcasetti gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A button to launch a color selection dialog</desc>
+  </info>
+
+  <title>ColorButton</title>
+  <media type="image" mime="image/png" src="media/colorbutton.png"/>
+  <p>This ColorButton launches a color selection dialog and prints in the terminal the RGB values of the color selected.</p>
+
+<code mime="text/x-python" style="numbered"><xi:include href="samples/colorbutton.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/GtkColorButton.html";>GtkColorButton</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkColorChooser.html";>GtkColorChooser</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gdk3/stable/gdk3-RGBA-Colors.html";>RGBA Colors</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/media/colorbutton.png b/platform-demos/C/media/colorbutton.png
new file mode 100644
index 0000000..427c28a
Binary files /dev/null and b/platform-demos/C/media/colorbutton.png differ
diff --git a/platform-demos/C/samples/colorbutton.py b/platform-demos/C/samples/colorbutton.py
new file mode 100644
index 0000000..503f4e1
--- /dev/null
+++ b/platform-demos/C/samples/colorbutton.py
@@ -0,0 +1,54 @@
+from gi.repository import Gtk
+from gi.repository import Gdk
+import sys
+
+class MyWindow(Gtk.ApplicationWindow):
+    def __init__(self, app):
+        Gtk.Window.__init__(self, title="ColorButton", application=app)
+        self.set_default_size(150, 50)
+        self.set_border_width(10)
+
+        # a colorbutton (which opens a dialogue window in
+        # which we choose a color)
+        button = Gtk.ColorButton()
+        # with a default color (blue, in this instance)
+        # if not chosen it will be black
+        color = Gdk.RGBA()
+        color.red = 0.0
+        color.green = 0.0
+        color.blue = 1.0
+        color.alpha = 0.5
+        button.set_rgba(color)
+
+        # choosing a color in the dialogue window emits a signal
+        button.connect("color-set", self.on_color_chosen)
+        self.button = button
+
+        # a label
+        label = Gtk.Label()
+        label.set_text("Click to choose a color")
+
+        # a grid to attach button and label
+        grid = Gtk.Grid()
+        grid.attach(button, 1, 1, 2, 1)
+        grid.attach(label, 1, 2, 2, 1)
+        self.add(grid)
+
+    # if a new color is chosen, we print it as rgb(r,g,b) in the terminal
+    def on_color_chosen(self, user_data):
+        print "You chose another color: " + self.button.get_rgba().to_string()
+
+class MyApplication(Gtk.Application):
+    def __init__(self):
+        Gtk.Application.__init__(self, application_id="org.example.colorbutton")
+
+    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/Makefile.am b/platform-demos/Makefile.am
index 71bb73e..40fba8c 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -31,6 +31,7 @@ demo_sources = \
 	samples/checkbutton.c			\
 	samples/checkbutton.py			\
 	samples/checkbutton.vala		\
+	samples/colorbutton.py			\
 	samples/combobox.py			\
 	samples/combobox.vala			\
 	samples/combobox_multicolumn.py		\
@@ -95,6 +96,7 @@ DOC_FIGURES = \
 	media/aboutdialog_GMenu.png		\
 	media/button.png			\
 	media/checkbutton.png			\
+	media/colorbutton.png			\
 	media/combobox.png			\
 	media/combobox_multicolumn.png			\
 	media/dialog.png			\
@@ -157,6 +159,7 @@ DOC_PAGES =				\
 	checkbutton.c.page		\
 	checkbutton.py.page		\
 	checkbutton.vala.page		\
+	colorbutton.py.page		\
 	combobox.py.page		\
 	combobox.vala.page		\
 	combobox_multicolumn.py.page	\



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