From 4b3914d49c2822c712480c6847a6c6887e80f136 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 18 Jul 2019 10:04:08 +1000 Subject: [PATCH] tuhi: take the mainloop out of Tuhi If we want to integrate this with TuhiGui, we can't have multiple mainloops. And there's nothing with Tuhi that needs it anyway, it's all about how it is being called. Which means we can just move this to the main method. Signed-off-by: Peter Hutterer --- tuhi/base.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tuhi/base.py b/tuhi/base.py index 242666a..59a5a02 100644 --- a/tuhi/base.py +++ b/tuhi/base.py @@ -279,6 +279,8 @@ class Tuhi(GObject.Object): (GObject.SignalFlags.RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)), 'device-connected': (GObject.SignalFlags.RUN_FIRST, None, (GObject.TYPE_PYOBJECT,)), + 'terminate': + (GObject.SignalFlags.RUN_FIRST, None, ()), } def __init__(self): @@ -297,7 +299,6 @@ class Tuhi(GObject.Object): self.devices = {} self._search_stop_handler = None - self.mainloop = GLib.MainLoop() def _on_tuhi_bus_name_acquired(self, dbus_server): self.bluez.connect_to_bluez() @@ -308,7 +309,7 @@ class Tuhi(GObject.Object): self.bluez.connect('device-updated', self._on_bluez_device_updated) def _on_tuhi_bus_name_lost(self, dbus_server): - self.mainloop.quit() + self.emit('terminate') def _on_start_search_requested(self, dbus_server, stop_handler): self._search_stop_handler = stop_handler @@ -406,9 +407,6 @@ class Tuhi(GObject.Object): else: self.bluez.stop_discovery() - def run(self): - self.mainloop.run() - def main(args=sys.argv): if sys.version_info < (3, 6): @@ -426,6 +424,9 @@ def main(args=sys.argv): logger.setLevel(logging.DEBUG) try: - Tuhi().run() + mainloop = GLib.MainLoop() + tuhi = Tuhi() + tuhi.connect('terminate', lambda tuhi: mainloop.quit()) + mainloop.run() except KeyboardInterrupt: pass