mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00

We're not benefiting from type checking yet, as mypy and pylint currently ignore the generated files
20 lines
476 B
Python
20 lines
476 B
Python
import re
|
|
import sys
|
|
import io
|
|
from PyQt5.uic import compileUi
|
|
|
|
ui_file = sys.argv[1]
|
|
py_file = sys.argv[2]
|
|
buf = io.StringIO()
|
|
compileUi(open(ui_file), buf, from_imports=True)
|
|
|
|
outdata = buf.getvalue()
|
|
outdata = outdata.replace(
|
|
"# -*- coding: utf-8 -*-", "# -*- coding: utf-8 -*-\nfrom aqt.utils import tr\n"
|
|
)
|
|
outdata = re.sub(
|
|
r'(?:QtGui\.QApplication\.)?_?translate\(".*?", "(.*?)"', "tr.\\1(", outdata
|
|
)
|
|
|
|
with open(py_file, "w") as file:
|
|
file.write(outdata)
|