From 389fc917b97c8425616e6c3dd1707f32ccbc71d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Wed, 4 Nov 2026 22:26:49 +0800 Subject: [PATCH] ui(dsh): use sliding intervention switch and clarify automatic repair --- docs/user/dsh-ai-supervision.md | 2 +- integration/dsh/task-plugin/client.js | 2 +- .../trial_task_center/ui/main_window.py | 5 +- .../trial_task_center/ui/toggle_switch.py | 58 +++++++++++++++++++ tests/ui/test_dsh_native_menu.py | 16 +++++ 5 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 src/dx_productivity/trial_task_center/ui/toggle_switch.py diff --git a/docs/user/dsh-ai-supervision.md b/docs/user/dsh-ai-supervision.md index e02efcf..8db2de4 100644 --- a/docs/user/dsh-ai-supervision.md +++ b/docs/user/dsh-ai-supervision.md @@ -58,7 +58,7 @@ DSH 使用独立原生子窗口承载 WebEngine,切回任务中心后保留原 ### 自动异常介入 -顶部常驻 **AI 自动介入** 开关,默认开启,重启后保留设置。关闭后不再接收新的自动异常介入,并清空尚未处理的队列;当前诊断继续保存证据,但不再发起自动重试。已经开始的工程执行继续遵循原来的暂停和强制结束按钮,关闭 AI 开关不会停止工程。 +顶部常驻 **AI 自动介入** 滑动开关,绿色为开启、灰色为关闭,支持鼠标点击和空格键切换,默认开启,重启后保留设置。关闭后不再接收新的自动异常介入,并清空尚未处理的队列;当前诊断继续保存证据,但不再发起自动重试。已经开始的工程执行继续遵循原来的暂停和强制结束按钮,关闭 AI 开关不会停止工程。 任务操作报错、单任务收尾有失败项,或批次包含失败/阻断任务时,会自动切入 DSH助手并创建专属诊断会话,不需要手动提问。原执行收尾后,AI 读取出错任务绑定的快照和脱敏事件;即使切换任务,诊断也不会串到另一个任务。 diff --git a/integration/dsh/task-plugin/client.js b/integration/dsh/task-plugin/client.js index 428b98e..e270650 100644 --- a/integration/dsh/task-plugin/client.js +++ b/integration/dsh/task-plugin/client.js @@ -9,7 +9,7 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{ h('h2',null,'DSH工具'), h('p',null,'面向 DxDesigner 器件替换任务的异常分析与执行监管。发现报错后自动介入,直接使用当前任务上下文,无需另外登录。'), h('h3',null,'工作方式'), - h('p',null,'在顶部切换任务中心和 DSH助手。“AI 自动介入”默认开启并记住设置,异常会自动新建诊断对话;关闭后不再接收自动诊断或发起自动重试。会话、任务选择和未发送草稿会保留。'), + h('p',null,'在顶部切换任务中心和 DSH助手。“AI 自动介入”滑动开关默认开启并记住设置,异常会自动新建对话,诊断后按规则尝试修复并核验,未解决则保留证据、转工单;关闭后不再接收自动诊断或发起自动重试。会话、任务选择和未发送草稿会保留。'), h('h3',null,'任务能力'), h('ul',null,...['在对话中创建和修改任务;具体工程与执行范围由原生窗口确认','实时监管当前执行、阶段、耗时与保存/失败/未命中计数','保存执行回执,重启后核对原队列并手动确认恢复','预览精确位号影响;仅有料号映射时明确标记未知匹配数量','检索历史异常经验,仅将持久化核验通过的记录标为已验证','只读同步已有 Git 工单状态与评论,查看本地证据','查看会话 Token、耗时与超时状态,配置响应时限并停止模型生成','设置任务优先级、执行时间与依赖,通过原生窗口确认排期'].map(text=>h('li',{key:text},text))), h('h3',null,'模型与数据'), diff --git a/src/dx_productivity/trial_task_center/ui/main_window.py b/src/dx_productivity/trial_task_center/ui/main_window.py index dbe1503..0b4e10f 100644 --- a/src/dx_productivity/trial_task_center/ui/main_window.py +++ b/src/dx_productivity/trial_task_center/ui/main_window.py @@ -23,6 +23,7 @@ from .material import AcrylicController, MaterialMainWindow from .icons import apply_icons, icon from .task_list import TaskList from .workers import ServiceWorker +from .toggle_switch import ToggleSwitch from .queries import LatestQuery from .resource_status import ResourceStatus from .task_log import TaskLogPresenter @@ -80,8 +81,8 @@ class TrialTaskCenterWindow(MaterialMainWindow): setattr(self, name, button) self.task_center_action.setChecked(True) navigation_layout.addStretch() - self.auto_intervention_check = QCheckBox('AI 自动介入', objectName='dshAutoIntervention') - self.auto_intervention_check.setToolTip('开启后异常自动新建诊断对话。关闭后不再接收异常或发起自动重试;当前诊断继续保存证据,已开始的执行不受影响。') + self.auto_intervention_check = ToggleSwitch('AI 自动介入', objectName='dshAutoIntervention') + self.auto_intervention_check.setToolTip('异常时自动新建对话,诊断后按规则尝试修复并核验;未解决则保留证据、转工单。关闭后不接收新异常或发起自动重试,当前诊断继续保存证据,已开始的执行不受影响。') navigation_layout.addWidget(self.auto_intervention_check) self.reduced_transparency_button = QToolButton(objectName='reduceTransparency') self.reduced_transparency_button.setText('减少透明度') diff --git a/src/dx_productivity/trial_task_center/ui/toggle_switch.py b/src/dx_productivity/trial_task_center/ui/toggle_switch.py new file mode 100644 index 0000000..ee5d34a --- /dev/null +++ b/src/dx_productivity/trial_task_center/ui/toggle_switch.py @@ -0,0 +1,58 @@ +"""A sliding switch retaining Qt checkbox keyboard and accessibility behavior.""" +from PySide6.QtCore import QEasingCurve, QRectF, QSize, Qt, QVariantAnimation +from PySide6.QtGui import QColor, QPainter, QPen +from PySide6.QtWidgets import QCheckBox + + +class ToggleSwitch(QCheckBox): + def __init__(self, text='', parent=None, **kwargs): + super().__init__(text, parent, **kwargs) + self._position = 0.0 + self._animation = QVariantAnimation(self) + self._animation.setDuration(160) + self._animation.setEasingCurve(QEasingCurve.Type.InOutCubic) + self._animation.valueChanged.connect(self._move_thumb) + self.toggled.connect(self._animate) + self.setCursor(Qt.CursorShape.PointingHandCursor) + + def sizeHint(self): + return QSize(self.fontMetrics().horizontalAdvance(self.text()) + 62, 34) + + def minimumSizeHint(self): + return self.sizeHint() + + def hitButton(self, position): + return self.rect().contains(position) + + def _move_thumb(self, value): + self._position = value + self.update() + + def _animate(self, checked): + self._animation.stop() + target = float(checked) + if not self.isVisible(): + self._move_thumb(target) + return + self._animation.setStartValue(self._position) + self._animation.setEndValue(target) + self._animation.start() + + def paintEvent(self, event): + painter = QPainter(self) + painter.setRenderHint(QPainter.RenderHint.Antialiasing) + if not self.isEnabled(): + painter.setOpacity(0.45) + painter.setPen(self.palette().windowText().color()) + painter.drawText(QRectF(4, 0, self.width() - 58, self.height()), + Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter, self.text()) + track = QRectF(self.width() - 48, (self.height() - 26) / 2, 44, 26) + painter.setPen(Qt.PenStyle.NoPen) + painter.setBrush(QColor('#32bd72' if self.isChecked() else '#c4cbd4')) + painter.drawRoundedRect(track, 13, 13) + painter.setBrush(QColor('#ffffff')) + painter.drawEllipse(QRectF(track.left() + 2 + self._position * 18, track.top() + 2, 22, 22)) + if self.hasFocus(): + painter.setBrush(Qt.BrushStyle.NoBrush) + painter.setPen(QPen(self.palette().highlight().color(), 1.5)) + painter.drawRoundedRect(QRectF(self.rect()).adjusted(1, 1, -1, -1), 6, 6) diff --git a/tests/ui/test_dsh_native_menu.py b/tests/ui/test_dsh_native_menu.py index ff619cf..fa6cf31 100644 --- a/tests/ui/test_dsh_native_menu.py +++ b/tests/ui/test_dsh_native_menu.py @@ -145,6 +145,22 @@ def test_auto_intervention_toggle_persists_and_disabled_errors_do_not_enqueue(ui reopened.close() +def test_intervention_switch_has_colored_track_and_supports_keyboard(ui, qtbot): + from PySide6.QtCore import QPoint + switch = ui.window.auto_intervention_check + def track_color(): + image = switch.grab().toImage() + scale = image.devicePixelRatio() + return image.pixelColor(round((switch.width() - 38) * scale), round(switch.height() / 2 * scale)) + green = track_color() + assert green.green() > green.red() + 30 + qtbot.mouseClick(switch, Qt.MouseButton.LeftButton, pos=QPoint(switch.width() - 5, switch.height() // 2)) + assert not switch.isChecked() + switch.setFocus() + qtbot.keyClick(switch, Qt.Key.Key_Space) + assert switch.isChecked() + + def test_taskless_error_automatically_queues_diagnosis(ui): window = ui.window window._task_id = None