[gnome-devel-docs] tutorials python: fontchooserwidget



commit 6d04990851e527bfd12810c924e1abc787bc57f1
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Sat Jul 14 09:39:11 2012 +0100

    tutorials python: fontchooserwidget

 platform-demos/C/fontchooserwidget.py.page    |   47 +++++++++++++++++++++++++
 platform-demos/C/media/fontchooserwidget.png  |  Bin 0 -> 44176 bytes
 platform-demos/C/samples/fontchooserwidget.py |   39 ++++++++++++++++++++
 platform-demos/Makefile.am                    |    3 ++
 4 files changed, 89 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/fontchooserwidget.py.page b/platform-demos/C/fontchooserwidget.py.page
new file mode 100644
index 0000000..04eec5d
--- /dev/null
+++ b/platform-demos/C/fontchooserwidget.py.page
@@ -0,0 +1,47 @@
+<?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="fontchooserwidget.py">
+  <info>
+    <link type="guide" xref="beginner.py#font-selectors"/>
+    <link type="seealso" xref="signals-callbacks.py"/>
+    <revision version="0.2" date="2012-05-05" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Marta Maria Casetti</name>
+      <email>mmcasetti gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A widget to choose a font</desc>
+  </info>
+
+  <title>FontChooserWidget</title>
+
+  <media type="image" mime="image/png" src="media/fontchooserwidget.png"/>
+  <p>A FontChooserWidget with a callback function.</p>
+
+  <links type="section" />
+
+  <section id="code">
+    <title>Code used to generate this example</title>
+    <code mime="text/x-python" style="numbered"><xi:include href="samples/fontchooserwidget.py" parse="text"><xi:fallback/></xi:include></code>
+  </section>
+  <section id="methods">
+    <title>Useful methods for a FontChooserWidget</title>
+    <p>For an explanation of signals and callback functions, see <link xref="signals-callbacks.py">this page</link>.</p>
+    <list>
+      <item><p>To set the font which is initially selected, use <code>set_font(font)</code> (where <code>font</code> is the font name) or <code>set_font_desc(font)</code> (where <code>font</code> is the PangoFontDescription).</p></item>
+      <item><p>To get the selected font use <code>get_font()</code> or <code>get_font_desc()</code>.</p></item>
+      <item><p>To change the text which is shown in the preview area, use <code>set_preview_text()</code>. </p></item>
+    </list>
+  </section>
+  <section id="references">
+    <title>API References</title>
+    <p>In this sample we used the following:</p>
+    <list>
+      <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkFontChooserWidget.html";>GtkFontChooserWidget</link></p></item>
+    </list>
+  </section>
+</page>
diff --git a/platform-demos/C/media/fontchooserwidget.png b/platform-demos/C/media/fontchooserwidget.png
new file mode 100644
index 0000000..9747f08
Binary files /dev/null and b/platform-demos/C/media/fontchooserwidget.png differ
diff --git a/platform-demos/C/samples/fontchooserwidget.py b/platform-demos/C/samples/fontchooserwidget.py
new file mode 100644
index 0000000..2bb1d58
--- /dev/null
+++ b/platform-demos/C/samples/fontchooserwidget.py
@@ -0,0 +1,39 @@
+from gi.repository import Gtk
+import sys
+
+class MyWindow(Gtk.ApplicationWindow):
+    def __init__(self, app):
+        Gtk.Window.__init__(self, title="FontChooserWidget", application=app)
+
+        # a font chooser
+        self.font_chooser = Gtk.FontChooserWidget()
+        # a default font
+        self.font_chooser.set_font("Bitstream Charter")
+        # a text to preview the font
+        self.font_chooser.set_preview_text("This is an example of preview text!")
+
+        # connect signal from the font chooser to the callback function
+        self.font_chooser.connect("notify::font", self.font_cb)
+
+        # add the font chooser to the window
+        self.add(self.font_chooser)
+
+    # callback function:
+    def font_cb(self, event, user_data):
+        # print in the terminal
+        print "You chose the font " + self.font_chooser.get_font()
+
+class MyApplication(Gtk.Application):
+    def __init__(self):
+        Gtk.Application.__init__(self)
+
+    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 bc009ea..047d555 100644
--- a/platform-demos/Makefile.am
+++ b/platform-demos/Makefile.am
@@ -49,6 +49,7 @@ demo_sources = \
 	samples/entry.vala			\
 	samples/filechooserdialog.vala		\
 	samples/filechooserdialog.ui		\
+	samples/fontchooserwidget.py			\
 	samples/fruitbat.png			\
 	samples/gentoopenguin.png		\
 	samples/gmenu.c				\
@@ -148,6 +149,7 @@ DOC_FIGURES = \
 	media/dialog.png			\
 	media/entry.png				\
 	media/fedora.png			\
+	media/fontchooserwidget.png		\
 	media/glade_select_toolbar.png		\
 	media/glade_toolbar_common.png		\
 	media/glade_toolbar_edit.png		\
@@ -245,6 +247,7 @@ DOC_PAGES =				\
 	entry.py.page			\
 	entry.vala.page			\
 	filechooserdialog.vala.page	\
+	fontchooserwidget.py.page	\
 	getting-ready.page		\
 	gmenu.c.page			\
 	gmenu.js.page			\



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