[gnome-devel-docs] tutorials python: example of gtk entry



commit 7bf5cd7f770781e094d3e7140372390d34c72d66
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Thu May 24 16:40:22 2012 +0100

    tutorials python: example of gtk entry

 platform-demos/C/entry.py.page    |   29 +++++++++++++++++++++++++++++
 platform-demos/C/samples/entry.py |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/entry.py.page b/platform-demos/C/entry.py.page
new file mode 100644
index 0000000..637bb20
--- /dev/null
+++ b/platform-demos/C/entry.py.page
@@ -0,0 +1,29 @@
+<page xmlns="http://projectmallard.org/1.0/";
+      xmlns:xi="http://www.w3.org/2001/XInclude";
+      type="guide" style="task"
+      id="entry.py">
+  <info>
+    <link type="guide" xref="beginner.py#entry"/>
+    <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 single line text entry field</desc>
+  </info>
+
+  <title>Entry</title>
+  <media type="image" mime="image/png" src="media/entry.png"/>
+  <p>This application greets you in the terminal with the name you provide.</p>
+
+<code mime="text/x-python" style="numbered"><xi:include href="samples/entry.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/GtkEntry.html";>GtkEntry</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/samples/entry.py b/platform-demos/C/samples/entry.py
new file mode 100644
index 0000000..6783895
--- /dev/null
+++ b/platform-demos/C/samples/entry.py
@@ -0,0 +1,34 @@
+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="What is your name?", application=app)
+        self.set_default_size(300, 100)
+        self.set_border_width(10)
+
+        name_box = Gtk.Entry()
+        name_box.connect("activate", self.cb_activate)
+
+        self.add(name_box)
+
+    # the button operates on the window
+    def cb_activate(self, entry):
+		name = entry.get_text()
+		print "\nHello " + name + "!\n"
+
+class MyApplication(Gtk.Application):
+    def __init__(self):
+        Gtk.Application.__init__(self, application_id="org.example.MyApplication")
+
+    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]