From 3a01c3625b93e328ea8276e9bf776db591938a9c Mon Sep 17 00:00:00 2001 From: Andrew Lorimer Date: Sat, 22 May 2021 16:49:39 +1000 Subject: [PATCH 1/1] UI bugfixing --- ppt_control/ppt_control.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/ppt_control/ppt_control.py b/ppt_control/ppt_control.py index d6a06d1..6648666 100755 --- a/ppt_control/ppt_control.py +++ b/ppt_control/ppt_control.py @@ -37,6 +37,7 @@ global refresh_daemon global status_label global http_label global ws_label +global reset_ppt_button global http_server scheduler = None current_slideshow = None @@ -50,12 +51,17 @@ http_label = None ws_label = None ws_daemon = None http_server = None +reset_ppt_button = None class Handler(server.SimpleHTTPRequestHandler): def __init__(self, *args, **kwargs): super().__init__(*args, directory=os.path.dirname(os.path.realpath(__file__)) + r'''\static''') + def log_request(self, code='-', size='-'): + return + + def translate_path(self, path): """Translate a /-separated PATH to the local filename syntax. @@ -82,10 +88,10 @@ class Handler(server.SimpleHTTPRequestHandler): try: path = config.prefs["Main"]["cache"] + "\\" + current_slideshow.name() except Exception as e: - path = os.path.join(os.path.dirname(os.path.realpath(__file__)), r'''\static\black.jpg''') + '/' + path = "black.jpg" logger.warning("Failed to get current slideshow name: ", e) else: - path = os.path.join(os.path.dirname(os.path.realpath(__file__)), r'''\static\black.jpg''') + '/' + path = "black.jpg" return path words.pop(0) else: @@ -224,6 +230,7 @@ def restart_http(): http_server = None refresh_status() start_http() + time.sleep(0.5) refresh_status() def start_ws(): @@ -253,6 +260,7 @@ class Slideshow: def unload(self): connect_ppt() + reset_ppt_button.config(state = tk.DISABLED) def refresh(self): try: @@ -391,7 +399,7 @@ class Slideshow: attempts += 1 elif slide == self.total_slides() + 1: try: - shutil.copyfileobj(open(os.path.dirname(os.path.realpath(__file__)), r'''\static\black.jpg''', 'rb'), open(destination, 'wb')) + shutil.copyfileobj(open(os.path.dirname(os.path.realpath(__file__)) + r'''\static\black.jpg''', 'rb'), open(destination, 'wb')) except Exception as e: logger.warning("Failed to copy black slide: " + str(e)) else: @@ -422,6 +430,8 @@ def refresh_status(): 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) def connect_ppt(): global STATE @@ -469,7 +479,7 @@ def open_settings(_=None): global interface_root interface_root = tk.Tk() interface_root.protocol("WM_DELETE_WINDOW", on_closing) - interface_root.iconphoto(False, tk.PhotoImage(file="static\icons\ppt.png")) + interface_root.iconphoto(False, tk.PhotoImage(file=os.path.dirname(os.path.realpath(__file__)) + r'''\static\icons\ppt.png''')) interface_root.geometry("600x300+300+300") app = Interface(interface_root) interface_thread = threading.Thread(target=interface_root.mainloop()) @@ -495,6 +505,7 @@ class Interface(ttk.Frame): global status_label global http_label global ws_label + global reset_ppt_button self.parent.title("ppt-control") self.style = ttk.Style() #self.style.theme_use("default") @@ -509,6 +520,7 @@ class Interface(ttk.Frame): save_button.place(x=400, y=280) reset_ppt_button = ttk.Button(self, text="Reconnect", command=connect_ppt) + reset_ppt_button.config(state = tk.DISABLED) reset_ppt_button.place(x=300, y=10) reset_http_button = ttk.Button(self, text="Restart", command=restart_http) -- 2.47.1