From b96555e95c8c1e5f9cc41f7a4f4f72b5e0e281fb Mon Sep 17 00:00:00 2001 From: DXC Date: Mon, 22 Jun 2026 16:14:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(base=5Fview):=20dispatch=5Fexecute=20?= =?UTF-8?q?=E8=B5=B0=E4=BA=8B=E4=BB=B6=E6=80=BB=E7=BA=BF=E4=BC=98=E5=85=88?= =?UTF-8?q?=EF=BC=8C=E7=88=B6=E9=93=BE=E7=88=AC=E9=93=BE=E9=99=8D=E7=BA=A7?= =?UTF-8?q?=E4=B8=BA=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BaseView.dispatch_execute 优先 publish RequestRunSingleStep 事件总线 (v1 pipeline_executor 已订阅),让 v1 GUI(water_quality_gui_v2.py) 也能接收 v2 view 的执行请求。父链爬链保留为 fallback(v2 MainView 直调 run_single_step)。两者都失败时 RuntimeError 错误信息增强为双重失败说明。 Why: v1 GUI 加载 v2 view 时原父链爬链找不到具备 run_single_step 方法 的主窗口容器(v1 MainView 无此方法),触发父级GUI对象 RuntimeError。 事件总线优先 + 父链 fallback 让 v1/v2 双 GUI 都可正常工作。 --- src/new/core/base_view.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/new/core/base_view.py b/src/new/core/base_view.py index 53da627..38e5c30 100644 --- a/src/new/core/base_view.py +++ b/src/new/core/base_view.py @@ -66,10 +66,24 @@ class BaseView(QWidget): 向主窗口请求执行某个步骤。 实现要点: - - 沿 ``self.parent()`` 一路向上爬,直到找到具备 - ``run_single_step`` 方法的祖先容器。 - - 找不到则抛出 ``RuntimeError``,便于在迁移早期定位未挂载的面板。 + - 优先走事件总线 ``RequestRunSingleStep``(v1 pipeline_executor 已订阅), + 让 v1 GUI(water_quality_gui_v2.py)也能接收 v2 view 的执行请求。 + - Fallback:沿 ``self.parent()`` 一路向上爬,直到找到具备 + ``run_single_step`` 方法的祖先容器(v2 MainView 直调模式)。 + - 两者都失败则抛出 ``RuntimeError``,便于在迁移早期定位未挂载的面板。 """ + # 1. 首选:事件总线(兼容 v1 GUI:pipeline_executor 订阅了 RequestRunSingleStep) + try: + from src.gui.core.event_bus import global_event_bus + global_event_bus.publish('RequestRunSingleStep', { + 'step_name': step_id, + 'config': {step_id: config}, + }) + return + except Exception: + pass # 事件总线不可用或导入失败时降级到父链 + + # 2. Fallback:沿 self.parent() 父链向上爬(v2 MainView 直调 run_single_step) ancestor = self.parent() while ancestor is not None and not hasattr(ancestor, "run_single_step"): ancestor = ancestor.parent() @@ -78,7 +92,7 @@ class BaseView(QWidget): ancestor.run_single_step(step_id, config) else: raise RuntimeError( - "[BaseView] dispatch_execute 失败:未在父链中找到 " - "具备 run_single_step 方法的主窗口容器 " + "[BaseView] dispatch_execute 失败:事件总线无订阅者," + "且父链中也未找到具备 run_single_step 方法的主窗口容器 " f"(step_id={step_id})" ) \ No newline at end of file