This commit is contained in:
Your Name
2026-09-07 10:07:47 +08:00
parent cf3fbdc5ef
commit d5164b7369
388 changed files with 19863 additions and 18720 deletions
+380 -380
View File
@@ -5,9 +5,9 @@ from __future__ import annotations
import logging
import os
import sys
import time
from collections.abc import Mapping, Sequence
from contextlib import suppress
import time
from collections.abc import Mapping, Sequence
from contextlib import suppress
from typing import Any
from PySide6.QtCore import QLibraryInfo, QLocale, QObject, Qt, QTimer, QTranslator
@@ -27,7 +27,7 @@ from doctor_workstation.config import AppConfig
from doctor_workstation.core import Session
from doctor_workstation.core.errors import AuthenticationExpiredError
from doctor_workstation.logging_setup import configure_logging
from doctor_workstation.resources import app_icon_path, video_dist_path
from doctor_workstation.resources import app_icon_path, video_dist_path
from doctor_workstation.services import (
DemoDoctorRepository,
RemoteDoctorRepository,
@@ -35,179 +35,179 @@ from doctor_workstation.services import (
build_repository,
)
from doctor_workstation.ui import LoginWindow, ShellWindow, apply_theme
from doctor_workstation.ui.dialogs.app_update import AppUpdateSession
from doctor_workstation.ui.widgets import (
first_value,
friendly_error,
gender_text,
get_value,
run_async,
from doctor_workstation.ui.dialogs.app_update import AppUpdateSession
from doctor_workstation.ui.widgets import (
first_value,
friendly_error,
gender_text,
get_value,
run_async,
set_authentication_expired_handler,
show_toast,
)
from doctor_workstation.video import BackendMode, launch_video_call
from doctor_workstation.video.window import WEBENGINE_AVAILABLE
LOGGER = logging.getLogger(__name__)
def _video_case_text(value: Any, *, limit: int = 2000) -> str:
"""Render a bounded, JSON-safe clinical value for the trusted call rail."""
if value in (None, "", [], {}):
return ""
if isinstance(value, Mapping):
parts = [
f"{key}:{_video_case_text(item, limit=limit)}"
for key, item in value.items()
if item not in (None, "", [], {})
]
return ";".join(part for part in parts if not part.endswith(":"))[:limit]
if isinstance(value, Sequence) and not isinstance(value, (str, bytes, bytearray)):
return "、".join(
part
for item in value
if (part := _video_case_text(item, limit=limit))
)[:limit]
return str(value).strip()[:limit]
def _video_identity(value: Any) -> str:
if value in (None, "") or isinstance(value, bool):
return ""
text = str(value).strip()
if not text:
return ""
with suppress(ValueError, TypeError):
return str(int(text))
return text
def _video_identity_matches(expected: Any, actual: Any) -> bool:
normalized_actual = _video_identity(actual)
return not normalized_actual or normalized_actual == _video_identity(expected)
def _build_video_patient_case(
detail: Any,
fallback_record: Any,
*,
diagnosis_id: Any,
patient_id: Any,
patient_name: str,
) -> dict[str, str]:
"""Reduce the readonly diagnosis aggregate to the fields needed in-call."""
if isinstance(detail, Mapping) and not get_value(detail, "diagnosis", None):
nested = get_value(detail, "data", None)
if isinstance(nested, Mapping):
detail = nested
diagnosis = get_value(detail, "diagnosis", None)
if not diagnosis and isinstance(detail, Mapping):
diagnosis = detail
diagnosis = diagnosis or {}
patient = get_value(detail, "patient", None) or {}
appointment = get_value(detail, "appointment", None) or {}
detail_diagnosis_id = first_value(diagnosis, "id", "diagnosis_id", default=None)
detail_patient_id = first_value(
diagnosis,
"source_patient_id",
default=first_value(
patient,
"source_patient_id",
default=None,
),
)
if not _video_identity_matches(
diagnosis_id,
detail_diagnosis_id,
) or not _video_identity_matches(patient_id, detail_patient_id):
detail = diagnosis = patient = appointment = {}
fallback_diagnosis_id = first_value(
fallback_record,
"diagnosis_id",
"id",
default=None,
)
fallback_patient_id = first_value(
fallback_record,
"source_patient_id",
"patient_id",
default=None,
)
if not _video_identity_matches(
diagnosis_id,
fallback_diagnosis_id,
) or not _video_identity_matches(patient_id, fallback_patient_id):
fallback_record = {}
sources = (diagnosis, patient, appointment, fallback_record)
def pick(*keys: str, limit: int = 2000) -> str:
for source in sources:
value = first_value(source, *keys, default=None)
text = _video_case_text(value, limit=limit)
if text:
return text
return ""
raw_gender = next(
(
first_value(source, "gender_desc", "gender", default=None)
for source in sources
if first_value(source, "gender_desc", "gender", default=None) not in (None, "")
),
None,
)
return {
"diagnosisId": _video_case_text(diagnosis_id, limit=80),
"name": pick("patient_name", "name", limit=120)
or _video_case_text(patient_name, limit=120)
or "患者",
"gender": "" if raw_gender in (None, "") else gender_text(raw_gender),
"age": pick("age", limit=20),
"height": pick("height", limit=20),
"weight": pick("weight", limit=20),
"diagnosisDate": pick("diagnosis_date", "diagnosis_date_text", limit=80),
"appointmentDate": pick(
"appointment_date",
"latest_appointment_date",
limit=80,
),
"clinicalDiagnosis": pick(
"clinical_diagnosis",
"diagnosis_name",
"disease_name",
),
"chiefComplaint": pick("chief_complaint", "complaint"),
"presentIllness": pick("present_illness", "present_illness_history", "symptoms"),
"pastHistory": pick("past_history_text", "past_history_desc", "past_history"),
"allergyHistory": pick(
"allergy_history_text",
"allergy_history_desc",
"allergy_history",
),
"personalHistory": pick(
"personal_history_text",
"personal_history_desc",
"personal_history",
),
"familyHistory": pick(
"family_history_text",
"family_history_desc",
"family_history",
),
"currentMedication": pick(
"current_medications",
"current_medicine",
"current_medication",
),
"tongue": pick("tongue", "tongue_coating"),
"pulse": pick("pulse", "pulse_condition"),
"prescriptionOpinion": pick("prescription_opinion", "prescription_advice"),
"remark": pick("remark"),
}
LOGGER = logging.getLogger(__name__)
def _video_case_text(value: Any, *, limit: int = 2000) -> str:
"""Render a bounded, JSON-safe clinical value for the trusted call rail."""
if value in (None, "", [], {}):
return ""
if isinstance(value, Mapping):
parts = [
f"{key}:{_video_case_text(item, limit=limit)}"
for key, item in value.items()
if item not in (None, "", [], {})
]
return ";".join(part for part in parts if not part.endswith(":"))[:limit]
if isinstance(value, Sequence) and not isinstance(value, (str, bytes, bytearray)):
return "、".join(
part
for item in value
if (part := _video_case_text(item, limit=limit))
)[:limit]
return str(value).strip()[:limit]
def _video_identity(value: Any) -> str:
if value in (None, "") or isinstance(value, bool):
return ""
text = str(value).strip()
if not text:
return ""
with suppress(ValueError, TypeError):
return str(int(text))
return text
def _video_identity_matches(expected: Any, actual: Any) -> bool:
normalized_actual = _video_identity(actual)
return not normalized_actual or normalized_actual == _video_identity(expected)
def _build_video_patient_case(
detail: Any,
fallback_record: Any,
*,
diagnosis_id: Any,
patient_id: Any,
patient_name: str,
) -> dict[str, str]:
"""Reduce the readonly diagnosis aggregate to the fields needed in-call."""
if isinstance(detail, Mapping) and not get_value(detail, "diagnosis", None):
nested = get_value(detail, "data", None)
if isinstance(nested, Mapping):
detail = nested
diagnosis = get_value(detail, "diagnosis", None)
if not diagnosis and isinstance(detail, Mapping):
diagnosis = detail
diagnosis = diagnosis or {}
patient = get_value(detail, "patient", None) or {}
appointment = get_value(detail, "appointment", None) or {}
detail_diagnosis_id = first_value(diagnosis, "id", "diagnosis_id", default=None)
detail_patient_id = first_value(
diagnosis,
"source_patient_id",
default=first_value(
patient,
"source_patient_id",
default=None,
),
)
if not _video_identity_matches(
diagnosis_id,
detail_diagnosis_id,
) or not _video_identity_matches(patient_id, detail_patient_id):
detail = diagnosis = patient = appointment = {}
fallback_diagnosis_id = first_value(
fallback_record,
"diagnosis_id",
"id",
default=None,
)
fallback_patient_id = first_value(
fallback_record,
"source_patient_id",
"patient_id",
default=None,
)
if not _video_identity_matches(
diagnosis_id,
fallback_diagnosis_id,
) or not _video_identity_matches(patient_id, fallback_patient_id):
fallback_record = {}
sources = (diagnosis, patient, appointment, fallback_record)
def pick(*keys: str, limit: int = 2000) -> str:
for source in sources:
value = first_value(source, *keys, default=None)
text = _video_case_text(value, limit=limit)
if text:
return text
return ""
raw_gender = next(
(
first_value(source, "gender_desc", "gender", default=None)
for source in sources
if first_value(source, "gender_desc", "gender", default=None) not in (None, "")
),
None,
)
return {
"diagnosisId": _video_case_text(diagnosis_id, limit=80),
"name": pick("patient_name", "name", limit=120)
or _video_case_text(patient_name, limit=120)
or "患者",
"gender": "" if raw_gender in (None, "") else gender_text(raw_gender),
"age": pick("age", limit=20),
"height": pick("height", limit=20),
"weight": pick("weight", limit=20),
"diagnosisDate": pick("diagnosis_date", "diagnosis_date_text", limit=80),
"appointmentDate": pick(
"appointment_date",
"latest_appointment_date",
limit=80,
),
"clinicalDiagnosis": pick(
"clinical_diagnosis",
"diagnosis_name",
"disease_name",
),
"chiefComplaint": pick("chief_complaint", "complaint"),
"presentIllness": pick("present_illness", "present_illness_history", "symptoms"),
"pastHistory": pick("past_history_text", "past_history_desc", "past_history"),
"allergyHistory": pick(
"allergy_history_text",
"allergy_history_desc",
"allergy_history",
),
"personalHistory": pick(
"personal_history_text",
"personal_history_desc",
"personal_history",
),
"familyHistory": pick(
"family_history_text",
"family_history_desc",
"family_history",
),
"currentMedication": pick(
"current_medications",
"current_medicine",
"current_medication",
),
"tongue": pick("tongue", "tongue_coating"),
"pulse": pick("pulse", "pulse_condition"),
"prescriptionOpinion": pick("prescription_opinion", "prescription_advice"),
"remark": pick("remark"),
}
class _ChineseQtTranslator(QTranslator):
@@ -313,7 +313,7 @@ class DemoVideoDialog(QDialog):
"background:#FFFFFF;color:#3F4E75;border:1px solid #E6EAF5;font-weight:600;}"
"QPushButton:hover{color:#4451E2;background:#F0F2FF;border-color:#5761F4;}"
"QPushButton:checked{color:#FFFFFF;background:#5761F4;border-color:#5761F4;}"
"QPushButton#Hangup{color:#FFFFFF;background:#F15B67;border-color:#F15B67;}"
"QPushButton#Hangup{color:#FFFFFF;background:#C23D4E;border-color:#C23D4E;}"
"QPushButton#Hangup:hover{background:#D94857;border-color:#D94857;}"
)
@@ -326,7 +326,7 @@ class DemoVideoDialog(QDialog):
header.addWidget(title)
header.addStretch(1)
demo = QLabel("● 演示模式 · 未连接腾讯云")
demo.setStyleSheet("color:#7886AA;font-size:12px;")
demo.setStyleSheet("color:#707584;font-size:12px;")
header.addWidget(demo)
self.duration_label = QLabel("00:00")
self.duration_label.setStyleSheet("font-weight:700;")
@@ -400,22 +400,22 @@ class ApplicationController(QObject):
"""Own windows, repositories and the authenticated application lifecycle."""
def __init__(self, application: QApplication, config: AppConfig) -> None:
super().__init__()
self.application = application
self.config = config
self.debug_mode = bool(getattr(config, "debug_mode", False))
self.token_store = TokenStore(config.config_dir / "credentials.json")
self.demo_repository = DemoDoctorRepository() if self.debug_mode else None
super().__init__()
self.application = application
self.config = config
self.debug_mode = bool(getattr(config, "debug_mode", False))
self.token_store = TokenStore(config.config_dir / "credentials.json")
self.demo_repository = DemoDoctorRepository() if self.debug_mode else None
self.remote_repository: RemoteDoctorRepository | None = None
self.login_window: LoginWindow | None = None
self.shell_window: ShellWindow | None = None
self.current_repository: Any = None
self.current_demo_mode = self.debug_mode and config.demo_mode
self.video_calls: dict[str, Any] = {}
self.video_pending: dict[str, object] = {}
self.demo_video_dialogs: dict[str, DemoVideoDialog] = {}
self._video_preview_state: dict[str, Any] | None = None
self._video_preview_generation = 0
self.current_demo_mode = self.debug_mode and config.demo_mode
self.video_calls: dict[str, Any] = {}
self.video_pending: dict[str, object] = {}
self.demo_video_dialogs: dict[str, DemoVideoDialog] = {}
self._video_preview_state: dict[str, Any] | None = None
self._video_preview_generation = 0
self._restore_generation = 0
self._restore_in_progress = False
self._restore_worker: Any = None
@@ -506,11 +506,11 @@ class ApplicationController(QObject):
if self.login_window is not None:
self.login_window.config = self.config
def _on_demo_mode_changed(self, enabled: bool) -> None:
allowed = self.debug_mode and enabled
self.current_demo_mode = allowed
if allowed:
self._cancel_session_restore()
def _on_demo_mode_changed(self, enabled: bool) -> None:
allowed = self.debug_mode and enabled
self.current_demo_mode = allowed
if allowed:
self._cancel_session_restore()
def _rebuild_remote_repository(self) -> None:
old = self.remote_repository
@@ -670,8 +670,8 @@ class ApplicationController(QObject):
self._login_guard_error("该账号需要先绑定企业微信,请在管理后台完成绑定后重新登录。")
return
demo_mode = self.debug_mode and bool(payload.get("demo_mode"))
payload["demo_mode"] = demo_mode
demo_mode = self.debug_mode and bool(payload.get("demo_mode"))
payload["demo_mode"] = demo_mode
if not demo_mode and not session.menu:
with suppress(Exception):
repository.logout()
@@ -715,17 +715,17 @@ class ApplicationController(QObject):
self._logout(message="登录状态已失效,请重新登录。")
return True
def _logout(self, *, message: str = "") -> None:
"""Clear authenticated resources and return to the login window."""
self._restore_video_preview(activate=False)
calls = tuple(self.video_calls.values())
def _logout(self, *, message: str = "") -> None:
"""Clear authenticated resources and return to the login window."""
self._restore_video_preview(activate=False)
calls = tuple(self.video_calls.values())
for call in calls:
with suppress(Exception):
call.close()
self._wait_for_video_lifecycle(calls, timeout=1.25)
self.video_calls.clear()
self.video_pending.clear()
self.video_calls.clear()
self.video_pending.clear()
for dialog in self.demo_video_dialogs.values():
dialog.close()
self.demo_video_dialogs.clear()
@@ -748,8 +748,8 @@ class ApplicationController(QObject):
patient_id = payload.get("patient_id")
diagnosis_id = payload.get("diagnosis_id")
patient_name = str(payload.get("patient_name") or "患者")
open_im = str(payload.get("mode") or "video").lower() == "im"
fallback_record = payload.get("record")
open_im = str(payload.get("mode") or "video").lower() == "im"
fallback_record = payload.get("record")
if patient_id in (None, "") or diagnosis_id in (None, ""):
show_toast(parent, "患者或诊单信息不完整,无法发起视频。", "danger", 4200)
return
@@ -803,49 +803,49 @@ class ApplicationController(QObject):
marker = object()
self.video_pending[call_key] = marker
def get_video_context() -> tuple[Any, dict[str, str]]:
ticket = repository.get_call_ticket(
patient_id=int(patient_id),
diagnosis_id=int(diagnosis_id),
)
detail: Any = {}
detail_loader = getattr(repository, "patient_detail", None)
if callable(detail_loader):
try:
detail = detail_loader(int(diagnosis_id))
except Exception as error:
LOGGER.warning(
"patient detail could not be loaded for video call",
extra={
"diagnosis_id": diagnosis_id,
"error_type": type(error).__name__,
},
)
patient_case = _build_video_patient_case(
detail,
fallback_record,
diagnosis_id=diagnosis_id,
patient_id=patient_id,
patient_name=patient_name,
)
return ticket, patient_case
def get_video_context() -> tuple[Any, dict[str, str]]:
ticket = repository.get_call_ticket(
patient_id=int(patient_id),
diagnosis_id=int(diagnosis_id),
)
detail: Any = {}
detail_loader = getattr(repository, "patient_detail", None)
if callable(detail_loader):
try:
detail = detail_loader(int(diagnosis_id))
except Exception as error:
LOGGER.warning(
"patient detail could not be loaded for video call",
extra={
"diagnosis_id": diagnosis_id,
"error_type": type(error).__name__,
},
)
patient_case = _build_video_patient_case(
detail,
fallback_record,
diagnosis_id=diagnosis_id,
patient_id=patient_id,
patient_name=patient_name,
)
return ticket, patient_case
def request_ticket() -> None:
if self.video_pending.get(call_key) is not marker:
return
run_async(
get_video_context,
on_success=lambda context: self._launch_video(
context[0],
diagnosis_id=diagnosis_id,
patient_id=patient_id,
repository=repository,
run_async(
get_video_context,
on_success=lambda context: self._launch_video(
context[0],
diagnosis_id=diagnosis_id,
patient_id=patient_id,
repository=repository,
call_key=call_key,
marker=marker,
open_im=open_im,
patient_name=patient_name,
patient_case=context[1],
),
open_im=open_im,
patient_name=patient_name,
patient_case=context[1],
),
on_error=lambda error: self._video_ticket_error(
call_key,
marker,
@@ -888,9 +888,9 @@ class ApplicationController(QObject):
repository: Any,
call_key: str,
marker: object,
open_im: bool = False,
patient_name: str = "患者",
patient_case: Mapping[str, Any] | None = None,
open_im: bool = False,
patient_name: str = "患者",
patient_case: Mapping[str, Any] | None = None,
) -> None:
if self.video_pending.get(call_key) is not marker:
return
@@ -916,13 +916,13 @@ class ApplicationController(QObject):
local_dist=video_dist_path(),
remote_url=self.config.video_web_url or None,
logger=logging.getLogger("doctor_workstation.video"),
open_im=open_im,
patient_name=patient_name,
patient_case=patient_case,
on_open_diagnosis=lambda current_id=diagnosis_id: (
self._open_video_diagnosis(current_id)
),
)
open_im=open_im,
patient_name=patient_name,
patient_case=patient_case,
on_open_diagnosis=lambda current_id=diagnosis_id: (
self._open_video_diagnosis(current_id)
),
)
except Exception as error:
LOGGER.exception("video call could not be launched")
show_toast(
@@ -931,123 +931,123 @@ class ApplicationController(QObject):
"danger",
5600,
)
return
self.video_calls[call_key] = call
return
self.video_calls[call_key] = call
qt_window = getattr(call, "qt_window", None)
if qt_window is not None:
qt_window.destroyed.connect(
lambda _obj=None, key=call_key, expected=call: self._release_video_call(
key,
expected,
)
)
def _open_video_diagnosis(self, diagnosis_id: Any) -> None:
"""Open the diagnosis while keeping its live video visible as a preview."""
shell = self.shell_window
if shell is None or self.current_repository is None:
return
dialog = shell.open_diagnosis_by_id(diagnosis_id, modeless=True)
if dialog is None:
return
call = self.video_calls.get(str(diagnosis_id))
video_window = getattr(call, "qt_window", None)
if video_window is not None:
self._show_video_preview(video_window, dialog)
def _show_video_preview(self, video_window: Any, dialog: QDialog) -> None:
"""Pin a compact call window above the modeless diagnosis drawer."""
current = self._video_preview_state
if current is not None and current.get("window") is not video_window:
self._restore_video_preview(activate=False)
self._video_preview_generation += 1
generation = self._video_preview_generation
if current is None or current.get("window") is not video_window:
try:
state = {
"window": video_window,
"geometry": video_window.geometry(),
"minimum_size": video_window.minimumSize(),
"maximized": video_window.isMaximized(),
"full_screen": video_window.isFullScreen(),
"stays_on_top": bool(
video_window.windowFlags()
& Qt.WindowType.WindowStaysOnTopHint
),
}
screen = video_window.screen() or QGuiApplication.primaryScreen()
available = screen.availableGeometry()
preview_width = min(540, max(460, round(available.width() * 0.29)))
preview_height = min(380, max(320, round(preview_width * 0.66)))
margin = 18
video_window.showNormal()
video_window.setMinimumSize(440, 300)
video_window.setWindowFlag(Qt.WindowType.WindowStaysOnTopHint, True)
video_window.resize(preview_width, preview_height)
video_window.move(
available.x() + available.width() - preview_width - margin,
available.y() + margin,
)
video_window.show()
self._video_preview_state = state
except RuntimeError:
self._video_preview_state = None
return
dialog.finished.connect(
lambda _result, expected=generation: self._restore_video_preview(expected)
)
try:
video_window.raise_()
dialog.raise_()
dialog.activateWindow()
except RuntimeError:
self._video_preview_state = None
def _restore_video_preview(
self,
generation: int | None = None,
*,
activate: bool = True,
) -> None:
if generation is not None and generation != self._video_preview_generation:
return
state = self._video_preview_state
if state is None:
return
self._video_preview_state = None
self._video_preview_generation += 1
window = state.get("window")
try:
window.setWindowFlag(
Qt.WindowType.WindowStaysOnTopHint,
bool(state.get("stays_on_top")),
)
window.setMinimumSize(state["minimum_size"])
window.setGeometry(state["geometry"])
if state.get("full_screen"):
window.showFullScreen()
elif state.get("maximized"):
window.showMaximized()
else:
window.showNormal()
window.raise_()
if activate:
window.activateWindow()
except (AttributeError, RuntimeError):
return
def _release_video_call(self, call_key: str, call: Any) -> None:
preview = self._video_preview_state
if preview is not None and preview.get("window") is getattr(call, "qt_window", None):
self._video_preview_state = None
self._video_preview_generation += 1
if self.video_calls.get(call_key) is call:
self.video_calls.pop(call_key, None)
)
)
def _open_video_diagnosis(self, diagnosis_id: Any) -> None:
"""Open the diagnosis while keeping its live video visible as a preview."""
shell = self.shell_window
if shell is None or self.current_repository is None:
return
dialog = shell.open_diagnosis_by_id(diagnosis_id, modeless=True)
if dialog is None:
return
call = self.video_calls.get(str(diagnosis_id))
video_window = getattr(call, "qt_window", None)
if video_window is not None:
self._show_video_preview(video_window, dialog)
def _show_video_preview(self, video_window: Any, dialog: QDialog) -> None:
"""Pin a compact call window above the modeless diagnosis drawer."""
current = self._video_preview_state
if current is not None and current.get("window") is not video_window:
self._restore_video_preview(activate=False)
self._video_preview_generation += 1
generation = self._video_preview_generation
if current is None or current.get("window") is not video_window:
try:
state = {
"window": video_window,
"geometry": video_window.geometry(),
"minimum_size": video_window.minimumSize(),
"maximized": video_window.isMaximized(),
"full_screen": video_window.isFullScreen(),
"stays_on_top": bool(
video_window.windowFlags()
& Qt.WindowType.WindowStaysOnTopHint
),
}
screen = video_window.screen() or QGuiApplication.primaryScreen()
available = screen.availableGeometry()
preview_width = min(540, max(460, round(available.width() * 0.29)))
preview_height = min(380, max(320, round(preview_width * 0.66)))
margin = 18
video_window.showNormal()
video_window.setMinimumSize(440, 300)
video_window.setWindowFlag(Qt.WindowType.WindowStaysOnTopHint, True)
video_window.resize(preview_width, preview_height)
video_window.move(
available.x() + available.width() - preview_width - margin,
available.y() + margin,
)
video_window.show()
self._video_preview_state = state
except RuntimeError:
self._video_preview_state = None
return
dialog.finished.connect(
lambda _result, expected=generation: self._restore_video_preview(expected)
)
try:
video_window.raise_()
dialog.raise_()
dialog.activateWindow()
except RuntimeError:
self._video_preview_state = None
def _restore_video_preview(
self,
generation: int | None = None,
*,
activate: bool = True,
) -> None:
if generation is not None and generation != self._video_preview_generation:
return
state = self._video_preview_state
if state is None:
return
self._video_preview_state = None
self._video_preview_generation += 1
window = state.get("window")
try:
window.setWindowFlag(
Qt.WindowType.WindowStaysOnTopHint,
bool(state.get("stays_on_top")),
)
window.setMinimumSize(state["minimum_size"])
window.setGeometry(state["geometry"])
if state.get("full_screen"):
window.showFullScreen()
elif state.get("maximized"):
window.showMaximized()
else:
window.showNormal()
window.raise_()
if activate:
window.activateWindow()
except (AttributeError, RuntimeError):
return
def _release_video_call(self, call_key: str, call: Any) -> None:
preview = self._video_preview_state
if preview is not None and preview.get("window") is getattr(call, "qt_window", None):
self._video_preview_state = None
self._video_preview_generation += 1
if self.video_calls.get(call_key) is call:
self.video_calls.pop(call_key, None)
def _forget_demo_dialog(self, call_key: str, dialog: DemoVideoDialog) -> None:
if self.demo_video_dialogs.get(call_key) is dialog:
@@ -1072,30 +1072,30 @@ class ApplicationController(QObject):
LOGGER.warning("video lifecycle cleanup exceeded its bounded deadline")
return complete
@staticmethod
def _apply_window_icon(window: QWidget) -> None:
icon_file = app_icon_path()
if icon_file.exists():
window.setWindowIcon(QIcon(str(icon_file)))
def request_quit(self) -> None:
"""Queue a normal application exit so owned resources are released."""
if self._shutting_down:
return
QTimer.singleShot(0, self.application.quit)
def shutdown(self) -> None:
@staticmethod
def _apply_window_icon(window: QWidget) -> None:
icon_file = app_icon_path()
if icon_file.exists():
window.setWindowIcon(QIcon(str(icon_file)))
def request_quit(self) -> None:
"""Queue a normal application exit so owned resources are released."""
if self._shutting_down:
return
QTimer.singleShot(0, self.application.quit)
def shutdown(self) -> None:
"""Invalidate asynchronous restoration and release owned resources."""
if self._shutting_down:
return
self._shutting_down = True
self._cancel_session_restore()
self.app_updater.shutdown()
set_authentication_expired_handler(None)
self._restore_video_preview(activate=False)
calls = tuple(self.video_calls.values())
self._shutting_down = True
self._cancel_session_restore()
self.app_updater.shutdown()
set_authentication_expired_handler(None)
self._restore_video_preview(activate=False)
calls = tuple(self.video_calls.values())
for call in calls:
with suppress(Exception):
call.close()
@@ -1167,7 +1167,7 @@ def _create_application(argv: list[str]) -> QApplication:
application.setOrganizationName("ZhenYangTang")
application.setOrganizationDomain("zhenyangtang.com")
application.setQuitOnLastWindowClosed(True)
icon_file = app_icon_path()
icon_file = app_icon_path()
if icon_file.exists():
application.setWindowIcon(QIcon(str(icon_file)))
apply_theme(application)
@@ -55,26 +55,25 @@ from .widgets import (
APPOINTMENT_DRAWER_QSS = r"""
QDialog#AppointmentDrawerOverlay {
background-color: transparent;
color: #111F46;
font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
font-size: 13px;
color: #1A1C1F;
font-size: 14px;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentDrawerPanel {
background-color: #FFFFFF;
border-left: 1px solid #E6EAF5;
border-left: 1px solid #EDEDEE;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentDrawerHeader {
background-color: #FFFFFF;
border: 0;
border-bottom: 1px solid #E6EAF5;
border-bottom: 1px solid #EDEDEE;
}
QDialog#AppointmentDrawerOverlay QLabel#AppointmentDrawerTitle {
color: #111F46;
color: #1A1C1F;
font-size: 18px;
font-weight: 700;
font-weight: 600;
}
QDialog#AppointmentDrawerOverlay QToolButton#AppointmentDrawerClose {
@@ -86,14 +85,14 @@ QDialog#AppointmentDrawerOverlay QToolButton#AppointmentDrawerClose {
border: 0;
border-radius: 4px;
background-color: transparent;
color: #7886AA;
color: #606163;
font-size: 22px;
font-weight: 400;
}
QDialog#AppointmentDrawerOverlay QToolButton#AppointmentDrawerClose:hover {
color: #4451E2;
background-color: #F0F2FF;
color: #1A1C1F;
background-color: #F0F0F0;
}
QDialog#AppointmentDrawerOverlay QScrollArea#AppointmentDrawerBody,
@@ -109,13 +108,13 @@ QDialog#AppointmentDrawerOverlay QWidget#AppointmentDrawerBodyContent {
}
QDialog#AppointmentDrawerOverlay QLabel[appointmentLabel="true"] {
color: #3F4E75;
color: #1A1C1F;
font-size: 14px;
font-weight: 500;
}
QDialog#AppointmentDrawerOverlay QLabel[appointmentMuted="true"] {
color: #7886AA;
color: #606163; font-size: 13px;
}
QDialog#AppointmentDrawerOverlay QComboBox,
@@ -123,28 +122,28 @@ QDialog#AppointmentDrawerOverlay QLineEdit,
QDialog#AppointmentDrawerOverlay QPlainTextEdit {
min-height: 30px;
padding: 0 11px;
border: 1px solid #E6EAF5;
border: 1px solid #EDEDEE;
border-radius: 9px;
background-color: #FFFFFF;
color: #111F46;
selection-background-color: #5761F4;
selection-color: #FFFFFF;
color: #1A1C1F;
selection-background-color: #EEF1FA;
selection-color: #1A1C1F; font-size: 14px;
}
QDialog#AppointmentDrawerOverlay QPlainTextEdit {
padding: 7px 11px;
padding: 7px 11px; font-size: 14px;
}
QDialog#AppointmentDrawerOverlay QComboBox:hover,
QDialog#AppointmentDrawerOverlay QLineEdit:hover,
QDialog#AppointmentDrawerOverlay QPlainTextEdit:hover {
border-color: #5761F4;
border-color: #8B9AD9;
}
QDialog#AppointmentDrawerOverlay QComboBox:focus,
QDialog#AppointmentDrawerOverlay QLineEdit:focus,
QDialog#AppointmentDrawerOverlay QPlainTextEdit:focus {
border: 2px solid #8D9BFF;
border: 2px solid #8B9AD9;
}
QDialog#AppointmentDrawerOverlay QComboBox::drop-down {
@@ -154,81 +153,81 @@ QDialog#AppointmentDrawerOverlay QComboBox::drop-down {
QDialog#AppointmentDrawerOverlay QComboBox QAbstractItemView {
background-color: #FFFFFF;
color: #111F46;
border: 1px solid #E6EAF5;
selection-background-color: #5761F4;
selection-color: #FFFFFF;
outline: 0;
color: #1A1C1F;
border: 1px solid #EDEDEE;
selection-background-color: #EEF1FA;
selection-color: #1A1C1F;
outline: 0; font-size: 14px;
}
QDialog#AppointmentDrawerOverlay QRadioButton {
min-height: 24px;
spacing: 8px;
color: #3F4E75;
color: #1A1C1F;
}
QDialog#AppointmentDrawerOverlay QRadioButton::indicator {
width: 12px;
height: 12px;
border-radius: 7px;
border: 1px solid #E6EAF5;
border: 1px solid #EDEDEE;
background-color: #FFFFFF;
}
QDialog#AppointmentDrawerOverlay QRadioButton::indicator:hover {
border-color: #5761F4;
border-color: #4156C4;
}
QDialog#AppointmentDrawerOverlay QRadioButton::indicator:checked {
width: 4px;
height: 4px;
border: 5px solid #5761F4;
border: 5px solid #4F63D9;
border-radius: 7px;
background-color: #FFFFFF;
}
QDialog#AppointmentDrawerOverlay QRadioButton:focus {
color: #4451E2;
color: #4F63D9;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentDate="true"] {
min-height: 38px;
max-height: 38px;
padding: 0;
border: 1px solid #E6EAF5;
border: 1px solid #EDEDEE;
border-radius: 8px;
background-color: #FFFFFF;
color: #3F4E75;
color: #1A1C1F;
font-size: 14px;
font-weight: 500;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentDate="true"]:hover {
color: #4451E2;
border-color: #5761F4;
background-color: #F0F2FF;
color: #4156C4;
border-color: #4156C4;
background-color: #EEF1FA;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentDate="true"]:focus {
border-color: #8D9BFF;
border-color: #8B9AD9;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentDate="true"]:checked {
color: #FFFFFF;
border-color: #5761F4;
background-color: #5761F4;
border-color: #4F63D9;
background-color: #4F63D9;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentSlotsPanel {
background-color: #F7F9FE;
background-color: #F7F7F7;
border: 0;
border-radius: 8px;
}
QDialog#AppointmentDrawerOverlay QLabel#AppointmentSlotsTitle {
color: #111F46;
color: #1A1C1F;
font-size: 15px;
font-weight: 600;
font-weight: 500;
}
QDialog#AppointmentDrawerOverlay QPushButton#AppointmentRefreshSlots {
@@ -238,87 +237,83 @@ QDialog#AppointmentDrawerOverlay QPushButton#AppointmentRefreshSlots {
border: 0;
border-radius: 4px;
background-color: transparent;
color: #4451E2;
color: #4F63D9;
font-size: 13px;
font-weight: 500;
}
QDialog#AppointmentDrawerOverlay QPushButton#AppointmentRefreshSlots:hover {
background-color: #F0F2FF;
background-color: #EEF1FA;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"] {
min-width: 110px;
min-height: 70px;
padding: 0 8px;
border: 2px solid #E6EAF5;
border: 2px solid #EDEDEE;
border-radius: 8px;
background-color: #FFFFFF;
color: #111F46;
color: #1A1C1F;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"] QLabel#AppointmentSlotTime {
color: #111F46;
color: #1A1C1F;
font-size: 15px;
font-weight: 600;
font-weight: 500;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"] QLabel#AppointmentSlotStatus {
padding: 0 8px;
border-radius: 4px;
background-color: #F4F4F5;
color: #7886AA;
font-size: 12px;
background-color: #F7F7F7;
color: #606163;
font-size: 13px;
font-weight: 400;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"][availability="available"] QLabel#AppointmentSlotStatus {
color: #17A77D;
color: #287B65;
background-color: #EAF9F3;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"]:hover:enabled {
color: #4451E2;
border-color: #5761F4;
background-color: #F0F2FF;
color: #4156C4;
border-color: #4156C4;
background-color: #EEF1FA;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"]:focus:enabled {
border-color: #8D9BFF;
border-color: #8B9AD9;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"]:checked {
color: #FFFFFF;
border-color: #5761F4;
background: qlineargradient(
x1:0, y1:0, x2:1, y2:1,
stop:0 #5761F4,
stop:1 #7769F7
);
border-color: #4F63D9;
background: #4F63D9;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"]:checked QLabel#AppointmentSlotTime,
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"]:checked QLabel#AppointmentSlotStatus {
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"] QLabel#AppointmentSlotTime[slotSelected="true"],
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"] QLabel#AppointmentSlotStatus[slotSelected="true"] {
color: #FFFFFF;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"]:checked QLabel#AppointmentSlotStatus {
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"] QLabel#AppointmentSlotStatus[slotSelected="true"] {
background-color: rgba(255, 255, 255, 46);
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"]:disabled {
color: #A4ADC3;
border-color: #E6EAF5;
background-color: #F0F2F8;
color: #8E8F90;
border-color: #EDEDEE;
background-color: #F7F7F7;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"]:disabled QLabel#AppointmentSlotTime,
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"]:disabled QLabel#AppointmentSlotStatus {
color: #A4ADC3;
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"] QLabel#AppointmentSlotTime:disabled,
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"] QLabel#AppointmentSlotStatus:disabled {
color: #8E8F90;
}
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"]:disabled QLabel#AppointmentSlotStatus {
background-color: #F0F2F8;
QDialog#AppointmentDrawerOverlay QPushButton[appointmentSlot="true"] QLabel#AppointmentSlotStatus:disabled {
background-color: #F7F7F7;
}
QDialog#AppointmentDrawerOverlay QWidget#AppointmentInlineEmpty {
@@ -326,13 +321,13 @@ QDialog#AppointmentDrawerOverlay QWidget#AppointmentInlineEmpty {
}
QDialog#AppointmentDrawerOverlay QLabel#AppointmentEmptyText {
color: #7886AA;
color: #606163;
font-size: 14px;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentAlert[kind="info"] {
background-color: #F0F4FF;
border: 1px solid #DDE5FF;
background-color: #EEF1FA;
border: 1px solid #EDEDEE;
border-radius: 9px;
}
@@ -355,65 +350,65 @@ QDialog#AppointmentDrawerOverlay QFrame#AppointmentAlert[kind="success"] {
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentAlert[kind="info"] QLabel {
color: #4D69ED;
color: #4F63D9;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentAlert[kind="warning"] QLabel {
color: #D38625;
color: #A9691D;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentAlert[kind="danger"] QLabel {
color: #F15B67;
color: #BE4B58;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentAlert[kind="success"] QLabel {
color: #17A77D;
color: #287B65;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentDrawerFooter {
background-color: #FFFFFF;
border: 0;
border-top: 1px solid #E6EAF5;
border-top: 1px solid #EDEDEE;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentDrawerFooter QPushButton {
min-height: 30px;
max-height: 30px;
padding: 0 15px;
border: 1px solid #E6EAF5;
border: 1px solid #EDEDEE;
border-radius: 9px;
background-color: #FFFFFF;
color: #3F4E75;
color: #1A1C1F;
font-size: 13px;
font-weight: 600;
font-weight: 500;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentDrawerFooter QPushButton:hover {
color: #4451E2;
border-color: #5761F4;
background-color: #F0F2FF;
color: #4156C4;
border-color: #4156C4;
background-color: #EEF1FA;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentDrawerFooter QPushButton:focus {
border-color: #8D9BFF;
border-color: #8B9AD9;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentDrawerFooter QPushButton[primary="true"] {
color: #FFFFFF;
border-color: #5761F4;
background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #5761F4, stop:1 #7769F7);
border-color: #4F63D9;
background: #4F63D9;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentDrawerFooter QPushButton[primary="true"]:hover {
color: #FFFFFF;
border-color: #4C57E9;
background-color: #4C57E9;
border-color: #4156C4;
background-color: #4156C4;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentDrawerFooter QPushButton:disabled {
color: #FFFFFF;
border-color: #E6EAF5;
background-color: #A4ADC3;
border-color: #EDEDEE;
background-color: #8E8F90;
}
QDialog#AppointmentDrawerOverlay QFrame#AppointmentLoadingOverlay {
@@ -422,7 +417,7 @@ QDialog#AppointmentDrawerOverlay QFrame#AppointmentLoadingOverlay {
}
QDialog#AppointmentDrawerOverlay QLabel#AppointmentLoadingText {
color: #7886AA;
color: #606163;
font-size: 14px;
}
@@ -436,11 +431,11 @@ QDialog#AppointmentDrawerOverlay QScrollBar:vertical {
QDialog#AppointmentDrawerOverlay QScrollBar::handle:vertical {
min-height: 30px;
border-radius: 3px;
background-color: #E6EAF5;
background-color: #EDEDEE;
}
QDialog#AppointmentDrawerOverlay QScrollBar::handle:vertical:hover {
background-color: #8D9BFF;
background-color: #E4E4E5;
}
QDialog#AppointmentDrawerOverlay QScrollBar::add-line:vertical,
@@ -722,15 +717,15 @@ class _EmptyIllustration(QWidget):
painter = QPainter(self)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.setPen(Qt.PenStyle.NoPen)
painter.setBrush(QColor("#EEF2F8"))
painter.setBrush(QColor("#F7F7F7"))
painter.drawEllipse(QRect(9, 48, 62, 8))
painter.setPen(QPen(QColor("#D8DEEA"), 1))
painter.setPen(QPen(QColor("#EDEDEE"), 1))
painter.setBrush(QColor("#FFFFFF"))
painter.drawRoundedRect(QRect(22, 21, 36, 27), 4, 4)
painter.setBrush(QColor("#E9EDFF"))
painter.setBrush(QColor("#F0F0F0"))
painter.drawRoundedRect(QRect(18, 15, 44, 12), 4, 4)
painter.setPen(QPen(QColor("#667085"), 2))
painter.setPen(QPen(QColor("#606163"), 2))
painter.drawLine(30, 35, 50, 35)
painter.drawLine(34, 41, 46, 41)
painter.end()
@@ -751,7 +746,7 @@ class _HoverLiftButton(QPushButton):
shadow = QGraphicsDropShadowEffect(self)
shadow.setBlurRadius(12)
shadow.setOffset(0, 4)
shadow.setColor(QColor(102, 117, 245, 72))
shadow.setColor(QColor(26, 28, 31, 72))
self.setGraphicsEffect(shadow)
self._lifted = True
super().enterEvent(event)
@@ -784,6 +779,15 @@ class _SlotCard(_HoverLiftButton):
self.status_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.status_label.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents, True)
layout.addWidget(self.status_label)
self.toggled.connect(self._sync_label_selection)
def _sync_label_selection(self, checked: bool) -> None:
# Qt does not reliably resolve ancestor pseudo states for child labels.
for label in (self.time_label, self.status_label):
label.setProperty("slotSelected", checked)
label.style().unpolish(label)
label.style().polish(label)
label.update()
class AppointmentDrawer(QDialog):
@@ -1705,7 +1709,7 @@ class AppointmentDrawer(QDialog):
def paintEvent(self, event: QPaintEvent) -> None: # noqa: N802 - Qt API
painter = QPainter(self)
painter.fillRect(self.rect(), QColor(8, 11, 20, 196))
painter.fillRect(self.rect(), QColor(26, 28, 31, 196))
painter.end()
super().paintEvent(event)
@@ -46,51 +46,51 @@ QFrame#ChatNotifyCard {
border: 1px solid #BBF0CE;
border-radius: 12px;
}
QFrame#ChatNotifyCard[kind="left"] { border-color: #D8DEEE; }
QFrame#ChatNotifyCard[kind="complete"] { border-color: #C3D6FF; }
QFrame#ChatNotifyCard[kind="left"] { border-color: #E4E4E5; }
QFrame#ChatNotifyCard[kind="complete"] { border-color: #8B9AD9; }
QLabel#ChatNotifyBadge {
min-width: 34px;
max-width: 34px;
min-height: 34px;
max-height: 34px;
color: #FFFFFF;
background-color: #22C55E;
background-color: #287B65;
border-radius: 9px;
font-size: 15px;
font-weight: 700;
}
QLabel#ChatNotifyBadge[kind="left"] { background-color: #8A94B3; }
QLabel#ChatNotifyBadge[kind="complete"] { background-color: #3B82F6; }
QLabel#ChatNotifyTitle { color: #1F2A44; font-size: 13px; font-weight: 700; }
QLabel#ChatNotifyDesc { color: #4A5878; font-size: 12px; }
QLabel#ChatNotifyTime { color: #8A94B3; font-size: 11px; }
QLabel#ChatNotifyBadge[kind="left"] { background-color: #6A6B6D; }
QLabel#ChatNotifyBadge[kind="complete"] { background-color: #4F63D9; }
QLabel#ChatNotifyTitle { color: #1A1C1F; font-size: 13px; font-weight: 700; }
QLabel#ChatNotifyDesc { color: #1A1C1F; font-size: 12px; }
QLabel#ChatNotifyTime { color: #6A6B6D; font-size: 11px; }
QPushButton#ChatNotifyOpen {
min-height: 26px;
padding: 0 10px;
color: #3F4E75;
background-color: #F4F6FC;
border: 1px solid #DDE3F2;
color: #4F63D9;
background-color: #EEF1FA;
border: 1px solid #EDEDEE;
border-radius: 7px;
font-size: 12px;
font-weight: 600;
}
QPushButton#ChatNotifyOpen:hover {
color: #4451E2;
background-color: #EEF1FF;
border-color: #8D9BFF;
color: #4156C4;
background-color: #EEF1FA;
border-color: #8B9AD9;
}
QPushButton#ChatNotifyClose {
min-width: 22px;
max-width: 22px;
min-height: 22px;
max-height: 22px;
color: #8A94B3;
color: #6A6B6D;
background-color: transparent;
border: 0;
border-radius: 6px;
font-size: 14px;
}
QPushButton#ChatNotifyClose:hover { color: #4A5878; background-color: #EDF0F7; }
QPushButton#ChatNotifyClose:hover { color: #1A1C1F; background-color: #F7F7F7; }
"""
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -134,63 +134,63 @@ def open_safe_http_url(target: str) -> bool:
_INLINE_PLAYER_QSS = """
QWidget#DiagnosisInlineRecordingPlayer {
background: #FFFFFF;
border: 1px solid #E6EAF5;
border: 1px solid #EDEDEE;
border-radius: 9px;
}
QFrame#DiagnosisInlineRecordingSurface {
background: #11182E;
background: #1A1C1F;
border: 0;
border-radius: 8px 8px 0 0;
}
QLabel#DiagnosisInlineRecordingPlaceholder {
color: #C7D0E8;
color: #E4E4E5;
font-size: 12px;
line-height: 1.4;
}
QLabel#DiagnosisInlineRecordingTime {
color: #64739A;
color: #6A6B6D;
font-size: 11px;
}
QPushButton[recordingControl="true"] {
min-height: 24px;
max-height: 24px;
padding: 0 8px;
color: #3F4E75;
background: #FAFBFE;
border: 1px solid #D8DEEE;
color: #1A1C1F;
background: #F7F7F7;
border: 1px solid #E4E4E5;
border-radius: 6px;
font-size: 11px;
font-weight: 600;
}
QPushButton[recordingControl="true"]:hover,
QPushButton[recordingControl="true"]:focus {
color: #4451E2;
background: #F0F2FF;
border-color: #8D9BFF;
color: #4156C4;
background: #EEF1FA;
border-color: #8B9AD9;
}
QPushButton#DiagnosisInlineRecordingPlay {
color: #FFFFFF;
background: #5761F4;
border-color: #5761F4;
background: #4F63D9;
border-color: #4F63D9;
}
QPushButton#DiagnosisInlineRecordingPlay:hover,
QPushButton#DiagnosisInlineRecordingPlay:focus {
color: #FFFFFF;
background: #4C57E9;
border-color: #4C57E9;
background: #4156C4;
border-color: #4156C4;
}
QPushButton[recordingControl="true"]:disabled {
color: #A4ADC3;
background: #F0F2F8;
border-color: #E6EAF5;
color: #8E8F90;
background: #F7F7F7;
border-color: #EDEDEE;
}
QSlider::groove:horizontal { height: 3px; background: #D8DEEE; border-radius: 1px; }
QSlider::sub-page:horizontal { background: #5761F4; border-radius: 1px; }
QSlider::groove:horizontal { height: 3px; background: #E4E4E5; border-radius: 1px; }
QSlider::sub-page:horizontal { background: #4F63D9; border-radius: 1px; }
QSlider::handle:horizontal {
width: 10px;
margin: -4px 0;
background: #FFFFFF;
border: 1px solid #5761F4;
border: 1px solid #4F63D9;
border-radius: 5px;
}
"""
@@ -466,11 +466,11 @@ class RecordingPlaybackCell(QWidget):
separator = QFrame()
separator.setObjectName("DiagnosisRecordingAlternateSeparator")
separator.setFrameShape(QFrame.Shape.HLine)
separator.setStyleSheet("color:#E6EAF5;")
separator.setStyleSheet("color:#EDEDEE;")
layout.addWidget(separator)
label = QLabel("备用地址")
label.setObjectName("DiagnosisRecordingAlternateLabel")
label.setStyleSheet("color:#7886AA; font-size:12px;")
label.setStyleSheet("color:#606163; font-size:12px;")
layout.addWidget(label)
links = QHBoxLayout()
links.setContentsMargins(0, 0, 0, 0)
@@ -490,7 +490,7 @@ class RecordingPlaybackCell(QWidget):
layout.addLayout(links)
self.link_status = QLabel("")
self.link_status.setObjectName("DiagnosisRecordingLinkStatus")
self.link_status.setStyleSheet("color:#D94856; font-size:11px;")
self.link_status.setStyleSheet("color:#BE4B58; font-size:11px;")
self.link_status.setWordWrap(True)
self.link_status.hide()
layout.addWidget(self.link_status)
@@ -722,41 +722,41 @@ def image_display_name(target: str, ordinal: int) -> str:
_IMAGE_PREVIEW_QSS = """
QDialog#DiagnosisImagePreview { background: #FFFFFF; }
QLabel#DiagnosisImagePreviewName { color: #1F2A44; font-size: 14px; font-weight: 600; }
QLabel#DiagnosisImagePreviewCounter { color: #64739A; font-size: 12px; }
QLabel#DiagnosisImagePreviewStatus { color: #64739A; font-size: 12px; }
QLabel#DiagnosisImagePreviewStatus[kind="danger"] { color: #C0392B; }
QLabel#DiagnosisImagePreviewStatus[kind="warning"] { color: #9A650F; }
QLabel#DiagnosisImagePreviewName { color: #1A1C1F; font-size: 14px; font-weight: 600; }
QLabel#DiagnosisImagePreviewCounter { color: #6A6B6D; font-size: 12px; }
QLabel#DiagnosisImagePreviewStatus { color: #6A6B6D; font-size: 12px; }
QLabel#DiagnosisImagePreviewStatus[kind="danger"] { color: #BE4B58; }
QLabel#DiagnosisImagePreviewStatus[kind="warning"] { color: #A9691D; }
QScrollArea#DiagnosisImagePreviewViewport {
background: #11182E;
border: 1px solid #E6EAF5;
background: #1A1C1F;
border: 1px solid #EDEDEE;
border-radius: 9px;
}
QLabel#DiagnosisImagePreviewCanvas {
background: #11182E;
color: #C7D0E8;
background: #1A1C1F;
color: #E4E4E5;
font-size: 12px;
}
QPushButton[imagePreviewControl="true"] {
min-height: 28px;
padding: 0 12px;
color: #3F4E75;
background: #FAFBFE;
border: 1px solid #D8DEEE;
color: #1A1C1F;
background: #F7F7F7;
border: 1px solid #E4E4E5;
border-radius: 7px;
font-size: 12px;
font-weight: 600;
}
QPushButton[imagePreviewControl="true"]:hover,
QPushButton[imagePreviewControl="true"]:focus {
color: #4451E2;
background: #F0F2FF;
border-color: #8D9BFF;
color: #4156C4;
background: #EEF1FA;
border-color: #8B9AD9;
}
QPushButton[imagePreviewControl="true"]:disabled {
color: #A4ADC3;
background: #F0F2F8;
border-color: #E6EAF5;
color: #8E8F90;
background: #F7F7F7;
border-color: #EDEDEE;
}
"""
File diff suppressed because it is too large Load Diff
@@ -18,13 +18,13 @@ from PySide6.QtWidgets import (
QWidget,
)
from ..infinite_list import InfiniteList
from ..theme import mark_business_dialog
from ..widgets import (
BusyOverlay,
EmptyState,
MessageBanner,
OverlayHost,
Pager,
SortableTable,
TableColumn,
first_value,
@@ -33,7 +33,6 @@ from ..widgets import (
get_value,
invoke,
page_items,
page_total,
run_async,
)
from .ai_consult import can_open_ai_consult, present_ai_consult
@@ -220,8 +219,8 @@ class AiConsultTargetDialog(QDialog):
self.body.busy_overlay = self.busy_overlay
root.addWidget(self.body, 1)
self.pager = Pager(self.PAGE_SIZE, self)
self.pager.page_changed.connect(self._change_page)
self.pager = InfiniteList(self.PAGE_SIZE, self)
self.pager.bind(self.table)
root.addWidget(self.pager)
self.buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Cancel, self)
@@ -266,42 +265,41 @@ class AiConsultTargetDialog(QDialog):
self.load(1)
def retry(self) -> None:
self.load(self._page)
def _change_page(self, page: int) -> None:
self.load(page)
self.load(1)
def load(self, page: int) -> None:
if not self._active:
return
self._page = max(1, int(page))
self._generation += 1
generation = self._generation
page_snapshot = self._page
keyword_snapshot = self.search_edit.text().strip()
self._invalidate_selection()
self._set_loading(True)
if keyword_snapshot != getattr(self, "_loaded_keyword", None):
self._invalidate_selection()
self._loaded_keyword = keyword_snapshot
self._set_loading(not self.pager.rows)
self.banner.clear()
run_async(
lambda: invoke(
self.pager.reload(
lambda requested_page: invoke(
self.repository,
"list_ai_patient_options",
page_no=page_snapshot,
page_no=requested_page,
page_size=self.PAGE_SIZE,
keyword=keyword_snapshot,
),
on_success=lambda result: self._apply_result(
result, generation, page_snapshot, keyword_snapshot
apply=lambda result: self._apply_result(
result, generation, keyword_snapshot
),
on_error=lambda error: self._apply_error(error, generation),
runner=run_async,
query_key=(keyword_snapshot,),
on_finished=lambda: self._finish_loading(generation),
)
def _apply_result(
self,
result: Any,
generation: int,
page_snapshot: int,
keyword_snapshot: str,
) -> None:
if not self._is_current(generation):
@@ -316,36 +314,32 @@ class AiConsultTargetDialog(QDialog):
for target in (AiConsultTarget.from_row(row) for row in page_items(result))
if target is not None
]
total = max(0, page_total(result, len(targets)))
page_count = max(1, (total + self.PAGE_SIZE - 1) // self.PAGE_SIZE)
if page_snapshot > page_count:
self.load(page_count)
return
self._page = page_snapshot
self.table.set_rows(targets)
self.table.setSortingEnabled(False)
self.table.clearSelection()
self.pager.update_state(page_snapshot, total)
self.empty_state.setVisible(not targets)
self.table.setVisible(bool(targets))
self._page = self.pager.page
self.empty_state.setVisible(not targets and not self.pager.has_more)
self.table.setVisible(bool(targets) or self.pager.has_more)
self.banner.clear()
self._set_loading(False)
def _apply_error(self, error: Exception, generation: int) -> None:
if not self._is_current(generation):
return
self.table.set_rows(())
self.table.setSortingEnabled(False)
self.table.clearSelection()
self.table.hide()
self.empty_state.show()
self.pager.update_state(1, 0)
if not self.pager.rows:
self.table.set_rows(())
self.table.setSortingEnabled(False)
self.table.clearSelection()
self.table.hide()
self.empty_state.show()
self.banner.show_message(
f"患者诊单加载失败:{friendly_error(error)}", "danger"
)
self._set_loading(False)
def _finish_loading(self, generation: int) -> None:
if self._is_current(generation):
self._set_loading(False)
def _is_current(self, generation: int) -> bool:
return self._active and generation == self._generation
@@ -365,7 +359,6 @@ class AiConsultTargetDialog(QDialog):
def _set_loading(self, loading: bool) -> None:
self._loading = loading
self.table.setEnabled(not loading)
self.pager.setEnabled(not loading)
self.start_button.setEnabled(False if loading else self.table.currentRow() >= 0)
self.busy_overlay.setVisible(loading)
if loading:
@@ -383,6 +376,7 @@ class AiConsultTargetDialog(QDialog):
def done(self, result: int) -> None:
self._active = False
self._generation += 1
self.pager.invalidate()
self._search_timer.stop()
super().done(result)
@@ -130,9 +130,9 @@ class AppUpdateDialog(QDialog):
self.badge = QLabel("必须更新后才能继续使用" if offer.force else "发现新版本")
self.badge.setObjectName("UpdateBadge")
self.badge.setStyleSheet(
"color:#B45309;background:#FFF5E6;border-radius:8px;padding:4px 10px;font-weight:600;"
"color:#A9691D;background:#FFF5E6;border-radius:8px;padding:4px 10px;font-weight:600;"
if offer.force
else "color:#4451E2;background:#F0F2FF;border-radius:8px;padding:4px 10px;font-weight:600;"
else "color:#4F63D9;background:#EEF1FA;border-radius:8px;padding:4px 10px;font-weight:600;"
)
root.addWidget(self.badge, 0, Qt.AlignmentFlag.AlignLeft)
@@ -146,7 +146,7 @@ class AppUpdateDialog(QDialog):
latest = offer.latest_version or "新版本"
self.version_label = QLabel(f"当前版本 {current} → 最新版本 {latest}")
self.version_label.setObjectName("UpdateVersionLabel")
self.version_label.setStyleSheet("color:#7886AA;")
self.version_label.setStyleSheet("color:#606163;")
root.addWidget(self.version_label)
self.notes = QTextEdit()
@@ -160,7 +160,7 @@ class AppUpdateDialog(QDialog):
self.status_label = QLabel("")
self.status_label.setObjectName("UpdateStatus")
self.status_label.setWordWrap(True)
self.status_label.setStyleSheet("color:#3F4E75;")
self.status_label.setStyleSheet("color:#1A1C1F;")
self.status_label.hide()
root.addWidget(self.status_label)
@@ -175,7 +175,7 @@ class AppUpdateDialog(QDialog):
self.progress_text = QLabel("")
self.progress_text.setObjectName("UpdateProgressText")
self.progress_text.setStyleSheet("color:#7886AA;font-size:12px;")
self.progress_text.setStyleSheet("color:#606163;font-size:12px;")
self.progress_text.hide()
root.addWidget(self.progress_text)
@@ -225,7 +225,7 @@ class AppUpdateDialog(QDialog):
def show_download_progress(self, received: int, total: int) -> None:
self.progress.show()
self.progress_text.show()
self.status_label.setStyleSheet("color:#3F4E75;")
self.status_label.setStyleSheet("color:#1A1C1F;")
self.status_label.setText("正在下载安装包…")
self.status_label.show()
if total > 0:
@@ -237,7 +237,7 @@ class AppUpdateDialog(QDialog):
self.progress_text.setText(_format_bytes(received))
def show_status(self, message: str, *, determinate: bool = False) -> None:
self.status_label.setStyleSheet("color:#3F4E75;")
self.status_label.setStyleSheet("color:#1A1C1F;")
self.status_label.setText(message)
self.status_label.show()
self.progress.show()
@@ -251,7 +251,7 @@ class AppUpdateDialog(QDialog):
def show_error(self, message: str) -> None:
self._busy = False
self.status_label.setText(message)
self.status_label.setStyleSheet("color:#F15B67;")
self.status_label.setStyleSheet("color:#BE4B58;")
self.status_label.show()
self.progress.hide()
self.progress_text.hide()
@@ -60,6 +60,7 @@ from ..diagnosis_drawer import (
)
from ..diagnosis_editors import DailyRecordEditorDialog
from ..diagnosis_media import RecordingPlaybackCell, RecordingPlayerDialog
from ..infinite_list import InfiniteList
from ..widgets import (
display_text,
first_value,
@@ -190,74 +191,74 @@ _ORDER_OFFSET_HELP = (
_ORDER_DETAIL_QSS = """
QDialog#DiagnosisOrderDetailOverlay { background: transparent; }
QFrame#DiagnosisOrderDetailScrim { background: rgba(30, 64, 175, 0.18); border: 0; }
QFrame#DiagnosisOrderDetailScrim { background: rgba(26, 28, 31, 0.18); border: 0; }
QFrame#DiagnosisOrderDetailDrawer {
background: #F7F9FE;
background: #F7F7F7;
border: 0;
border-left: 1px solid #DDE7FF;
border-left: 1px solid #F0F0F0;
}
QFrame#DiagnosisOrderDetailHeader {
background: #FFFFFF;
border: 0;
border-bottom: 1px solid #DDE7FF;
border-bottom: 1px solid #F0F0F0;
}
QLabel#DiagnosisOrderDetailTitle { color: #15224A; font-size: 19px; font-weight: 650; }
QLabel#DiagnosisOrderDetailMeta { color: #7481A3; font-size: 12px; }
QLabel#DiagnosisOrderDetailTitle { color: #1A1C1F; font-size: 19px; font-weight: 650; }
QLabel#DiagnosisOrderDetailMeta { color: #606163; font-size: 12px; }
QLabel#DiagnosisOrderReadonlyBadge {
color: #3F4E75;
background: #F7F9FE;
border: 1px solid #E2E7F4;
color: #1A1C1F;
background: #F7F7F7;
border: 1px solid #EDEDEE;
border-radius: 4px;
padding: 3px 7px;
font-size: 11px;
font-weight: 600;
}
QScrollArea#DiagnosisOrderDetailScroll { border: 0; background: #F7F9FE; }
QScrollArea#DiagnosisOrderDetailScroll > QWidget > QWidget { background: #F7F9FE; }
QScrollArea#DiagnosisOrderDetailScroll { border: 0; background: #F7F7F7; }
QScrollArea#DiagnosisOrderDetailScroll > QWidget > QWidget { background: #F7F7F7; }
QFrame[orderAmountCard="true"] {
background: #FFFFFF;
border: 1px solid #DDE7FF;
border: 1px solid #F0F0F0;
border-radius: 9px;
}
QLabel[orderAmountTitle="true"] { color: #7481A3; font-size: 11px; font-weight: 550; }
QLabel[orderAmountTitle="true"] { color: #606163; font-size: 11px; font-weight: 550; }
QLabel[orderAmountValue="true"] {
color: #15224A;
color: #1A1C1F;
font-size: 18px;
font-weight: 700;
}
QLabel[orderAmountTone="danger"] { color: #C43E55; }
QLabel[orderAmountTone="success"] { color: #16876C; }
QLabel[orderAmountTone="warning"] { color: #9A6813; }
QLabel[orderAmountTone="danger"] { color: #BE4B58; }
QLabel[orderAmountTone="success"] { color: #287B65; }
QLabel[orderAmountTone="warning"] { color: #A9691D; }
QFrame[orderDetailSection="true"] {
background: #FFFFFF;
border: 1px solid #E2E7F4;
border: 1px solid #EDEDEE;
border-radius: 10px;
}
QLabel[orderSectionTitle="true"] { color: #15224A; font-size: 15px; font-weight: 650; }
QLabel[orderSectionHint="true"] { color: #7481A3; font-size: 11px; }
QLabel[orderSectionTitle="true"] { color: #1A1C1F; font-size: 15px; font-weight: 650; }
QLabel[orderSectionHint="true"] { color: #606163; font-size: 11px; }
QFrame[orderField="true"] {
background: #F2F6FE;
border: 1px solid #E2E7F4;
background: #F7F7F7;
border: 1px solid #EDEDEE;
border-radius: 7px;
}
QLabel[orderFieldLabel="true"] { color: #7481A3; font-size: 11px; }
QLabel[orderFieldValue="true"] { color: #15224A; font-size: 13px; }
QLabel[orderFieldLabel="true"] { color: #6A6B6D; font-size: 11px; }
QLabel[orderFieldValue="true"] { color: #1A1C1F; font-size: 13px; }
QLabel[orderEmptyState="true"] {
color: #7481A3;
background: #F2F6FE;
border: 1px dashed #C9D8F2;
color: #606163;
background: #F7F7F7;
border: 1px dashed #E4E4E5;
border-radius: 5px;
padding: 18px 12px;
font-size: 12px;
}
QFrame#DiagnosisOrderTimelineItem { border: 0; border-left: 2px solid #93B4F4; }
QLabel#DiagnosisOrderTimelineTime { color: #7481A3; font-size: 11px; }
QLabel#DiagnosisOrderTimelineTitle { color: #15224A; font-size: 12px; font-weight: 600; }
QLabel#DiagnosisOrderTimelineBody { color: #7481A3; font-size: 12px; }
QFrame#DiagnosisOrderTimelineItem { border: 0; border-left: 2px solid #8B9AD9; }
QLabel#DiagnosisOrderTimelineTime { color: #606163; font-size: 11px; }
QLabel#DiagnosisOrderTimelineTitle { color: #1A1C1F; font-size: 12px; font-weight: 600; }
QLabel#DiagnosisOrderTimelineBody { color: #606163; font-size: 12px; }
QFrame#DiagnosisOrderDetailFooter {
background: #FFFFFF;
border: 0;
border-top: 1px solid #DDE7FF;
border-top: 1px solid #F0F0F0;
}
"""
@@ -1003,8 +1004,8 @@ class DiagnosisDialog(QDialog):
self.readonly_back_button.setCursor(Qt.CursorShape.PointingHandCursor)
self.readonly_back_button.setStyleSheet(
"QPushButton{height:32px;padding:0 8px;border:0;background:transparent;"
"color:#5265F6;font-size:13px;font-weight:500;}"
"QPushButton:hover,QPushButton:focus{background:#F0F2FF;border-radius:6px;}"
"color:#1A1C1F;font-size:13px;font-weight:500;}"
"QPushButton:hover,QPushButton:focus{background:#EEF1FA;border-radius:6px;}"
)
self.readonly_back_button.clicked.connect(self.reject)
left_layout.addWidget(self.readonly_back_button)
@@ -1532,20 +1533,11 @@ class DiagnosisDialog(QDialog):
layout.addWidget(toolbar)
self.orders_table = self._new_table("orders", "DiagnosisTableOrders")
layout.addWidget(self.orders_table, 1)
footer = QHBoxLayout()
self.orders_summary = QLabel("共 0 条")
self.orders_summary.setObjectName("DiagnosisOrdersSummary")
footer.addWidget(self.orders_summary)
footer.addStretch(1)
self.orders_previous = QPushButton("上一页")
self.orders_previous.clicked.connect(lambda: self._change_orders_page(-1))
footer.addWidget(self.orders_previous)
self.orders_page_label = QLabel("1 / 1")
footer.addWidget(self.orders_page_label)
self.orders_next = QPushButton("下一页")
self.orders_next.clicked.connect(lambda: self._change_orders_page(1))
footer.addWidget(self.orders_next)
layout.addLayout(footer)
self.orders_list = InfiniteList(self._orders_page_size, page)
for table in self._table_registry["orders"]:
self.orders_list.bind(table)
self._orders_footer_layout = layout
layout.addWidget(self.orders_list)
return page
def _wrap_tab(self, object_name: str, body: QWidget) -> QScrollArea:
@@ -2021,6 +2013,13 @@ class DiagnosisDialog(QDialog):
self._daily_todo_status = None
self._orders_page = 1
self._orders_total = 0
self.orders_list.reset()
footer_layout = (
self._readonly_sections["orders"].layout()
if self._standalone_readonly
else self._orders_footer_layout
)
footer_layout.addWidget(self.orders_list)
self._detail = authoritative_detail if authoritative_detail is not None else seed
self.save_button.set_state("idle")
self.refresh_permissions()
@@ -2315,6 +2314,7 @@ class DiagnosisDialog(QDialog):
self._generation += 1
self._save_generation += 1
self._orders_generation += 1
self.orders_list.invalidate()
self._order_detail_generation += 1
self._daily_mutation_generation += 1
self._notes_mutation_generation += 1
@@ -2639,6 +2639,9 @@ class DiagnosisDialog(QDialog):
return
if not force and (key in self._loaded_tabs or key in self._loading_tabs):
return
if key == "orders":
self._load_orders()
return
self._tab_generations[key] += 1
generation = self._tab_generations[key]
diagnosis_id = self._diagnosis_id
@@ -2732,10 +2735,9 @@ class DiagnosisDialog(QDialog):
self._fill_prescriptions(page_items(result))
elif key == "orders":
rows = page_items(result)
self._orders_page = 1
self._orders_page = self.orders_list.page
self._orders_total = page_total(result, len(rows))
self._fill_orders(rows)
self._update_orders_pager()
elif key == "assign":
self._fill_assignments(page_items(result))
elif key == "appointment":
@@ -3448,8 +3450,7 @@ class DiagnosisDialog(QDialog):
panel.set_unavailable("切换到聊天记录后加载归档数据。")
for panel in self._daily_panels:
panel.clear()
self.orders_summary.setText("共 0 条")
self.orders_page_label.setText("1 / 1")
self.orders_list.update_state(1, 0)
@staticmethod
def _set_row(table: QTableWidget, row: int, values: Sequence[Any]) -> None:
@@ -4067,6 +4068,9 @@ class DiagnosisDialog(QDialog):
)
for row_index, row in enumerate(rows):
order_id = _int(first_value(row, "id", "order_id"), 0)
item = table.item(row_index, 0)
if item is not None:
item.setData(Qt.ItemDataRole.UserRole, row)
if (
self._can_order_detail
and order_id > 0
@@ -4738,52 +4742,44 @@ class DiagnosisDialog(QDialog):
if generation == self._order_detail_generation and diagnosis_id == self._diagnosis_id:
self._show_message(friendly_error(error), "danger")
def _update_orders_pager(self) -> None:
pages = max(1, (self._orders_total + self._orders_page_size - 1) // self._orders_page_size)
self.orders_summary.setText(f"共 {self._orders_total} 条")
self.orders_page_label.setText(f"{self._orders_page} / {pages}")
self.orders_previous.setEnabled(self._orders_page > 1)
self.orders_next.setEnabled(self._orders_page < pages)
def _change_orders_page(self, offset: int) -> None:
def _load_orders(self) -> None:
if not self._can_patient_orders or self._diagnosis_id <= 0:
return
pages = max(1, (self._orders_total + self._orders_page_size - 1) // self._orders_page_size)
target_page = self._orders_page + offset
if target_page < 1 or target_page > pages:
return
self._orders_generation += 1
generation = self._orders_generation
self._tab_generations["orders"] += 1
generation = self._tab_generations["orders"]
diagnosis_id = self._diagnosis_id
patient_id = self._patient_id
self._show_message("正在加载患者订单…", "info")
run_async(
lambda: self._query_orders(diagnosis_id, patient_id, target_page),
on_success=lambda result: self._apply_orders_page(
result, diagnosis_id, target_page, generation
self._loading_tabs.add("orders")
if not self.orders_list.rows:
self._set_tab_loading("orders")
self.orders_list.reload(
lambda page: self._query_orders(diagnosis_id, patient_id, page),
apply=lambda result: self._apply_orders_result(
result, diagnosis_id, generation
),
on_error=lambda error: self._orders_error(error, diagnosis_id, generation),
on_error=lambda error: self._tab_load_error(
"orders", error, diagnosis_id, generation
),
runner=run_async,
query_key=(diagnosis_id, patient_id),
)
def _apply_orders_page(
def _apply_orders_result(
self,
result: Any,
diagnosis_id: int,
page: int,
generation: int,
) -> None:
if generation != self._orders_generation or diagnosis_id != self._diagnosis_id:
if (
generation != self._tab_generations["orders"]
or diagnosis_id != self._diagnosis_id
or not self._authoritative_detail_loaded
):
return
rows = page_items(result)
self._orders_page = page
self._orders_total = page_total(result, len(rows))
self._fill_orders(rows)
self._update_orders_pager()
self._clear_message()
def _orders_error(self, error: Exception, diagnosis_id: int, generation: int) -> None:
if generation == self._orders_generation and diagnosis_id == self._diagnosis_id:
self._show_message(friendly_error(error), "danger")
if self.orders_list.page == 0:
self._fill_orders([])
return
self._apply_tab_result("orders", result, diagnosis_id, generation)
def _save(self) -> None:
if (
@@ -40,76 +40,76 @@ _STATUS_LABELS = {
"invalid": "无效录音",
}
_STATUS_COLORS = {
"recording": "#5364F5",
"pending": "#B26A00",
"uploading": "#2F6FEB",
"uploaded": "#07966B",
"failed": "#DC4054",
"invalid": "#7886AA",
"recording": "#1A1C1F",
"pending": "#A9691D",
"uploading": "#1A1C1F",
"uploaded": "#287B65",
"failed": "#BE4B58",
"invalid": "#606163",
}
_BUSINESS_TIMEZONE = timezone(timedelta(hours=8))
_LOCAL_AUDIO_QSS = """
QDialog#LocalAudioQueueDialog {
background: #F6F8FD;
color: #111F46;
background: #F7F7F7;
color: #1A1C1F;
}
QFrame#LocalAudioQueueHeader, QFrame#LocalAudioQueueSummary,
QFrame#LocalAudioQueueTableCard, QFrame#LocalAudioQueueFooter {
background: #FFFFFF;
border: 1px solid #E2E7F4;
border: 1px solid #EDEDEE;
border-radius: 14px;
}
QLabel#LocalAudioQueueTitle {
color: #111F46;
color: #1A1C1F;
font-size: 20px;
font-weight: 700;
}
QLabel#LocalAudioQueueSubtitle, QLabel#LocalAudioQueueHint {
color: #6E7C9F;
color: #6A6B6D;
font-size: 13px;
}
QLabel[queueSummary="true"] {
background: #F3F5FB;
border: 1px solid #E6EAF5;
background: #F7F7F7;
border: 1px solid #EDEDEE;
border-radius: 10px;
color: #3F4E75;
color: #1A1C1F;
font-size: 13px;
font-weight: 600;
padding: 8px 12px;
}
QPushButton {
min-height: 34px;
border: 1px solid #D9E0F2;
border: 1px solid #EDEDEE;
border-radius: 9px;
background: #FFFFFF;
color: #354365;
color: #1A1C1F;
padding: 0 14px;
font-weight: 600;
}
QPushButton:hover { background: #F1F3FF; border-color: #AEB8FF; }
QPushButton:disabled { color: #A5AFC6; background: #F7F8FC; }
QPushButton:hover { background: #EEF1FA; border-color: #8B9AD9; }
QPushButton:disabled { color: #8E8F90; background: #F7F7F7; }
QPushButton[variant="primary"] {
color: #FFFFFF;
background: #5661F4;
border-color: #5661F4;
background: #4F63D9;
border-color: #4F63D9;
}
QPushButton[variant="danger"] { color: #D83E51; background: #FFF6F7; }
QPushButton[variant="danger"] { color: #BE4B58; background: #FFF6F7; }
QTableWidget#LocalAudioQueueTable {
background: #FFFFFF;
alternate-background-color: #FAFBFE;
alternate-background-color: #F7F7F7;
border: 0;
gridline-color: #E8ECF5;
color: #263452;
selection-background-color: #EEF1FF;
selection-color: #111F46;
gridline-color: #EDEDEE;
color: #1A1C1F;
selection-background-color: #EEF1FA;
selection-color: #1A1C1F;
}
QTableWidget#LocalAudioQueueTable::item { padding: 8px; }
QHeaderView::section {
background: #F5F7FC;
color: #53617F;
background: #F7F7F7;
color: #6A6B6D;
border: 0;
border-bottom: 1px solid #E1E6F1;
border-bottom: 1px solid #EDEDEE;
padding: 10px 8px;
font-weight: 700;
}
@@ -371,7 +371,7 @@ class LocalAudioQueueDialog(QDialog):
self._status_column,
_STATUS_LABELS.get(record.status, record.status),
)
status_item.setForeground(QColor(_STATUS_COLORS.get(record.status, "#53617F")))
status_item.setForeground(QColor(_STATUS_COLORS.get(record.status, "#606163")))
status_item.setToolTip(
f"已尝试 {record.attempts} 次"
+ (f"\nCOS:{record.uploaded_url}" if record.uploaded_url else "")
File diff suppressed because it is too large Load Diff
@@ -143,75 +143,75 @@ def diagnosis_ai_task(prompt: str) -> str:
PRESCRIPTION_AI_QSS = """
QDialog#PrescriptionAiDialog {
color: #17203F;
background-color: #F7F9FE;
font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
color: #1A1C1F;
background-color: #F7F7F7;
font-size: 13px;
}
QDialog#PrescriptionAiDialog QPushButton {
min-height: 34px;
padding: 0 16px;
color: #4F5B75;
color: #1A1C1F;
background-color: #FFFFFF;
border: 1px solid #DCE3F2;
border: 1px solid #EDEDEE;
border-radius: 7px;
font-weight: 500;
}
QDialog#PrescriptionAiDialog QPushButton:hover {
color: #4D57D8;
background-color: #F0F2FF;
border-color: #D8DCFF;
color: #4156C4;
background-color: #EEF1FA;
border-color: #8B9AD9;
}
QDialog#PrescriptionAiDialog QPushButton:pressed {
color: #FFFFFF;
background-color: #4D57D8;
border-color: #4D57D8;
background-color: #354BB4;
border-color: #354BB4;
}
QDialog#PrescriptionAiDialog QPushButton[variant="primary"] {
color: #FFFFFF;
background-color: #5761F4;
border-color: #5761F4;
background-color: #4F63D9;
border-color: #4F63D9;
}
QDialog#PrescriptionAiDialog QPushButton[variant="primary"]:hover {
background-color: #6871F6;
border-color: #6871F6;
background-color: #4156C4;
border-color: #4156C4;
}
QDialog#PrescriptionAiDialog QPushButton[variant="link"] {
color: #4D57D8;
color: #4F63D9;
background-color: transparent;
border-color: transparent;
}
QDialog#PrescriptionAiDialog QPushButton[variant="link"]:hover {
background-color: #F0F2FF;
background-color: #EEF1FA;
}
QLabel#PrescriptionAiTitle {
color: #17203F;
color: #1A1C1F;
font-size: 20px;
font-weight: 700;
}
QLabel#PrescriptionAiSubtitle {
color: #78849D;
color: #606163;
font-size: 13px;
}
QFrame#PrescriptionAiSnapshot {
background-color: #FFFFFF;
border: 1px solid #DCE3F2;
border: 1px solid #EDEDEE;
border-radius: 10px;
}
QLabel#PrescriptionAiSnapshotLabel {
color: #4D57D8;
color: #1A1C1F;
font-size: 12px;
font-weight: 600;
}
QLabel#PrescriptionAiSnapshotBody {
color: #26304F;
color: #1A1C1F;
font-size: 13px;
line-height: 1.65;
}
QFrame#PrescriptionAiSummary {
background-color: #F0F2FF;
background-color: #F0F0F0;
border: 0;
border-left: 3px solid #5761F4;
border-left: 3px solid #4F63D9;
border-radius: 0 9px 9px 0;
}
QFrame#PrescriptionAiCaution {
@@ -220,56 +220,56 @@ QFrame#PrescriptionAiCaution {
border-radius: 9px;
}
QLabel#PrescriptionAiSectionTitle {
color: #17203F;
color: #1A1C1F;
font-size: 14px;
font-weight: 600;
}
QLabel#PrescriptionAiBody {
color: #37415E;
color: #1A1C1F;
font-size: 13px;
line-height: 1.75;
}
QTextBrowser#PrescriptionAiAnswer {
color: #34436B;
color: #1A1C1F;
background-color: #FFFFFF;
border: 1px solid #E3E8F4;
border: 1px solid #EDEDEE;
border-radius: 10px;
padding: 12px 14px;
selection-color: #17203F;
selection-background-color: #DDE2FF;
selection-color: #1A1C1F;
selection-background-color: #EEF1FA;
}
QLabel#PrescriptionAiMuted {
color: #8A94AA;
color: #6A6B6D;
font-size: 12px;
line-height: 1.65;
}
QFrame#PrescriptionAiMeta {
background: transparent;
border: 0;
border-bottom: 1px solid #E3E8F4;
border-bottom: 1px solid #EDEDEE;
}
QDialog#PrescriptionAiDialog QTabWidget::pane {
background-color: #FFFFFF;
border: 1px solid #DCE3F2;
border: 1px solid #EDEDEE;
border-radius: 10px;
top: -1px;
}
QDialog#PrescriptionAiDialog QTabBar::tab {
min-height: 36px;
padding: 0 18px;
color: #78849D;
color: #606163;
background-color: transparent;
border: 0;
border-bottom: 2px solid transparent;
}
QDialog#PrescriptionAiDialog QTabBar::tab:hover {
color: #4D57D8;
background-color: #F5F7FC;
color: #4156C4;
background-color: #F7F7F7;
}
QDialog#PrescriptionAiDialog QTabBar::tab:selected {
color: #4D57D8;
background-color: #F0F2FF;
border-bottom: 2px solid #5761F4;
color: #4F63D9;
background-color: #EEF1FA;
border-bottom: 2px solid #4F63D9;
font-weight: 600;
}
QDialog#PrescriptionAiDialog QScrollArea,
@@ -278,15 +278,15 @@ QDialog#PrescriptionAiDialog QScrollArea > QWidget > QWidget {
border: 0;
}
QDialog#PrescriptionAiDialog QTextEdit {
color: #17203F;
color: #1A1C1F;
background-color: #FFFFFF;
border: 1px solid #DCE3F2;
border: 1px solid #EDEDEE;
border-radius: 8px;
padding: 10px;
selection-background-color: #E3E6FF;
selection-background-color: #EEF1FA;
}
QDialog#PrescriptionAiDialog QTextEdit:focus {
border: 1px solid #5761F4;
border: 1px solid #8B9AD9;
}
QDialog#PrescriptionAiDialog QScrollBar:vertical {
width: 10px;
@@ -295,7 +295,7 @@ QDialog#PrescriptionAiDialog QScrollBar:vertical {
}
QDialog#PrescriptionAiDialog QScrollBar::handle:vertical {
min-height: 32px;
background-color: #C8D0E0;
background-color: #D2D2D3;
border-radius: 4px;
}
QDialog#PrescriptionAiDialog QScrollBar::add-line:vertical,
@@ -305,20 +305,20 @@ QDialog#PrescriptionAiDialog QScrollBar::sub-line:vertical {
"""
_AI_ANSWER_DOCUMENT_CSS = (
"body { color:#34436B; font-size:14px; line-height:1.72; } "
"h1 { color:#15224A; font-size:20px; margin:14px 0 8px; line-height:1.4; } "
"h2 { color:#15224A; font-size:17px; margin:14px 0 7px; line-height:1.42; } "
"h3,h4 { color:#15224A; font-size:15px; margin:12px 0 6px; line-height:1.45; } "
"body { color:#1A1C1F; font-size:14px; line-height:1.72; } "
"h1 { color:#1A1C1F; font-size:20px; margin:14px 0 8px; line-height:1.4; } "
"h2 { color:#1A1C1F; font-size:17px; margin:14px 0 7px; line-height:1.42; } "
"h3,h4 { color:#1A1C1F; font-size:15px; margin:12px 0 6px; line-height:1.45; } "
"p { margin:6px 0; line-height:1.72; } "
"ul,ol { margin:7px 0 8px 22px; } li { margin:4px 0; line-height:1.65; } "
"strong { color:#15224A; font-weight:700; } "
"blockquote { color:#596788; background:#F5F7FC; border-left:3px solid #7B84F7; "
"strong { color:#1A1C1F; font-weight:700; } "
"blockquote { color:#606163; background:#F7F7F7; border-left:3px solid #8B9AD9; "
"margin:9px 0; padding:7px 10px; } "
"code { color:#33406B; background:#EEF1FF; } "
"pre { color:#33406B; background:#F0F3FA; margin:8px 0; padding:9px; } "
"code { color:#1A1C1F; background:#F0F0F0; } "
"pre { color:#1A1C1F; background:#F7F7F7; margin:8px 0; padding:9px; } "
"table { border-collapse:collapse; margin:8px 0; } "
"th,td { border:1px solid #DCE3F2; padding:6px 8px; } "
"th { color:#15224A; background:#F5F7FC; font-weight:700; }"
"th,td { border:1px solid #EDEDEE; padding:6px 8px; } "
"th { color:#1A1C1F; background:#F7F7F7; font-weight:700; }"
)
_AI_ANSWER_MARKDOWN_FEATURES = (
QTextDocument.MarkdownFeature.MarkdownDialectGitHub
@@ -1181,7 +1181,7 @@ class PrescriptionAiReportDialog(QDialog):
def _list_html(self, items: Any, empty: str) -> str:
values = [str(item).strip() for item in (items or []) if str(item).strip()]
if not values:
return f'<span style="color:#8A94AA;">{html.escape(empty)}</span>'
return f'<span style="color:#6A6B6D;">{html.escape(empty)}</span>'
bullets = "".join(f"<li>{html.escape(item)}</li>" for item in values)
return f'<ul style="margin:0;padding-left:18px;">{bullets}</ul>'
@@ -1398,7 +1398,7 @@ class PrescriptionAiReportDialog(QDialog):
content.setTextFormat(Qt.TextFormat.RichText)
cell_layout.addWidget(heading)
cell_layout.addWidget(content)
grid.addWidget(cell, index // 2, index % 2)
grid.addWidget(cell, index // 2, index % 2, Qt.AlignmentFlag.AlignTop)
self.host_layout.addWidget(grid_host)
if report.get("compatibility_analysis"):
self._section("配伍分析", str(report.get("compatibility_analysis") or ""))
+76 -95
View File
@@ -21,6 +21,7 @@ from PySide6.QtGui import (
QResizeEvent,
)
from PySide6.QtWidgets import (
QApplication,
QCheckBox,
QFrame,
QGraphicsDropShadowEffect,
@@ -43,7 +44,7 @@ from PySide6.QtWidgets import (
from doctor_workstation import __version__
from doctor_workstation.resources import app_icon_path, brand_lockup_path
from .theme import crisp_pixmap
from . import icons
from .widgets import BusyOverlay, MessageBanner, friendly_error, invoke, run_async
@@ -71,7 +72,7 @@ class _VisibleCheckBox(QCheckBox):
)
painter = QPainter(self)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
color = QColor("#FFFFFF" if self.isEnabled() else "#98A2B3")
color = QColor("#FFFFFF" if self.isEnabled() else "#8E8F90")
painter.setPen(QPen(color, 2, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap))
painter.drawLine(
QPoint(indicator.left() + 4, indicator.center().y()),
@@ -90,7 +91,7 @@ class _AccountLineEdit(QLineEdit):
super().paintEvent(event)
painter = QPainter(self)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.setPen(_round_pen("#8292B6", 1.5))
painter.setPen(_round_pen("#6A6B6D", 1.5))
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawEllipse(QRectF(24, 14.5, 8, 8))
painter.drawRoundedRect(QRectF(19, 27, 18, 9), 4.5, 4.5)
@@ -104,7 +105,7 @@ class _DemoCheckBox(_VisibleCheckBox):
painter = QPainter(self)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
center = QPointF(self.width() - 9, self.height() / 2)
painter.setPen(_round_pen("#92A0BF", 1.4))
painter.setPen(_round_pen("#8E8F90", 1.4))
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawEllipse(center, 7, 7)
painter.drawLine(center + QPointF(0, -1), center + QPointF(0, 4))
@@ -112,10 +113,9 @@ class _DemoCheckBox(_VisibleCheckBox):
def _font(pixel_size: int, weight: QFont.Weight = QFont.Weight.Normal) -> QFont:
font = QFont("Microsoft YaHei UI")
font = QFont(QApplication.font())
font.setPixelSize(pixel_size)
font.setWeight(weight)
font.setHintingPreference(QFont.HintingPreference.PreferFullHinting)
return font
@@ -291,10 +291,10 @@ class _BrandPanel(QWidget):
bounds = QRectF(self.rect()).adjusted(0.5, 0.5, -0.5, -0.5)
background = QLinearGradient(bounds.topLeft(), bounds.bottomRight())
background.setColorAt(0.0, QColor("#FFFFFF"))
background.setColorAt(0.7, QColor("#FEFEFF"))
background.setColorAt(1.0, QColor("#F9FBFF"))
background.setColorAt(0.7, QColor("#FFFFFF"))
background.setColorAt(1.0, QColor("#F7F7F7"))
painter.setBrush(background)
painter.setPen(QPen(QColor("#E4E9F4"), 1))
painter.setPen(QPen(QColor("#EDEDEE"), 1))
painter.drawRoundedRect(bounds, 24, 24)
width, height = float(self.width()), float(self.height())
@@ -315,15 +315,15 @@ class _BrandPanel(QWidget):
tag_rect = QRectF(left, 238, 119, 40)
painter.setPen(Qt.PenStyle.NoPen)
painter.setBrush(QColor("#F0F2FF"))
painter.setBrush(QColor("#EEF1FA"))
painter.drawRoundedRect(tag_rect, 11, 11)
painter.setFont(_font(17, QFont.Weight.DemiBold))
painter.setPen(QColor("#5265F6"))
painter.setFont(_font(17, QFont.Weight.Medium))
painter.setPen(QColor("#4F63D9"))
painter.drawText(tag_rect, Qt.AlignmentFlag.AlignCenter, "医生工作站")
copy_left = left + 4
painter.setFont(_font(51, QFont.Weight.Bold))
painter.setPen(QColor("#14224A"))
painter.setFont(_font(48, QFont.Weight.Medium))
painter.setPen(QColor("#1A1C1F"))
painter.drawText(QPointF(copy_left, 354), "把诊间工作,")
painter.drawText(QPointF(copy_left, 424), "留在一个")
prefix_width = painter.fontMetrics().horizontalAdvance("留在一个")
@@ -333,8 +333,8 @@ class _BrandPanel(QWidget):
copy_left + prefix_width + 264,
0,
)
highlight.setColorAt(0.0, QColor("#4258EC"))
highlight.setColorAt(1.0, QColor("#6975FF"))
highlight.setColorAt(0.0, QColor("#4F63D9"))
highlight.setColorAt(1.0, QColor("#4F63D9"))
painter.setPen(QPen(QBrush(highlight), 1))
painter.drawText(QPointF(copy_left + prefix_width, 424), "安静的界面里")
suffix_x = (
@@ -342,19 +342,19 @@ class _BrandPanel(QWidget):
+ prefix_width
+ painter.fontMetrics().horizontalAdvance("安静的界面里")
)
painter.setPen(QColor("#14224A"))
painter.setPen(QColor("#1A1C1F"))
painter.drawText(QPointF(suffix_x, 424), "。")
body_left = left + 6
painter.setFont(_font(20))
painter.setPen(QColor("#7181A7"))
painter.setPen(QColor("#606163"))
painter.drawText(
QPointF(body_left, 492), "接诊、问诊、患者与处方信息统一呈现,"
)
painter.drawText(QPointF(body_left, 525), "帮助医生专注于每一次沟通。")
painter.setFont(_font(16))
painter.setPen(QColor("#7484A9"))
painter.setPen(QColor("#6A6B6D"))
painter.drawText(
QPointF(body_left, height - 85), "本工作站仅供获授权的医疗人员使用"
)
@@ -366,7 +366,7 @@ class _RevealButton(QToolButton):
del event
painter = QPainter(self)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
color = QColor("#8796B8" if self.isEnabled() else "#B8C0D1")
color = QColor("#6A6B6D" if self.isEnabled() else "#BDBDBE")
painter.setPen(_round_pen(color, 2))
painter.setBrush(Qt.BrushStyle.NoBrush)
eye = QPainterPath(QPointF(7, self.height() / 2))
@@ -392,11 +392,11 @@ class _ServerButton(QPushButton):
painter = QPainter(self)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
rect = QRectF(self.rect()).adjusted(0.75, 0.75, -0.75, -0.75)
painter.setBrush(QColor("#F8FAFF") if self.underMouse() else QColor("#FFFFFF"))
painter.setPen(QPen(QColor("#D8DFEE"), 1.5))
painter.setBrush(QColor("#FFFFFF") if self.underMouse() else QColor("#FFFFFF"))
painter.setPen(QPen(QColor("#E4E4E5"), 1.5))
painter.drawRoundedRect(rect, 12, 12)
color = QColor("#17264B" if self.isEnabled() else "#A2ABC0")
painter.setPen(_round_pen("#7C8DB2", 1.8))
color = QColor("#1A1C1F" if self.isEnabled() else "#8E8F90")
painter.setPen(_round_pen("#6A6B6D", 1.8))
center = QPointF(29, self.height() / 2)
painter.drawEllipse(center, 8, 8)
painter.drawEllipse(center, 2.8, 2.8)
@@ -420,7 +420,7 @@ class _ServerButton(QPushButton):
Qt.AlignmentFlag.AlignVCenter | Qt.AlignmentFlag.AlignLeft,
"服务器设置",
)
painter.setPen(_round_pen("#94A1BC", 2))
painter.setPen(_round_pen("#8E8F90", 2))
x, y = self.width() - 28, self.height() / 2
if self.isChecked():
painter.drawLine(QPointF(x - 5, y + 3), QPointF(x, y - 3))
@@ -482,12 +482,8 @@ class LoginWindow(QMainWindow):
canvas.setStyleSheet(
"""
QWidget#LoginCanvas {
color: #17264B;
background: qlineargradient(
x1:0, y1:0, x2:1, y2:1,
stop:0 #F8FAFF, stop:0.58 #FBFCFF, stop:1 #F1F5FF
);
font-family: "Microsoft YaHei UI";
color: #1A1C1F;
background-color: #F4F6FA;
font-size: 16px;
}
QWidget#LoginBrandPanel {
@@ -496,28 +492,28 @@ class LoginWindow(QMainWindow):
}
QFrame#LoginCard {
background-color: #FFFFFF;
border: 1px solid #E1E6F0;
border: 1px solid #EDEDEE;
border-radius: 20px;
}
QFrame#LoginCard QFrame#SubtleCard {
background-color: #F8FAFF;
border: 1px solid #DCE2EF;
background-color: #FFFFFF;
border: 1px solid #E4E4E5;
border-radius: 12px;
}
QFrame#LoginCard QLabel { color: #17264B; background: transparent; }
QFrame#LoginCard QLabel[role="muted"] { color: #7382A5; }
QFrame#LoginCard QLabel { color: #1A1C1F; background: transparent; }
QFrame#LoginCard QLabel[role="muted"] { color: #606163; }
QFrame#LoginCard QLabel[role="danger"] { color: #C43E55; }
QFrame#LoginCard QCheckBox#AllowSelfSignedCertificate { color: #9A6813; }
QFrame#LoginCard QLineEdit,
QFrame#LoginCard QSpinBox {
color: #17264B;
color: #1A1C1F;
background-color: #FFFFFF;
border: 1px solid #D6DEED;
border: 1px solid #E4E4E5;
border-radius: 12px;
padding: 0 16px;
font-size: 17px;
selection-background-color: #E5E9FF;
selection-color: #17264B;
selection-background-color: #EEF1FA;
selection-color: #1A1C1F;
}
QFrame#LoginCard QLineEdit#AccountEdit {
min-height: 52px;
@@ -525,9 +521,9 @@ class LoginWindow(QMainWindow):
padding-left: 52px;
}
QFrame#LoginCard QLineEdit:hover,
QFrame#LoginCard QSpinBox:hover { border-color: #9AA8FF; }
QFrame#LoginCard QSpinBox:hover { border-color: #8B9AD9; }
QFrame#LoginCard QLineEdit:focus,
QFrame#LoginCard QSpinBox:focus { border: 1.5px solid #7080F7; }
QFrame#LoginCard QSpinBox:focus { border: 1.5px solid #8B9AD9; }
QFrame#LoginCard QLineEdit#PasswordEdit {
border: 0;
border-radius: 0;
@@ -537,31 +533,31 @@ class LoginWindow(QMainWindow):
QFrame#LoginCard QCheckBox#DemoModeCheck { spacing: 10px; }
QFrame#PasswordField {
background-color: #FFFFFF;
border: 1px solid #D6DEED;
border: 1px solid #E4E4E5;
border-radius: 12px;
}
QFrame#PasswordField:focus-within { border-color: #7080F7; }
QFrame#PasswordField:focus-within { border-color: #8B9AD9; }
QFrame#LoginCard QCheckBox {
color: #6F7FA3;
color: #606163;
spacing: 13px;
font-size: 16px;
}
QFrame#LoginCard QCheckBox::indicator {
width: 22px;
height: 22px;
border: 1px solid #CFD8EB;
border: 1px solid #E4E4E5;
border-radius: 6px;
background-color: #FFFFFF;
}
QFrame#LoginCard QCheckBox::indicator:hover { border-color: #7A8AF8; }
QFrame#LoginCard QCheckBox::indicator:hover { border-color: #8B9AD9; }
QFrame#LoginCard QCheckBox::indicator:checked {
border-color: #6475F5;
background-color: #6475F5;
border-color: #4F63D9;
background-color: #4F63D9;
}
QFrame#LoginCard QToolButton#PasswordReveal {
min-width: 87px;
max-width: 87px;
color: #8290B0;
color: #6A6B6D;
background: transparent;
border: 0;
padding: 0;
@@ -570,14 +566,11 @@ class LoginWindow(QMainWindow):
min-height: 58px;
max-height: 58px;
color: #FFFFFF;
background: qlineargradient(
x1:0, y1:0, x2:1, y2:0,
stop:0 #5B6BF1, stop:0.55 #6675FA, stop:1 #5865F2
);
background-color: #4F63D9;
border: 0;
border-radius: 12px;
font-size: 18px;
font-weight: 700;
font-weight: 500;
}
QFrame#LoginCard QPushButton#ServerSettingsToggle {
min-height: 56px;
@@ -585,17 +578,17 @@ class LoginWindow(QMainWindow):
padding: 0;
}
QFrame#LoginCard QPushButton[variant="primary"]:hover {
background-color: #5262ED;
background-color: #4156C4;
}
QFrame#LoginCard QPushButton[variant="secondary"] {
color: #4353BD;
background-color: #EDF0FF;
border: 1px solid #D3DAFC;
color: #1A1C1F;
background-color: #F0F0F0;
border: 1px solid #E4E4E5;
border-radius: 9px;
}
QFrame#LoginCard QPushButton[variant="secondary"]:hover {
background-color: #DCE3FF;
border-color: #8B98F8;
background-color: #E4E4E5;
border-color: #8B9AD9;
}
QScrollArea#LoginAreaScroll,
QScrollArea#LoginAreaScroll > QWidget > QWidget {
@@ -629,6 +622,12 @@ class LoginWindow(QMainWindow):
spacing = 20
self.login_root.setContentsMargins(*margins)
self.login_root.setSpacing(spacing)
# Keep the form fully visible when the 60/40 desktop split would
# otherwise crop its fixed-width card. Small windows focus on login.
self.brand_panel.setVisible(width >= 1120)
self.login_area_layout.setContentsMargins(
0, min(104, max(24, (event.size().height() - 694) // 2)), 0, 12
)
super().resizeEvent(event)
def _build_brand_panel(self) -> QWidget:
@@ -647,20 +646,19 @@ class LoginWindow(QMainWindow):
area.setFrameShape(QFrame.Shape.NoFrame)
area.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
area.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
area.setMinimumWidth(492)
content = QWidget()
content.setObjectName("LoginAreaContent")
area.setWidget(content)
self.login_scroll = area
outer = QVBoxLayout(content)
# The supplied 1536×1024 capture contains a 60 px native title bar.
# Its card begins at y=198, i.e. y=138 in the 1536×964 client area.
# The root starts at y=34, so the deterministic lead inset is 104 px.
outer.setContentsMargins(0, 104, 0, 0)
self.login_area_layout = outer
outer.setContentsMargins(0, 40, 0, 12)
self.card = QFrame()
self.card.setObjectName("LoginCard")
self.card.setFixedWidth(480)
self.card.setMinimumHeight(694)
self.card.setMinimumHeight(620)
self.card.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Minimum)
card_shadow = QGraphicsDropShadowEffect(self.card)
card_shadow.setBlurRadius(38)
@@ -675,13 +673,13 @@ class LoginWindow(QMainWindow):
title = QLabel("欢迎回来")
title.setObjectName("LoginTitle")
title.setStyleSheet("color:#14224A; font-size:33px; font-weight:700;")
title.setStyleSheet("color:#1A1C1F; font-size:30px; font-weight:500;")
title.setContentsMargins(1, -3, 0, 3)
title.setFixedHeight(46)
card_layout.addWidget(title)
subtitle = QLabel("使用医生账号登录工作站")
subtitle.setProperty("role", "muted")
subtitle.setStyleSheet("color:#7382A5; font-size:18px;")
subtitle.setStyleSheet("color:#606163; font-size:18px;")
subtitle.setContentsMargins(1, 8, 0, 0)
subtitle.setFixedHeight(27)
card_layout.addWidget(subtitle)
@@ -691,7 +689,7 @@ class LoginWindow(QMainWindow):
card_layout.addWidget(self.error_banner)
account_label = QLabel("账号")
account_label.setStyleSheet("color:#17264B; font-size:18px; font-weight:600;")
account_label.setStyleSheet("color:#1A1C1F; font-size:16px; font-weight:500;")
account_label.setContentsMargins(0, -2, 0, 2)
account_label.setFixedHeight(24)
card_layout.addWidget(account_label)
@@ -707,7 +705,7 @@ class LoginWindow(QMainWindow):
card_layout.addSpacing(21)
password_label = QLabel("密码")
password_label.setStyleSheet("color:#17264B; font-size:18px; font-weight:600;")
password_label.setStyleSheet("color:#1A1C1F; font-size:16px; font-weight:500;")
password_label.setContentsMargins(0, -3, 0, 3)
password_label.setFixedHeight(24)
card_layout.addWidget(password_label)
@@ -777,16 +775,16 @@ class LoginWindow(QMainWindow):
divider.setSpacing(18)
line_left = QFrame()
line_left.setFrameShape(QFrame.Shape.HLine)
line_left.setStyleSheet("color:#DFE4F0; background:#DFE4F0; max-height:1px;")
line_left.setStyleSheet("color:#EDEDEE; background:#EDEDEE; max-height:1px;")
divider.addWidget(line_left, 1)
divider_text = QLabel("或")
divider_text.setAlignment(Qt.AlignmentFlag.AlignCenter)
divider_text.setStyleSheet("color:#7C89A8; font-size:16px;")
divider_text.setStyleSheet("color:#6A6B6D; font-size:16px;")
divider_text.setFixedSize(38, 22)
divider.addWidget(divider_text)
line_right = QFrame()
line_right.setFrameShape(QFrame.Shape.HLine)
line_right.setStyleSheet("color:#DFE4F0; background:#DFE4F0; max-height:1px;")
line_right.setStyleSheet("color:#EDEDEE; background:#EDEDEE; max-height:1px;")
divider.addWidget(line_right, 1)
debug_settings_layout.addLayout(divider)
debug_settings_layout.addSpacing(20)
@@ -873,7 +871,7 @@ class LoginWindow(QMainWindow):
footnote_row.addWidget(lock)
footnote = QLabel("登录即表示你同意遵守机构的数据安全与隐私规范。")
footnote.setProperty("role", "muted")
footnote.setStyleSheet("color:#7A89AA; font-size:15px;")
footnote.setStyleSheet("color:#6A6B6D; font-size:15px;")
footnote.setContentsMargins(0, -4, 0, 4)
footnote.setWordWrap(True)
footnote.setFixedHeight(40)
@@ -882,12 +880,12 @@ class LoginWindow(QMainWindow):
self.version_label = QLabel(f"当前版本 {__version__}")
self.version_label.setObjectName("LoginVersionLabel")
self.version_label.setProperty("role", "muted")
self.version_label.setStyleSheet("color:#8B98B5; font-size:13px;")
self.version_label.setStyleSheet("color:#6A6B6D; font-size:13px;")
self.version_label.setContentsMargins(0, 8, 0, 0)
card_layout.addWidget(self.version_label, 0, Qt.AlignmentFlag.AlignRight)
outer.addWidget(
self.card, 0, Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
self.card, 0, Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop
)
outer.addStretch(1)
self.busy_overlay = BusyOverlay(self.card, "正在验证账号…")
@@ -899,28 +897,11 @@ class LoginWindow(QMainWindow):
@staticmethod
def _account_icon() -> QIcon:
pixmap = crisp_pixmap(24)
painter = QPainter(pixmap)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.setPen(_round_pen("#8292B6", 2))
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawEllipse(QPointF(12, 7.5), 4.2, 4.2)
painter.drawRoundedRect(QRectF(4.5, 14, 15, 7), 3.5, 3.5)
painter.end()
return QIcon(pixmap)
return icons.icon("user", "muted", 24)
@staticmethod
def _lock_icon() -> QIcon:
pixmap = crisp_pixmap(20)
painter = QPainter(pixmap)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.setPen(_round_pen("#8FA0C4", 1.6))
painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawRoundedRect(QRectF(5, 8, 10, 9), 2, 2)
painter.drawArc(QRectF(7, 3, 6, 9), 0, 180 * 16)
painter.drawLine(QPointF(10, 11), QPointF(10, 14))
painter.end()
return QIcon(pixmap)
return icons.icon("lock", "muted", 20)
def _restore_settings(self) -> None:
configured_account = getattr(self.config, "remembered_account", "")
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+363 -139
View File
@@ -1,13 +1,4 @@
"""Application-wide visual system for the AI consultation workstation.
The palette and density follow the supplied product references: a quiet blue
canvas, crisp white data surfaces, luminous indigo actions and compact tables.
Every size in the interface comes from the token tables below. Before they
existed the UI had grown 19 distinct font sizes and 8 control heights, which is
what made neighbouring controls look subtly mismatched; keep new work on the
scale instead of introducing another one-off pixel value.
"""
"""Shared typography and neutral reading surfaces for the clinical workspace."""
from __future__ import annotations
@@ -17,12 +8,15 @@ from pathlib import Path
from string import Template
from typing import Any
from PySide6.QtCore import QEvent, QObject, Qt
from PySide6.QtCore import QEvent, QObject, QPointF, Qt
from PySide6.QtGui import (
QColor,
QFont,
QFontDatabase,
QPainter,
QPainterPath,
QPalette,
QPen,
QPixmap,
QTextBlockFormat,
QTextCharFormat,
@@ -35,50 +29,57 @@ from PySide6.QtWidgets import (
QFileDialog,
QInputDialog,
QMessageBox,
QPlainTextEdit,
QScrollArea,
QTextBrowser,
QTextEdit,
)
# Canonical semantic tokens. The legacy teal/ink aliases remain available to
# callers while the stylesheet itself is generated from this mapping.
from doctor_workstation.resources import resource_path
# ``motion`` deliberately imports nothing from this module, so this stays a
# one-way dependency: tokens here, animation there.
from . import motion
# Neutral reading colors follow the installed Codex light chrome defaults.
# Brand accents are independent of reading ink; use opaque text for stable contrast.
# The legacy teal/ink aliases remain for existing callers.
COLORS = {
# Sampled from the supplied 1710 x 920 product comps. The window edge is
# the only blue-tinted surface; the application workspace itself is an
# almost-white #FCFDFE field.
"canvas": "#EEF3FD",
"canvas_mid": "#F7F9FE",
"canvas_glow": "#E5ECFD",
"canvas": "#F4F6FA",
"canvas_mid": "#FFFFFF",
"canvas_glow": "#EEF1FA",
"surface": "#FFFFFF",
"surface_alt": "#FAFBFE",
"raised": "#F5F7FC",
"glass": "rgba(255, 255, 255, 252)",
"glass_alt": "rgba(248, 250, 255, 252)",
"line": "#E6EAF5",
"line_soft": "rgba(82, 97, 246, 40)",
"text": "#111F46",
"text_soft": "#3F4E75",
"muted": "#7886AA",
"disabled_surface": "#F0F2F8",
"disabled_text": "#A4ADC3",
"indigo": "#5761F4",
"indigo_hover": "#4C57E9",
"indigo_pressed": "#4451E2",
"indigo_pale": "#F0F2FF",
"focus": "#8D9BFF",
"selection": "#EDF0FF",
"success": "#17A77D",
"success_pale": "#EAF9F3",
"warning": "#D38625",
"warning_pale": "#FFF5E6",
"danger": "#F15B67",
"danger_pale": "#FFF1F3",
"info": "#4D69ED",
"info_pale": "#F0F4FF",
"surface_alt": "#F7F7F7",
"raised": "#F7F7F7",
"glass": "#FFFFFF",
"glass_alt": "#F7F7F7",
"line": "#EDEDEE",
"line_soft": "#E4E4E5",
"text": "#1A1C1F",
"text_soft": "#606163",
"muted": "#6A6B6D",
"disabled_surface": "#F2F2F2",
"disabled_text": "#8E8F90",
"indigo": "#4F63D9",
"indigo_hover": "#4156C4",
"indigo_pressed": "#354BB4",
"indigo_pale": "#EEF1FA",
"focus": "#8B9AD9",
"selection": "#EEF1FA",
"success": "#287B65",
"success_pale": "#EEF7F3",
"warning": "#A9691D",
"warning_pale": "#FCF5E9",
"danger": "#BE4B58",
"danger_pale": "#FCF0F2",
"info": "#4F63D9",
"info_pale": "#EEF1FA",
# Backward-compatible names used by older UI code and integrations.
"ink": "#111F46",
"ink_soft": "#3F4E75",
"teal": "#5761F4",
"teal_dark": "#4451E2",
"teal_pale": "#F0F2FF",
"ink": "#1A1C1F",
"ink_soft": "#606163",
"teal": "#4F63D9",
"teal_dark": "#354BB4",
"teal_pale": "#EEF1FA",
}
@@ -87,32 +88,47 @@ COLORS = {
# more ink than Latin at the same pixel size, so the steps are spaced widely
# enough that two adjacent levels are always distinguishable.
TYPE = {
"fs_caption": "12px", # table headers, hints, badges, timestamps
"fs_body": "13px", # default UI text
"fs_strong": "14px", # emphasised body, dialog prompts
"fs_caption": "13px", # table headers, hints, badges, timestamps
"fs_body": "14px", # default UI text
"fs_strong": "15px", # emphasised body, dialog prompts
"fs_section": "16px", # card and section titles
"fs_title": "20px", # page titles, dialog titles
"fs_display": "26px", # metric values, empty-state glyphs
}
# The bundled variable font supplies real Regular, Medium and Semibold faces.
# Keep ordinary controls at Medium and reserve Semibold for headings.
WEIGHTS = {
"fw_body": "400",
"fw_control": "500",
"fw_heading": "600",
}
# --- Control metrics ------------------------------------------------------
# Three interactive heights. ``h_default`` drops from the previous 36px: the
# old value made every toolbar, filter row and inline action read as heavy,
# which is the main reason the workspace felt clunky.
# Controls leave room for the 14px reading size without increasing table density.
METRICS = {
"h_compact": "28px", # inline row actions, chips, links
"h_default": "32px", # buttons, inputs, combos, tabs
"h_default": "34px", # buttons, inputs, combos, tabs
"h_cta": "38px", # primary dialog actions, sidebar navigation
"h_bar": "52px", # dialog header / footer bars
"r_sm": "6px",
"r_md": "8px",
"r_lg": "12px",
"r_xl": "16px",
# Corner radii. These existed before but the pages invented their own, so
# the same role - a card - shipped at 10, 11, 12, 13, 14 and 16 px across
# six pages. Nothing in a product is a "10px card"; it is either a card or
# it is not, and it should round like every other card next to it.
#
# Nesting rule: an element sitting flush inside a rounded container takes
# ``outer - gap``. Where the gap is bigger than the outer radius the inner
# element is far enough from the corner that its own radius is free.
"r_xs": "4px", # chips, badges, tiny status pills
"r_sm": "6px", # inline row actions, tags
"r_md": "8px", # buttons, inputs, combo boxes
"r_lg": "12px", # cards, filter bars, panels
"r_xl": "16px", # the shell surfaces the cards sit on
"pad_control": "12px", # horizontal padding inside default controls
"pad_compact": "9px",
}
_QSS_TOKENS = {**COLORS, **TYPE, **METRICS}
_QSS_TOKENS = {**COLORS, **TYPE, **WEIGHTS, **METRICS}
def crisp_pixmap(width: int, height: int | None = None) -> QPixmap:
@@ -144,8 +160,8 @@ GLOBAL_QSS = Template(
QWidget {
color: $text;
background-color: transparent;
font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
font-size: $fs_body;
font-weight: $fw_body;
}
QMainWindow, QDialog, QWidget#LoginCanvas {
@@ -170,7 +186,7 @@ QDialog[businessDialog="true"] QFrame[dialogRole="header"] {
QDialog[businessDialog="true"] QLabel[dialogRole="title"] {
color: $text;
font-size: $fs_section;
font-weight: 700;
font-weight: $fw_control;
}
QDialog[businessDialog="true"] QLabel[dialogRole="subtitle"] {
color: $muted;
@@ -214,48 +230,43 @@ QInputDialog QLabel {
font-size: $fs_strong;
}
QWidget#AppCanvas {
background-color: qlineargradient(
x1: 0, y1: 0, x2: 1, y2: 1,
stop: 0 $canvas,
stop: 0.58 $canvas_mid,
stop: 1 $canvas_glow
);
background-color: $canvas;
border-radius: 18px;
}
QWidget#ShellWorkspace, QStackedWidget#ShellPageStack {
background-color: #FCFDFE;
background-color: $canvas_mid;
}
QLabel[role="muted"] { color: $muted; }
QLabel[role="danger"] { color: $danger; }
QLabel[role="breadcrumb"] { color: $muted; font-size: $fs_caption; }
QLabel[role="breadcrumbSeparator"] { color: #ADB5C9; font-size: $fs_strong; }
QLabel[role="breadcrumbCurrent"] { color: $text_soft; font-size: $fs_caption; font-weight: 600; }
QLabel[role="breadcrumbSeparator"] { color: #8E8F90; font-size: $fs_strong; }
QLabel[role="breadcrumbCurrent"] { color: $text_soft; font-size: $fs_caption; font-weight: $fw_control; }
QLabel[role="eyebrow"] {
color: $indigo_hover;
font-size: $fs_caption;
font-weight: 700;
font-weight: $fw_control;
letter-spacing: 0.04em;
}
QLabel[role="pageTitle"] {
color: $text;
font-size: $fs_title;
font-weight: 700;
font-weight: $fw_heading;
}
QLabel[role="sectionTitle"] {
color: $text;
font-size: $fs_section;
font-weight: 700;
font-weight: $fw_control;
}
QLabel[role="display"] {
color: $text;
font-size: $fs_display;
font-weight: 700;
font-weight: $fw_heading;
}
QLabel[role="metric"] {
color: $text;
font-size: $fs_title;
font-weight: 700;
font-weight: $fw_heading;
}
QFrame#Card, QFrame#Panel, QFrame#FilterBar, QFrame#DetailPanel,
@@ -277,19 +288,19 @@ QFrame#MetricCard {
}
QFrame#MetricCard:hover { border-color: $line_soft; background-color: $surface_alt; }
QFrame#MetricCard QLabel[role="metricTitle"] { color: $muted; font-size: $fs_caption; }
QFrame#MetricCard QLabel[role="metricValue"] { color: $text; font-size: $fs_title; font-weight: 700; }
QFrame#MetricCard QLabel[role="metricValue"] { color: $text; font-size: $fs_title; font-weight: $fw_heading; }
QFrame#MetricCard QLabel[role="metricHint"] { color: $muted; font-size: $fs_caption; }
QFrame#ReceptionDetailPanel { background-color: transparent; border: 0; }
QFrame#ReceptionAiCard {
min-height: 132px;
background-color: #F8FAFF;
background-color: #FFFFFF;
border: 1px solid $line_soft;
border-radius: 13px;
}
QLabel#ReceptionAiTitle {
color: $indigo_pressed;
font-size: $fs_strong;
font-weight: 700;
font-weight: $fw_control;
}
QFrame#ReceptionAiCard QPushButton[variant="secondary"] {
min-height: $h_compact;
@@ -302,7 +313,7 @@ QLabel#MetricGlyph {
border: 1px solid $line_soft;
border-radius: 11px;
font-size: $fs_section;
font-weight: 700;
font-weight: $fw_heading;
}
QLabel#MetricGlyph[kind="success"] { color: $success; background-color: $success_pale; }
QLabel#MetricGlyph[kind="warning"] { color: $warning; background-color: $warning_pale; }
@@ -318,7 +329,7 @@ QGroupBox {
border: 1px solid $line;
border-radius: 12px;
background-color: $glass;
font-weight: 600;
font-weight: $fw_control;
}
QGroupBox::title {
subcontrol-origin: margin;
@@ -334,7 +345,7 @@ QPushButton {
border-radius: $r_md;
background-color: $surface;
color: $text;
font-weight: 600;
font-weight: $fw_control;
}
QPushButton:hover {
background-color: $raised;
@@ -345,7 +356,8 @@ QPushButton:pressed {
border-color: $indigo_pressed;
}
QPushButton:focus {
border: 2px solid $focus;
border: 1px solid $indigo;
background-color: $indigo_pale;
}
QPushButton:checked {
color: #FFFFFF;
@@ -361,10 +373,7 @@ QPushButton:disabled {
QPushButton[variant="primary"] {
color: #FFFFFF;
background-color: qlineargradient(
x1: 0, y1: 0, x2: 1, y2: 0,
stop: 0 $indigo, stop: 1 #7769F7
);
background-color: $indigo;
border-color: $indigo;
}
QPushButton[variant="primary"]:hover,
@@ -377,7 +386,10 @@ QPushButton[variant="primary"]:checked {
background-color: $indigo_pressed;
border-color: $indigo_pressed;
}
QPushButton[variant="primary"]:focus { border: 2px solid $focus; }
QPushButton[variant="primary"]:focus {
border: 1px solid $indigo_pressed;
background-color: $indigo_hover;
}
QPushButton[variant="primary"]:disabled {
color: $disabled_text;
background-color: $surface_alt;
@@ -410,7 +422,7 @@ QWidget#RowActions QPushButton[rowAction="true"] {
background-color: transparent;
border: 1px solid transparent;
border-radius: $r_sm;
font-weight: 600;
font-weight: $fw_control;
}
QWidget#RowActions QPushButton[rowAction="true"]:hover {
color: $indigo_pressed;
@@ -436,7 +448,7 @@ QToolButton#RowActionsMore {
background-color: transparent;
border: 1px solid transparent;
border-radius: $r_sm;
font-weight: 600;
font-weight: $fw_control;
}
QToolButton#RowActionsMore:hover {
color: $text;
@@ -457,7 +469,7 @@ QPushButton#NoteAttachmentPreview {
background-color: $surface_alt;
border: 1px solid $line;
border-radius: 8px;
font-weight: 500;
font-weight: $fw_control;
}
QPushButton#NoteAttachmentPreview:hover {
background-color: $indigo_pale;
@@ -503,15 +515,15 @@ QPushButton[variant="success"] {
background-color: $success;
border-color: $success;
}
QPushButton[variant="success"]:hover { background-color: #65D4B7; border-color: #65D4B7; }
QPushButton[variant="success"]:pressed { background-color: #319F84; border-color: #319F84; }
QPushButton[variant="success"]:hover { background-color: #216A56; border-color: #216A56; }
QPushButton[variant="success"]:pressed { background-color: #1B5746; border-color: #1B5746; }
QPushButton[variant="warning"] {
color: #FFFFFF;
background-color: $warning;
border-color: $warning;
}
QPushButton[variant="warning"]:hover { background-color: #F0C97C; border-color: #F0C97C; }
QPushButton[variant="warning"]:pressed { background-color: #B99045; border-color: #B99045; }
QPushButton[variant="warning"]:hover { background-color: #925B19; border-color: #925B19; }
QPushButton[variant="warning"]:pressed { background-color: #794B14; border-color: #794B14; }
QPushButton[variant="ghost"] {
color: $text_soft;
@@ -536,7 +548,7 @@ QPushButton[variant="link"] {
background-color: transparent;
border-color: transparent;
}
QPushButton[variant="link"]:hover { color: $focus; background-color: $indigo_pale; }
QPushButton[variant="link"]:hover { color: $indigo_hover; background-color: $indigo_pale; }
QPushButton[variant="link"]:pressed { color: $indigo_hover; background-color: $surface_alt; }
QPushButton[variant="chip"] {
min-height: $h_compact;
@@ -564,7 +576,7 @@ QPushButton[variant="nav"] {
background-color: transparent;
color: $muted;
text-align: left;
font-weight: 600;
font-weight: $fw_control;
}
QPushButton[variant="nav"]:hover { background-color: $surface_alt; color: $text; }
QPushButton[variant="nav"]:pressed { background-color: $indigo_pale; }
@@ -580,7 +592,7 @@ QToolButton {
}
QToolButton:hover { color: $text; background-color: $surface_alt; border-color: $line; }
QToolButton:pressed { background-color: $indigo_pale; border-color: $indigo_pressed; }
QToolButton:focus { border: 2px solid $focus; }
QToolButton:focus { border: 1px solid $indigo; background-color: $indigo_pale; }
QToolButton:checked { color: #FFFFFF; background-color: $indigo_pressed; border-color: $indigo_hover; }
QToolButton:disabled { color: $disabled_text; background-color: transparent; border-color: transparent; }
QToolButton[diagnosisChip="true"] {
@@ -616,8 +628,8 @@ QDoubleSpinBox:hover, QKeySequenceEdit:hover { border-color: $indigo_hover; }
QLineEdit:focus, QTextEdit:focus, QPlainTextEdit:focus, QComboBox:focus,
QDateEdit:focus, QDateTimeEdit:focus, QTimeEdit:focus, QSpinBox:focus,
QDoubleSpinBox:focus, QKeySequenceEdit:focus {
border: 2px solid $focus;
background-color: $surface_alt;
border: 1px solid $indigo;
background-color: $surface;
}
QLineEdit:read-only, QTextEdit:read-only, QPlainTextEdit:read-only {
color: $muted;
@@ -676,7 +688,7 @@ QCheckBox::indicator:disabled, QRadioButton::indicator:disabled {
QAbstractItemView, QTableWidget, QTableView, QListWidget, QListView, QTreeWidget, QTreeView {
color: $text;
background-color: $surface;
alternate-background-color: #FBFCFF;
alternate-background-color: $surface_alt;
border: 0;
border-radius: 12px;
gridline-color: $line;
@@ -684,7 +696,7 @@ QAbstractItemView, QTableWidget, QTableView, QListWidget, QListView, QTreeWidget
selection-color: $text;
outline: 0;
}
QAbstractItemView:focus { border: 1px solid $indigo_hover; }
QAbstractItemView:focus { border: 0; }
QTableWidget::item, QTableView::item {
padding: 6px 8px;
border-bottom: 1px solid $line;
@@ -695,14 +707,14 @@ QTableWidget::item:selected, QTableView::item:selected {
background-color: $selection;
}
QHeaderView::section {
background-color: #F7F9FE;
background-color: $raised;
color: $muted;
border: 0;
border-right: 1px solid $line;
border-right: 0;
border-bottom: 1px solid $line;
padding: 7px 8px;
font-size: $fs_caption;
font-weight: 700;
font-weight: $fw_control;
}
QHeaderView::section:hover { color: $text; background-color: $raised; }
QTableCornerButton::section { background-color: $surface_alt; border: 0; }
@@ -736,7 +748,7 @@ QTabBar::tab {
background-color: transparent;
border: 1px solid transparent;
border-radius: 9px;
font-weight: 600;
font-weight: $fw_control;
}
QTabBar::tab:hover { color: $text; background-color: $surface_alt; }
QTabBar::tab:focus { border-color: $focus; }
@@ -788,8 +800,8 @@ QMenu::item {
border-radius: $r_sm;
background-color: transparent;
}
QMenu::item:selected { color: #FFFFFF; background-color: $indigo_pressed; }
QMenu::item:pressed { background-color: $indigo; }
QMenu::item:selected { color: $indigo_pressed; background-color: $indigo_pale; }
QMenu::item:pressed { color: #FFFFFF; background-color: $indigo; }
QMenu::item:disabled { color: $disabled_text; background-color: transparent; }
QMenu::item[danger="true"] { color: $danger; }
QMenu::item[danger="true"]:selected { color: $danger; background-color: $danger_pale; }
@@ -841,8 +853,8 @@ QScrollBar::handle:vertical {
min-height: $h_compact;
border-radius: 4px;
}
QScrollBar::handle:vertical:hover { background: $indigo_pressed; }
QScrollBar::handle:vertical:pressed { background: $indigo; }
QScrollBar::handle:vertical:hover { background: #A7B1C9; }
QScrollBar::handle:vertical:pressed { background: #8894B2; }
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { height: 0; }
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical { background: transparent; }
QScrollBar:horizontal {
@@ -855,8 +867,8 @@ QScrollBar::handle:horizontal {
min-width: 30px;
border-radius: 4px;
}
QScrollBar::handle:horizontal:hover { background: $indigo_pressed; }
QScrollBar::handle:horizontal:pressed { background: $indigo; }
QScrollBar::handle:horizontal:hover { background: #A7B1C9; }
QScrollBar::handle:horizontal:pressed { background: #8894B2; }
QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal { width: 0; }
QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal { background: transparent; }
@@ -885,7 +897,7 @@ QLabel#StatusBadge {
border: 1px solid transparent;
border-radius: $r_sm;
font-size: $fs_caption;
font-weight: 700;
font-weight: $fw_control;
}
QLabel#StatusBadge[kind="neutral"] { color: $muted; background-color: $surface_alt; border-color: $line; }
QLabel#StatusBadge[kind="success"] { color: $success; background-color: $success_pale; border-color: rgba(73, 198, 165, 72); }
@@ -902,7 +914,7 @@ QWidget#Pager QLabel#PagerActive {
border: 1px solid $indigo;
border-radius: 8px;
font-size: $fs_caption;
font-weight: 700;
font-weight: $fw_control;
}
QWidget#Pager QPushButton {
min-height: $h_compact;
@@ -918,7 +930,7 @@ QLabel#EmptyStateGlyph {
border: 1px solid $line_soft;
border-radius: 22px;
font-size: $fs_display;
font-weight: 500;
font-weight: $fw_control;
}
QFrame#MessageBanner {
@@ -927,7 +939,7 @@ QFrame#MessageBanner {
color: $text_soft;
}
QFrame#MessageBanner QLabel { background-color: transparent; }
QFrame#MessageBanner QLabel#MessageBannerIcon { font-weight: 700; }
QFrame#MessageBanner QLabel#MessageBannerIcon { font-weight: $fw_heading; }
QFrame#MessageBanner[kind="info"] { color: $info; background-color: $info_pale; border-color: rgba(120, 167, 255, 82); }
QFrame#MessageBanner[kind="success"] { color: $success; background-color: $success_pale; border-color: rgba(73, 198, 165, 82); }
QFrame#MessageBanner[kind="warning"] { color: $warning; background-color: $warning_pale; border-color: rgba(228, 185, 103, 82); }
@@ -943,7 +955,7 @@ QLabel#Toast {
border: 1px solid $line_soft;
border-radius: 11px;
padding: 11px 16px;
font-weight: 600;
font-weight: $fw_control;
}
QLabel#Toast[kind="info"] { color: $info; background-color: $info_pale; border-color: rgba(120, 167, 255, 96); }
QLabel#Toast[kind="success"] { color: $success; background-color: $success_pale; border-color: rgba(73, 198, 165, 96); }
@@ -978,7 +990,7 @@ QLabel#UserAvatar {
border: 1px solid $line_soft;
border-radius: 18px;
font-size: $fs_strong;
font-weight: 700;
font-weight: $fw_heading;
}
QWidget#LoginBrandPanel {
background-color: qlineargradient(
@@ -997,6 +1009,29 @@ QFrame#LoginCard {
QSplitter::handle { background-color: transparent; width: 8px; height: 8px; }
QSplitter::handle:hover { background-color: $indigo_pressed; }
QPushButton[variant="secondary"]:disabled,
QPushButton[variant="secondary"]:checked:disabled,
QPushButton[variant="success"]:disabled,
QPushButton[variant="success"]:checked:disabled,
QPushButton[variant="warning"]:disabled,
QPushButton[variant="warning"]:checked:disabled,
QPushButton[variant="danger"]:disabled,
QPushButton[variant="danger"]:checked:disabled,
QPushButton[variant="dangerGhost"]:disabled,
QPushButton[variant="dangerGhost"]:checked:disabled,
QPushButton[variant="ghost"]:disabled,
QPushButton[variant="ghost"]:checked:disabled,
QPushButton[variant="link"]:disabled,
QPushButton[variant="link"]:checked:disabled,
QPushButton[variant="chip"]:disabled,
QPushButton[variant="chip"]:checked:disabled,
QPushButton[variant="nav"]:disabled,
QPushButton[variant="nav"]:checked:disabled {
color: $disabled_text;
background-color: $disabled_surface;
border-color: $line;
}
QToolTip {
color: $text;
background-color: $raised;
@@ -1024,6 +1059,166 @@ _BLOCK_RHYTHM = {
}
# --- Surfaces -------------------------------------------------------------
# There is deliberately no drop-shadow system here. One was tried: a painted
# layer behind each page's cards, on the theory that flat outlines were what
# made the workspace look unfinished. It does not work in this palette. The
# cards are #FFFFFF sitting on a #FFFFFF workspace - barely one percent apart -
# so a shadow has no tonal room to read as depth and instead composites into a
# neutral grey rim around every card, which against the blue-tinted ground looks
# like a dirty second border rather than elevation.
#
# Depth in this product comes from the border and the fill, not from shadow.
# --- Control indicator glyphs --------------------------------------------
# Styling ``QCheckBox::indicator`` with a background and border but no image
# tells Qt to stop drawing its own tick, so every checked box in the product
# rendered as a plain indigo square and the partially-checked state was an
# unlabelled grey one. Selection columns on the prescription, patient and
# diagnosis tables all depend on that tick, so the marks are painted here and
# handed back to the stylesheet as cached PNGs.
_INDICATOR_BOX = 15
_INDICATOR_REVISION = "1"
#: The dropdown caret is the one glyph Fusion still drew itself - a solid
#: triangle sitting beside an otherwise entirely stroked icon set. Rendering it
#: here brings every QComboBox, date field and tool-button menu onto the same
#: 24-unit grid as the rest of the product.
_CARET_BOX = 12
def _indicator_pixmap(kind: str, color: str, ratio: int, box_size: int | None = None) -> QPixmap:
box = (box_size or _INDICATOR_BOX) * ratio
pixmap = QPixmap(box, box)
pixmap.fill(Qt.GlobalColor.transparent)
painter = QPainter(pixmap)
try:
painter.setRenderHint(QPainter.RenderHint.Antialiasing, True)
scale = box / 24.0
painter.scale(scale, scale)
pen = QPen(QColor(color), 3.4)
pen.setCapStyle(Qt.PenCapStyle.RoundCap)
pen.setJoinStyle(Qt.PenJoinStyle.RoundJoin)
painter.setPen(pen)
painter.setBrush(Qt.BrushStyle.NoBrush)
if kind == "check":
path = QPainterPath(QPointF(5.0, 12.5))
path.lineTo(QPointF(10.0, 17.5))
path.lineTo(QPointF(19.0, 6.5))
painter.drawPath(path)
elif kind == "dash":
painter.drawLine(QPointF(6.0, 12.0), QPointF(18.0, 12.0))
elif kind == "dot":
painter.setPen(Qt.PenStyle.NoPen)
painter.setBrush(QColor(color))
painter.drawEllipse(QPointF(12.0, 12.0), 4.6, 4.6)
elif kind == "caret":
pen.setWidthF(2.6)
painter.setPen(pen)
path = QPainterPath(QPointF(6.0, 9.5))
path.lineTo(QPointF(12.0, 15.5))
path.lineTo(QPointF(18.0, 9.5))
painter.drawPath(path)
finally:
painter.end()
return pixmap
def _indicator_asset_dir() -> Path | None:
try:
from platformdirs import user_cache_dir
from ..config import APP_AUTHOR, APP_NAME
directory = Path(user_cache_dir(APP_NAME, APP_AUTHOR)) / "indicators"
except Exception: # pragma: no cover - falls back to the user home
directory = Path.home() / ".zhenyangdoctor" / "indicators"
try:
directory.mkdir(parents=True, exist_ok=True)
except OSError: # pragma: no cover - read-only deployment
return None
return directory
def _indicator_url(kind: str, color: str, box_size: int | None = None) -> str | None:
"""Return a stylesheet ``url()`` body for one indicator mark, or None."""
directory = _indicator_asset_dir()
if directory is None:
return None
stem = f"{kind}-{color.lstrip('#').lower()}-{box_size or _INDICATOR_BOX}-{_INDICATOR_REVISION}"
base = directory / f"{stem}.png"
# Qt resolves the ``@2x`` companion itself on scaled displays, which keeps
# the mark crisp at the 125%/150% factors clinic workstations run at.
retina = directory / f"{stem}@2x.png"
try:
if not base.exists() and not _indicator_pixmap(kind, color, 1, box_size).save(
str(base), "PNG"
):
return None
if not retina.exists():
_indicator_pixmap(kind, color, 2, box_size).save(str(retina), "PNG")
except OSError: # pragma: no cover - read-only deployment
return None
return base.as_posix()
def _indicator_qss() -> str:
"""Stylesheet fragment that restores the tick, dash and radio dot."""
marks = {
"check": _indicator_url("check", "#FFFFFF"),
"check_disabled": _indicator_url("check", COLORS["disabled_text"]),
"dash": _indicator_url("dash", "#FFFFFF"),
"dot": _indicator_url("dot", "#FFFFFF"),
"dot_disabled": _indicator_url("dot", COLORS["disabled_text"]),
"caret": _indicator_url("caret", COLORS["muted"], _CARET_BOX),
"caret_disabled": _indicator_url("caret", COLORS["disabled_text"], _CARET_BOX),
}
if any(value is None for value in marks.values()):
return ""
return f"""
QCheckBox::indicator:checked {{ image: url({marks["check"]}); }}
QCheckBox::indicator:indeterminate {{
background-color: {COLORS["indigo"]};
border: 1px solid {COLORS["indigo"]};
border-radius: 4px;
image: url({marks["dash"]});
}}
QCheckBox::indicator:checked:disabled {{ image: url({marks["check_disabled"]}); }}
QRadioButton::indicator:checked {{ image: url({marks["dot"]}); }}
QRadioButton::indicator:checked:disabled {{ image: url({marks["dot_disabled"]}); }}
QComboBox::down-arrow, QDateEdit::down-arrow, QDateTimeEdit::down-arrow,
QTimeEdit::down-arrow {{
width: {_CARET_BOX}px;
height: {_CARET_BOX}px;
image: url({marks["caret"]});
}}
/* A tool button's menu indicator defaults to the bottom-right corner, which was
invisible while it was Fusion's 6 px triangle and became obvious once it was a
12 px chevron - the caret dropped below the label instead of sitting beside
it. Anchor it to the right edge; the buttons that show one already reserve
right padding for it, so nothing here changes their metrics. */
QToolButton::menu-indicator {{
width: {_CARET_BOX}px;
height: {_CARET_BOX}px;
image: url({marks["caret"]});
subcontrol-origin: padding;
subcontrol-position: right center;
right: 6px;
}}
/* Re-assert the suppressions that the block above would otherwise override.
These live here rather than in the main sheet because this fragment is
appended after it, and a later rule wins in Qt when specificity ties. */
QToolButton#RowActionsMore::menu-indicator {{ width: 0; height: 0; image: none; }}
QComboBox::down-arrow:disabled, QDateEdit::down-arrow:disabled,
QDateTimeEdit::down-arrow:disabled, QTimeEdit::down-arrow:disabled,
QToolButton::menu-indicator:disabled {{ image: url({marks["caret_disabled"]}); }}
"""
def _block_is_all_bold(block: Any) -> bool:
"""True when every visible run in the block is bold.
@@ -1100,7 +1295,7 @@ def apply_reading_rhythm(browser: QTextBrowser, *, role: str) -> None:
char_format = QTextCharFormat()
char_format.setFont(heading_font)
if role != "doctor":
char_format.setForeground(QColor("#111B3F"))
char_format.setForeground(QColor("#1A1C1F"))
cursor.setPosition(block.position())
cursor.setPosition(
block.position() + block.length() - 1,
@@ -1123,14 +1318,21 @@ def _apply_group(
def _register_preferred_cjk_fonts() -> str:
"""Make the bundled/offscreen Windows runtime aware of its CJK fonts.
"""Prefer the shipped outline font, with native CJK faces as a fallback."""
Qt's offscreen platform does not always enumerate the Windows font
collection. Registering the already-installed YaHei collection only
when it is missing prevents Chinese text from degrading to tofu boxes in
packaged captures and headless visual checks. Other platforms continue
to use their native PingFang/Noto fallback.
"""
app = QApplication.instance()
registered = getattr(app, "_doctor_bundled_font_family", None)
if registered:
return registered
bundled_font = resource_path("fonts", "NotoSansSC-VF.ttf")
if bundled_font.is_file():
font_id = QFontDatabase.addApplicationFont(str(bundled_font))
families = QFontDatabase.applicationFontFamilies(font_id) if font_id >= 0 else []
if families:
family = families[0]
if app is not None:
app._doctor_bundled_font_family = family
return family
platform_families = {
"win32": ("Microsoft YaHei UI", "Microsoft YaHei"),
@@ -1259,12 +1461,27 @@ class _BusinessDialogStyleFilter(QObject):
or dialog.testAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
)
#: The filter is installed on the QApplication, so it is handed every event
#: in the process - roughly 5,000 per list refresh. Only two event types
#: matter, and bailing on the type before touching ``isinstance`` keeps the
#: hot path to a single comparison.
_WATCHED = frozenset({QEvent.Type.Polish, QEvent.Type.Show})
#: Reading surfaces that get eased wheel scrolling when they are polished.
#: Deliberately not every ``QAbstractScrollArea``: animating the scrollbar of
#: an item view that hosts a widget per row means repainting those widgets
#: for the length of the animation, which would trade a jerky scroll for a
#: slow one. The list pages opt their own tables in individually.
_SMOOTH_SCROLL = (QScrollArea, QTextEdit, QTextBrowser, QPlainTextEdit)
def eventFilter(self, watched: QObject, event: QEvent) -> bool: # noqa: N802
event_type = event.type()
if isinstance(watched, QDialogButtonBox) and event_type in {
QEvent.Type.Polish,
QEvent.Type.Show,
}:
if event_type not in self._WATCHED:
return False
if event_type is QEvent.Type.Polish and isinstance(watched, self._SMOOTH_SCROLL):
motion.install_smooth_scroll(watched)
return False
if isinstance(watched, QDialogButtonBox):
_polish_dialog_buttons(watched)
elif isinstance(watched, QDialog) and event_type == QEvent.Type.Polish:
# Window flags can only be changed before the dialog is on screen,
@@ -1305,11 +1522,17 @@ def apply_theme(app: QApplication) -> None:
app.setStyle("Fusion")
cjk_family = _register_preferred_cjk_fonts()
# Pin the Windows CJK face explicitly. A comma-separated QSS fallback
# list can resolve to Qt's generic sans face in offscreen/native title-bar
# captures, which changes glyph width and can even yield tofu boxes.
application_font = QFont(app.font())
application_font.setFamily(cjk_family)
# Resolve once for both styled widgets and custom-painted table cells.
application_font = QFont(cjk_family)
application_font.setPixelSize(int(TYPE["fs_body"].removesuffix("px")))
application_font.setWeight(QFont.Weight.Normal)
application_font.setStyleStrategy(
QFont.StyleStrategy.PreferAntialias
| QFont.StyleStrategy.PreferOutline
)
# Keep the platform's pixel fitting and subpixel rendering available.
# Forcing grayscale plus vertical-only hinting softens small Windows text.
application_font.setHintingPreference(QFont.HintingPreference.PreferDefaultHinting)
app.setFont(application_font)
palette = QPalette()
active = {
@@ -1324,7 +1547,7 @@ def apply_theme(app: QApplication) -> None:
QPalette.ColorRole.ButtonText: COLORS["text"],
QPalette.ColorRole.Base: COLORS["surface"],
QPalette.ColorRole.Window: COLORS["canvas"],
QPalette.ColorRole.Shadow: "#B7C0D2",
QPalette.ColorRole.Shadow: "#C2C2C2",
QPalette.ColorRole.Highlight: COLORS["indigo"],
QPalette.ColorRole.HighlightedText: "#FFFFFF",
QPalette.ColorRole.Link: COLORS["info"],
@@ -1347,7 +1570,7 @@ def apply_theme(app: QApplication) -> None:
QPalette.ColorRole.ButtonText: COLORS["disabled_text"],
QPalette.ColorRole.Base: COLORS["disabled_surface"],
QPalette.ColorRole.Window: COLORS["canvas"],
QPalette.ColorRole.Shadow: "#C8CFDC",
QPalette.ColorRole.Shadow: "#D2D2D2",
QPalette.ColorRole.Highlight: COLORS["line"],
QPalette.ColorRole.HighlightedText: COLORS["disabled_text"],
QPalette.ColorRole.Link: COLORS["disabled_text"],
@@ -1362,7 +1585,7 @@ def apply_theme(app: QApplication) -> None:
_apply_group(palette, QPalette.ColorGroup.Inactive, active)
_apply_group(palette, QPalette.ColorGroup.Disabled, disabled)
app.setPalette(palette)
app.setStyleSheet(GLOBAL_QSS)
app.setStyleSheet(GLOBAL_QSS + _indicator_qss())
_install_business_dialog_styling(app)
@@ -1373,6 +1596,7 @@ __all__ = [
"GLOBAL_QSS",
"METRICS",
"TYPE",
"WEIGHTS",
"apply_theme",
"crisp_pixmap",
"mark_business_dialog",
+85 -11
View File
@@ -10,7 +10,15 @@ from dataclasses import dataclass
from datetime import date, datetime
from typing import Any
from PySide6.QtCore import QObject, QRunnable, Qt, QThreadPool, QTimer, Signal, Slot
from PySide6.QtCore import (
QObject,
QRunnable,
Qt,
QThreadPool,
QTimer,
Signal,
Slot,
)
from PySide6.QtGui import QColor, QPainter, QPaintEvent, QResizeEvent
from PySide6.QtWidgets import (
QAbstractItemView,
@@ -35,6 +43,8 @@ from doctor_workstation.core.errors import (
AuthenticationExpiredError,
)
from . import icons, motion
AuthenticationExpiredHandler = Callable[[AuthenticationExpiredError], bool]
_AUTHENTICATION_EXPIRED_HANDLER: AuthenticationExpiredHandler | None = None
@@ -470,6 +480,8 @@ class PageHeader(QWidget):
) -> None:
super().__init__(parent)
self.setObjectName("PageHeader")
self._compact = False
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
layout = QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(8)
@@ -514,7 +526,31 @@ class PageHeader(QWidget):
def set_subtitle(self, text: str) -> None:
self.subtitle_label.setText(text)
self.subtitle_label.setVisible(bool(text))
self.subtitle_label.setVisible(bool(text) and not self._compact)
self.title_label.setToolTip(text if self._compact else "")
def set_compact(self, compact: bool = True) -> None:
"""Use a single title/action row on list pages with foldable search."""
self._compact = compact
layout = self.layout()
breadcrumb = layout.itemAt(0).layout()
for index in range(breadcrumb.count()):
widget = breadcrumb.itemAt(index).widget()
if widget is not None:
widget.setVisible(not compact)
self.subtitle_label.setVisible(bool(self.subtitle_label.text()) and not compact)
self.title_label.setToolTip(self.subtitle_label.text() if compact else "")
layout.setSpacing(0 if compact else 8)
layout.setAlignment(Qt.AlignmentFlag.AlignVCenter)
heading = layout.itemAt(1).layout()
heading.setAlignment(Qt.AlignmentFlag.AlignVCenter)
heading.itemAt(0).layout().setSpacing(0 if compact else 3)
self.actions.setSpacing(8)
if compact:
self.setFixedHeight(44)
else:
self.setMinimumHeight(0)
self.setMaximumHeight(16777215)
class MetricCard(QFrame):
@@ -636,7 +672,9 @@ class MessageBanner(QFrame):
layout = QHBoxLayout(self)
layout.setContentsMargins(12, 9, 12, 9)
layout.setSpacing(9)
self.icon = QLabel("i", self)
# The banner used to letter its own icons - a lowercase "i", a "!", and
# a U+2713 whose shape depended on whichever font happened to cover it.
self.icon = QLabel(self)
self.icon.setObjectName("MessageBannerIcon")
self.icon.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.icon.setFixedSize(20, 20)
@@ -647,18 +685,33 @@ class MessageBanner(QFrame):
layout.addWidget(self.label, 1)
self.setVisible(bool(text))
#: Banner kind -> shared glyph and colour role.
_ICONS = {
"info": ("info", "info"),
"success": ("check_circle", "success"),
"warning": ("alert", "warning"),
"danger": ("alert", "danger"),
}
def show_message(self, text: str, kind: str = "info") -> None:
glyphs = {"info": "i", "success": "✓", "warning": "!", "danger": "!"}
glyph, role = self._ICONS.get(kind, self._ICONS["info"])
self.label.setText(text)
self.icon.setText(glyphs.get(kind, "i"))
self.icon.setPixmap(icons.pixmap(glyph, role, 16))
self.setProperty("kind", kind)
self.style().unpolish(self)
self.style().polish(self)
self.setVisible(bool(text))
if not text:
self.setVisible(False)
return
if self.isVisible():
return
motion.fade_in(self, duration=motion.FAST)
def clear(self) -> None:
self.setVisible(False)
self.label.clear()
if self.isVisible():
motion.fade_out(self, duration=motion.FAST, on_finished=self.label.clear)
else:
self.label.clear()
class Toast(QLabel):
@@ -670,7 +723,10 @@ class Toast(QLabel):
self.hide()
self._timer = QTimer(self)
self._timer.setSingleShot(True)
self._timer.timeout.connect(self.hide)
self._timer.timeout.connect(self._dismiss)
def _dismiss(self) -> None:
motion.fade_out(self, duration=motion.BASE)
def show_message(self, text: str, kind: str = "info", duration: int = 2800) -> None:
self.setText(text)
@@ -682,7 +738,7 @@ class Toast(QLabel):
if parent is not None:
self.move(max(16, parent.width() - self.width() - 24), 20)
self.raise_()
self.show()
motion.fade_in(self, duration=motion.FAST)
self._timer.start(duration)
@@ -730,7 +786,7 @@ class _BusyTrack(QWidget):
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.setPen(Qt.PenStyle.NoPen)
rect = self.rect()
painter.setBrush(QColor("#D8DEEA"))
painter.setBrush(QColor("#E4E4E5"))
painter.drawRoundedRect(rect, 3, 3)
chunk_width = max(36, int(rect.width() * 0.32))
span = rect.width() + chunk_width
@@ -766,6 +822,16 @@ class BusyOverlay(QFrame):
self.raise_()
super().showEvent(event)
def reveal(self) -> None:
"""Fade the guard in, so a fast response never flashes a grey slab."""
if not self.isVisible():
motion.fade_in(self, duration=motion.FAST)
def dismiss(self) -> None:
if self.isVisible():
motion.fade_out(self, duration=motion.FAST)
class OverlayHost(QWidget):
"""Widget base that automatically sizes a BusyOverlay child."""
@@ -795,11 +861,19 @@ class SortableTable(QTableWidget):
self.setColumnCount(len(self.columns))
self.setHorizontalHeaderLabels([column.title for column in self.columns])
self.setAlternatingRowColors(True)
# Row separation already comes from the ``::item`` bottom border, so the
# grid only added a column rule that cut across every row - and it kept
# drawing past the last populated column, leaving a stray vertical line
# hanging in the empty part of the table.
self.setShowGrid(False)
self.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
self.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
self.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
self.setHorizontalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel)
self.setVerticalScrollMode(QAbstractItemView.ScrollMode.ScrollPerPixel)
# Per-pixel mode only smooths dragging; the wheel still jumped three rows
# at a time, which is how most of a list actually gets read.
motion.install_smooth_scroll(self)
self.setMinimumHeight(0)
self.setSortingEnabled(True)
self.verticalHeader().setVisible(False)