重构pq_config、修改切换面板清空旧逻辑

This commit is contained in:
xinzhu.yin
2026-05-19 11:50:53 +08:00
parent 405b6047b9
commit c42287b7d7
6 changed files with 324 additions and 687 deletions

View File

@@ -145,6 +145,8 @@ class PQAutomationApp:
self.pattern_service = PatternService(self)
# 结果管理器:按 test_type 保留每次测试结果,始终存在,避免未初始化错误
self.results = PQResultStore()
# 图表快照:按 test_type 缓存最近一次各图表的绘制参数,切换类型时可恢复
self._chart_snapshots: dict = {} # {test_type: {chart_name: args_tuple}}
# 加载上次保存的设置
self.config_file = self.get_config_path()
@@ -541,6 +543,34 @@ class PQAutomationApp:
self._switch_signal_format_tabs(test_type)
self._switch_chart_tabs_by_test_type(test_type)
self.sync_gamut_toolbar()
self._restore_charts_for_type(test_type)
def _save_chart_snapshot(self, test_type: str, chart_name: str, args: tuple):
"""保存某次绘图的参数,以便切换测试类型时可以重绘。"""
if test_type not in self._chart_snapshots:
self._chart_snapshots[test_type] = {}
self._chart_snapshots[test_type][chart_name] = args
def _restore_charts_for_type(self, test_type: str):
"""
切换测试类型后恢复图表显示:
- 该类型有历史结果 → 切换活跃结果 + 重绘所有已缓存图表
- 该类型无历史结果 → 清空图表 + 禁用保存按钮
"""
self.results.set_active(test_type)
snapshots = self._chart_snapshots.get(test_type)
if not snapshots:
self.clear_chart()
if hasattr(self, "save_btn"):
self.save_btn.config(state=tk.DISABLED)
return
for chart_name, args in snapshots.items():
plot_fn = getattr(self, f"plot_{chart_name}", None)
if plot_fn:
try:
plot_fn(*args)
except Exception:
pass
def _check_start_preconditions(self):
"""检查开始测试前置条件:设备连接 & 未在测试中。"""