fix: 终极状态回滚 + 三个 panel 短路径导包修复
- water_quality_gui_v2.py:回滚机制由 panel_registry.get_tab_index 改为基于 PANEL_REGISTRY[current_tab_idx]['step_id'] 的索引反查,消除不存在的 get_tab_index 导致回滚期间二次崩溃并被静默吞噬的幽灵跳步根因
This commit is contained in:
@ -14,7 +14,7 @@ from typing import List, Optional
|
|||||||
_HERE = os.path.dirname(os.path.abspath(__file__))
|
_HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
if _HERE not in sys.path:
|
if _HERE not in sys.path:
|
||||||
sys.path.insert(0, _HERE)
|
sys.path.insert(0, _HERE)
|
||||||
from _step_path_resolver import resolve_subdir, get_step_output_path
|
from src.gui.panels._step_path_resolver import resolve_subdir, get_step_output_path
|
||||||
|
|
||||||
from PyQt5.QtCore import Qt, QThread, pyqtSignal
|
from PyQt5.QtCore import Qt, QThread, pyqtSignal
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
|
|||||||
@ -12,7 +12,7 @@ from pathlib import Path
|
|||||||
_HERE = os.path.dirname(os.path.abspath(__file__))
|
_HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
if _HERE not in sys.path:
|
if _HERE not in sys.path:
|
||||||
sys.path.insert(0, _HERE)
|
sys.path.insert(0, _HERE)
|
||||||
from _step_path_resolver import resolve_subdir
|
from src.gui.panels._step_path_resolver import resolve_subdir
|
||||||
|
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QWidget, QVBoxLayout, QGroupBox, QFormLayout, QLabel,
|
QWidget, QVBoxLayout, QGroupBox, QFormLayout, QLabel,
|
||||||
|
|||||||
@ -12,7 +12,7 @@ from pathlib import Path
|
|||||||
_HERE = os.path.dirname(os.path.abspath(__file__))
|
_HERE = os.path.dirname(os.path.abspath(__file__))
|
||||||
if _HERE not in sys.path:
|
if _HERE not in sys.path:
|
||||||
sys.path.insert(0, _HERE)
|
sys.path.insert(0, _HERE)
|
||||||
from _step_path_resolver import get_step_output_path, resolve_step_widget, resolve_subdir
|
from src.gui.panels._step_path_resolver import get_step_output_path, resolve_step_widget, resolve_subdir
|
||||||
|
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QWidget, QVBoxLayout, QGroupBox, QFormLayout, QGridLayout,
|
QWidget, QVBoxLayout, QGroupBox, QFormLayout, QGridLayout,
|
||||||
|
|||||||
@ -482,22 +482,20 @@ class WaterQualityGUI(QMainWindow):
|
|||||||
QMessageBox.critical(self, "面板加载失败",
|
QMessageBox.critical(self, "面板加载失败",
|
||||||
f"加载页面时发生严重错误:\n{e}\n\n详见终端日志。")
|
f"加载页面时发生严重错误:\n{e}\n\n详见终端日志。")
|
||||||
|
|
||||||
# ====== 新增:状态回滚(解决幽灵跳转/假死) ======
|
# ====== 终极状态回滚机制 ======
|
||||||
# 既然右侧未能成功切换,必须强制将左侧导航栏的选中项退回到与右侧一致
|
|
||||||
self._step_list.blockSignals(True)
|
self._step_list.blockSignals(True)
|
||||||
try:
|
try:
|
||||||
current_tab_idx = self._tab_widget.currentIndex()
|
current_tab_idx = self._tab_widget.currentIndex()
|
||||||
from src.gui.core.panel_registry import get_tab_index
|
from src.gui.core.panel_registry import PANEL_REGISTRY
|
||||||
# 遍历左侧列表,找到属于当前显示的 tab_index 的那个 step
|
if 0 <= current_tab_idx < len(PANEL_REGISTRY):
|
||||||
for i in range(self._step_list.count()):
|
correct_step_id = PANEL_REGISTRY[current_tab_idx]['step_id']
|
||||||
item_node = self._step_list.item(i)
|
for i in range(self._step_list.count()):
|
||||||
if item_node:
|
item_node = self._step_list.item(i)
|
||||||
node_data = item_node.data(Qt.UserRole)
|
if item_node and item_node.data(Qt.UserRole) == correct_step_id:
|
||||||
if node_data and node_data != "stage_header" and get_tab_index(node_data) == current_tab_idx:
|
|
||||||
self._step_list.setCurrentRow(i)
|
self._step_list.setCurrentRow(i)
|
||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
pass # 回滚期间如果发生异常,默默忽略,防止二次崩溃
|
pass
|
||||||
finally:
|
finally:
|
||||||
self._step_list.blockSignals(False)
|
self._step_list.blockSignals(False)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user