moses-palmer / pystray

GNU General Public License v3.0
473 stars 59 forks source link

Icon remains at re-opening #62

Open ghost opened 4 years ago

ghost commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Hello, I am using python 3.8 on windows 10 64 latest updates. I installed the package via pip. Anyway I solved this problem with a modified version of lptraybuster in csharp to clear ghost icons but I want a clean python only app. Regression means that it will be fixed in future? Best regards -------- Ursprüngliche Nachricht --------Von: moses-palmer notifications@github.comDatum: Sa., 18. Juli 2020, 11:59An: moses-palmer/pystray pystray@noreply.github.comCc: sfranklus sfrank@lus-design.de, Author author@noreply.github.comBetreff: Re: [moses-palmer/pystray] Icon remains at re-opening (#62) 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?

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.