From 0431a2d98e93aad5fd773c7f6f1b85164271ec14 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Fri, 19 Aug 2022 14:09:06 +0200 Subject: [PATCH] Add an experimental shutdown handler --- gui.py | 3 ++- main.py | 4 ++-- twitch.py | 8 -------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/gui.py b/gui.py index 97088db..15db42b 100644 --- a/gui.py +++ b/gui.py @@ -1629,6 +1629,7 @@ class GUIManager: root.iconbitmap(resource_path("pickaxe.ico")) # window icon root.title(WINDOW_TITLE) # window title root.protocol("WM_DELETE_WINDOW", self.close) # hook the X window closing button + root.protocol("WM_ENDSESSION", self.close) # hook the Windows shutdown signal root.bind_all("", self.unfocus) # pressing ESC unfocuses selection # Image cache for displaying images self._cache = ImageCache(self) @@ -1781,7 +1782,7 @@ class GUIManager: await asyncio.sleep(0.05) self._poll_task = None - def close(self): + def close(self, *args): """ Requests the GUI application to close. The window itself will be closed in the closing sequence later. diff --git a/main.py b/main.py index a00104f..f62ecc8 100644 --- a/main.py +++ b/main.py @@ -160,8 +160,8 @@ exit_status = 0 loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) client = Twitch(settings) -signal.signal(signal.SIGINT, lambda *_: client.signal_close()) -signal.signal(signal.SIGTERM, lambda *_: client.signal_close()) +signal.signal(signal.SIGINT, lambda *_: client.gui.close()) +signal.signal(signal.SIGTERM, lambda *_: client.gui.close()) try: loop.run_until_complete(client.run()) except CaptchaRequired: diff --git a/twitch.py b/twitch.py index 51a9327..21b7c14 100644 --- a/twitch.py +++ b/twitch.py @@ -121,14 +121,6 @@ class Twitch: # perfect for GUI usage return partial(self.change_state, state) - def signal_close(self): - """ - Called when the application is requested to close by the operating system, - usually by receiving a SIGINT or SIGTERM. - """ - # delegate this to the same action as the user clicking on the X in the GUI window - self.gui.close() - def close(self): """ Called when the application is requested to close by the user,