UI bugfixing
authorAndrew Lorimer <andrew@lorimer.id.au>
Sat, 22 May 2021 06:49:39 +0000 (16:49 +1000)
committerAndrew Lorimer <andrew@lorimer.id.au>
Sat, 22 May 2021 06:49:39 +0000 (16:49 +1000)
ppt_control/ppt_control.py
index d6a06d1ee2c295bfd05b573dba4a94c782376333..664866677a3749a5aa48ca271f75a7789c50622f 100755 (executable)
@@ -37,6 +37,7 @@ global refresh_daemon
 global status_label\r
 global http_label\r
 global ws_label\r
 global status_label\r
 global http_label\r
 global ws_label\r
+global reset_ppt_button\r
 global http_server\r
 scheduler = None\r
 current_slideshow = None\r
 global http_server\r
 scheduler = None\r
 current_slideshow = None\r
@@ -50,12 +51,17 @@ http_label = None
 ws_label = None\r
 ws_daemon = None\r
 http_server = None\r
 ws_label = None\r
 ws_daemon = None\r
 http_server = None\r
+reset_ppt_button = None\r
 \r
 \r
 class Handler(server.SimpleHTTPRequestHandler):\r
     def __init__(self, *args, **kwargs):\r
         super().__init__(*args, directory=os.path.dirname(os.path.realpath(__file__)) + r'''\static''')\r
         \r
 \r
 \r
 class Handler(server.SimpleHTTPRequestHandler):\r
     def __init__(self, *args, **kwargs):\r
         super().__init__(*args, directory=os.path.dirname(os.path.realpath(__file__)) + r'''\static''')\r
         \r
+    def log_request(self, code='-', size='-'):\r
+        return\r
+\r
+        \r
     def translate_path(self, path):\r
         """Translate a /-separated PATH to the local filename syntax.\r
 \r
     def translate_path(self, path):\r
         """Translate a /-separated PATH to the local filename syntax.\r
 \r
@@ -82,10 +88,10 @@ class Handler(server.SimpleHTTPRequestHandler):
                 try:\r
                     path = config.prefs["Main"]["cache"] + "\\" + current_slideshow.name()\r
                 except Exception as e:\r
                 try:\r
                     path = config.prefs["Main"]["cache"] + "\\" + current_slideshow.name()\r
                 except Exception as e:\r
-                    path = os.path.join(os.path.dirname(os.path.realpath(__file__)), r'''\static\black.jpg''') + '/'\r
+                    path = "black.jpg"\r
                     logger.warning("Failed to get current slideshow name: ", e)\r
             else:\r
                     logger.warning("Failed to get current slideshow name: ", e)\r
             else:\r
-                path = os.path.join(os.path.dirname(os.path.realpath(__file__)), r'''\static\black.jpg''') + '/'\r
+                path = "black.jpg"\r
                 return path\r
             words.pop(0)\r
         else:\r
                 return path\r
             words.pop(0)\r
         else:\r
@@ -224,6 +230,7 @@ def restart_http():
         http_server = None\r
         refresh_status()\r
     start_http()\r
         http_server = None\r
         refresh_status()\r
     start_http()\r
+    time.sleep(0.5)\r
     refresh_status()\r
 \r
 def start_ws():\r
     refresh_status()\r
 \r
 def start_ws():\r
@@ -253,6 +260,7 @@ class Slideshow:
 \r
     def unload(self):\r
         connect_ppt()\r
 \r
     def unload(self):\r
         connect_ppt()\r
+        reset_ppt_button.config(state = tk.DISABLED)\r
 \r
     def refresh(self):\r
         try:\r
 \r
     def refresh(self):\r
         try:\r
@@ -391,7 +399,7 @@ class Slideshow:
                     attempts += 1\r
             elif slide == self.total_slides() + 1:\r
                 try:\r
                     attempts += 1\r
             elif slide == self.total_slides() + 1:\r
                 try:\r
