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