implement systray status
authorAndrew Lorimer <andrew@lorimer.id.au>
Sat, 22 May 2021 07:06:17 +0000 (17:06 +1000)
committerAndrew Lorimer <andrew@lorimer.id.au>
Sat, 22 May 2021 07:06:17 +0000 (17:06 +1000)
ppt_control/ppt_control.py
index 664866677a3749a5aa48ca271f75a7789c50622f..8537f81af4f3ce20ab5961a6775f2de28fc3dee5 100755 (executable)
@@ -39,6 +39,7 @@ global http_label
 global ws_label\r
 global reset_ppt_button\r
 global http_server\r
 global ws_label\r
 global reset_ppt_button\r
 global http_server\r
+global icon\r
 scheduler = None\r
 current_slideshow = None\r
 interface_root = None\r
 scheduler = None\r
 current_slideshow = None\r
 interface_root = None\r
@@ -52,6 +53,7 @@ ws_label = None
 ws_daemon = None\r
 http_server = None\r
 reset_ppt_button = None\r
 ws_daemon = None\r
 http_server = None\r
 reset_ppt_button = None\r
+icon = None\r
 \r
 \r
 class Handler(server.SimpleHTTPRequestHandler):\r
 \r
 \r
 class Handler(server.SimpleHTTPRequestHandler):\r
@@ -438,8 +440,11 @@ def connect_ppt():
     global refresh_daemon\r
     if STATE["connected"] == 1:\r
         logger.info("Disconnected from PowerPoint instance")\r
     global refresh_daemon\r
     if STATE["connected"] == 1:\r
         logger.info("Disconnected from PowerPoint instance")\r
+        icon.notify("Disconnected from PowerPoint instance")\r
         refresh_daemon.do_run = False\r
         STATE = copy(STATE_DEFAULT)\r
         refresh_daemon.do_run = False\r
         STATE = copy(STATE_DEFAULT)\r
+        if icon is not None:\r
+            refresh_menu()\r
         refresh_status()\r
         logger.debug("State is now " + str(STATE))\r
     while True:\r
         refresh_status()\r
         logger.debug("State is now " + str(STATE))\r
     while True:\r
@@ -450,6 +455,9 @@ def connect_ppt():
             STATE["connected"] = 1\r
             STATE["current"] = current_slideshow.current_slide()\r
             STATE["total"] = current_slideshow.total_slides()\r
             STATE["connected"] = 1\r
             STATE["current"] = current_slideshow.current_slide()\r
             STATE["total"] = current_slideshow.total_slides()\r
+            icon.notify("Connected to PowerPoint instance")\r
+            if icon is not None:\r
+                refresh_menu()\r
             refresh_status()\r
             logger.info("Connected to PowerPoint instance")\r
             refresh_daemon = threading.Thread(name="refresh_daemon", target=refresh_interval)\r
             refresh_status()\r
             logger.info("Connected to PowerPoint instance")\r
             refresh_daemon = threading.Thread(name="refresh_daemon", target=refresh_interval)\r
@@ -546,16 +554,19 @@ def exit_action(icon):
     icon.visible = False\r
     icon.stop()\r
 \r
     icon.visible = False\r
     icon.stop()\r
 \r
-def show_icon():\r
-    logger.debug("Starting system tray icon")\r
-    icon = pystray.Icon("ppt-control")\r
-    icon.menu = (pystray.MenuItem("Status", lambda: null_action(), enabled=False),\r
-            pystray.MenuItem("Restart", lambda: start()),\r
+def refresh_menu():\r
+    icon.menu = (pystray.MenuItem("Status: " + "dis"*(not STATE["connected"]) + "connected", lambda: null_action(), enabled=False),\r
             pystray.MenuItem("Stop", lambda: exit_action(icon)),\r
             pystray.MenuItem("Settings", lambda: open_settings())\r
             )\r
             pystray.MenuItem("Stop", lambda: exit_action(icon)),\r
             pystray.MenuItem("Settings", lambda: open_settings())\r
             )\r
+\r
+def show_icon():\r
+    global icon\r
+    logger.debug("Starting system tray icon")\r
+    icon = pystray.Icon("ppt-control")\r
     icon.icon = Image.open(os.path.dirname(os.path.realpath(__file__)) + r'''\static\icons\ppt.ico''')\r
     icon.title = "ppt-control"\r
     icon.icon = Image.open(os.path.dirname(os.path.realpath(__file__)) + r'''\static\icons\ppt.ico''')\r
     icon.title = "ppt-control"\r
+    refresh_menu()\r
     icon.visible = True\r
     icon.run(setup=start)\r
 \r
     icon.visible = True\r
     icon.run(setup=start)\r
 \r