openfm-qt/prebuild.py

41 lines
945 B
Python
Raw Normal View History

2023-07-10 17:04:47 +02:00
# coding=utf-8
2023-07-08 20:20:56 +02:00
2023-07-10 01:29:19 +02:00
import sys
2023-07-08 20:20:56 +02:00
import os
2023-07-10 01:29:19 +02:00
from shutil import which
2023-07-10 18:05:59 +02:00
import logging
2023-07-08 20:20:56 +02:00
2023-07-10 02:10:52 +02:00
UI_DIR = "assets/ui"
2023-07-10 01:29:19 +02:00
2023-07-10 18:05:59 +02:00
logging.basicConfig(level=logging.INFO)
2023-07-10 01:29:19 +02:00
class UICNotFound(Exception):
pass
if sys.platform == "linux":
exe = "pyside6-uic"
exe_alt = "/usr/lib/qt6/uic"
elif sys.platform == "win32":
exe = "pyside6-uic.exe"
exe_alt = None
2023-07-10 18:05:59 +02:00
UI_DIR = UI_DIR.replace("/", "\\")
2023-07-10 01:29:19 +02:00
if not which(exe) and not which(exe_alt):
raise UICNotFound("User Interface Compiler binary not found.")
elif not which(exe) and which(exe_alt):
exe = exe_alt
2023-07-10 18:05:59 +02:00
logging.info("Building UI files...")
2023-07-10 01:29:19 +02:00
for f in os.listdir(UI_DIR):
if exe == "/usr/lib/qt6/uic":
__flags = "--generator python"
2023-07-10 18:05:59 +02:00
else:
__flags = ""
cmd = f"{exe} {UI_DIR}/{f} -o openfm_qt/ui_{f[:-3]}.py {__flags}"
if sys.platform == "win32":
cmd = cmd.replace("/", "\\")
os.system(cmd)
logging.info(f"Successfully builded {f} as ui_{f[:-3]}.py")