1921 @return tuple of directory name (string) and source file name (string) |
1923 @return tuple of directory name (string) and source file name (string) |
1922 """ |
1924 """ |
1923 return py_dir, "Ui_{0}".format(py_file) |
1925 return py_dir, "Ui_{0}".format(py_file) |
1924 |
1926 |
1925 |
1927 |
1926 def compileUiFiles(): |
1928 def __compileOneUi(ui_path, mapFunc=None): |
1927 """ |
1929 """ |
1928 Compile the .ui files to Python sources. |
1930 Function to compile a single form file to Python code. |
1929 """ |
1931 |
1930 from PyQt6.uic import compileUiDir |
1932 @param ui_path path of the Qt form file |
1931 |
1933 @type str |
1932 compileUiDir(eric7SourceDir, True, __pyName) |
1934 @param mapFunc function to change directory and/or name of the resulting Python file |
|
1935 (defaults to None) |
|
1936 @type func (optional) |
|
1937 """ |
|
1938 from PyQt6.uic import compileUi |
|
1939 |
|
1940 py_dir, py_file = os.path.split(ui_path[:-3] + ".py") |
|
1941 |
|
1942 # Allow the caller to change the name of the .py file or generate |
|
1943 # it in a different directory. |
|
1944 if mapFunc is not None: |
|
1945 py_dir, py_file = mapFunc(py_dir, py_file) |
|
1946 |
|
1947 # Make sure the destination directory exists. |
|
1948 os.makedirs(py_dir, exist_ok=True) |
|
1949 |
|
1950 py_path = os.path.join(py_dir, py_file) |
|
1951 |
|
1952 with open(py_path, "w", encoding="utf-8") as py_file: |
|
1953 compileUi(ui_path, py_file, execute=False, indent=4) |
|
1954 |
|
1955 |
|
1956 def compileUiDir(root, recurse=False, mapFunc=None, workers=1): |
|
1957 """ |
|
1958 Function to compile all Qt form files of a directory or directory tree |
|
1959 to Python code. |
|
1960 |
|
1961 @param root directory to scan for Qt form files (i.e. files ending with '.ui' |
|
1962 @type str |
|
1963 @param recurse flag indicating to recurse into sub-directories (defaults to False) |
|
1964 @type bool (optional) |
|
1965 @param mapFunc function to change directory and/or name of the resulting Python file |
|
1966 (defaults to None) |
|
1967 @type func (optional) |
|
1968 @param workers number of worker processes to be used to compile (defaults to 1) |
|
1969 @type int (optional) |
|
1970 """ |
|
1971 if recurse: |
|
1972 ui_files = [] |
|
1973 for rootDir, _, files in os.walk(root): |
|
1974 ui_files.extend( |
|
1975 os.path.join(rootDir, ui) for ui in files if ui.endswith(".ui") |
|
1976 ) |
|
1977 else: |
|
1978 ui_files = [ |
|
1979 os.path.join(root, ui) |
|
1980 for ui in os.listdir(root) |
|
1981 if os.path.isfile(os.path.join(root, ui) and ui.endswith(".ui")) |
|
1982 ] |
|
1983 |
|
1984 ProcessPoolExecutor = None |
|
1985 if workers != 1: |
|
1986 try: |
|
1987 from concurrent.futures import ProcessPoolExecutor # __IGNORE_WARNING__ |
|
1988 except NotImplementedError: |
|
1989 workers = 1 |
|
1990 |
|
1991 if workers != 1 and ProcessPoolExecutor is not None: |
|
1992 # If workers == 0, let ProcessPoolExecutor determine worker count. |
|
1993 workers = workers or None |
|
1994 with ProcessPoolExecutor(max_workers=workers) as executor: |
|
1995 executor.map( |
|
1996 partial(__compileOneUi, mapFunc=mapFunc), |
|
1997 ui_files, |
|
1998 ) |
|
1999 else: |
|
2000 for ui_file in ui_files: |
|
2001 __compileOneUi(ui_file, mapFunc=mapFunc) |
1933 |
2002 |
1934 |
2003 |
1935 def prepareInfoFile(fileName): |
2004 def prepareInfoFile(fileName): |
1936 """ |
2005 """ |
1937 Function to prepare an Info.py file when installing from source. |
2006 Function to prepare an Info.py file when installing from source. |
2272 # step 1: remove old Ui_*.py files |
2341 # step 1: remove old Ui_*.py files |
2273 for root, _, files in os.walk(sourceDir): |
2342 for root, _, files in os.walk(sourceDir): |
2274 for file in [f for f in files if fnmatch.fnmatch(f, "Ui_*.py")]: |
2343 for file in [f for f in files if fnmatch.fnmatch(f, "Ui_*.py")]: |
2275 os.remove(os.path.join(root, file)) |
2344 os.remove(os.path.join(root, file)) |
2276 # step 2: compile the forms |
2345 # step 2: compile the forms |
2277 compileUiFiles() |
2346 compileUiDir(eric7SourceDir, recurse=True, mapFunc=__pyName, workers=0) |
2278 print(" Done") |
2347 print(" Done") |
2279 |
2348 |
2280 if doCompile: |
2349 if doCompile: |
2281 print("Compiling source files ...", end="", flush=True) |
2350 print("Compiling source files ...", end="", flush=True) |
2282 skipRe = re.compile(r"DebugClients[\\/]Python[\\/]") |
2351 skipRe = re.compile(r"DebugClients[\\/]Python[\\/]") |