-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Qt5 backwards compatibility for UI generation (#303)
Attempts to fully support PyQt5 backwards compatibility based on feedback from @PrentissLiu
- Loading branch information
1 parent
206ff99
commit 0c21a90
Showing
3 changed files
with
26 additions
and
9 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
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
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,14 +1,21 @@ | ||
import subprocess | ||
|
||
|
||
def build_ui(in_file, out_file): | ||
stdout = subprocess.run(["pyuic6", in_file], stdout=subprocess.PIPE).stdout | ||
|
||
lines = stdout.decode("utf-8").replace("__relpath__", "") | ||
|
||
with open(out_file, "w") as sources: | ||
sources.write(lines) | ||
stdout = subprocess.Popen(["pyuic6", in_file], stdout=subprocess.PIPE, text=True).stdout | ||
|
||
with open(out_file, 'w') as sources: | ||
for line in iter(stdout.readline, ""): | ||
if line.startswith("from PyQt6 import"): | ||
imports = line.split("import")[1].strip() | ||
sources.write(f"""try: | ||
from PyQt6 import {imports} | ||
except: | ||
from PyQt5 import {imports} | ||
QtCore.Qt.AlignmentFlag.AlignLeading = QtCore.Qt.AlignLeading | ||
QtCore.Qt.AlignmentFlag.AlignTrailing = QtCore.Qt.AlignTrailing | ||
""") | ||
else: | ||
sources.write(line) | ||
|
||
build_ui("morph/readability.ui", "morph/readability_ui.py") | ||
build_ui("morph/readability_settings.ui", "morph/readability_settings_ui.py") |