From: Andrew Lorimer Date: Sat, 22 May 2021 03:59:54 +0000 (+1000) Subject: add stop function to systray icon X-Git-Tag: v0.0.3~7 X-Git-Url: https://git.lorimer.id.au/ppt-control.git/diff_plain/cb1dae530d3bafdbf00802167fe47957cec75a48 add stop function to systray icon --- diff --git a/ppt_control/ppt_control.py b/ppt_control/ppt_control.py index 5ff80ef..d6a06d1 100755 --- a/ppt_control/ppt_control.py +++ b/ppt_control/ppt_control.py @@ -469,7 +469,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="static\icons\ppt.png")) interface_root.geometry("600x300+300+300") app = Interface(interface_root) interface_thread = threading.Thread(target=interface_root.mainloop()) @@ -529,13 +529,21 @@ class Interface(ttk.Frame): refresh_status() +def exit_action(icon): + logger.debug("User requested shutdown") + icon.visible = False + icon.stop() def show_icon(): logger.debug("Starting system tray icon") - menu = (pystray.MenuItem("Status", lambda: null_action(), enabled=False), + icon = pystray.Icon("ppt-control") + icon.menu = (pystray.MenuItem("Status", lambda: null_action(), enabled=False), pystray.MenuItem("Restart", lambda: start()), - pystray.MenuItem("Settings", lambda: open_settings())) - icon = pystray.Icon("ppt-control", Image.open(os.path.dirname(os.path.realpath(__file__)) + r'''\static\icons\ppt.ico'''), "ppt-control", menu) + pystray.MenuItem("Stop", lambda: exit_action(icon)), + pystray.MenuItem("Settings", lambda: open_settings()) + ) + icon.icon = Image.open(os.path.dirname(os.path.realpath(__file__)) + r'''\static\icons\ppt.ico''') + icon.title = "ppt-control" icon.visible = True icon.run(setup=start) @@ -579,6 +587,7 @@ def start_interface(): # Start systray icon and server show_icon() + sys.exit(0) if __name__ == "__main__": start_interface()