From 7052642590db0b693af45e01fdc1e8bc5eb46f75 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 21 May 2014 10:21:36 +0100 Subject: Terminate the application when closing the window Use GtkApplication to manage the application lifecycle, and quit the application when the window is closed. --- python-gnome-app | 19 ++++++++++++++++--- 1 file 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) -- cgit