From 46b87a5f4d1103ac86b03960c5f0f87bac7b44a2 Mon Sep 17 00:00:00 2001 From: huantian Date: Tue, 29 Jun 2021 21:39:09 -0700 Subject: [PATCH] Fix more pyinstalelr bugs aa --- LevelSync.spec | 4 ++-- src/initial.py | 7 ++++++- src/loops.py | 4 ++-- src/main.py | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/LevelSync.spec b/LevelSync.spec index 4f96be6..bead93d 100644 --- a/LevelSync.spec +++ b/LevelSync.spec @@ -6,8 +6,8 @@ block_cipher = None a = Analysis(['run.py'], pathex=['./'], binaries=[], - datas=[('res/icon.ico', 'res/icon.ico')], - hiddenimports=[], + datas=[('res/icon.ico', 'res')], + hiddenimports=['pystray._win32'], hookspath=[], runtime_hooks=[], excludes=[], diff --git a/src/initial.py b/src/initial.py index ae4e037..26c4fc8 100644 --- a/src/initial.py +++ b/src/initial.py @@ -7,7 +7,12 @@ def resource_path(relative_path): """Get absolute path to resource, relative to .exe, works for dev and for PyInstaller""" - return os.path.join(sys.path[0], relative_path) + if getattr(sys, 'frozen', False): + base_path = os.path.split(sys.executable)[0] + else: + base_path = sys.path[0] + + return os.path.join(base_path, relative_path) def bundled_path(relative_path): diff --git a/src/loops.py b/src/loops.py index 3b47b81..ee66478 100644 --- a/src/loops.py +++ b/src/loops.py @@ -129,7 +129,7 @@ def error(message: str) -> None: notification = Notify() notification.title = "LevelSync Error!!!!" notification.message = message - notification.icon = initial.bundled_path('res/icon.ico') + notification.icon = initial.bundled_path(os.path.join('res', 'icon.ico')) notification.send(block=True) @@ -147,7 +147,7 @@ def notification(message: str) -> None: notification = Notify() notification.title = "LevelSync" notification.message = message - notification.icon = initial.bundled_path('res/icon.ico') + notification.icon = initial.bundled_path(os.path.join('res', 'icon.ico')) notification.send(block=True) diff --git a/src/main.py b/src/main.py index aef96ba..18b3858 100644 --- a/src/main.py +++ b/src/main.py @@ -27,7 +27,7 @@ def main() -> None: pystray.MenuItem('Quit', exit) ) - with Image.open(bundled_path('res/icon.ico')) as im: + with Image.open(bundled_path(os.path.join('res', 'icon.ico'))) as im: im.load() icon.icon = im