更新
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
"""独立窗口统一全屏控制器。
|
||||
|
||||
为所有可从主工作台弹出的独立窗口提供一致的全屏体验:
|
||||
|
||||
* ``F11`` 切换全屏 / 退出全屏;
|
||||
* 全屏状态下 ``Esc`` 只负责退出全屏(非全屏时不拦截,窗口原有的 Esc 关闭/取消照旧);
|
||||
* 退出全屏后恢复进入前的几何位置与最大化状态。
|
||||
|
||||
伴随视窗(左翼 / 右翼 / 独立副窗)的全屏由 ``SpatialWingManager`` 负责,
|
||||
因为它还要额外恢复停靠方位与停靠模式;其余顶层窗口统一通过
|
||||
:func:`install_window_fullscreen` 挂载本控制器。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtCore import QEvent, QObject, QRect, Qt, Signal
|
||||
from PySide6.QtGui import QKeySequence, QShortcut
|
||||
from PySide6.QtWidgets import QWidget
|
||||
|
||||
FULLSCREEN_ENTER_TEXT = "全屏"
|
||||
FULLSCREEN_EXIT_TEXT = "退出全屏"
|
||||
FULLSCREEN_ENTER_TIP = "全屏查看(F11)"
|
||||
FULLSCREEN_EXIT_TIP = "退出全屏,恢复原窗口位置(F11 / Esc)"
|
||||
|
||||
_CONTROLLER_ATTR = "_doctor_fullscreen_controller"
|
||||
|
||||
|
||||
def fullscreen_button_text(active: bool) -> str:
|
||||
"""全屏按钮文案:全屏中显示“退出全屏”,否则显示“全屏”。"""
|
||||
|
||||
return FULLSCREEN_EXIT_TEXT if active else FULLSCREEN_ENTER_TEXT
|
||||
|
||||
|
||||
def fullscreen_button_tip(active: bool) -> str:
|
||||
return FULLSCREEN_EXIT_TIP if active else FULLSCREEN_ENTER_TIP
|
||||
|
||||
|
||||
class WindowFullscreenController(QObject):
|
||||
"""为单个顶层窗口提供全屏切换、快捷键与几何恢复。"""
|
||||
|
||||
toggled = Signal(bool)
|
||||
|
||||
def __init__(self, window: QWidget) -> None:
|
||||
super().__init__(window)
|
||||
self._window = window
|
||||
self._saved_geometry: QRect | None = None
|
||||
self._saved_maximized = False
|
||||
self._last_state = window.isFullScreen()
|
||||
|
||||
self.toggle_shortcut = QShortcut(QKeySequence(Qt.Key.Key_F11), window)
|
||||
self.toggle_shortcut.setContext(Qt.ShortcutContext.WindowShortcut)
|
||||
self.toggle_shortcut.activated.connect(self.toggle)
|
||||
|
||||
# 仅在全屏时启用,避免抢占窗口原有的 Esc 取消/关闭行为。
|
||||
self.escape_shortcut = QShortcut(QKeySequence(Qt.Key.Key_Escape), window)
|
||||
self.escape_shortcut.setContext(Qt.ShortcutContext.WindowShortcut)
|
||||
self.escape_shortcut.activated.connect(self.exit)
|
||||
|
||||
window.installEventFilter(self)
|
||||
self._sync_shortcuts()
|
||||
|
||||
@property
|
||||
def window(self) -> QWidget:
|
||||
return self._window
|
||||
|
||||
@property
|
||||
def is_fullscreen(self) -> bool:
|
||||
return self._window.isFullScreen()
|
||||
|
||||
@property
|
||||
def saved_geometry(self) -> QRect | None:
|
||||
return QRect(self._saved_geometry) if self._saved_geometry is not None else None
|
||||
|
||||
def toggle(self) -> None:
|
||||
if self.is_fullscreen:
|
||||
self.exit()
|
||||
else:
|
||||
self.enter()
|
||||
|
||||
def enter(self) -> None:
|
||||
window = self._window
|
||||
# 被嵌入伴随视窗等非顶层场景时,全屏交由宿主处理。
|
||||
if not window.isWindow() or window.isFullScreen():
|
||||
return
|
||||
self._saved_maximized = window.isMaximized()
|
||||
self._saved_geometry = QRect(
|
||||
window.normalGeometry() if self._saved_maximized else window.geometry()
|
||||
)
|
||||
window.showFullScreen()
|
||||
window.raise_()
|
||||
self._emit_if_changed()
|
||||
|
||||
def exit(self) -> None:
|
||||
window = self._window
|
||||
if not window.isFullScreen():
|
||||
return
|
||||
if self._saved_maximized:
|
||||
window.showMaximized()
|
||||
else:
|
||||
window.showNormal()
|
||||
if self._saved_geometry is not None and self._saved_geometry.isValid():
|
||||
window.setGeometry(self._saved_geometry)
|
||||
self._saved_geometry = None
|
||||
self._saved_maximized = False
|
||||
self._emit_if_changed()
|
||||
|
||||
def _sync_shortcuts(self) -> None:
|
||||
is_window = self._window.isWindow()
|
||||
self.toggle_shortcut.setEnabled(is_window)
|
||||
self.escape_shortcut.setEnabled(is_window and self._window.isFullScreen())
|
||||
|
||||
def _emit_if_changed(self) -> None:
|
||||
self._sync_shortcuts()
|
||||
state = self._window.isFullScreen()
|
||||
if state != self._last_state:
|
||||
self._last_state = state
|
||||
self.toggled.emit(state)
|
||||
|
||||
def eventFilter(self, watched: QObject, event: QEvent) -> bool: # noqa: N802 - Qt virtual
|
||||
if watched is self._window and event.type() in {
|
||||
QEvent.Type.WindowStateChange,
|
||||
QEvent.Type.ParentChange,
|
||||
QEvent.Type.Show,
|
||||
}:
|
||||
self._emit_if_changed()
|
||||
return False
|
||||
|
||||
|
||||
def install_window_fullscreen(window: QWidget) -> WindowFullscreenController:
|
||||
"""为顶层窗口挂载(幂等)全屏控制器并返回它。"""
|
||||
|
||||
existing = getattr(window, _CONTROLLER_ATTR, None)
|
||||
if isinstance(existing, WindowFullscreenController):
|
||||
return existing
|
||||
controller = WindowFullscreenController(window)
|
||||
setattr(window, _CONTROLLER_ATTR, controller)
|
||||
return controller
|
||||
|
||||
|
||||
def window_fullscreen_controller(window: QWidget) -> WindowFullscreenController | None:
|
||||
controller = getattr(window, _CONTROLLER_ATTR, None)
|
||||
return controller if isinstance(controller, WindowFullscreenController) else None
|
||||
|
||||
|
||||
__all__ = [
|
||||
"FULLSCREEN_ENTER_TEXT",
|
||||
"FULLSCREEN_EXIT_TEXT",
|
||||
"WindowFullscreenController",
|
||||
"fullscreen_button_text",
|
||||
"fullscreen_button_tip",
|
||||
"install_window_fullscreen",
|
||||
"window_fullscreen_controller",
|
||||
]
|
||||
@@ -262,6 +262,8 @@ def _painted_icon(kind: str, color: str = "accent", size: int = 16) -> QIcon:
|
||||
# ``UserRole`` on every column, so the delegate reads its own data from offsets
|
||||
# above it.
|
||||
_ROLE_TAG_KIND = Qt.ItemDataRole.UserRole + 10
|
||||
# AI 两列无数据时只绘制的灰色占位提示;DisplayRole 保持为空,点击/复制仍按“无数据”处理。
|
||||
_ROLE_AI_PLACEHOLDER = Qt.ItemDataRole.UserRole + 11
|
||||
_ROLE_AVATAR = Qt.ItemDataRole.UserRole + 11
|
||||
_ROLE_LEAD_ICON = Qt.ItemDataRole.UserRole + 12
|
||||
|
||||
@@ -963,6 +965,11 @@ class _PrescriptionInfoDelegate(QStyledItemDelegate):
|
||||
painter.setPen(QColor(foreground))
|
||||
painter.drawText(pill, Qt.AlignmentFlag.AlignCenter, label)
|
||||
elif column != 2:
|
||||
if not text and column in (11, 12):
|
||||
text = str(index.data(_ROLE_AI_PLACEHOLDER) or "")
|
||||
font.setPixelSize(13)
|
||||
painter.setFont(font)
|
||||
painter.setPen(QColor(PALETTE["disabled"]))
|
||||
lines = text.rsplit(" · ", 2) if column == 5 else text.rsplit(" ", 1) if column == 10 else text.splitlines()
|
||||
if len(lines) > 1:
|
||||
primary, secondary = lines[0], " · ".join(lines[1:]) if column == 5 else lines[1]
|
||||
@@ -1230,6 +1237,75 @@ class _PrescriptionBlueTable(SortableTable):
|
||||
button.setIcon(_blue_prescription_icon(kind, PALETTE["danger"] if kind == "trash" else PALETTE["accent"]))
|
||||
|
||||
|
||||
class _TableHeightGrip(QWidget):
|
||||
"""列表底部的拖拽条:向下拖把处方列表拉高(页面随之滚动),双击恢复自适应高度。"""
|
||||
|
||||
def __init__(self, card: QWidget, scroll: QScrollArea, minimum: int) -> None:
|
||||
super().__init__(card)
|
||||
self._card = card
|
||||
self._scroll = scroll
|
||||
self._minimum = minimum
|
||||
self._dragging = False
|
||||
self.setObjectName("PrescriptionTableHeightGrip")
|
||||
self.setFixedHeight(10)
|
||||
self.setCursor(Qt.CursorShape.SizeVerCursor)
|
||||
self.setToolTip("拖动调整处方列表高度,双击恢复默认")
|
||||
self.setAccessibleName("调整处方列表高度")
|
||||
scroll.verticalScrollBar().rangeChanged.connect(self._follow_drag)
|
||||
|
||||
def paintEvent(self, _event: Any) -> None: # noqa: N802
|
||||
painter = QPainter(self)
|
||||
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
painter.setPen(Qt.PenStyle.NoPen)
|
||||
painter.setBrush(QColor(PALETTE["accent"] if self._dragging or self.underMouse() else PALETTE["disabled"]))
|
||||
painter.drawRoundedRect(QRectF(self.width() / 2 - 20, self.height() / 2 - 1.5, 40, 3), 1.5, 1.5)
|
||||
|
||||
def enterEvent(self, event: Any) -> None: # noqa: N802
|
||||
self.update()
|
||||
super().enterEvent(event)
|
||||
|
||||
def leaveEvent(self, event: Any) -> None: # noqa: N802
|
||||
self.update()
|
||||
super().leaveEvent(event)
|
||||
|
||||
def mousePressEvent(self, event: QMouseEvent) -> None: # noqa: N802
|
||||
if event.button() == Qt.MouseButton.LeftButton:
|
||||
self._dragging = True
|
||||
self.update()
|
||||
event.accept()
|
||||
return
|
||||
super().mousePressEvent(event)
|
||||
|
||||
def mouseMoveEvent(self, event: QMouseEvent) -> None: # noqa: N802
|
||||
if not self._dragging:
|
||||
super().mouseMoveEvent(event)
|
||||
return
|
||||
# 以卡片顶边为基准换算,页面滚动后拖拽条仍跟随鼠标。
|
||||
bottom = self._card.mapFromGlobal(event.globalPosition().toPoint()).y() + self.height() // 2
|
||||
self._card.setMinimumHeight(max(self._minimum, bottom))
|
||||
event.accept()
|
||||
|
||||
def _follow_drag(self, *_args: Any) -> None:
|
||||
# 卡片变高后滚动范围才会更新,此时把拖拽条滚入视野,鼠标继续向下拖即可持续拉高。
|
||||
if self._dragging:
|
||||
self._scroll.ensureWidgetVisible(self, 0, 4)
|
||||
|
||||
def mouseReleaseEvent(self, event: QMouseEvent) -> None: # noqa: N802
|
||||
if self._dragging and event.button() == Qt.MouseButton.LeftButton:
|
||||
self._dragging = False
|
||||
self.update()
|
||||
event.accept()
|
||||
return
|
||||
super().mouseReleaseEvent(event)
|
||||
|
||||
def mouseDoubleClickEvent(self, event: QMouseEvent) -> None: # noqa: N802
|
||||
if event.button() == Qt.MouseButton.LeftButton:
|
||||
self._card.setMinimumHeight(self._minimum)
|
||||
event.accept()
|
||||
return
|
||||
super().mouseDoubleClickEvent(event)
|
||||
|
||||
|
||||
class PrescriptionsPage(QWidget):
|
||||
"""Complete issued-prescription route: list, workflow actions, print, and orders."""
|
||||
|
||||
@@ -1262,7 +1338,10 @@ class PrescriptionsPage(QWidget):
|
||||
self._mutation_pending = False
|
||||
self._audit_check_pending = False
|
||||
self._ai_statuses: dict[int, dict[str, Any]] = {}
|
||||
self._ai_stale: set[int] = set()
|
||||
self._ai_enabled = False
|
||||
self._ai_off_hint = "" # AI 未启用时单元格显示的原因;空串表示尚未查询完成
|
||||
self._ai_error_streak = 0 # 状态请求连续失败次数,用于区分偶发失败与服务不可用
|
||||
self._agreement_visible = False
|
||||
self._capability_agreement_visible = False
|
||||
self._ai_capability_token = 0
|
||||
@@ -1590,6 +1669,8 @@ class PrescriptionsPage(QWidget):
|
||||
self.stack.widget(1).layout().itemAt(0).setAlignment(Qt.AlignmentFlag.AlignHCenter)
|
||||
layout.addWidget(self.stack, 1)
|
||||
layout.addWidget(self.pager)
|
||||
self.table_height_grip = _TableHeightGrip(card, self.scroll, card.minimumHeight())
|
||||
layout.addWidget(self.table_height_grip)
|
||||
return card
|
||||
|
||||
def resizeEvent(self, event: Any) -> None:
|
||||
@@ -1725,7 +1806,8 @@ class PrescriptionsPage(QWidget):
|
||||
self._ai_timer.stop()
|
||||
self._ai_request_token += 1
|
||||
self._ai_pending = False
|
||||
self._ai_statuses.clear()
|
||||
# 刷新时不清空 AI 缓存(否则整列先闪空再回来),只标记过期,重新查询后替换。
|
||||
self._ai_stale = set(self._ai_statuses)
|
||||
self._loading = True
|
||||
self._refresh_pending = False
|
||||
self._generation += 1
|
||||
@@ -1876,7 +1958,9 @@ class PrescriptionsPage(QWidget):
|
||||
actions_host,
|
||||
)
|
||||
)
|
||||
if self._ai_enabled and self._can_view_ai_report(row):
|
||||
# 与工具栏“AI 报告”同一判定:未启用自动分析时仍可查看历史报告,
|
||||
# 按钮不随状态接口的成败出现/消失。
|
||||
if self._can_view_ai_report(row):
|
||||
actions.addWidget(
|
||||
_row_action_button(
|
||||
"eye", "AI 报告",
|
||||
@@ -1946,7 +2030,7 @@ class PrescriptionsPage(QWidget):
|
||||
self._sync_row_mutation_actions()
|
||||
self.table.resizeRowsToContents()
|
||||
|
||||
def _visible_ai_ids(self) -> list[int]:
|
||||
def _visible_ai_ids(self, *, visible_only: bool = True) -> list[int]:
|
||||
if not self.isVisible() or not self.table.isVisible():
|
||||
return []
|
||||
ids = []
|
||||
@@ -1955,7 +2039,7 @@ class PrescriptionsPage(QWidget):
|
||||
item = self.table.item(index, 0)
|
||||
# Column 0 may be horizontally off-screen; use row geometry only.
|
||||
top = self.table.rowViewportPosition(index)
|
||||
if item is None or top + self.table.rowHeight(index) <= 0 or top >= viewport.height():
|
||||
if item is None or (visible_only and (top + self.table.rowHeight(index) <= 0 or top >= viewport.height())):
|
||||
continue
|
||||
row = item.data(Qt.ItemDataRole.UserRole)
|
||||
if _is_blank_prescription(row):
|
||||
@@ -1963,7 +2047,24 @@ class PrescriptionsPage(QWidget):
|
||||
value = _int(first_value(row, "id", "prescription_id"), 0)
|
||||
if value > 0:
|
||||
ids.append(value)
|
||||
return list(dict.fromkeys(ids))[:100]
|
||||
ids = list(dict.fromkeys(ids))
|
||||
return ids[:100] if visible_only else ids
|
||||
|
||||
def _wanted_ai_ids(self) -> list[int]:
|
||||
"""可见行优先(含仍在分析中的行),其余已加载但从未查询过的行随后补齐。
|
||||
|
||||
只查可见行时,快速下拉越过的行和恰好压在视口边缘的行永远拿不到状态,
|
||||
看起来就像“一滑动 AI 结果就没了”。
|
||||
"""
|
||||
visible = [value for value in self._visible_ai_ids()
|
||||
if self._needs_ai_status(value) or batch_running(self._ai_statuses[value])]
|
||||
rest = [value for value in self._visible_ai_ids(visible_only=False)
|
||||
if self._needs_ai_status(value) and value not in visible]
|
||||
return (visible + rest)[:100]
|
||||
|
||||
def _needs_ai_status(self, value: int) -> bool:
|
||||
# 过期的缓存(刷新或重新授权后)继续显示,直到新结果到达再替换。
|
||||
return value not in self._ai_statuses or value in self._ai_stale
|
||||
|
||||
def _schedule_ai_statuses(self) -> None:
|
||||
if self.isVisible():
|
||||
@@ -1981,17 +2082,18 @@ class PrescriptionsPage(QWidget):
|
||||
return
|
||||
method = getattr(self.repository, "list_prescription_ai_statuses", None)
|
||||
if not has_permission(self.permissions, "tcm.prescriptionAi/statuses", default=False):
|
||||
self._ai_off_hint = "无权查看"
|
||||
self._set_ai_enabled(False)
|
||||
self.ai_status_notice.setText("AI 分析:当前账号没有查看分析状态的权限,请联系管理员授权。")
|
||||
return
|
||||
if not callable(method):
|
||||
self._ai_off_hint = "暂不支持"
|
||||
self._set_ai_enabled(False)
|
||||
self.ai_status_notice.setText("AI 分析:当前数据模式暂不支持此功能。")
|
||||
return
|
||||
if self._ai_pending:
|
||||
return
|
||||
ids = self._visible_ai_ids()
|
||||
ids = [value for value in ids if value not in self._ai_statuses or batch_running(self._ai_statuses[value])]
|
||||
ids = self._wanted_ai_ids()
|
||||
if not ids:
|
||||
self._ai_timer.stop()
|
||||
if self.table.rowCount() == 0:
|
||||
@@ -2012,13 +2114,10 @@ class PrescriptionsPage(QWidget):
|
||||
self._ai_pending = False
|
||||
|
||||
def _set_ai_enabled(self, enabled: bool) -> None:
|
||||
changed = enabled != self._ai_enabled
|
||||
self._ai_enabled = enabled
|
||||
if not enabled:
|
||||
self._ai_statuses.clear()
|
||||
self._render_ai_statuses()
|
||||
if changed:
|
||||
self._decorate_rows()
|
||||
|
||||
def _set_agreement_visible(self, visible: bool) -> None:
|
||||
self._agreement_visible = visible
|
||||
@@ -2034,11 +2133,12 @@ class PrescriptionsPage(QWidget):
|
||||
token, generation = self._ai_capability_token, self._generation
|
||||
self._ai_request_token += 1
|
||||
self._ai_pending = False
|
||||
self._capability_agreement_visible = False
|
||||
self._set_agreement_visible(False)
|
||||
# 不在请求前先隐藏一致度:旧值保留到权限结果返回,拒绝时再统一剥离,避免每次刷新/切回页面整列闪空。
|
||||
method = getattr(self.repository, "get_prescription_ai_capabilities", None)
|
||||
self._ai_capability_pending = callable(method)
|
||||
if not callable(method):
|
||||
self._capability_agreement_visible = False
|
||||
self._set_agreement_visible(False)
|
||||
return
|
||||
run_async(method,
|
||||
on_success=lambda result: self._ai_capabilities_ready(result, token, generation),
|
||||
@@ -2052,8 +2152,9 @@ class PrescriptionsPage(QWidget):
|
||||
self._set_agreement_visible(self._capability_agreement_visible)
|
||||
if self._capability_agreement_visible:
|
||||
# A previous deny discarded scores, including completed cached batches.
|
||||
# Fetch them again after a fresh grant rather than displaying that cache.
|
||||
self._ai_statuses.clear()
|
||||
# Fetch them again after a fresh grant; keep showing the (already
|
||||
# stripped) cache meanwhile instead of blanking every row.
|
||||
self._ai_stale = set(self._ai_statuses)
|
||||
if self.isVisible() and not self._loading:
|
||||
self._load_ai_statuses()
|
||||
|
||||
@@ -2062,6 +2163,8 @@ class PrescriptionsPage(QWidget):
|
||||
return
|
||||
data = _row_mapping(result)
|
||||
self._set_agreement_visible(self._capability_agreement_visible and data.get("agreement_visible") is True)
|
||||
self._ai_off_hint = "未启用"
|
||||
self._ai_error_streak = 0
|
||||
self._set_ai_enabled(data.get("enabled") is True)
|
||||
if not self._ai_enabled:
|
||||
self._ai_timer.stop()
|
||||
@@ -2079,6 +2182,7 @@ class PrescriptionsPage(QWidget):
|
||||
+ ("可查看逐味对照。" if self._agreement_visible else ""))
|
||||
for value in ids:
|
||||
self._ai_statuses[value] = {}
|
||||
self._ai_stale.discard(value)
|
||||
for batch in data.get("items") or []:
|
||||
value = _int(get_value(batch, "prescription_id"), 0)
|
||||
if value in ids:
|
||||
@@ -2088,6 +2192,21 @@ class PrescriptionsPage(QWidget):
|
||||
self._ai_timer.start()
|
||||
else:
|
||||
self._ai_timer.stop()
|
||||
if any(self._needs_ai_status(value) for value in self._visible_ai_ids(visible_only=False)):
|
||||
# 单次最多 100 条;请求期间新加载/滚入的行接着补查,不等下一次滚动。
|
||||
self._ai_scroll_timer.start()
|
||||
|
||||
def _ai_placeholder(self, row: Any, batch: Any) -> str:
|
||||
"""AI 列无结果时的简短灰色提示,避免空白单元格看起来“飘”。"""
|
||||
if _is_blank_prescription(row):
|
||||
return "空白处方"
|
||||
if not self._ai_enabled:
|
||||
return self._ai_off_hint or "加载中…"
|
||||
if not self._agreement_visible:
|
||||
return "无权查看"
|
||||
if batch is None:
|
||||
return "加载中…"
|
||||
return "暂无分析"
|
||||
|
||||
def _render_ai_statuses(self) -> None:
|
||||
sorting = self.table.isSortingEnabled()
|
||||
@@ -2099,6 +2218,7 @@ class PrescriptionsPage(QWidget):
|
||||
value = _int(first_value(row, "id", "prescription_id"), 0)
|
||||
batch = self._ai_statuses.get(value)
|
||||
state = agreement = tooltip = ""
|
||||
hint = self._ai_placeholder(row, batch)
|
||||
if self._ai_enabled and self._agreement_visible and batch and not _is_blank_prescription(row):
|
||||
if batch.get("status") not in (None, "", "blank", "not_generated"):
|
||||
state = state_text(batch)
|
||||
@@ -2110,8 +2230,11 @@ class PrescriptionsPage(QWidget):
|
||||
if item.text() != text:
|
||||
item.setText(text)
|
||||
changed = True
|
||||
item.setToolTip(tooltip if text else "")
|
||||
item.setData(Qt.ItemDataRole.AccessibleTextRole, text)
|
||||
# 原因只在“AI 分析”列提示一次;一致度列有状态无分数时说明原因,否则显示灰色破折号。
|
||||
placeholder = "" if text else hint if column == 11 else "暂无一致度" if state else "—"
|
||||
item.setData(_ROLE_AI_PLACEHOLDER, placeholder)
|
||||
item.setToolTip(tooltip if text else "" if placeholder == "—" else placeholder)
|
||||
item.setData(Qt.ItemDataRole.AccessibleTextRole, text or ("" if placeholder == "—" else placeholder))
|
||||
if changed:
|
||||
self.table.resizeRowsToContents()
|
||||
finally:
|
||||
@@ -2120,7 +2243,15 @@ class PrescriptionsPage(QWidget):
|
||||
def _ai_statuses_error(self, error: Exception, token: int, generation: int) -> None:
|
||||
if token == self._ai_request_token and generation == self._generation:
|
||||
self._ai_timer.stop()
|
||||
self._ai_error_streak += 1
|
||||
if self._ai_enabled and self._ai_error_streak <= 3:
|
||||
# 已有结果时,下拉补查失败只是暂时的:保留已显示的分析与按钮,稍后自动重试,
|
||||
# 不能因为一次失败就把整列清空。连续失败多次才按“暂不可用”处理。
|
||||
self.ai_status_notice.setToolTip("部分处方的 AI 状态加载失败,正在自动重试:" + friendly_error(error))
|
||||
self._ai_timer.start()
|
||||
return
|
||||
self._set_agreement_visible(False)
|
||||
self._ai_off_hint = "暂不可用"
|
||||
self._set_ai_enabled(False)
|
||||
self.ai_status_notice.setText("AI 分析暂不可用:请稍后刷新;持续无法使用时,请联系管理员检查服务。")
|
||||
self.ai_status_notice.setToolTip(friendly_error(error))
|
||||
|
||||
@@ -63,6 +63,7 @@ from PySide6.QtWidgets import (
|
||||
)
|
||||
|
||||
from . import icons, motion
|
||||
from .fullscreen import fullscreen_button_text, fullscreen_button_tip
|
||||
from .reception_style import body_family, heading_family
|
||||
|
||||
SPATIAL_WING_QSS = """
|
||||
@@ -129,6 +130,28 @@ QPushButton#SpatialWingDetachBtn:hover {
|
||||
border-color: #0E6F5C;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
QPushButton#SpatialWingFullscreenBtn {
|
||||
min-width: 40px;
|
||||
min-height: 26px;
|
||||
max-height: 26px;
|
||||
padding: 0 9px;
|
||||
border-radius: 13px;
|
||||
border: 1px solid #DCE7E4;
|
||||
background-color: #FFFFFF;
|
||||
color: #4D6561;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
}
|
||||
QPushButton#SpatialWingFullscreenBtn:hover {
|
||||
background-color: #E7F4F0;
|
||||
border-color: #9ED0C3;
|
||||
color: #0E6F5C;
|
||||
}
|
||||
QPushButton#SpatialWingFullscreenBtn:checked {
|
||||
background-color: #0E6F5C;
|
||||
border-color: #0E6F5C;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
QPushButton#SpatialWingCloseBtn {
|
||||
min-width: 28px;
|
||||
max-width: 28px;
|
||||
@@ -220,6 +243,7 @@ class _WingHeaderBar(QFrame):
|
||||
|
||||
side_requested = Signal(str)
|
||||
mode_toggle_requested = Signal()
|
||||
fullscreen_requested = Signal()
|
||||
close_requested = Signal()
|
||||
manual_drag_started = Signal()
|
||||
|
||||
@@ -280,6 +304,15 @@ class _WingHeaderBar(QFrame):
|
||||
self.detach_btn.clicked.connect(self.mode_toggle_requested.emit)
|
||||
layout.addWidget(self.detach_btn)
|
||||
|
||||
# 全屏查看:铺满当前屏幕,退出后恢复原停靠方位、模式与窗口位置。
|
||||
self.fullscreen_btn = QPushButton(fullscreen_button_text(False), self)
|
||||
self.fullscreen_btn.setObjectName("SpatialWingFullscreenBtn")
|
||||
self.fullscreen_btn.setCheckable(True)
|
||||
self.fullscreen_btn.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||
self.fullscreen_btn.setToolTip(fullscreen_button_tip(False))
|
||||
self.fullscreen_btn.clicked.connect(self._on_fullscreen_clicked)
|
||||
layout.addWidget(self.fullscreen_btn)
|
||||
|
||||
self.close_btn = QPushButton("×", self)
|
||||
self.close_btn.setObjectName("SpatialWingCloseBtn")
|
||||
self.close_btn.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||
@@ -287,6 +320,16 @@ class _WingHeaderBar(QFrame):
|
||||
self.close_btn.clicked.connect(self.close_requested.emit)
|
||||
layout.addWidget(self.close_btn)
|
||||
|
||||
def _on_fullscreen_clicked(self) -> None:
|
||||
# 勾选态由管理器回写,避免点击后与真实全屏状态不一致。
|
||||
self.fullscreen_btn.setChecked(not self.fullscreen_btn.isChecked())
|
||||
self.fullscreen_requested.emit()
|
||||
|
||||
def set_fullscreen(self, active: bool) -> None:
|
||||
self.fullscreen_btn.setChecked(active)
|
||||
self.fullscreen_btn.setText(fullscreen_button_text(active))
|
||||
self.fullscreen_btn.setToolTip(fullscreen_button_tip(active))
|
||||
|
||||
def set_metadata(
|
||||
self,
|
||||
*,
|
||||
@@ -295,7 +338,9 @@ class _WingHeaderBar(QFrame):
|
||||
icon_kind: str = "ai",
|
||||
side: str = "right",
|
||||
mode: str = "docked",
|
||||
fullscreen: bool = False,
|
||||
) -> None:
|
||||
self.set_fullscreen(fullscreen)
|
||||
self.icon_badge.setPixmap(icons.icon(icon_kind, "#0E6F5C", 15).pixmap(15, 15))
|
||||
resolved_title = title or "伴随工作视窗"
|
||||
self.title_label.setText(resolved_title)
|
||||
@@ -321,7 +366,11 @@ class _WingHeaderBar(QFrame):
|
||||
def mousePressEvent(self, event: QMouseEvent) -> None: # noqa: N802
|
||||
if event.button() == Qt.MouseButton.LeftButton:
|
||||
win = self.window()
|
||||
if win is not None and getattr(win, "_is_companion_sidecar", False):
|
||||
if (
|
||||
win is not None
|
||||
and getattr(win, "_is_companion_sidecar", False)
|
||||
and not win.isFullScreen()
|
||||
):
|
||||
child = self.childAt(event.position().toPoint())
|
||||
if child is None or isinstance(child, QLabel):
|
||||
handle = win.windowHandle()
|
||||
@@ -476,7 +525,8 @@ class CompanionSidecarWindow(QWidget):
|
||||
self._arrival_anim.valueChanged.connect(self._on_arrival_tick)
|
||||
self._arrival_anim.finished.connect(self._on_arrival_done)
|
||||
|
||||
QShortcut(QKeySequence("Esc"), self, activated=self._emit_escape)
|
||||
# Esc 由挂载其中的 SpatialWingCard 统一处理(全屏时先退出全屏,否则关闭视窗),
|
||||
# 这里不再重复注册,避免同一窗口内两个 Esc 快捷键互相冲突而都不触发。
|
||||
|
||||
def animate_arrival(self, target_rect: QRect, *, side: str) -> None:
|
||||
self._arrival_anim.stop()
|
||||
@@ -537,7 +587,7 @@ class CompanionSidecarWindow(QWidget):
|
||||
return edges
|
||||
|
||||
def mousePressEvent(self, event: QMouseEvent) -> None: # noqa: N802
|
||||
if event.button() == Qt.MouseButton.LeftButton:
|
||||
if event.button() == Qt.MouseButton.LeftButton and not self.isFullScreen():
|
||||
edges = self._edges(event.position())
|
||||
handle = self.windowHandle()
|
||||
if edges and handle is not None and handle.startSystemResize(edges):
|
||||
@@ -600,6 +650,7 @@ class SpatialWingManager(QObject):
|
||||
self._right_layout.addWidget(self.card, 1)
|
||||
self.card.header.side_requested.connect(self.set_side)
|
||||
self.card.header.mode_toggle_requested.connect(self.toggle_mode)
|
||||
self.card.header.fullscreen_requested.connect(self.toggle_fullscreen)
|
||||
self.card.header.close_requested.connect(self.close_wing)
|
||||
|
||||
self._side = "right" # "left" | "right"
|
||||
@@ -616,9 +667,22 @@ class SpatialWingManager(QObject):
|
||||
self._sidecar: CompanionSidecarWindow | None = None
|
||||
self._saved_shell_geom: tuple[bool, QRect, QSize] | None = None
|
||||
self._syncing_geometry = False
|
||||
# 全屏前的停靠模式、方位与独立副窗几何;为 None 表示当前未全屏。
|
||||
self._fullscreen_restore: tuple[str, str, QRect | None] | None = None
|
||||
|
||||
self.shell.installEventFilter(self)
|
||||
QShortcut(QKeySequence("Esc"), self.card, activated=self.close_wing)
|
||||
QShortcut(QKeySequence("Esc"), self.card, activated=self._on_escape)
|
||||
# F11 仅在焦点位于伴随视窗内时生效,不影响主工作台。
|
||||
f11 = QShortcut(QKeySequence(Qt.Key.Key_F11), self.card, activated=self.toggle_fullscreen)
|
||||
f11.setContext(Qt.ShortcutContext.WidgetWithChildrenShortcut)
|
||||
|
||||
@property
|
||||
def is_fullscreen(self) -> bool:
|
||||
return self._fullscreen_restore is not None
|
||||
|
||||
@property
|
||||
def sidecar(self) -> CompanionSidecarWindow | None:
|
||||
return self._sidecar
|
||||
|
||||
@property
|
||||
def is_open(self) -> bool:
|
||||
@@ -638,7 +702,10 @@ class SpatialWingManager(QObject):
|
||||
|
||||
def set_side(self, side: str) -> None:
|
||||
normalized = "left" if str(side).strip().lower() == "left" else "right"
|
||||
# 全屏时点左翼/右翼:先退出全屏恢复原状,再按新方位停靠。
|
||||
self.exit_fullscreen()
|
||||
if normalized == self._side and self.is_open:
|
||||
self._sync_header()
|
||||
return
|
||||
self._side = normalized
|
||||
if self.is_open:
|
||||
@@ -646,7 +713,9 @@ class SpatialWingManager(QObject):
|
||||
|
||||
def set_mode(self, mode: str) -> None:
|
||||
normalized = "sidecar" if str(mode).strip().lower() == "sidecar" else "docked"
|
||||
self.exit_fullscreen()
|
||||
if normalized == self._mode and self.is_open:
|
||||
self._sync_header()
|
||||
return
|
||||
self._mode = normalized
|
||||
if self.is_open:
|
||||
@@ -655,19 +724,91 @@ class SpatialWingManager(QObject):
|
||||
def toggle_mode(self) -> None:
|
||||
self.set_mode("sidecar" if self._mode == "docked" else "docked")
|
||||
|
||||
def update_header(self, *, title: str | None = None, subtitle: str | None = None) -> None:
|
||||
if title is not None:
|
||||
self._title = title
|
||||
if subtitle is not None:
|
||||
self._subtitle = subtitle
|
||||
# ── 全屏查看 ──────────────────────────────────────────────────────────
|
||||
|
||||
def toggle_fullscreen(self) -> None:
|
||||
if self.is_fullscreen:
|
||||
self.exit_fullscreen()
|
||||
else:
|
||||
self.enter_fullscreen()
|
||||
|
||||
def enter_fullscreen(self) -> None:
|
||||
"""把当前伴随视窗铺满主工作台所在屏幕;记录停靠状态以便原样恢复。"""
|
||||
|
||||
if not self.is_open or self.is_fullscreen:
|
||||
return
|
||||
sidecar_geom: QRect | None = None
|
||||
if self._mode == "sidecar" and self._sidecar is not None and self._sidecar.isVisible():
|
||||
sidecar_geom = QRect(self._sidecar.geometry())
|
||||
self._fullscreen_restore = (self._mode, self._side, sidecar_geom)
|
||||
|
||||
sidecar = self._ensure_sidecar()
|
||||
if self._mode == "docked":
|
||||
# 嵌入态:把卡片临时移到独立窗口里全屏,主工作台布局保持不变。
|
||||
self.left_dock.hide()
|
||||
self.right_dock.hide()
|
||||
self.splitter.setSizes([0, max(800, self.shell.width()), 0])
|
||||
sidecar.mount_card(self.card)
|
||||
# 先放到主工作台所在位置,确保全屏落在同一块屏幕上。
|
||||
sidecar.setGeometry(self.shell.geometry())
|
||||
self.card.glide_veil.cancel()
|
||||
sidecar.showFullScreen()
|
||||
sidecar.raise_()
|
||||
sidecar.activateWindow()
|
||||
self.card.setFocus(Qt.FocusReason.OtherFocusReason)
|
||||
self._sync_header()
|
||||
|
||||
def exit_fullscreen(self) -> None:
|
||||
"""退出全屏并恢复进入前的停靠模式、左/右翼方位与独立副窗位置。"""
|
||||
|
||||
restore = self._fullscreen_restore
|
||||
if restore is None:
|
||||
return
|
||||
self._fullscreen_restore = None
|
||||
mode, side, sidecar_geom = restore
|
||||
self._mode = mode
|
||||
self._side = side
|
||||
sidecar = self._sidecar
|
||||
if sidecar is not None and sidecar.isFullScreen():
|
||||
sidecar.showNormal()
|
||||
if not self.is_open:
|
||||
self._sync_header()
|
||||
return
|
||||
if mode == "docked":
|
||||
self._apply_placement()
|
||||
return
|
||||
self._sync_header()
|
||||
if sidecar is not None:
|
||||
if sidecar_geom is not None and sidecar_geom.isValid():
|
||||
sidecar.setGeometry(sidecar_geom)
|
||||
else:
|
||||
self._arrange_shell_and_sidecar(initial=True)
|
||||
sidecar.show()
|
||||
sidecar.raise_()
|
||||
|
||||
def _on_escape(self) -> None:
|
||||
if self.is_fullscreen:
|
||||
self.exit_fullscreen()
|
||||
else:
|
||||
self.close_wing()
|
||||
|
||||
def _sync_header(self) -> None:
|
||||
self.card.header.set_metadata(
|
||||
title=self._title,
|
||||
subtitle=self._subtitle,
|
||||
icon_kind=self._icon_kind,
|
||||
side=self._side,
|
||||
mode=self._mode,
|
||||
fullscreen=self.is_fullscreen,
|
||||
)
|
||||
|
||||
def update_header(self, *, title: str | None = None, subtitle: str | None = None) -> None:
|
||||
if title is not None:
|
||||
self._title = title
|
||||
if subtitle is not None:
|
||||
self._subtitle = subtitle
|
||||
self._sync_header()
|
||||
|
||||
def _should_animate_wing(self) -> bool:
|
||||
return (
|
||||
self.shell.isVisible()
|
||||
@@ -865,13 +1006,10 @@ class SpatialWingManager(QObject):
|
||||
)
|
||||
|
||||
def _apply_placement(self) -> None:
|
||||
self.card.header.set_metadata(
|
||||
title=self._title,
|
||||
subtitle=self._subtitle,
|
||||
icon_kind=self._icon_kind,
|
||||
side=self._side,
|
||||
mode=self._mode,
|
||||
)
|
||||
self._sync_header()
|
||||
if self.is_fullscreen:
|
||||
# 全屏期间切换内容时保持全屏,停靠位置待退出全屏时再恢复。
|
||||
return
|
||||
if self._mode == "sidecar":
|
||||
self._mount_in_sidecar()
|
||||
else:
|
||||
@@ -1043,6 +1181,8 @@ class SpatialWingManager(QObject):
|
||||
def close_wing(self, *, from_dialog: bool = False) -> None:
|
||||
if not self.is_open and (self._sidecar is None or not self._sidecar.isVisible()):
|
||||
return
|
||||
# 关闭前先退出全屏,下次打开仍回到原来的停靠方位与模式。
|
||||
self.exit_fullscreen()
|
||||
self._teardown_active(reject_dialog=not from_dialog)
|
||||
self.left_dock.hide()
|
||||
self.right_dock.hide()
|
||||
@@ -1064,7 +1204,9 @@ class SpatialWingManager(QObject):
|
||||
def eventFilter(self, watched: QObject, event: QEvent) -> bool: # noqa: N802
|
||||
if watched is self.shell and self._mode == "sidecar" and self.is_open and self._sidecar is not None:
|
||||
et = event.type()
|
||||
if et in {QEvent.Type.Move, QEvent.Type.Resize} and not self._syncing_geometry:
|
||||
if et in {QEvent.Type.Move, QEvent.Type.Resize} and self.is_fullscreen:
|
||||
pass
|
||||
elif et in {QEvent.Type.Move, QEvent.Type.Resize} and not self._syncing_geometry:
|
||||
if self._sidecar.magnet_locked and not self.shell.isMinimized():
|
||||
main_g = self.shell.frameGeometry()
|
||||
gap = 10
|
||||
|
||||
@@ -1021,29 +1021,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;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -1549,6 +1549,24 @@ def _size_new_window_to_main(window: QWidget) -> None:
|
||||
)
|
||||
|
||||
|
||||
def _install_dialog_fullscreen(dialog: QDialog) -> None:
|
||||
"""给以独立顶层窗口打开的业务对话框挂载 F11 全屏 / Esc 退出全屏。
|
||||
|
||||
嵌入伴随视窗的对话框由伴随视窗标题栏的“全屏”按钮负责;消息框、输入框、
|
||||
确认浮层等临时提示与固定尺寸的小窗不需要全屏。
|
||||
"""
|
||||
|
||||
if not dialog.isWindow() or dialog.property("hostedInSpatialWing"):
|
||||
return
|
||||
if isinstance(dialog, (QMessageBox, QInputDialog, QFileDialog)):
|
||||
return
|
||||
if dialog.property("skipSpatialWing") or dialog.minimumSize() == dialog.maximumSize():
|
||||
return
|
||||
from .fullscreen import install_window_fullscreen
|
||||
|
||||
install_window_fullscreen(dialog)
|
||||
|
||||
|
||||
class _BusinessDialogStyleFilter(QObject):
|
||||
"""Style dynamically-created Qt dialogs just before they become visible."""
|
||||
|
||||
@@ -1623,6 +1641,7 @@ class _BusinessDialogStyleFilter(QObject):
|
||||
_polish_dialog_buttons(button_box)
|
||||
if not self._is_native_or_overlay(watched):
|
||||
mark_business_dialog(watched)
|
||||
_install_dialog_fullscreen(watched)
|
||||
if isinstance(watched, QMessageBox):
|
||||
icon_kinds = {
|
||||
QMessageBox.Icon.Information: "info",
|
||||
|
||||
@@ -527,6 +527,7 @@ if WEBENGINE_AVAILABLE: # pragma: no cover - GUI behavior needs an integration
|
||||
self._companion_toggle.setCheckable(True)
|
||||
self._companion_toggle.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||
hud_row.addWidget(self._companion_toggle)
|
||||
self._install_fullscreen_toggle(hud, hud_row)
|
||||
shell_layout.addWidget(hud)
|
||||
|
||||
stage_row = QHBoxLayout()
|
||||
@@ -582,6 +583,37 @@ if WEBENGINE_AVAILABLE: # pragma: no cover - GUI behavior needs an integration
|
||||
self.web_view.loadFinished.connect(self._on_load_finished)
|
||||
self.web_view.setUrl(QUrl(self.location.url))
|
||||
|
||||
def _install_fullscreen_toggle(self, hud: Any, hud_row: Any) -> None:
|
||||
"""在视频窗顶栏挂载统一的“全屏 / 退出全屏”按钮(F11 切换,Esc 退出)。"""
|
||||
|
||||
from ..ui.fullscreen import (
|
||||
fullscreen_button_text,
|
||||
fullscreen_button_tip,
|
||||
install_window_fullscreen,
|
||||
)
|
||||
|
||||
controller = install_window_fullscreen(self)
|
||||
button = QPushButton(fullscreen_button_text(False), hud)
|
||||
button.setObjectName("VideoHudFullscreenBtn")
|
||||
button.setCheckable(True)
|
||||
button.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||
button.setToolTip(fullscreen_button_tip(False))
|
||||
|
||||
def _sync(active: bool) -> None:
|
||||
button.setChecked(active)
|
||||
button.setText(fullscreen_button_text(active))
|
||||
button.setToolTip(fullscreen_button_tip(active))
|
||||
|
||||
def _clicked(_checked: bool = False) -> None:
|
||||
controller.toggle()
|
||||
_sync(controller.is_fullscreen)
|
||||
|
||||
button.clicked.connect(_clicked)
|
||||
controller.toggled.connect(_sync)
|
||||
hud_row.addWidget(button)
|
||||
self._fullscreen_controller = controller
|
||||
self._fullscreen_button = button
|
||||
|
||||
def _configure_settings(self, settings: Any) -> None:
|
||||
attributes = getattr(QWebEngineSettings, "WebAttribute", QWebEngineSettings)
|
||||
values = (
|
||||
|
||||
+2029
-1905
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,245 @@
|
||||
"""独立窗口全屏查看:切换、快捷键与退出后的几何 / 停靠状态恢复(offscreen,全程离线)。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
import pytest
|
||||
from PySide6.QtCore import QRect
|
||||
from PySide6.QtTest import QTest
|
||||
from PySide6.QtWidgets import QApplication, QDialog, QLabel, QVBoxLayout
|
||||
|
||||
from doctor_workstation.core.permissions import PermissionSet
|
||||
from doctor_workstation.services.demo_repository import DEMO_PERMISSIONS, DemoDoctorRepository
|
||||
from doctor_workstation.ui.fullscreen import (
|
||||
FULLSCREEN_ENTER_TEXT,
|
||||
FULLSCREEN_EXIT_TEXT,
|
||||
install_window_fullscreen,
|
||||
window_fullscreen_controller,
|
||||
)
|
||||
from doctor_workstation.ui.shell_spatial import SpatialShellWindow
|
||||
from doctor_workstation.ui.theme import apply_theme
|
||||
|
||||
|
||||
def _settle(app: QApplication, rounds: int = 8) -> None:
|
||||
for _ in range(rounds):
|
||||
app.processEvents()
|
||||
QTest.qWait(8)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def application() -> QApplication:
|
||||
app = QApplication.instance() or QApplication([])
|
||||
apply_theme(app)
|
||||
return app
|
||||
|
||||
|
||||
def _plain_dialog() -> QDialog:
|
||||
dialog = QDialog()
|
||||
dialog.setProperty("doctorSkipOpenGeometry", True)
|
||||
layout = QVBoxLayout(dialog)
|
||||
layout.addWidget(QLabel("诊断与药方 · AI 分析报告", dialog))
|
||||
return dialog
|
||||
|
||||
|
||||
def test_controller_toggles_fullscreen_and_restores_geometry(application: QApplication) -> None:
|
||||
dialog = _plain_dialog()
|
||||
dialog.show()
|
||||
dialog.setGeometry(120, 90, 640, 480)
|
||||
_settle(application)
|
||||
original = QRect(dialog.geometry())
|
||||
controller = install_window_fullscreen(dialog)
|
||||
assert install_window_fullscreen(dialog) is controller
|
||||
states: list[bool] = []
|
||||
controller.toggled.connect(states.append)
|
||||
try:
|
||||
# 非全屏时 Esc 不被拦截,保留对话框原有的取消语义。
|
||||
assert controller.toggle_shortcut.isEnabled()
|
||||
assert not controller.escape_shortcut.isEnabled()
|
||||
|
||||
controller.toggle_shortcut.activated.emit() # 模拟 F11
|
||||
_settle(application)
|
||||
assert dialog.isFullScreen()
|
||||
assert controller.escape_shortcut.isEnabled()
|
||||
assert controller.saved_geometry == original
|
||||
|
||||
controller.escape_shortcut.activated.emit() # 模拟 Esc
|
||||
_settle(application)
|
||||
assert not dialog.isFullScreen()
|
||||
assert dialog.isVisible()
|
||||
assert dialog.geometry() == original
|
||||
assert not controller.escape_shortcut.isEnabled()
|
||||
assert states == [True, False]
|
||||
|
||||
# F11 再按两次:进入后再退出,同样回到原位。
|
||||
controller.toggle()
|
||||
_settle(application)
|
||||
controller.toggle()
|
||||
_settle(application)
|
||||
assert not dialog.isFullScreen()
|
||||
assert dialog.geometry() == original
|
||||
finally:
|
||||
dialog.close()
|
||||
dialog.deleteLater()
|
||||
|
||||
|
||||
def test_controller_restores_maximized_state(application: QApplication) -> None:
|
||||
dialog = _plain_dialog()
|
||||
dialog.setGeometry(100, 100, 600, 420)
|
||||
dialog.showMaximized()
|
||||
_settle(application)
|
||||
controller = install_window_fullscreen(dialog)
|
||||
try:
|
||||
controller.enter()
|
||||
_settle(application)
|
||||
assert dialog.isFullScreen()
|
||||
controller.exit()
|
||||
_settle(application)
|
||||
assert not dialog.isFullScreen()
|
||||
assert dialog.isMaximized()
|
||||
finally:
|
||||
dialog.close()
|
||||
dialog.deleteLater()
|
||||
|
||||
|
||||
def test_top_level_business_dialog_gets_fullscreen_on_show(application: QApplication) -> None:
|
||||
dialog = _plain_dialog()
|
||||
dialog.resize(700, 500)
|
||||
try:
|
||||
dialog.show()
|
||||
_settle(application)
|
||||
controller = window_fullscreen_controller(dialog)
|
||||
assert controller is not None
|
||||
controller.enter()
|
||||
_settle(application)
|
||||
assert dialog.isFullScreen()
|
||||
controller.exit()
|
||||
_settle(application)
|
||||
assert not dialog.isFullScreen()
|
||||
finally:
|
||||
dialog.close()
|
||||
dialog.deleteLater()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def shell(application: QApplication):
|
||||
repo = DemoDoctorRepository()
|
||||
session = repo.login(repo.DEMO_ACCOUNT, repo.DEMO_PASSWORD)
|
||||
window = SpatialShellWindow(
|
||||
repo,
|
||||
{"session": session, "user": session.user, "demo_mode": True},
|
||||
PermissionSet(DEMO_PERMISSIONS),
|
||||
)
|
||||
window.resize(1520, 920)
|
||||
window.show()
|
||||
_settle(application, 24)
|
||||
try:
|
||||
yield window
|
||||
finally:
|
||||
window.wing_manager.close_all()
|
||||
window.close()
|
||||
window.deleteLater()
|
||||
_settle(application, 4)
|
||||
|
||||
|
||||
def test_docked_wing_fullscreen_and_restores_dock(shell, application: QApplication) -> None:
|
||||
shell._open_active_patient_ai_report()
|
||||
_settle(application)
|
||||
wm = shell.wing_manager
|
||||
header = wm.card.header
|
||||
assert wm.is_open and wm.mode == "docked" and wm.side == "right"
|
||||
assert header.fullscreen_btn.text() == FULLSCREEN_ENTER_TEXT
|
||||
shell_geom = QRect(shell.geometry())
|
||||
|
||||
header.fullscreen_btn.click()
|
||||
_settle(application)
|
||||
assert wm.is_fullscreen
|
||||
assert wm.sidecar is not None and wm.sidecar.isFullScreen()
|
||||
assert wm.card.window() is wm.sidecar
|
||||
assert header.fullscreen_btn.text() == FULLSCREEN_EXIT_TEXT
|
||||
assert header.fullscreen_btn.isChecked()
|
||||
# 全屏下卡片铺满整个窗口,内容不再被挤压。
|
||||
assert wm.card.width() >= wm.sidecar.width() - 2
|
||||
assert not shell.right_wing_dock.isVisible()
|
||||
|
||||
# 全屏时 Esc 只退出全屏,不关闭视窗。
|
||||
wm._on_escape()
|
||||
_settle(application)
|
||||
assert wm.is_open
|
||||
assert not wm.is_fullscreen
|
||||
assert wm.mode == "docked" and wm.side == "right"
|
||||
assert shell.right_wing_dock.isVisible()
|
||||
assert wm.card.window() is shell
|
||||
assert not wm.sidecar.isVisible()
|
||||
assert header.fullscreen_btn.text() == FULLSCREEN_ENTER_TEXT
|
||||
assert not header.fullscreen_btn.isChecked()
|
||||
assert shell.geometry() == shell_geom
|
||||
|
||||
# 非全屏时 Esc 仍然关闭视窗。
|
||||
wm._on_escape()
|
||||
_settle(application)
|
||||
assert not wm.is_open
|
||||
|
||||
|
||||
def test_left_sidecar_fullscreen_restores_side_mode_and_geometry(
|
||||
shell, application: QApplication
|
||||
) -> None:
|
||||
shell._open_active_patient_ai_report()
|
||||
_settle(application)
|
||||
wm = shell.wing_manager
|
||||
wm.set_side("left")
|
||||
wm.set_mode("sidecar")
|
||||
_settle(application)
|
||||
sidecar = wm.sidecar
|
||||
assert sidecar is not None and sidecar.isVisible()
|
||||
sidecar.setGeometry(sidecar.x(), sidecar.y(), 460, 700)
|
||||
_settle(application)
|
||||
before = QRect(sidecar.geometry())
|
||||
|
||||
wm.toggle_fullscreen() # F11 与按钮共用同一入口
|
||||
_settle(application)
|
||||
assert sidecar.isFullScreen()
|
||||
assert wm.card.header.left_btn.isChecked()
|
||||
|
||||
wm.toggle_fullscreen()
|
||||
_settle(application)
|
||||
assert not sidecar.isFullScreen()
|
||||
assert wm.mode == "sidecar" and wm.side == "left"
|
||||
assert sidecar.geometry() == before
|
||||
assert wm.card.header.detach_btn.text() == "↙ 嵌回主窗"
|
||||
|
||||
|
||||
def test_switching_side_while_fullscreen_exits_first(shell, application: QApplication) -> None:
|
||||
shell._open_active_patient_ai_report()
|
||||
_settle(application)
|
||||
wm = shell.wing_manager
|
||||
wm.enter_fullscreen()
|
||||
_settle(application)
|
||||
assert wm.is_fullscreen
|
||||
|
||||
wm.card.header.left_btn.click()
|
||||
_settle(application)
|
||||
assert not wm.is_fullscreen
|
||||
assert wm.mode == "docked" and wm.side == "left"
|
||||
assert shell.left_wing_dock.isVisible()
|
||||
assert not wm.sidecar.isVisible()
|
||||
|
||||
|
||||
def test_close_wing_while_fullscreen_restores_placement(shell, application: QApplication) -> None:
|
||||
shell._open_active_patient_ai_report()
|
||||
_settle(application)
|
||||
wm = shell.wing_manager
|
||||
wm.enter_fullscreen()
|
||||
_settle(application)
|
||||
wm.close_wing()
|
||||
_settle(application)
|
||||
assert not wm.is_fullscreen
|
||||
assert not wm.sidecar.isVisible()
|
||||
assert wm.mode == "docked"
|
||||
|
||||
shell._open_active_patient_ai_report()
|
||||
_settle(application)
|
||||
assert wm.mode == "docked" and shell.right_wing_dock.isVisible()
|
||||
assert wm.card.header.fullscreen_btn.text() == FULLSCREEN_ENTER_TEXT
|
||||
Reference in New Issue
Block a user