Files
xuetang/app/scripts/render_diagnosis_shell_visual.py
2026-09-08 11:40:15 +08:00

83 lines
2.6 KiB
Python

"""Render the diagnosis list inside the real application shell."""
from __future__ import annotations
import os
from pathlib import Path
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
from PySide6.QtCore import QThreadPool
from PySide6.QtGui import QFont, QFontDatabase
from PySide6.QtWidgets import QApplication
from doctor_workstation.services import DemoDoctorRepository
from doctor_workstation.ui import ShellWindow, apply_theme
def render() -> list[Path]:
app = QApplication.instance() or QApplication([])
apply_theme(app)
font_path = Path("C:/Windows/Fonts/msyh.ttc")
if font_path.is_file():
font_id = QFontDatabase.addApplicationFont(str(font_path))
families = QFontDatabase.applicationFontFamilies(font_id)
if families:
app.setFont(QFont(families[0], 9))
root = Path(__file__).resolve().parents[1]
output = root / "artifacts" / "diagnosis_visual"
output.mkdir(parents=True, exist_ok=True)
paths: list[Path] = []
# Keep the two regression sizes and add a full-HD deliverable for design review.
for width, height in ((1024, 640), (1440, 900), (1920, 1080)):
repository = DemoDoctorRepository()
session = repository.login(
repository.DEMO_ACCOUNT,
repository.DEMO_PASSWORD,
)
shell = ShellWindow(
repository,
{"session": session, "demo_mode": True},
permissions=session.permissions,
)
shell.resize(width, height)
shell.show()
# Exercise the real visited-page contract so the evidence includes
# a fixed landing tab, a closable visited tab, and the active diagnosis tab.
another_key = next(
(
key
for key in ("patients", "reception", "prescriptions")
if key in shell.pages and key != "consultations"
),
None,
)
if another_key is not None:
shell.navigate(another_key)
shell.navigate("consultations")
QThreadPool.globalInstance().waitForDone(3000)
for _ in range(10):
app.processEvents()
page = shell.pages["consultations"]
page.poll_timer.stop()
page.page_scroll.verticalScrollBar().setValue(0)
app.processEvents()
path = output / f"diagnosis_shell_{width}x{height}.png"
if not shell.grab().save(str(path), "PNG"):
raise RuntimeError(f"failed to save {path}")
paths.append(path)
shell.close()
app.processEvents()
return paths
if __name__ == "__main__":
for rendered in render():
print(rendered)