summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid King <amigadave@amigadave.com>2014-05-21 10:21:36 +0100
committerDavid King <amigadave@amigadave.com>2014-05-21 10:29:50 +0100
commit7052642590db0b693af45e01fdc1e8bc5eb46f75 (patch)
tree18a18ecf878036108b2aae1dc6cb3d14ffded532
parentef157fb26fdc7a66c25568ae21b351acd2c149b4 (diff)
downloadpython-gnome-app-7052642590db0b693af45e01fdc1e8bc5eb46f75.tar.gz
python-gnome-app-7052642590db0b693af45e01fdc1e8bc5eb46f75.tar.xz
python-gnome-app-7052642590db0b693af45e01fdc1e8bc5eb46f75.zip
Terminate the application when closing the window
Use GtkApplication to manage the application lifecycle, and quit the application when the window is closed.
-rwxr-xr-xpython-gnome-app19
1 files changed, 16 insertions, 3 deletions
diff --git a/python-gnome-app b/python-gnome-app
index 09625d3..440e95f 100755
--- a/python-gnome-app
+++ b/python-gnome-app
@@ -1,8 +1,21 @@
#!/usr/bin/python3
+import sys
from gi.repository import Gtk
-window = Gtk.Window()
-window.show_all()
-Gtk.main()
+class PythonApp(Gtk.Application):
+
+ def __init__(self):
+ Gtk.Application.__init__(
+ self, application_id="org.example.PythonGnome")
+
+ self.connect("activate", self.on_activate)
+
+ def on_activate(self, app):
+ window = Gtk.ApplicationWindow(application=app)
+ window.show_all()
+
+app = PythonApp()
+exit_status = app.run(None)
+sys.exit(exit_status)