From 2b5e9e9c7745e0b01d2de4214bbda850023d05c8 Mon Sep 17 00:00:00 2001 From: kevim Date: Fri, 12 May 2023 09:22:08 -0300 Subject: [PATCH 1/3] Fixing realpath, adding Python 10 requirements. Adding pyinstaller to generate exe easily --- .gitignore | 1 - REQUIREMENTS.txt | 5 ++-- alarm-clock/alarm_sound.py | 2 +- alarm-clock/app.py | 4 +-- app.spec | 50 ++++++++++++++++++++++++++++++++++++++ build-exe.bat | 1 + 6 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 app.spec create mode 100644 build-exe.bat diff --git a/.gitignore b/.gitignore index c9a26d9..e180e2b 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,3 @@ MANIFEST # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest -*.spec \ No newline at end of file diff --git a/REQUIREMENTS.txt b/REQUIREMENTS.txt index 9f26d71..c929c5b 100644 --- a/REQUIREMENTS.txt +++ b/REQUIREMENTS.txt @@ -1,2 +1,3 @@ -Pillow==8.1.1 -pygame==1.9.6 +Pillow +pygame +pyinstaller \ No newline at end of file diff --git a/alarm-clock/alarm_sound.py b/alarm-clock/alarm_sound.py index c3b745a..49b7193 100644 --- a/alarm-clock/alarm_sound.py +++ b/alarm-clock/alarm_sound.py @@ -13,7 +13,7 @@ def __init__(self, parent, file="default", set_window=False): self.set_window = set_window self.thread = Thread(target=self.on_active, daemon=True) if file == "default": - self.file = relpath("alarm-clock/assets/sounds/beep_beep.wav") + self.file = relpath("assets/sounds/beep_beep.wav") wav = wave.open(self.file) frequency = wav.getframerate() pygame.mixer.init(frequency=frequency) diff --git a/alarm-clock/app.py b/alarm-clock/app.py index 703f951..d9caf68 100644 --- a/alarm-clock/app.py +++ b/alarm-clock/app.py @@ -28,8 +28,8 @@ def __init__(self, width, height): def configure_window(self): self.title("Alarm Clock") self.geometry(f"{self.width}x{self.height}+100+100") - self.minsize(600, 185) - image_path = relpath("alarm-clock/assets/pictures/icon_2.ico") + self.minsize(300, 185) + image_path = relpath("assets/pictures/icon_2.ico") image = ImageTk.PhotoImage(file=image_path) self.iconphoto(False, image) diff --git a/app.spec b/app.spec new file mode 100644 index 0000000..0e071ba --- /dev/null +++ b/app.spec @@ -0,0 +1,50 @@ +# -*- mode: python ; coding: utf-8 -*- + + +block_cipher = None + + +a = Analysis( + ['alarm-clock\\app.py'], + pathex=['alarm-clock'], + binaries=[], + datas=[('alarm-clock\\assets','assets' )], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False, +) +pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) + +exe = EXE( + pyz, + a.scripts, + [], + exclude_binaries=True, + name='app', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=False, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, +) +coll = COLLECT( + exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='app', +) diff --git a/build-exe.bat b/build-exe.bat new file mode 100644 index 0000000..f6edf5d --- /dev/null +++ b/build-exe.bat @@ -0,0 +1 @@ +pyinstaller alarm-clock\app.py --distpath .\dist\ --add-data alarm-clock\assets:. -p alarm-clock \ No newline at end of file From 39100efd6445066079d7f29805de9cb208a0cd6f Mon Sep 17 00:00:00 2001 From: kevim Date: Fri, 12 May 2023 09:33:36 -0300 Subject: [PATCH 2/3] One file test --- app.spec | 20 +++++++------------- build-exe.bat | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app.spec b/app.spec index 0e071ba..feb20fe 100644 --- a/app.spec +++ b/app.spec @@ -8,7 +8,7 @@ a = Analysis( ['alarm-clock\\app.py'], pathex=['alarm-clock'], binaries=[], - datas=[('alarm-clock\\assets','assets' )], + datas=[('alarm-clock/assets', 'assets')], hiddenimports=[], hookspath=[], hooksconfig={}, @@ -24,13 +24,17 @@ pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE( pyz, a.scripts, + a.binaries, + a.zipfiles, + a.datas, [], - exclude_binaries=True, - name='app', + name='alarm-clock', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, + upx_exclude=[], + runtime_tmpdir=None, console=False, disable_windowed_traceback=False, argv_emulation=False, @@ -38,13 +42,3 @@ exe = EXE( codesign_identity=None, entitlements_file=None, ) -coll = COLLECT( - exe, - a.binaries, - a.zipfiles, - a.datas, - strip=False, - upx=True, - upx_exclude=[], - name='app', -) diff --git a/build-exe.bat b/build-exe.bat index f6edf5d..409e1b5 100644 --- a/build-exe.bat +++ b/build-exe.bat @@ -1 +1 @@ -pyinstaller alarm-clock\app.py --distpath .\dist\ --add-data alarm-clock\assets:. -p alarm-clock \ No newline at end of file +pyinstaller --onefile alarm-clock\app.py --distpath .\windows-x86_64\ -p alarm-clock \ No newline at end of file From 995d00284b04cf694088a3b7de1785c285ba7e74 Mon Sep 17 00:00:00 2001 From: kevim Date: Fri, 12 May 2023 09:59:28 -0300 Subject: [PATCH 3/3] Executable command success --- app.spec => alarm-clock.spec | 18 ++++++++++++------ build-exe.bat | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) rename app.spec => alarm-clock.spec (83%) diff --git a/app.spec b/alarm-clock.spec similarity index 83% rename from app.spec rename to alarm-clock.spec index feb20fe..34084ee 100644 --- a/app.spec +++ b/alarm-clock.spec @@ -8,7 +8,7 @@ a = Analysis( ['alarm-clock\\app.py'], pathex=['alarm-clock'], binaries=[], - datas=[('alarm-clock/assets', 'assets')], + datas=[('alarm-clock\\assets', 'assets')], hiddenimports=[], hookspath=[], hooksconfig={}, @@ -24,17 +24,13 @@ pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE( pyz, a.scripts, - a.binaries, - a.zipfiles, - a.datas, [], + exclude_binaries=True, name='alarm-clock', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, - upx_exclude=[], - runtime_tmpdir=None, console=False, disable_windowed_traceback=False, argv_emulation=False, @@ -42,3 +38,13 @@ exe = EXE( codesign_identity=None, entitlements_file=None, ) +coll = COLLECT( + exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='alarm-clock', +) diff --git a/build-exe.bat b/build-exe.bat index 409e1b5..a07d787 100644 --- a/build-exe.bat +++ b/build-exe.bat @@ -1 +1 @@ -pyinstaller --onefile alarm-clock\app.py --distpath .\windows-x86_64\ -p alarm-clock \ No newline at end of file +pyinstaller alarm-clock\app.py -w --add-data alarm-clock\assets;assets --distpath .\dist\windows-x86_64\ --name alarm-clock -p alarm-clock \ No newline at end of file