moses-palmer / pystray

GNU General Public License v3.0
461 stars 57 forks source link

Icon visibility not updating #132

Open nab138 opened 1 year ago

nab138 commented 1 year ago

So I've been having a weird issue: I initilize the tray just fine and all the buttons work, but when I click show window the tray icon doesn't disappear. If I close the window again, none of the buttons work on the tray (but they are visible). I am integrating with tkinter using the following code:

def quit_window(icon, item):
   icon.stop()
   root.destroy()

def show_window(icon, item):
   icon.stop()
   root.after(0, root.deiconify())

def hide_window():
   root.withdraw()
   icon.run()

image=Image.open(resource_path("altserver.ico"))
menu=(item('Show', show_window), item('Quit', quit_window))
icon=pystray.Icon("name", image, "AltServer", menu)

root.protocol('WM_DELETE_WINDOW', hide_window)

root.mainloop()

I read #124, and tried the suggestion there to run the icon in a separate thread and manipulate the visibility instead:

def hide_window():
   root.withdraw()
   icon.visible = True
def startTray(icon):
    print("Starting tray")
def quit_window(icon, item):
   icon.stop()
   root.destroy()

def show_window(icon, item):
   icon.visible = False
   root.after(0, root.deiconify())

def installAltStoreTray(icon, item):
    show_window(icon, item)
    installAltStore()
image=Image.open(resource_path("altserver.ico"))
menu=(item("Install AltStore", installAltStoreTray), item('Show', show_window), item('Quit', quit_window))
icon=pystray.Icon("name", image, "AltServer", menu)

threading.Thread(target=lambda:icon.run(startTray)).start()

And this has the exact same result (tray works the first time, doesn't disappear, no buttons work the second time) I am running Linux Mint 20.3 and python3.8.

sphh commented 1 year ago

I have exactly the same issue, but I use only .run() (no embedding into another framework).

I can also add, that in my installation the AppIndicator is used.

For the cause (and a fix) see #134.

moses-palmer commented 1 year ago

@nab138, #134 has been merged. Did this solve your issue?