From e5bb9c5cd911dde0f41198ffd0be74a06bcf775b Mon Sep 17 00:00:00 2001 From: DXC Date: Thu, 18 Jun 2026 13:59:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=87=92=E5=8A=A0=E8=BD=BD=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E5=AE=B9=E9=94=99=20+=20=E7=8A=B6=E6=80=81=E5=9B=9E?= =?UTF-8?q?=E6=BB=9A=E6=9C=BA=E5=88=B6=20+=20Step=2011=20NameError=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 导航容错(v2._on_step_list_changed) - try-except 包裹懒加载 + setCurrentIndex,避免导航崩溃导致左右脱节 - 新增状态回滚机制:右侧切换失败时强制将左侧导航栏选中项退回当前显示 tab_index 对应的 step,消除"幽灵跳转/假死"(blockSignals 防 setCurrentRow 二次触发回调) Step 11 NameError - step11_map_panel 顶部补 import get_step_output_path,消除 update_from_config 中 NameError --- src/gui/panels/step11_map_panel.py | 2 +- src/gui/water_quality_gui_v2.py | 34 +++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/gui/panels/step11_map_panel.py b/src/gui/panels/step11_map_panel.py index 6d454b6..346acb2 100644 --- a/src/gui/panels/step11_map_panel.py +++ b/src/gui/panels/step11_map_panel.py @@ -14,7 +14,7 @@ from typing import List, Optional _HERE = os.path.dirname(os.path.abspath(__file__)) if _HERE not in sys.path: sys.path.insert(0, _HERE) -from _step_path_resolver import resolve_subdir +from _step_path_resolver import resolve_subdir, get_step_output_path from PyQt5.QtCore import Qt, QThread, pyqtSignal from PyQt5.QtWidgets import ( diff --git a/src/gui/water_quality_gui_v2.py b/src/gui/water_quality_gui_v2.py index 8d7f80e..51ae36e 100644 --- a/src/gui/water_quality_gui_v2.py +++ b/src/gui/water_quality_gui_v2.py @@ -471,9 +471,37 @@ class WaterQualityGUI(QMainWindow): tab_index = get_tab_index(item_data) if tab_index < 0: return - # 先触发懒加载再切 Tab,避免 removeTab/insertTab 与导航事件重叠 - self._panel_factory.get_panel(item_data) - self._tab_widget.setCurrentIndex(tab_index) + try: + # 先触发懒加载再切 Tab,避免 removeTab/insertTab 与导航事件重叠 + self._panel_factory.get_panel(item_data) + self._tab_widget.setCurrentIndex(tab_index) + except Exception as e: + import traceback + traceback.print_exc() + from PyQt5.QtWidgets import QMessageBox + QMessageBox.critical(self, "面板加载失败", + f"加载页面时发生严重错误:\n{e}\n\n详见终端日志。") + + # ====== 新增:状态回滚(解决幽灵跳转/假死) ====== + # 既然右侧未能成功切换,必须强制将左侧导航栏的选中项退回到与右侧一致 + self._step_list.blockSignals(True) + try: + current_tab_idx = self._tab_widget.currentIndex() + from src.gui.core.panel_registry import get_tab_index + # 遍历左侧列表,找到属于当前显示的 tab_index 的那个 step + for i in range(self._step_list.count()): + item_node = self._step_list.item(i) + if item_node: + node_data = item_node.data(Qt.UserRole) + if node_data and node_data != "stage_header" and get_tab_index(node_data) == current_tab_idx: + self._step_list.setCurrentRow(i) + break + except Exception: + pass # 回滚期间如果发生异常,默默忽略,防止二次崩溃 + finally: + self._step_list.blockSignals(False) + + return # 动态更新上一步/下一步按钮可用状态 self._prev_btn.setEnabled(self._find_prev_step_row(index) is not None)