From: Andrew Lorimer Date: Sat, 22 May 2021 07:59:15 +0000 (+1000) Subject: fix UI threading bugs X-Git-Tag: v0.0.3~2 X-Git-Url: https://git.lorimer.id.au/ppt-control.git/diff_plain/5c11a82f5f504c91a01c64dbcfd6bbcd05be4aff fix UI threading bugs --- diff --git a/ppt_control/ppt_control.py b/ppt_control/ppt_control.py index 8537f81..1f4cfde 100755 --- a/ppt_control/ppt_control.py +++ b/ppt_control/ppt_control.py @@ -32,6 +32,7 @@ global STATE global STATE_DEFAULT global current_slideshow global interface_root +global interface_thread global logger global refresh_daemon global status_label @@ -43,6 +44,7 @@ global icon scheduler = None current_slideshow = None interface_root = None +interface_thread = None CONFIG_FILE = r'''..\ppt-control.ini''' LOGFILE = r'''..\ppt-control.log''' logger = None @@ -262,7 +264,6 @@ class Slideshow: def unload(self): connect_ppt() - reset_ppt_button.config(state = tk.DISABLED) def refresh(self): try: @@ -428,12 +429,14 @@ def refresh_interval(): time.sleep(0.5) def refresh_status(): - if status_label is not None: - status_label.config(text="PowerPoint status: " + ("not " if not STATE["connected"] else "") + "connected") - http_label.config(text="HTTP server: " + ("not " if http_server is None else "") + "running") - #ws_label.config(text="WebSocket server: " + ("not " if ws_daemon is not None or not ws_daemon.is_alive() else "") + "running") - if reset_ppt_button is not None: - reset_ppt_button.config(state = tk.DISABLED if not STATE["connected"] else tk.NORMAL) + if interface_root is not None and interface_root.state == "normal": + if status_label is not None: + status_label.config(text="PowerPoint status: " + ("not " if not STATE["connected"] else "") + "connected") + if http_label is not None: + http_label.config(text="HTTP server: " + ("not " if http_server is None else "") + "running") + #ws_label.config(text="WebSocket server: " + ("not " if ws_daemon is not None or not ws_daemon.is_alive() else "") + "running") + if reset_ppt_button is not None: + reset_ppt_button.config(state = tk.DISABLED if not STATE["connected"] else tk.NORMAL) def connect_ppt(): global STATE @@ -441,6 +444,8 @@ def connect_ppt(): if STATE["connected"] == 1: logger.info("Disconnected from PowerPoint instance") icon.notify("Disconnected from PowerPoint instance") + if reset_ppt_button is not None: + reset_ppt_button.config(state = tk.DISABLED) refresh_daemon.do_run = False STATE = copy(STATE_DEFAULT) if icon is not None: @@ -478,13 +483,19 @@ def on_closing(): global status_label global http_label global ws_label + global interface_thread status_label = None http_label = None ws_label = None + logger.debug("Destroying interface root") interface_root.destroy() + logger.debug("Destroying interface thread") + interface_thread.root.quit() + interface_thread = None def open_settings(_=None): global interface_root + global interface_thread interface_root = tk.Tk() interface_root.protocol("WM_DELETE_WINDOW", on_closing) interface_root.iconphoto(False, tk.PhotoImage(file=os.path.dirname(os.path.realpath(__file__)) + r'''\static\icons\ppt.png'''))