Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Qt5 backwards compatibility for UI generation #303

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion morph/readability_settings_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
# run again. Do not edit this file unless you know what you are doing.


from PyQt6 import QtCore, QtWidgets
try:
from PyQt6 import QtCore, QtGui, QtWidgets
except:
from PyQt5 import QtCore, QtGui, QtWidgets
QtCore.Qt.AlignmentFlag.AlignLeading = QtCore.Qt.AlignLeading
QtCore.Qt.AlignmentFlag.AlignTrailing = QtCore.Qt.AlignTrailing


class Ui_ReadabilitySettingsDialog(object):
Expand Down
7 changes: 6 additions & 1 deletion morph/readability_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
# run again. Do not edit this file unless you know what you are doing.


from PyQt6 import QtCore, QtGui, QtWidgets
try:
from PyQt6 import QtCore, QtGui, QtWidgets
except:
from PyQt5 import QtCore, QtGui, QtWidgets
QtCore.Qt.AlignmentFlag.AlignLeading = QtCore.Qt.AlignLeading
QtCore.Qt.AlignmentFlag.AlignTrailing = QtCore.Qt.AlignTrailing


class Ui_ReadabilityDialog(object):
Expand Down
21 changes: 14 additions & 7 deletions scripts/build_ui.py
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")