Files
zyt/app/scripts/render_ui_comfort_visual.py
2026-09-07 12:30:42 +08:00

94 lines
3.5 KiB
Python

"""Render the clinical reading surfaces with demo data and production fonts."""
from __future__ import annotations
import argparse
import json
import os
from pathlib import Path
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
from PySide6.QtCore import Qt, QThreadPool
from PySide6.QtGui import QFontInfo, QGuiApplication, QPalette
from PySide6.QtTest import QTest
from PySide6.QtWidgets import QApplication
from doctor_workstation.services import DemoDoctorRepository
from doctor_workstation.ui import ShellWindow, apply_theme
def _settle(app: QApplication) -> None:
for _ in range(4):
QThreadPool.globalInstance().waitForDone(3000)
app.processEvents()
QTest.qWait(100)
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--output", type=Path, default=Path("artifacts/ui_comfort"))
parser.add_argument("--width", type=int, default=1536)
parser.add_argument("--height", type=int, default=912)
args = parser.parse_args()
args.output.mkdir(parents=True, exist_ok=True)
QGuiApplication.setHighDpiScaleFactorRoundingPolicy(
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough
)
app = QApplication.instance() or QApplication([])
apply_theme(app)
repo = DemoDoctorRepository()
session = repo.login(repo.DEMO_ACCOUNT, repo.DEMO_PASSWORD)
shell = ShellWindow(
repo, {"session": session, "demo_mode": True}, permissions=session.permissions
)
shell.resize(args.width, args.height)
shell.show()
try:
shell.navigate("reception")
_settle(app)
page = shell.pages["reception"]
page._set_queue_filter(None)
_settle(app)
# A synthetic multiline case tests paragraph rhythm without capturing
# a live patient or connecting to a production service.
page.case_labels["present"].setText(
"患者自述近期口干,睡眠较浅,日常饮食与作息较规律。\n"
"近一周已记录空腹血糖,复诊时携带记录与既往检查报告。\n"
"问诊记录包含当前不适、变化时间、生活习惯与既往用药,供医生核对。"
)
app.processEvents()
if not shell.grab().save(str(args.output / "reception.png")):
raise RuntimeError("Could not save reception preview")
daily = next(
index
for index in range(page.detail_tabs.count())
if page.detail_tabs.tabText(index) == "日常记录"
)
page.detail_tabs.setCurrentIndex(daily)
_settle(app)
if not shell.grab().save(str(args.output / "daily_records.png")):
raise RuntimeError("Could not save daily-record preview")
metrics = {
"family": QFontInfo(app.font()).family(),
"pixel_size": app.font().pixelSize(),
"font_strategy": app.font().styleStrategy().value,
"font_hinting": app.font().hintingPreference().name,
"text_color": app.palette().color(QPalette.ColorRole.Text).name(),
"device_pixel_ratio": shell.devicePixelRatioF(),
"window": [shell.width(), shell.height()],
"daily_table_font": QFontInfo(page.daily_panel.matrix.font()).family(),
"daily_table_size": page.daily_panel.matrix.font().pixelSize(),
}
(args.output / "render.json").write_text(
json.dumps(metrics, ensure_ascii=False, indent=2), encoding="utf-8"
)
print(args.output)
finally:
_settle(app)
shell.close()
if __name__ == "__main__":
main()