From e96a69e9941b7163fd451aadebd7db778dd343db Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 11 Apr 2012 11:21:26 +0100 Subject: [PATCH 5/5] dialler: use GtkApplication --- examples/client/python/dialler.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/examples/client/python/dialler.py b/examples/client/python/dialler.py index 82c712b..44cd325 100755 --- a/examples/client/python/dialler.py +++ b/examples/client/python/dialler.py @@ -25,6 +25,7 @@ from gi.repository import GObject from gi.repository import Gio from gi.repository import Gtk from gi.repository import TelepathyGLib as Tp +import sys GObject.threads_init() @@ -33,13 +34,13 @@ USER_ACTION_TIME_NOT_USER_ACTION = 0 ACCOUNT_MANAGER_FEATURE_CORE = GLib.quark_from_string( 'tp-account-manager-feature-core') -class Dialler(GObject.GObject): - __gsignals__ = { - 'finished': (GObject.SIGNAL_RUN_FIRST, None, ()), - } +class Dialler(Gtk.Application): def __init__(self): - GObject.GObject.__init__(self) + Gtk.Application.__init__(self, + application_id='im.telepathy.TpGLib.Example.PythonDialler', + flags=Gio.ApplicationFlags.NON_UNIQUE) + self.connect('activate', self._activate_cb) self.dbus = Tp.DBusDaemon.dup() self.am = Tp.AccountManager.dup() @@ -48,8 +49,15 @@ class Dialler(GObject.GObject): self.potential_handlers = set() self.handlers = Gtk.ListStore(str, str) + self.window = None + + def _activate_cb(self, data): + if self.window is not None: + self.window.present() + return + self.window = Gtk.Window() - self.window.connect('delete-event', Gtk.main_quit) + self.window.connect('delete-event', lambda *ignored: self.quit()) self.grid = Gtk.Grid() self.grid.props.margin = 6 self.grid.props.column_spacing = 6 @@ -87,6 +95,7 @@ class Dialler(GObject.GObject): self.dial_button.props.sensitive = False self.window.show_all() + self.add_window(self.window) self.am.prepare_async([], self._am_cb, None) Gio.bus_get(Gio.BusType.SESSION, None, @@ -190,5 +199,4 @@ class Dialler(GObject.GObject): if __name__ == '__main__': Tp.debug_set_flags("all") - dialler = Dialler() - Gtk.main() + sys.exit(Dialler().run(sys.argv)) -- 1.7.9.5