From 80c2a5e90071bfdd208cfc2dae1d31d916ca0d8d Mon Sep 17 00:00:00 2001 From: Adam Saudagar Date: Sun, 18 Oct 2020 06:20:25 +0530 Subject: [PATCH] fixed situations where app doesnt shut down without crash - when bot is closed while engine is running - when start is pressed when the game is minimized, then app is closed --- fishy/engine/common/window.py | 3 ++- fishy/gui/main_gui.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fishy/engine/common/window.py b/fishy/engine/common/window.py index 5583f9e..e28310d 100644 --- a/fishy/engine/common/window.py +++ b/fishy/engine/common/window.py @@ -29,7 +29,8 @@ class WindowClient: WindowClient.clients.append(self) def destory(self): - WindowClient.clients.remove(self) + if self in WindowClient.clients: + WindowClient.clients.remove(self) if len(WindowClient.clients) == 0: window_server.stop() logging.info("window server stopped") diff --git a/fishy/gui/main_gui.py b/fishy/gui/main_gui.py index efd1222..3db6f5f 100644 --- a/fishy/gui/main_gui.py +++ b/fishy/gui/main_gui.py @@ -24,6 +24,7 @@ def _apply_theme(gui: 'GUI'): gui._console["fg"] = "#ffffff" if dark else "#000000" +# noinspection PyProtectedMember def _create(gui: 'GUI'): engines = gui.engines @@ -105,8 +106,12 @@ def _create(gui: 'GUI'): hotkey.set_hotkey(Key.F9, gui.funcs.start_engine) + # noinspection PyProtectedMember def set_destroy(): - gui._destroyed = True + if gui._bot_running: + logging.info("Turn off the bot engine first") + else: + gui._destroyed = True gui._root.protocol("WM_DELETE_WINDOW", set_destroy) gui._destroyed = False