Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icon visibility not updating #132

Open
nab138 opened this issue Oct 23, 2022 · 2 comments
Open

Icon visibility not updating #132

nab138 opened this issue Oct 23, 2022 · 2 comments

Comments

@nab138
Copy link

nab138 commented Oct 23, 2022

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
Copy link
Contributor

sphh commented Nov 9, 2022

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
Copy link
Owner

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

@moses-palmer moses-palmer reopened this Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants