From 57f7779e66393a82af5f422c3e1a17379e5f4dc0 Mon Sep 17 00:00:00 2001 From: Isaac Holston Date: Wed, 15 Nov 2023 19:20:22 -0700 Subject: [PATCH] fix: update executable icon path --- .gitignore | 5 ++++- tray.py | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 61c1f79..5547b62 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .idea -__pycache__/ \ No newline at end of file +__pycache__/ +build +dist +main.spec \ No newline at end of file diff --git a/tray.py b/tray.py index 145729e..df50d41 100644 --- a/tray.py +++ b/tray.py @@ -1,4 +1,6 @@ import pystray +import os +import sys from PIL import Image @@ -7,7 +9,8 @@ class TrayIcon: def __init__(self, acceptor): self.name = "Heimerdinger" self.display_name = "Heimerdinger" - self.image = Image.open("icon.png") + self.icon = "icon.png" + self.image = Image.open(self.resource_path()) self.start_pause = "Pause" self.acceptor = acceptor self.start_pause_item = pystray.MenuItem(lambda text: self.start_pause, self.pause) @@ -15,6 +18,11 @@ def __init__(self, acceptor): self.menu = pystray.Menu(self.start_pause_item, self.exit_item) self.icon = pystray.Icon(self.name, self.image, self.display_name, self.menu) + def resource_path(self): + if hasattr(sys, '_MEIPASS'): + return os.path.join(sys._MEIPASS, self.icon) + return os.path.join(os.path.abspath("."), self.icon) + def run(self): self.acceptor.run() self.icon.run()