epson_print_conf/epson_print_conf.spec

144 lines
4.1 KiB
RPMSpec
Raw Normal View History

2024-07-29 05:13:15 -04:00
# -*- mode: python ; coding: utf-8 -*-
import argparse
2024-08-13 12:01:12 -04:00
import os
import os.path
from PIL import Image, ImageDraw, ImageFont
from PyInstaller.utils.hooks import collect_submodules, collect_data_files
2024-08-13 12:01:12 -04:00
def create_image(png_file, text):
2024-08-13 16:47:44 -04:00
x_size = 800
y_size = 150
font_size = 30
img = Image.new('RGB', (x_size, y_size), color='black')
fnt = ImageFont.truetype('arialbd.ttf', font_size)
2024-08-13 12:01:12 -04:00
d = ImageDraw.Draw(img)
shadow_offset = 2
bbox = d.textbbox((0, 0), text, font=fnt)
2024-08-13 16:47:44 -04:00
x, y = (x_size-bbox[2])/2, (y_size-bbox[3])/2
2024-08-13 12:01:12 -04:00
d.text((x+shadow_offset, y+shadow_offset), text, font=fnt, fill='gray')
d.text((x, y), text, font=fnt, fill='#baf8f8')
img.save(png_file, 'PNG')
2024-07-29 05:13:15 -04:00
parser = argparse.ArgumentParser()
parser.add_argument("--default", action="store_true")
2024-08-13 16:47:44 -04:00
parser.add_argument("--version", action="store", default=None)
2024-07-29 05:13:15 -04:00
options = parser.parse_args()
PROGRAM = [ 'gui.py' ]
2024-08-13 12:01:12 -04:00
BASENAME = 'epson_print_conf'
DATAS = [(BASENAME + '.pickle', '.')]
SPLASH_IMAGE = BASENAME + '.png'
2024-08-13 16:47:44 -04:00
version = (
"ui.VERSION = '" + options.version.replace('v', '') + "'"
) if options.version else ""
2024-08-13 12:01:12 -04:00
create_image(
SPLASH_IMAGE, 'Epson Printer Configuration tool loading...'
)
if not options.default and not os.path.isfile(DATAS[0][0]):
print("\nMissing file", DATAS[0][0], "without using the default option.")
quit()
gui_wrapper = """import pyi_splash
import pickle
2024-08-13 16:47:44 -04:00
import ui
2024-08-13 12:01:12 -04:00
from os import path
2024-08-13 16:47:44 -04:00
""" + version + """
2024-08-13 12:01:12 -04:00
path_to_pickle = path.abspath(
path.join(path.dirname(__file__), '""" + DATAS[0][0] + """')
)
with open(path_to_pickle, 'rb') as fp:
conf_dict = pickle.load(fp)
2024-08-13 16:47:44 -04:00
app = ui.EpsonPrinterUI(conf_dict=conf_dict, replace_conf=False)
2024-08-13 12:01:12 -04:00
pyi_splash.close()
app.mainloop()
"""
2024-07-29 05:13:15 -04:00
if options.default:
DATAS = []
2024-08-13 12:01:12 -04:00
gui_wrapper = """import pyi_splash
import pickle
2024-08-13 16:47:44 -04:00
import ui
2024-08-13 12:01:12 -04:00
from os import path
2024-08-13 16:47:44 -04:00
""" + version + """
app = ui.main()
2024-08-13 12:01:12 -04:00
pyi_splash.close()
app.mainloop()
"""
with open(PROGRAM[0], 'w') as file:
file.write(gui_wrapper)
2024-07-29 05:13:15 -04:00
# black submodules: https://github.com/pyinstaller/pyinstaller/issues/8270
black_submodules = collect_submodules('black')
blib2to3_submodules = collect_submodules('blib2to3')
# "black" data files: https://github.com/pyinstaller/pyinstaller/issues/8270
blib2to3_data = collect_data_files('blib2to3')
2024-07-29 05:13:15 -04:00
a = Analysis(
PROGRAM,
pathex=[],
binaries=[],
datas=DATAS + blib2to3_data, # the latter required by black
hiddenimports=[
'babel.numbers',
# The following modules are needed by "black": https://github.com/pyinstaller/pyinstaller/issues/8270
'30fcd23745efe32ce681__mypyc',
'6b397dd64e00b5aff23d__mypyc', 'click', 'json', 'platform',
'mypy_extensions', 'pathspec', '_black_version', 'platformdirs'
] + black_submodules + blib2to3_submodules, # the last two required by black
2024-07-29 05:13:15 -04:00
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
2024-08-13 12:01:12 -04:00
splash = Splash(
SPLASH_IMAGE,
binaries=a.binaries,
datas=a.datas,
text_pos=None,
text_size=12,
minify_script=True,
always_on_top=True,
)
2024-07-29 05:13:15 -04:00
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
2024-08-13 12:01:12 -04:00
splash,
splash.binaries,
2024-07-29 05:13:15 -04:00
[],
2024-08-13 12:01:12 -04:00
name=BASENAME,
2024-07-30 02:17:43 -04:00
debug=False, # Setting to True gives you progress messages from the executable (for console=False there will be annoying MessageBoxes on Windows).
2024-07-29 05:13:15 -04:00
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
2024-08-13 12:01:12 -04:00
console=options.default, # On Windows or Mac OS governs whether to use the console executable or the windowed executable. Always True on Linux/Unix (always console executable - it does not matter there).
2024-07-30 02:17:43 -04:00
disable_windowed_traceback=False, # Disable traceback dump of unhandled exception in windowed (noconsole) mode (Windows and macOS only)
2024-08-13 12:01:12 -04:00
hide_console='hide-early', # Windows only. In console-enabled executable, hide or minimize the console window ('hide-early', 'minimize-early', 'hide-late', 'minimize-late')
2024-07-29 05:13:15 -04:00
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
2024-08-13 12:01:12 -04:00
os.remove(SPLASH_IMAGE)
os.remove(PROGRAM[0])