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 remains at re-opening #62

Open
ghost opened this issue Jul 18, 2020 · 2 comments
Open

Icon remains at re-opening #62

ghost opened this issue Jul 18, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 18, 2020

Hello, I am using your code and noticed that it not deleting old inactive icons at start. Do you have any idea how i can achieve this?
My current code looks like this and works very well with exit button, but when i re-open the app it spams me inactive icons which are disposed when i hover them:

`
import pystray
from PIL import Image, ImageDraw, ImageColor
from pystray import Menu as menu, MenuItem as item

class ApplicationIcon:
icon = pystray.Icon('test name')
state = False
state_exit = False
current_ws_state = None
last_state = None

def __init__(self):
    self.icon.visible = False
    self.icon.icon = self.create_image()
    self.icon.menu = menu(
        item('Get Servers', None, enabled=False),
        item('Status', None, enabled=False),
        item(
            'Start Server',
            self.on_clicked,
            checked=lambda item: self.state),
        item('-> Exit', self.on_clicked_exit,
             checked=lambda item: self.state_exit, enabled=True)
    )
    self.icon.run()

def on_clicked(self, icon, current_item):
    self.state = not current_item.checked

def on_clicked_exit(self, icon, current_item):
    self.state_exit = not current_item.checked
    icon.visible = False
    icon.stop()

@staticmethod
def create_image():
    width = 240
    height = 240

    color1 = ImageColor.getrgb("blue")
    color2 = ImageColor.getrgb("red")
    image = Image.new('RGB', (width, height), color1)
    dc = ImageDraw.Draw(image)
    dc.rectangle(
        (width // 2, 0, width, height // 2),
        fill=color2)
    dc.rectangle(
        (0, height // 2, width // 2, height),
        fill=color2)

    return image

AppIcon = ApplicationIcon()
`

Thanks in advance & Best regards

Sascha

@moses-palmer
Copy link
Owner

Thank you for your report.

This might be a regression in later versions. Can you please provide information about your operating system, Python version and version of pystray? Did you install using pip or clone this repo?

@ghost
Copy link
Author

ghost commented Jul 20, 2020 via email

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

1 participant