From bb4f87e5ed618582849d0a7d59ac7664e8716d84 Mon Sep 17 00:00:00 2001 From: Samuel Sloniker Date: Sun, 21 Jul 2024 14:46:36 -0700 Subject: [PATCH] Partially fix icon in Windows builds --- README.md | 10 ++++++---- build-windows.bat | 6 +++--- navpoint/fix_path.py | 16 ++++++++++++++++ navpoint/gui.py | 5 +++-- 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 navpoint/fix_path.py diff --git a/README.md b/README.md index 9a4c979..1665178 100755 --- a/README.md +++ b/README.md @@ -24,11 +24,13 @@ connect to Navpoint Desktop. ## Licensing Navpoint Desktop is released under the [GNU General Public License -v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html), except the file -`navpoint/get_ip.py`, which is released under [Creative Commons -Attribution-ShareAlike 4.0 +v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html), except the files +`navpoint/get_ip.py` and `navpoint.fix_path`, which are released under +[Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/) due to use of -[code published on Stack Overflow](https://stackoverflow.com/a/28950776). +code published on Stack Overflow +([`get_ip.py`](https://stackoverflow.com/a/28950776) and +[`fix_path.py`](https://stackoverflow.com/a/53605128)). Navpoint Mobile is released under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html). diff --git a/build-windows.bat b/build-windows.bat index fa9bd91..0b8c2bd 100755 --- a/build-windows.bat +++ b/build-windows.bat @@ -1,3 +1,3 @@ -pyinstaller -w -F --hidden-import tornado.web main.py -move dist/main.exe dist/navpoint-windows-%PROCESSOR_ARCHITECTURE%.exe - +REM rd /q /s dist +REM md dist +pyinstaller --windowed --onefile --hidden-import tornado.web -i=icon.ico --add-data icon.ico:files --name=navpoint-windows-%PROCESSOR_ARCHITECTURE%.exe main.py diff --git a/navpoint/fix_path.py b/navpoint/fix_path.py new file mode 100644 index 0000000..be068cc --- /dev/null +++ b/navpoint/fix_path.py @@ -0,0 +1,16 @@ +# Copyright 2018 Stack Overflow user "Kamal" +# Copyright 2024 Samuel Sloniker +# +# https://stackoverflow.com/a/53605128 +# +# Used, modified, and released under CC BY-SA 4.0: +# https://creativecommons.org/licenses/by-sa/4.0/ + +import sys +import os.path + +def fix_path(path): + if getattr(sys, 'frozen', False): + return os.path.join(sys._MEIPASS, "files", path) + else: + return path diff --git a/navpoint/gui.py b/navpoint/gui.py index 6c10dfd..fcdb6e0 100755 --- a/navpoint/gui.py +++ b/navpoint/gui.py @@ -1,5 +1,6 @@ import tkinter as tk import pyqrcode +import navpoint.fix_path def run(link): @@ -19,8 +20,8 @@ def run(link): label.config(image=image) try: - window.iconbitmap("icon.ico") - except tk.TclError: + window.iconbitmap(navpoint.fix_path.fix_path("icon.ico")) + except ImportError:#tk.TclError: pass