Skip to content

Commit

Permalink
no alqtendpy
Browse files Browse the repository at this point in the history
  • Loading branch information
epcAnker committed Nov 13, 2023
1 parent f4f1d62 commit cd27338
Showing 1 changed file with 65 additions and 2 deletions.
67 changes: 65 additions & 2 deletions epyqlib/builduiepyqlib.py
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],
)

0 comments on commit cd27338

Please sign in to comment.