[gnome-devel-docs] tutorials python: an aboutdialog example



commit 78f5c0b1d0fac702d2b0a87903610308350234f3
Author: Marta Maria Casetti <mmcasetti gmail com>
Date:   Tue May 22 17:11:34 2012 +0100

    tutorials python: an aboutdialog example

 platform-demos/C/aboutdialog.py.page    |   33 +++++++++++++++
 platform-demos/C/samples/aboutdialog.py |   68 +++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/aboutdialog.py.page b/platform-demos/C/aboutdialog.py.page
new file mode 100644
index 0000000..c1e0272
--- /dev/null
+++ b/platform-demos/C/aboutdialog.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="aboutdialog.py">
+  <info>
+    <link type="guide" xref="beginner.py#windows"/>
+    <revision version="0.1" date="2012-05-21" status="draft"/>
+
+    <credit type="author copyright">
+      <name>Marta Maria Casetti</name>
+      <email>mmcasetti gmail com</email>
+      <years>2012</years>
+    </credit>
+
+    <desc>A window that displays information about an application</desc>
+  </info>
+
+  <title>AboutDialog</title>
+  <media type="image" mime="image/png" src="media/aboutdialog_GMenu.png"/>
+  <p>An AboutDialog example using Gtk.ApplicationWindow and Menu (the "about" is displayed if "About" in the menu is selected).</p>
+
+<code mime="text/x-python" style="numbered">
+<xi:include href="samples/aboutdialog.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/GtkApplication.html";>GtkApplication</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkApplicationWindow.html";>GtkApplicationWindow</link></p></item>
+  <item><p><link href="http://developer.gnome.org/gtk3/3.4/GtkAboutDialog.html";>GtkAboutDialog</link></p></item>
+</list>
+</page>
diff --git a/platform-demos/C/samples/aboutdialog.py b/platform-demos/C/samples/aboutdialog.py
new file mode 100644
index 0000000..6462e21
--- /dev/null
+++ b/platform-demos/C/samples/aboutdialog.py
@@ -0,0 +1,68 @@
+from gi.repository import GLib
+from gi.repository import Gtk
+from gi.repository import Gio
+import sys
+ 
+# This is the window
+class MyWindow(Gtk.ApplicationWindow):
+ 
+    #constructor
+    def __init__(self, app):
+        Gtk.Window.__init__(self, title="AboutDialog Example", application=app)
+        self.set_default_size(200, 200)
+ 
+        # We create the message_action and connect the
+        # signal and add the action to the application.
+        about_action = Gio.SimpleAction.new("about", None)
+        about_action.connect("activate", self.about_cb)
+        app.add_action(about_action)
+        self.show_all()
+
+    def about_cb(self, action, parameter):
+        aboutdialog = Gtk.AboutDialog()
+        
+        #lists of authors and documenters (will be used later)
+        authors = ["GNOME Documentation Team", None]
+        documenters = ["GNOME Documentation Team", None]
+        
+        aboutdialog.set_program_name("AboutDialog Example")
+        aboutdialog.set_copyright("Copyright \xc2\xa9 2012 GNOME Documentation Team")
+        aboutdialog.set_authors(authors)
+        aboutdialog.set_documenters(documenters)
+        aboutdialog.set_website("http://developer.gnome.org";)
+        aboutdialog.set_website_label("GNOME Developer Website")
+        
+        # to close the aboutdialog when "close" is clicked
+        aboutdialog.connect("response", self.on_close)
+        
+        aboutdialog.show()
+        
+    def on_close(self, action, parameter):
+        action.destroy()
+
+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 quit_cb(self, action, parameter):
+        self.quit()
+ 
+    def do_startup (self):
+        Gtk.Application.do_startup (self)
+ 
+        menu = Gio.Menu()
+        menu.append ("About", "app.about")
+        menu.append("Quit", "app.quit")
+        self.set_app_menu (menu)
+ 
+        quit_action = Gio.SimpleAction.new("quit", None)
+        quit_action.connect("activate", self.quit_cb)
+        self.add_action(quit_action)
+ 
+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]