- Remove find_ghostscript() and print_pdf_with_ghostscript() from print_label.py - SumatraPDF is now the primary print method with -print-settings noscale - Fix SumatraPDF arg order: file_path moved to last position - Add -appdata-dir so SumatraPDF reads conf/SumatraPDF-settings.txt (PrintScale=noscale) - win32api ShellExecute kept as last-resort fallback - Remove GhostScript bundling from LabelPrinter.spec and build_exe.py - Add conf/ folder pre-flight check to build_exe.py - Rebuild dist/LabelPrinter.exe (41 MB, SumatraPDF-only)
100 lines
3.3 KiB
Python
100 lines
3.3 KiB
Python
"""
|
|
PyInstaller build script for Label Printer GUI
|
|
Run this to create a standalone Windows executable.
|
|
|
|
IMPORTANT: This script MUST be run on Windows to generate a Windows .exe file.
|
|
If run on Linux/macOS, it will create a Linux/macOS binary that won't work on Windows.
|
|
|
|
To build for Windows:
|
|
1. Copy this project to a Windows machine
|
|
2. Install dependencies: pip install -r requirements_windows.txt
|
|
3. Run this script: python build_exe.py
|
|
4. The Windows .exe will be created in the dist/ folder
|
|
|
|
Printing method
|
|
---------------
|
|
SumatraPDF is bundled inside the exe and used for all printing.
|
|
It sends the PDF at its exact 35x25 mm page size via -print-settings noscale.
|
|
No GhostScript installation required on the build or target machine.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
|
|
# Get the current directory
|
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
def check_conf_folder():
|
|
"""
|
|
Verify that required files are present in the conf\ folder before building.
|
|
Returns True if all required files exist, False otherwise.
|
|
"""
|
|
required = [
|
|
os.path.join('conf', 'SumatraPDF.exe'),
|
|
os.path.join('conf', 'SumatraPDF-settings.txt'),
|
|
os.path.join('conf', 'label_template_ok.svg'),
|
|
os.path.join('conf', 'label_template_nok.svg'),
|
|
os.path.join('conf', 'label_template.svg'),
|
|
]
|
|
all_ok = True
|
|
for f in required:
|
|
if os.path.exists(f):
|
|
print(f" OK: {f}")
|
|
else:
|
|
print(f" MISSING: {f}")
|
|
all_ok = False
|
|
return all_ok
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print("=" * 60)
|
|
print("Label Printer GUI - PyInstaller Build")
|
|
print("=" * 60)
|
|
|
|
# Change to script directory so relative paths work
|
|
os.chdir(script_dir)
|
|
|
|
# Step 1: Verify conf\ folder contents
|
|
print("\n[1/2] Checking conf\\ folder...")
|
|
if not check_conf_folder():
|
|
print("\nERROR: One or more required conf\\ files are missing.")
|
|
print("Place SumatraPDF.exe and the SVG templates in the conf\\ folder, then retry.")
|
|
sys.exit(1)
|
|
|
|
# Step 2: Build with PyInstaller using the handcrafted spec file.
|
|
print("\n[2/2] Building standalone executable via LabelPrinter.spec...")
|
|
print("This may take a few minutes...\n")
|
|
|
|
try:
|
|
result = subprocess.run(
|
|
['pyinstaller', 'LabelPrinter.spec',
|
|
'--distpath=./dist', '--workpath=./build', '-y'],
|
|
check=True,
|
|
)
|
|
|
|
print("\n" + "=" * 60)
|
|
print("Build Complete!")
|
|
print("=" * 60)
|
|
print("\nExecutable location: ./dist/LabelPrinter.exe")
|
|
print("\nBundled components:")
|
|
print(" - SumatraPDF (primary printing, noscale 35x25 mm)")
|
|
print(" - SVG templates, conf files")
|
|
print("\nYou can now:")
|
|
print(" 1. Double-click LabelPrinter.exe to run")
|
|
print(" 2. Copy the dist\\ folder to target machines")
|
|
print(" 3. No extra software installation required on target machines")
|
|
print("\nNote: First run may take a moment as Kivy initializes")
|
|
except subprocess.CalledProcessError as e:
|
|
print("\n" + "=" * 60)
|
|
print("Build Failed!")
|
|
print("=" * 60)
|
|
print(f"\nError code: {e.returncode}")
|
|
print("\nPlease check the error messages above for details.")
|
|
sys.exit(1)
|
|
except Exception as e:
|
|
print(f"\nFatal error: {e}")
|
|
sys.exit(1)
|
|
|