-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,72 @@ | ||
import alqtendpy.compileui | ||
# import alqtendpy.compileui | ||
import io | ||
import pathlib | ||
|
||
import PyQt5.uic | ||
|
||
|
||
def _do_nothing(*args, **kwargs): | ||
pass | ||
|
||
|
||
def compile_ui( | ||
file_paths=(), | ||
directory_paths=(), | ||
extension=".ui", | ||
suffix="_ui", | ||
encoding="utf-8", | ||
output=_do_nothing, | ||
qtpy=False, | ||
): | ||
paths = collect_paths( | ||
file_paths=file_paths, | ||
directory_paths=directory_paths, | ||
extension=extension, | ||
) | ||
|
||
compile_paths( | ||
ui_paths=paths, | ||
suffix=suffix, | ||
encoding=encoding, | ||
output=output, | ||
qtpy=qtpy, | ||
) | ||
|
||
|
||
def collect_paths(file_paths=(), directory_paths=(), extension=".ui"): | ||
file_paths = [pathlib.Path(path) for path in file_paths] | ||
|
||
for directory in directory_paths: | ||
path = pathlib.Path(directory) | ||
found_paths = path.rglob("*" + extension) | ||
file_paths.extend(found_paths) | ||
|
||
return file_paths | ||
|
||
|
||
def compile_paths( | ||
ui_paths, | ||
suffix="_ui", | ||
encoding="utf-8", | ||
output=_do_nothing, | ||
qtpy=False, | ||
): | ||
for path in ui_paths: | ||
in_path = path | ||
out_path = path.with_name(f"{path.stem}{suffix}.py") | ||
|
||
output(f"Converting: {in_path} -> {out_path}") | ||
intermediate = io.StringIO() | ||
PyQt5.uic.compileUi(in_path, intermediate) | ||
intermediate = intermediate.getvalue() | ||
if qtpy: | ||
intermediate = intermediate.replace("PyQt5", "qtpy") | ||
with open(out_path, "w", encoding=encoding) as out_file: | ||
out_file.write(intermediate) | ||
|
||
|
||
def compile_ui(): | ||
print("epyqlib::compile_ui building UI in epyqlib") | ||
alqtendpy.compileui.compile_ui( | ||
compile_ui( | ||
directory_paths=[pathlib.Path(__file__).parent], | ||
) |