[gnome-devel-docs] tutorials python: messagedialog window
- From: Tiffany Antopolski <antopolski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] tutorials python: messagedialog window
- Date: Tue, 22 May 2012 22:32:23 +0000 (UTC)
commit e0affa4487a1979cc02a38abc54b9b0c0e0d9950
Author: Marta Maria Casetti <mmcasetti gmail com>
Date: Mon May 14 09:08:51 2012 +0100
tutorials python: messagedialog window
platform-demos/C/messagedialog.py.page | 25 +++++++++++
platform-demos/C/samples/messagedialog.py | 67 +++++++++++++++++++++++++++++
2 files changed, 92 insertions(+), 0 deletions(-)
---
diff --git a/platform-demos/C/messagedialog.py.page b/platform-demos/C/messagedialog.py.page
new file mode 100644
index 0000000..8de24fd
--- /dev/null
+++ b/platform-demos/C/messagedialog.py.page
@@ -0,0 +1,25 @@
+<page xmlns="http://projectmallard.org/1.0/"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ type="guide" style="task"
+ id="messagedialog.py">
+ <info>
+ <link type="guide" xref="beginner.py#windows"/>
+ <revision version="0.1" date="2012-04-07" status="stub"/>
+
+ <credit type="author copyright">
+ <name>Marta Maria Casetti</name>
+ <email>mmcasetti gmail com</email>
+ <years>2012</years>
+ </credit>
+
+ <desc>A message window</desc>
+ </info>
+
+ <title>MessageDialog</title>
+ <media type="image" mime="image/png" src="media/messagedialog.png"/>
+ <p>A message dialog which prints messages on the terminal, depending on your choices.</p>
+
+<code mime="text/x-python" style="numbered">
+<xi:include href="samples/messagedialog.py" parse="text"><xi:fallback/></xi:include>
+</code>
+</page>
diff --git a/platform-demos/C/samples/messagedialog.py b/platform-demos/C/samples/messagedialog.py
new file mode 100644
index 0000000..832cbf4
--- /dev/null
+++ b/platform-demos/C/samples/messagedialog.py
@@ -0,0 +1,67 @@
+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="GMenu Example", application=app)
+ label = Gtk.Label()
+ label.set_text("This application goes boom!")
+ self.add(label)
+ self.set_default_size(400, 200)
+
+ # We create the message_action and connect the
+ # signal and add the action to the application.
+ message_action = Gio.SimpleAction.new("message", None)
+ message_action.connect("activate", self.message_cb)
+ app.add_action (message_action)
+
+ def dialog_response(self, widget, response_id):
+ if response_id == Gtk.ResponseType.OK:
+ print "*boom*"
+ elif response_id == Gtk.ResponseType.CANCEL:
+ print "good choice"
+ elif response_id == Gtk.ResponseType.DELETE_EVENT:
+ print "dialog closed or cancelled"
+
+ def message_cb(self, action, parameter):
+ messagedialog = Gtk.MessageDialog (self,
+ Gtk.DialogFlags.MODAL,
+ Gtk.MessageType.WARNING,
+ Gtk.ButtonsType.OK_CANCEL,
+ "This action will cause the universe to stop existing.")
+ messagedialog.connect("response", self.dialog_response)
+ messagedialog.show()
+
+
+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 ("Message", "app.message")
+ 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]