ico file for windows build and setup for windows

This commit is contained in:
robert 2026-01-06 19:37:57 +01:00
parent 835ac2e9a6
commit 9bd189a4a9
2 changed files with 97 additions and 36 deletions

BIN
AppIcon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

133
setup.py
View file

@ -1,41 +1,102 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys import sys
from setuptools import setup import platform
from pathlib import Path
import subprocess
# Application metadata def check_pyinstaller():
APP_NAME = "PNG Metadata Editor" """Check if PyInstaller is installed and available"""
APP_VERSION = "1.0.0" try:
AUTHOR = "Robert Tusa" subprocess.run(
DESCRIPTION = "A graphical tool for viewing and editing metadata in PNG files" [sys.executable, "-m", "PyInstaller", "--version"],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
return True
except (subprocess.CalledProcessError, FileNotFoundError):
return False
# Read the long description from README def install_pyinstaller():
with open('README.md', 'r', encoding='utf-8') as f: """Install PyInstaller if not already installed"""
long_description = f.read() print("PyInstaller not found. Installing now...")
try:
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "--upgrade", "pyinstaller"],
stdout=subprocess.DEVNULL
)
print("PyInstaller installed successfully.")
return True
except subprocess.CalledProcessError as e:
print(f"Failed to install PyInstaller: {e}")
return False
setup( def main():
name=APP_NAME, # Check and install PyInstaller if needed
version=APP_VERSION, if not check_pyinstaller():
description=DESCRIPTION, if not install_pyinstaller():
long_description=long_description, print("Error: PyInstaller installation failed. Please install it manually:")
long_description_content_type='text/markdown', print("pip install pyinstaller")
author=AUTHOR, sys.exit(1)
author_email='robert@tusa.at', # Replace with your email
url='https://git.tusa.at/robert/png-meta-editor', # Replace with your repo # Check if requirements.txt exists and install dependencies
license='MIT', req_file = Path("requirements.txt")
python_requires='>=3.6', if req_file.exists():
app=['png-meta-editor.py'], # Your main script print("\nInstalling dependencies from requirements.txt...")
data_files=[('', try:
['AppIcon.icns', 'version.txt'])], # Include these files subprocess.check_call(
options={ [sys.executable, "-m", "pip", "install", "-r", "requirements.txt"],
'py2app': { stdout=subprocess.DEVNULL
'argv_emulation': True, )
'iconfile': 'AppIcon.icns', except subprocess.CalledProcessError as e:
'plist': { print(f"Warning: Failed to install some dependencies: {e}")
'CFBundleName': APP_NAME, else:
'CFBundleShortVersionString': APP_VERSION, print("\nWarning: requirements.txt not found. Installing default dependencies...")
'CFBundleVersion': APP_VERSION, try:
}, subprocess.check_call(
}, [sys.executable, "-m", "pip", "install", "pillow>=9.0.0", "pngmeta>=1.0.0"],
}, stdout=subprocess.DEVNULL
setup_requires=['py2app'], )
) except subprocess.CalledProcessError as e:
print(f"Warning: Failed to install default dependencies: {e}")
# Determine platform-specific build options
system = platform.system()
base_args = [
"--name", "PNG Metadata Editor",
"--windowed",
"--onefile"
]
# Check for version.txt
version_file = Path("version.txt")
if version_file.exists():
print(f"\nUsing version info from {version_file}")
base_args.extend(["--version-file", "version.txt"])
else:
print("\nWarning: version.txt not found. Using default version.")
if system == "Windows":
base_args.extend(["--icon", "AppIcon.ico"])
elif system == "Darwin": # macOS
base_args.extend(["--icon", "AppIcon.icns"])
else: # Linux
pass
# Build the PyInstaller command
pyinstaller_args = ["--distpath", "dist", "--workpath", "build"] + base_args
cmd = [sys.executable, "-m", "PyInstaller"] + pyinstaller_args + ["png-meta-editor.py"]
print(f"\nBuilding PNG Metadata Editor for {system}...")
try:
result = subprocess.run(cmd)
if result.returncode == 0:
print("\nBuild completed successfully!")
print(f"Your executable is in the dist/ folder")
return result.returncode
except subprocess.CalledProcessError as e:
print(f"\nBuild failed with error: {e}")
return 1
if __name__ == "__main__":
sys.exit(main())