summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid King <amigadave@amigadave.com>2014-05-21 11:46:22 +0100
committerDavid King <amigadave@amigadave.com>2014-05-21 11:53:55 +0100
commit279df35098654e78b8d678e65988aa701e0f71b6 (patch)
treedc991cb2162560250ca004150b10ba6f27601cff
parent7052642590db0b693af45e01fdc1e8bc5eb46f75 (diff)
downloadpython-gnome-app-279df35098654e78b8d678e65988aa701e0f71b6.tar.gz
python-gnome-app-279df35098654e78b8d678e65988aa701e0f71b6.tar.xz
python-gnome-app-279df35098654e78b8d678e65988aa701e0f71b6.zip
Add actions and handlers for hello world and quit
Create two actions, "hello-world" and "quit", and add them to the application (which is an implementation of GActionMap). Connect the "activate" signal of the actions to handlers. Add an accelerator for each action, so that they can be triggered with a keyboard shortcut.
-rwxr-xr-xpython-gnome-app25
1 files changed, 22 insertions, 3 deletions
diff --git a/python-gnome-app b/python-gnome-app
index 440e95f..a69f801 100755
--- a/python-gnome-app
+++ b/python-gnome-app
@@ -1,7 +1,7 @@
#!/usr/bin/python3
import sys
-from gi.repository import Gtk
+from gi.repository import Gio, Gtk
class PythonApp(Gtk.Application):
@@ -11,10 +11,29 @@ class PythonApp(Gtk.Application):
self, application_id="org.example.PythonGnome")
self.connect("activate", self.on_activate)
+ self.connect("startup", self.on_startup)
+
+ def on_startup(self, app):
+ self.window = Gtk.ApplicationWindow(application=app)
+
+ hello_world = Gio.SimpleAction(name="hello-world", parameter_type=None)
+ self.add_action(hello_world)
+ self.add_accelerator("<Primary>h", "app.hello-world", None)
+ hello_world.connect("activate", self.on_hello_world)
+
+ quit = Gio.SimpleAction(name="quit", parameter_type=None)
+ self.add_action(quit)
+ self.add_accelerator("<Primary>q", "app.quit", None)
+ quit.connect("activate", self.on_quit)
def on_activate(self, app):
- window = Gtk.ApplicationWindow(application=app)
- window.show_all()
+ self.window.show_all()
+
+ def on_hello_world(self, action=None, param=None):
+ print("Hello world!")
+
+ def on_quit(self, action=None, param=None):
+ self.quit()
app = PythonApp()
exit_status = app.run(None)