scripts/compileUiFiles.py

Tue, 03 Jan 2023 17:00:42 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 03 Jan 2023 17:00:42 +0100
branch
eric7-maintenance
changeset 9669
73a9cf535429
parent 9653
e67609152c5e
child 9986
2c571c1c7b0d
permissions
-rw-r--r--

Prepared the changelog file for a bug fix release.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright (c) 2009 - 2023 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Script for eric to compile all .ui files to Python source.
"""

import os
import sys

from PyQt6.uic import compileUiDir


def __pyName(py_dir, py_file):
    """
    Local function to create the Python source file name for the compiled
    .ui file.

    @param py_dir suggested name of the directory (string)
    @param py_file suggested name for the compile source file (string)
    @return tuple of directory name (string) and source file name (string)
    """
    return py_dir, "Ui_{0}".format(py_file)


def compileUiFiles():
    """
    Compile the .ui files to Python sources.
    """
    if os.path.exists("src"):
        # eric7 with 'src' layout
        compileUiDir(os.path.join("src", "eric7"), recurse=True, map=__pyName)
    elif os.path.exists("eric7"):
        # old layout or invoked from within 'src'
        compileUiDir("eric7", recurse=True, map=__pyName)
    else:
        print("No valid 'eric7' source layout could be found. Aborting...")


def main(argv):
    """
    The main function of the script.

    @param argv the list of command line arguments.
    """
    # Compile .ui files
    print("Compiling user interface files...")
    compileUiFiles()


if __name__ == "__main__":
    try:
        main(sys.argv)
    except SystemExit:
        raise
    except Exception:
        print(
            "\nAn internal error occured.  Please report all the output of the"
            " program, \nincluding the following traceback, to"
            " eric-bugs@eric-ide.python-projects.org.\n"
        )
        raise

#
# eflag: noqa = M801

eric ide

mercurial