fix(base_view): dispatch_execute 走事件总线优先,父链爬链降级为 fallback
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 都可正常工作。
This commit is contained in:
@ -66,10 +66,24 @@ class BaseView(QWidget):
|
|||||||
向主窗口请求执行某个步骤。
|
向主窗口请求执行某个步骤。
|
||||||
|
|
||||||
实现要点:
|
实现要点:
|
||||||
- 沿 ``self.parent()`` 一路向上爬,直到找到具备
|
- 优先走事件总线 ``RequestRunSingleStep``(v1 pipeline_executor 已订阅),
|
||||||
``run_single_step`` 方法的祖先容器。
|
让 v1 GUI(water_quality_gui_v2.py)也能接收 v2 view 的执行请求。
|
||||||
- 找不到则抛出 ``RuntimeError``,便于在迁移早期定位未挂载的面板。
|
- 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()
|
ancestor = self.parent()
|
||||||
while ancestor is not None and not hasattr(ancestor, "run_single_step"):
|
while ancestor is not None and not hasattr(ancestor, "run_single_step"):
|
||||||
ancestor = ancestor.parent()
|
ancestor = ancestor.parent()
|
||||||
@ -78,7 +92,7 @@ class BaseView(QWidget):
|
|||||||
ancestor.run_single_step(step_id, config)
|
ancestor.run_single_step(step_id, config)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"[BaseView] dispatch_execute 失败:未在父链中找到 "
|
"[BaseView] dispatch_execute 失败:事件总线无订阅者,"
|
||||||
"具备 run_single_step 方法的主窗口容器 "
|
"且父链中也未找到具备 run_single_step 方法的主窗口容器 "
|
||||||
f"(step_id={step_id})"
|
f"(step_id={step_id})"
|
||||||
)
|
)
|
||||||
Reference in New Issue
Block a user