forked from PathOfBuildingCommunity/PathOfBuilding-Python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-ui.py
82 lines (70 loc) · 2.58 KB
/
build-ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
Creates .py script from .ui files in the /src/ui/ folder
"""
import os
import sys
from colorama import Fore
from pathlib import Path
from subprocess import Popen, PIPE
import PySide6
def get_uic_exe():
pyside_dir = Path(PySide6.__file__).resolve().parent
print(sys.platform)
# Don't know if this is overkill but just something that could be
# utilized if running on different machines. (L28 too)
#
# Could use some further tweaking if that usecase above is correct.
if sys.platform != "win32":
exe = pyside_dir / "Qt" / "libexec" / "uic"
else:
exe = pyside_dir / "uic.exe"
print(exe)
return exe
def get_rcc_exe():
pyside_dir = Path(PySide6.__file__).resolve().parent
if sys.platform != "win32":
exe = pyside_dir / "Qt" / "libexec" / "rcc"
else:
exe = pyside_dir / "rcc.exe"
return exe
def generate_py_from_ui():
exe = get_uic_exe()
for path in Path("./Assets/ui_files/").glob("*.ui"):
Path("src", "ui").mkdir(exist_ok=True)
outpath = Path("src", "ui", path.name).with_suffix(".py")
ui_time = os.path.getmtime(path)
if os.path.isfile(outpath) and ui_time == os.path.getmtime(outpath):
print(f"skipping {outpath}, exists and no change.")
pass
else:
cmd = [os.fspath(exe), "-g", "python", str(path), "-o", str(outpath)]
proc = Popen(cmd, stderr=PIPE)
out, err = proc.communicate()
if err:
msg = err.decode("utf-8")
command = " ".join(cmd)
print(f"{Fore.RED}Error: {msg}{Fore.RESET}\nwhile executing '{command}'")
else:
print(path, ">>", Fore.GREEN, outpath, Fore.RESET)
os.utime(outpath, (ui_time, ui_time))
def generate_qrc():
exe = get_rcc_exe()
path = "./Assets/PoB.qrc"
outpath = Path("src", "PoB_rc").with_suffix(".py")
ui_time = os.path.getmtime(path)
if os.path.isfile(outpath) and ui_time == os.path.getmtime(outpath):
print(f"skipping {outpath}, exists and no change.")
pass
else:
cmd = [os.fspath(exe), "-g", "python", str(path), "-o", str(outpath)]
proc = Popen(cmd, stderr=PIPE)
out, err = proc.communicate()
if err:
msg = err.decode("utf-8")
command = " ".join(cmd)
print(f"{Fore.RED}Error: {msg}{Fore.RESET}\nwhile executing '{command}'")
else:
print(path, ">>", Fore.GREEN, outpath, Fore.RESET)
os.utime(outpath, (ui_time, ui_time))
generate_py_from_ui()
generate_qrc()