diff --git a/src/dx_productivity/trial_task_center/ui/dsh_status.py b/src/dx_productivity/trial_task_center/ui/dsh_status.py index cb343e7..1c529e9 100644 --- a/src/dx_productivity/trial_task_center/ui/dsh_status.py +++ b/src/dx_productivity/trial_task_center/ui/dsh_status.py @@ -1,6 +1,6 @@ """Non-blocking model readiness and visible automatic-intervention state.""" -from PySide6.QtCore import QObject, QPointF, QRectF, QSize, Qt, QThreadPool, QTimer -from PySide6.QtGui import QColor, QFontMetricsF, QPainter +from PySide6.QtCore import QObject, QRectF, QSize, Qt, QThreadPool, QTimer +from PySide6.QtGui import QColor, QPainter from PySide6.QtWidgets import QApplication, QToolButton from ...dsh.availability import check_availability @@ -12,9 +12,10 @@ class DshStatusIndicator(QToolButton): def __init__(self, parent=None): super().__init__(parent, objectName='dshAiStatus') self.setAutoRaise(True) + self.setFocusPolicy(Qt.FocusPolicy.TabFocus) self.setCursor(Qt.CursorShape.PointingHandCursor) self.setStyleSheet('QToolButton#dshAiStatus, QToolButton#dshAiStatus:hover, ' - 'QToolButton#dshAiStatus:pressed {border: none; background: transparent; padding: 0 2px;}') + 'QToolButton#dshAiStatus:pressed {border: none; background: transparent; padding: 0;}') self.set_state('checking', '检查配置', '正在检查本地 AI 配置,普通任务不受影响。') def set_state(self, state, label, details): @@ -22,15 +23,14 @@ class DshStatusIndicator(QToolButton): 'unavailable': '#e04b5a', 'attention': '#e04b5a', 'silent': '#929aa6'} self._light_color = QColor(colors[state]) self.setProperty('state', state) - self.setText('AI · ' + label) - self.setToolTip(details) + self.setText('') + self.setToolTip('AI 自动介入:' + label + '\n' + details) self.setAccessibleName('AI 自动介入:' + label) self.setAccessibleDescription(details) self.update() def sizeHint(self): - self.ensurePolished() - return QSize(self.fontMetrics().horizontalAdvance(self.text()) + 28, 34) + return QSize(28, 34) def minimumSizeHint(self): return self.sizeHint() @@ -38,18 +38,14 @@ class DshStatusIndicator(QToolButton): def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.RenderHint.Antialiasing) - metrics = QFontMetricsF(painter.font()) - baseline = (self.height() - metrics.height()) / 2 + metrics.ascent() - # The lamp follows the rendered glyphs, including Chinese fallback fonts. - center_y = baseline + metrics.tightBoundingRect(self.text()).center().y() + light = QRectF((self.width() - 10) / 2, (self.height() - 10) / 2, 10, 10) painter.setPen(Qt.PenStyle.NoPen) painter.setBrush(self._light_color) - painter.drawEllipse(QRectF(4, center_y - 5, 10, 10)) - painter.setPen(self.palette().buttonText().color()) - painter.drawText(QPointF(22, baseline), self.text()) + painter.drawEllipse(light) if self.hasFocus(): painter.setPen(self.palette().highlight().color()) - painter.drawLine(QPointF(22, baseline + 2), QPointF(self.width() - 4, baseline + 2)) + painter.setBrush(Qt.BrushStyle.NoBrush) + painter.drawEllipse(light.adjusted(-3, -3, 3, 3)) class DshStatusController(QObject): @@ -143,7 +139,9 @@ class DshStatusController(QObject): reason = scrub(str(row.get('message') or getattr(request, 'message', '') or '任务异常'))[:500] owner = row.get('task_name') or row.get('task_id') or getattr(request, 'task_id', '') stages = {'collecting': '收集证据', 'analyzing': '分析异常', 'reflecting': '复盘与补充证据', - 'retrying': '按规则重试', 'cleaning_resources': '清理自有资源', 'verifying': '核验处理结果'} + 'retrying': '按规则重试', 'cleaning_resources': '清理自有资源', 'verifying': '核验处理结果', + 'pending_issue': '保存证据与提交工单', 'escalated': '整理工单结果', + 'resolved': '保存核验结果', 'observed_cleared': '保存现场核验', 'cancelled': '取消并保存证据'} stage = stages.get(row.get('status'), '准备介入' if getattr(automation, 'worker', None) else '等待介入') indicator.set_state('working', '介入中', f'AI 因以下异常介入:{reason}\n' + (f'所属任务:{owner}\n' if owner else '') + diff --git a/tests/ui/test_dsh_status_indicator.py b/tests/ui/test_dsh_status_indicator.py index 6a29294..bd0af13 100644 --- a/tests/ui/test_dsh_status_indicator.py +++ b/tests/ui/test_dsh_status_indicator.py @@ -38,7 +38,9 @@ def test_switch_off_shows_grey_silent_even_without_key(no_model, ui, qtbot): assert hasattr(window, 'ai_status_indicator'), 'Silent mode needs a grey status lamp' qtbot.mouseClick(window.auto_intervention_check, Qt.MouseButton.LeftButton) assert window.ai_status_indicator.property('state') == 'silent' - assert '静默' in window.ai_status_indicator.text() + assert window.ai_status_indicator.text() == '' + assert '静默' in window.ai_status_indicator.toolTip() + assert '静默' in window.ai_status_indicator.accessibleName() assert '已关闭' in window.ai_status_indicator.toolTip() @@ -47,6 +49,7 @@ def test_indicator_tooltip_explains_live_intervention_reason_and_stage(no_model, assert hasattr(window, 'ai_status_indicator'), 'The old cancel button does not explain intervention' window._dsh_status._received({'available': True, 'code': 'available', 'message': 'Configured'}) assert window.ai_status_indicator.property('state') == 'idle' + idle_size = window.ai_status_indicator.sizeHint() assert '待机' in window.ai_status_indicator.toolTip() automation = SimpleNamespace(worker=object(), pending=[], can_cancel=True, latest={'status': 'reflecting', 'message': 'BOM 表头缺少旧料号', 'task_name': 'Board-A'}, @@ -54,6 +57,8 @@ def test_indicator_tooltip_explains_live_intervention_reason_and_stage(no_model, monkeypatch.setattr(window, '_dsh_automation', automation) window._update_gates() assert window.ai_status_indicator.property('state') == 'working' + assert window.ai_status_indicator.text() == '' + assert window.ai_status_indicator.sizeHint() == idle_size assert 'BOM 表头缺少旧料号' in window.ai_status_indicator.toolTip() assert 'Board-A' in window.ai_status_indicator.toolTip() assert '复盘' in window.ai_status_indicator.toolTip()