fix: 导航状态锁防抖 + 运行按钮中间槽函数(修复乱跳与无响应双 Bug)

Bug1 导航乱跳:_on_step_list_changed 先调 get_panel 触发懒加载再 setCurrentIndex,避免 removeTab/insertTab 索引偏移导致跳页错乱。_on_tab_changed 加 _is_syncing 守卫斩断乒乓效应。Bug2 按钮无响应:新增 _on_run_all_clicked 中间槽函数替代直接连接,内含 print 探针 + try/except 兜底。
This commit is contained in:
DXC
2026-06-18 09:01:25 +08:00
parent f1cc339d4a
commit 2d45610aa6

View File

@ -88,6 +88,8 @@ class WaterQualityGUI(QMainWindow):
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(my_appid) ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(my_appid)
super().__init__() super().__init__()
self._is_syncing = False
icon_path = get_resource_path("data/icons-1/uitubiao.ico") icon_path = get_resource_path("data/icons-1/uitubiao.ico")
self.setWindowIcon(QIcon(icon_path)) self.setWindowIcon(QIcon(icon_path))
@ -358,7 +360,7 @@ class WaterQualityGUI(QMainWindow):
self._run_all_btn = QPushButton("> 运行完整流程") self._run_all_btn = QPushButton("> 运行完整流程")
self._run_all_btn.setStyleSheet(ModernStylesheet.get_button_stylesheet('success')) self._run_all_btn.setStyleSheet(ModernStylesheet.get_button_stylesheet('success'))
self._run_all_btn.setMinimumHeight(35) self._run_all_btn.setMinimumHeight(35)
self._run_all_btn.clicked.connect(self._pipeline_executor.run_full_pipeline) self._run_all_btn.clicked.connect(self._on_run_all_clicked)
btn_layout.addWidget(self._run_all_btn) btn_layout.addWidget(self._run_all_btn)
self._stop_btn = QPushButton("⏹ 停止") self._stop_btn = QPushButton("⏹ 停止")
@ -417,11 +419,21 @@ class WaterQualityGUI(QMainWindow):
work_dir = data.get('work_dir', '') work_dir = data.get('work_dir', '')
self.statusBar().showMessage(f"工作目录: {work_dir}") self.statusBar().showMessage(f"工作目录: {work_dir}")
def _on_run_all_clicked(self):
print("==== 按钮确实被按下了 ====", flush=True)
try:
self._pipeline_executor.run_full_pipeline()
except Exception as e:
print(f"执行器调用崩溃: {e}")
traceback.print_exc()
# ================================================================ # ================================================================
# 导航 ↔ Tab 双向同步(纯 UI 路由) # 导航 ↔ Tab 双向同步(纯 UI 路由)
# ================================================================ # ================================================================
def _on_step_list_changed(self, index): def _on_step_list_changed(self, index):
if self._is_syncing:
return
if index < 0: if index < 0:
return return
item = self._step_list.item(index) item = self._step_list.item(index)
@ -432,10 +444,21 @@ class WaterQualityGUI(QMainWindow):
return return
from src.gui.core.panel_registry import get_tab_index from src.gui.core.panel_registry import get_tab_index
tab_index = get_tab_index(item_data) tab_index = get_tab_index(item_data)
if tab_index >= 0: if tab_index < 0:
return
self._is_syncing = True
try:
# ★ 先触发懒加载get_panel 内部 _ensure_loaded 自带 blockSignals
# 保护 removeTab/insertTab面板实例化完成后再切 Tab
# 此时 _ensure_loaded 发现已加载直接返回,不再触发索引偏移
self._panel_factory.get_panel(item_data)
self._tab_widget.setCurrentIndex(tab_index) self._tab_widget.setCurrentIndex(tab_index)
finally:
self._is_syncing = False
def _on_tab_changed(self, index): def _on_tab_changed(self, index):
if self._is_syncing:
return
if index < 0: if index < 0:
return return
from src.gui.core.panel_registry import get_step_id_by_tab_index from src.gui.core.panel_registry import get_step_id_by_tab_index
@ -447,7 +470,11 @@ class WaterQualityGUI(QMainWindow):
if not item: if not item:
continue continue
if item.data(Qt.UserRole) == target_step_id: if item.data(Qt.UserRole) == target_step_id:
self._is_syncing = True
try:
self._step_list.setCurrentRow(row) self._step_list.setCurrentRow(row)
finally:
self._is_syncing = False
break break
# ================================================================ # ================================================================