-                    shutil.copyfileobj(open(os.path.dirname(os.path.realpath(__file__)), r'''\static\black.jpg''', 'rb'), open(destination, 'wb'))\r
+                    shutil.copyfileobj(open(os.path.dirname(os.path.realpath(__file__)) + r'''\static\black.jpg''', 'rb'), open(destination, 'wb'))\r
                 except Exception as e:\r
                     logger.warning("Failed to copy black slide: " + str(e))\r
             else:\r
                 except Exception as e:\r
                     logger.warning("Failed to copy black slide: " + str(e))\r
             else:\r
@@ -422,6 +430,8 @@ def refresh_status():
         status_label.config(text="PowerPoint status: " + ("not " if not STATE["connected"] else "") +  "connected")\r
         http_label.config(text="HTTP server: " + ("not " if http_server is None else "") +  "running")\r
         #ws_label.config(text="WebSocket server: " + ("not " if ws_daemon is not None or not ws_daemon.is_alive() else "") +  "running")\r
         status_label.config(text="PowerPoint status: " + ("not " if not STATE["connected"] else "") +  "connected")\r
         http_label.config(text="HTTP server: " + ("not " if http_server is None else "") +  "running")\r
         #ws_label.config(text="WebSocket server: " + ("not " if ws_daemon is not None or not ws_daemon.is_alive() else "") +  "running")\r
+    if reset_ppt_button is not None:\r
+        reset_ppt_button.config(state = tk.DISABLED if not STATE["connected"] else tk.NORMAL)\r
 \r
 def connect_ppt():\r
     global STATE\r
 \r
 def connect_ppt():\r
     global STATE\r
@@ -469,7 +479,7 @@ def open_settings(_=None):
     global interface_root\r
     interface_root = tk.Tk()\r
     interface_root.protocol("WM_DELETE_WINDOW", on_closing)\r
     global interface_root\r
     interface_root = tk.Tk()\r
     interface_root.protocol("WM_DELETE_WINDOW", on_closing)\r
-    interface_root.iconphoto(False, tk.PhotoImage(file="static\icons\ppt.png"))\r
+    interface_root.iconphoto(False, tk.PhotoImage(file=os.path.dirname(os.path.realpath(__file__)) + r'''\static\icons\ppt.png'''))\r
     interface_root.geometry("600x300+300+300")\r
     app = Interface(interface_root)\r
     interface_thread = threading.Thread(target=interface_root.mainloop())\r
     interface_root.geometry("600x300+300+300")\r
     app = Interface(interface_root)\r
     interface_thread = threading.Thread(target=interface_root.mainloop())\r
@@ -495,6 +505,7 @@ class Interface(ttk.Frame):
         global status_label\r
         global http_label\r
         global ws_label\r
         global status_label\r
         global http_label\r
         global ws_label\r
+        global reset_ppt_button\r
         self.parent.title("ppt-control")\r
         self.style = ttk.Style()\r
         #self.style.theme_use("default")\r
         self.parent.title("ppt-control")\r
         self.style = ttk.Style()\r
         #self.style.theme_use("default")\r
@@ -509,6 +520,7 @@ class Interface(ttk.Frame):
         save_button.place(x=400, y=280)\r
 \r
         reset_ppt_button = ttk.Button(self, text="Reconnect", command=connect_ppt)\r
         save_button.place(x=400, y=280)\r
 \r
         reset_ppt_button = ttk.Button(self, text="Reconnect", command=connect_ppt)\r
+        reset_ppt_button.config(state = tk.DISABLED)\r
         reset_ppt_button.place(x=300, y=10)\r
 \r
         reset_http_button = ttk.Button(self, text="Restart", command=restart_http)\r
         reset_ppt_button.place(x=300, y=10)\r
 \r
         reset_http_button = ttk.Button(self, text="Restart", command=restart_http)\r