2020-11-01 05:26:58 +01:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import io
|
2021-10-05 05:18:43 +02:00
|
|
|
from PyQt6.uic import compileUi
|
2020-11-01 05:26:58 +01:00
|
|
|
|
|
|
|
ui_file = sys.argv[1]
|
|
|
|
py_file = sys.argv[2]
|
|
|
|
buf = io.StringIO()
|
2021-10-05 05:18:43 +02:00
|
|
|
compileUi(open(ui_file), buf)
|
2020-11-01 05:26:58 +01:00
|
|
|
|
|
|
|
outdata = buf.getvalue()
|
2020-11-17 10:55:18 +01:00
|
|
|
outdata = outdata.replace(
|
2021-10-05 05:18:43 +02:00
|
|
|
"from PyQt6 import QtCore, QtGui, QtWidgets",
|
|
|
|
"from PyQt6 import QtCore, QtGui, QtWidgets\nfrom aqt.utils import tr\n"
|
2020-11-17 10:55:18 +01:00
|
|
|
)
|
|
|
|
outdata = re.sub(
|
2021-03-26 06:03:51 +01:00
|
|
|
r'(?:QtGui\.QApplication\.)?_?translate\(".*?", "(.*?)"', "tr.\\1(", outdata
|
2020-11-17 10:55:18 +01:00
|
|
|
)
|
2020-11-01 05:26:58 +01:00
|
|
|
|
2021-03-26 07:06:02 +01:00
|
|
|
|
|
|
|
outlines = []
|
2021-04-14 10:22:02 +02:00
|
|
|
qt_bad_types = [
|
|
|
|
".connect(",
|
|
|
|
]
|
2021-03-26 07:06:02 +01:00
|
|
|
for line in outdata.splitlines():
|
|
|
|
for substr in qt_bad_types:
|
|
|
|
if substr in line:
|
|
|
|
line = line + " # type: ignore"
|
|
|
|
break
|
2021-10-05 06:44:07 +02:00
|
|
|
if line == "from . import icons_rc":
|
|
|
|
continue
|
|
|
|
line = line.replace(":/icons/", "icons:")
|
2021-10-05 05:18:43 +02:00
|
|
|
line = line.replace("QAction.PreferencesRole", "QAction.MenuRole.PreferencesRole")
|
|
|
|
line = line.replace("QAction.AboutRole", "QAction.MenuRole.AboutRole")
|
|
|
|
line = line.replace("QComboBox.AdjustToMinimumContentsLength", "QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLength")
|
2021-03-26 07:06:02 +01:00
|
|
|
outlines.append(line)
|
|
|
|
|
2020-11-01 05:26:58 +01:00
|
|
|
with open(py_file, "w") as file:
|
2021-03-26 07:06:02 +01:00
|
|
|
file.write("\n".join(outlines))
|