File: compile_ui_files.py

package info (click to toggle)
finalcif 156%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 53,700 kB
  • sloc: python: 50,427; cpp: 67; sh: 51; makefile: 22
file content (31 lines) | stat: -rw-r--r-- 894 bytes parent folder | download
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
import subprocess
from pathlib import Path


def fix_comment(pyfile: Path) -> str:
    txt = pyfile.read_text()
    lines = txt.splitlines(keepends=True)
    for num, line in enumerate(lines):
        lines[num] = line.replace('PySide6', 'qtpy')
    lines[5] = ''#f"## Form generated from reading UI file '{uifile.name}'\n"
    lines[7] = ''#'"## Created by: Qt User Interface Compiler\n"
    txt = ''.join(lines)
    return txt


def compile_ui():
    ui_files = (Path(__file__).parent.parent / 'finalcif').rglob('*.ui')
    for ui_file in ui_files:
        compile_ui_file(ui_file)


def compile_ui_file(ui_file: Path) -> None:
    py_file = ui_file.with_suffix('.py')
    subprocess.check_output(['pyside6-uic', '-a', ui_file, '-o', py_file])
    print(py_file, 'finished')
    txt = fix_comment(pyfile=py_file)
    py_file.write_text(data=txt)


if __name__ == '__main__':
    compile_ui()