File: regenerate_example_ui.py

package info (click to toggle)
pyside6 6.10.2-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 48,184 kB
  • sloc: python: 205,032; cpp: 92,990; xml: 18,587; javascript: 1,182; sh: 163; makefile: 89
file content (37 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download | duplicates (3)
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
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
from __future__ import annotations

"""
regenerate_example_ui.py
========================

Regenerates the ui files of the PySide examples.
"""


import subprocess
import sys
from pathlib import Path

UIC_COMMAND = "pyside6-uic"


def generate_ui_file(ui_file):
    """Regenerate the ui file."""
    target_file = ui_file.parent / f"ui_{ui_file.stem}.py"
    if not target_file.is_file():
        print(target_file, " does not exist.", file=sys.stderr)
        return

    print("Regenerating ", ui_file, target_file)
    ex = subprocess.call([UIC_COMMAND, ui_file, "-o", target_file])
    if ex != 0:
        print(f"{UIC_COMMAND} failed for {ui_file}", file=sys.stderr)
        sys.exit(ex)


if __name__ == '__main__':
    examples_path = Path(__file__).resolve().parent.parent / "examples"
    for ui_file in examples_path.glob("**/*.ui"):
        generate_ui_file(ui_file)