修复UCD调用异常、保存结果按钮异常

This commit is contained in:
xinzhu.yin
2026-06-15 10:58:51 +08:00
parent c8ad244c45
commit dc096a9805
6 changed files with 65 additions and 15 deletions

View File

@@ -67,6 +67,16 @@ from app.runner.test_runner import TestRunnerMixin
plt.rcParams["font.family"] = ["sans-serif"]
plt.rcParams["font.sans-serif"] = ["Microsoft YaHei"]
class _LegacyUcdConnected:
"""Shim for legacy ``self.ucd.status`` checks after the UCD service refactor."""
status = True
_LEGACY_UCD_CONNECTED = _LegacyUcdConnected()
class PQAutomationApp(
ConfigIOMixin,
ChartFrameMixin,
@@ -207,6 +217,7 @@ class PQAutomationApp(
# 创建测试类型选择区域
self.create_test_type_frame()
self._setup_connection_event_handlers()
self.refresh_connection_indicators()
# 创建操作按钮区域
self.create_operation_frame()
# 创建结果图表区域
@@ -235,6 +246,18 @@ class PQAutomationApp(
anchor=tk.E,
).pack(side=tk.RIGHT)
@property
def is_ucd_connected(self) -> bool:
"""UCD323 是否已连接(统一入口,替代旧的 ``self.ucd.status``)。"""
return self.signal_service.is_connected
@property
def ucd(self):
"""Legacy UCD handle: ``None`` when disconnected, truthy object with ``.status`` when connected."""
if not self.is_ucd_connected:
return None
return _LEGACY_UCD_CONNECTED
def _setup_connection_event_handlers(self) -> None:
"""订阅连接事件,驱动 UCD / CA 指示灯(替代轮询 controller.status"""
@@ -463,19 +486,38 @@ class PQAutomationApp(
self._chart_snapshots[test_type] = {}
self._chart_snapshots[test_type][chart_name] = args
def _has_saveable_results(self, test_type: str) -> bool:
"""判断指定测试类型是否有可保存的历史结果。"""
snapshots = self._chart_snapshots.get(test_type) or {}
return bool(snapshots) or (
hasattr(self, "results") and self.results.has(test_type)
)
def _sync_save_button_state(self):
"""根据当前测试类型是否有可保存结果,同步保存按钮状态。"""
if not hasattr(self, "save_btn"):
return
if getattr(self, "testing", False):
self.save_btn.config(state=tk.DISABLED)
return
test_type = self.test_type_var.get() if hasattr(self, "test_type_var") else None
if not test_type:
return
state = tk.NORMAL if self._has_saveable_results(test_type) else tk.DISABLED
self.save_btn.config(state=state)
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:
if not self._has_saveable_results(test_type):
self.clear_chart()
if hasattr(self, "save_btn"):
self.save_btn.config(state=tk.DISABLED)
self._sync_save_button_state()
return
snapshots = self._chart_snapshots.get(test_type) or {}
for chart_name, args in snapshots.items():
plot_fn = getattr(self, f"plot_{chart_name}", None)
if plot_fn:
@@ -483,6 +525,7 @@ class PQAutomationApp(
plot_fn(*args)
except Exception:
pass
self._sync_save_button_state()
def _check_start_preconditions(self):
"""检查开始测试前置条件:设备连接 & 未在测试中。"""