File: rebuildUi.py

package info (click to toggle)
python-pyqtgraph 0.13.7-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,068 kB
  • sloc: python: 54,043; makefile: 129; ansic: 40; sh: 2
file content (60 lines) | stat: -rw-r--r-- 1,544 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
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
#!/usr/bin/python
"""
Script for compiling Qt Designer .ui files to .py
"""


import os
import subprocess
import sys

pyqt6uic = 'pyuic6'

usage = """Compile .ui files to .py for PyQt6

  Usage: python rebuildUi.py [--force] [.ui files|search paths]

  May specify a list of .ui files and/or directories to search recursively for .ui files.
"""

args = sys.argv[1:]

if '--force' in args:
    force = True
    args.remove('--force')
else:
    force = False

if len(args) == 0:
    print(usage)
    sys.exit(-1)

uifiles = []
for arg in args:
    if os.path.isfile(arg) and arg.endswith('.ui'):
        uifiles.append(arg)
    elif os.path.isdir(arg):
        # recursively search for ui files in this directory
        for path, sd, files in os.walk(arg):
            uifiles.extend(os.path.join(path, f) for f in files if f.endswith('.ui'))
    else:
        print('Argument "%s" is not a directory or .ui file.' % arg)
        sys.exit(-1)

compiler = pyqt6uic
extension = '_generic.py'
# rebuild all requested ui files
for ui in uifiles:
    base, _ = os.path.splitext(ui)
    py = base + ext
    if not force and os.path.exists(py) and os.stat(ui).st_mtime <= os.stat(py).st_mtime:
        print(f"Skipping {py}; already compiled.")
    else:
        cmd = f'{compiler} {ui} > {py}'
        print(cmd)
        try:
            subprocess.check_call(cmd, shell=True)
        except subprocess.CalledProcessError:
            os.remove(py)
        else:
            print(f"{py} created, modify import to import from pyqtgraph.Qt not PyQt6")