修改引用逻辑、新增Pattern更改界面、新增Calman灰阶界面

This commit is contained in:
xinzhu.yin
2026-05-27 11:26:28 +08:00
parent a903c17cb3
commit dff4e0df4d
24 changed files with 3327 additions and 386 deletions

View File

@@ -13,6 +13,12 @@ from tkinter import filedialog, messagebox
import ttkbootstrap as ttk
from PIL import Image
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pqAutomationApp import PQAutomationApp
@@ -27,7 +33,7 @@ _DEFAULT_SAMPLES = [
]
def create_single_step_panel(self):
def create_single_step_panel(self: "PQAutomationApp"):
"""创建单步调试面板。"""
frame = ttk.Frame(self.content_frame)
self.single_step_frame = frame
@@ -246,12 +252,12 @@ def create_single_step_panel(self):
_load_default_samples(self)
def toggle_single_step_panel(self):
def toggle_single_step_panel(self: "PQAutomationApp"):
"""切换单步调试面板。"""
self.show_panel("single_step")
def _load_default_samples(self):
def _load_default_samples(self: "PQAutomationApp"):
self.single_step_samples = [dict(item) for item in _DEFAULT_SAMPLES]
_refresh_sample_list(self, select_index=0 if self.single_step_samples else None)
self.single_step_status_var.set(
@@ -259,7 +265,7 @@ def _load_default_samples(self):
)
def _refresh_sample_list(self, select_index=None):
def _refresh_sample_list(self: "PQAutomationApp", select_index=None):
self.single_step_listbox.delete(0, tk.END)
for sample in self.single_step_samples:
self.single_step_listbox.insert(
@@ -280,14 +286,14 @@ def _refresh_sample_list(self, select_index=None):
self.single_step_status_var.set("样本列表为空")
def _on_sample_select(self):
def _on_sample_select(self: "PQAutomationApp"):
selection = self.single_step_listbox.curselection()
if not selection:
return
_select_sample(self, selection[0])
def _select_sample(self, index):
def _select_sample(self: "PQAutomationApp", index):
sample = self.single_step_samples[index]
self.single_step_current_index = index
self.single_step_name_var.set(sample["name"])
@@ -297,7 +303,7 @@ def _select_sample(self, index):
self.single_step_status_var.set(f"当前样本: {sample['name']}")
def _import_samples_csv(self):
def _import_samples_csv(self: "PQAutomationApp"):
path = filedialog.askopenfilename(
title="选择单步调试样本 CSV",
filetypes=[("CSV 文件", "*.csv"), ("所有文件", "*.*")],
@@ -334,7 +340,7 @@ def _import_samples_csv(self):
self.log_gui.log(f"单步调试样本已导入: {len(samples)}", level="success")
def _delete_current_sample(self):
def _delete_current_sample(self: "PQAutomationApp"):
if self.single_step_current_index is None:
return
removed = self.single_step_samples.pop(self.single_step_current_index)
@@ -343,7 +349,7 @@ def _delete_current_sample(self):
self.single_step_status_var.set(f"已删除样本: {removed['name']}")
def _upsert_sample(self):
def _upsert_sample(self: "PQAutomationApp"):
try:
sample = {
"name": self.single_step_name_var.get().strip(),
@@ -387,7 +393,7 @@ def _format_float(value):
return f"{number:.4f}"
def _build_color_patch(self, hex_value):
def _build_color_patch(self: "PQAutomationApp", hex_value):
if not self.signal_service.is_connected:
raise RuntimeError("请先连接 UCD323 设备")
width, height = self.signal_service.current_resolution()
@@ -401,7 +407,7 @@ def _build_color_patch(self, hex_value):
return file_path
def _send_current_patch(self):
def _send_current_patch(self: "PQAutomationApp"):
if self.single_step_current_index is None:
messagebox.showinfo("提示", "请先选择一个样本")
return
@@ -428,7 +434,7 @@ def _send_current_patch(self):
threading.Thread(target=worker, daemon=True).start()
def _measure_current_sample(self):
def _measure_current_sample(self: "PQAutomationApp"):
if self.single_step_current_index is None:
messagebox.showinfo("提示", "请先选择一个样本")
return
@@ -457,7 +463,7 @@ def _measure_current_sample(self):
threading.Thread(target=worker, daemon=True).start()
def _commit_result(self):
def _commit_result(self: "PQAutomationApp"):
if self.single_step_current_index is None:
messagebox.showinfo("提示", "请先选择一个样本")
return
@@ -509,14 +515,14 @@ def _commit_result(self):
self.single_step_status_var.set(f"已记录结果ΔE2000={record['delta_e']}")
def _clear_results(self):
def _clear_results(self: "PQAutomationApp"):
self.single_step_results = []
for item in self.single_step_result_tree.get_children():
self.single_step_result_tree.delete(item)
self.single_step_status_var.set("结果已清空")
def _export_results_csv(self):
def _export_results_csv(self: "PQAutomationApp"):
if not self.single_step_results:
messagebox.showinfo("提示", "暂无可导出的调试结果")
return
@@ -547,4 +553,25 @@ def _export_results_csv(self):
self.log_gui.log(f"单步调试结果已导出: {path}", level="success")
self.single_step_status_var.set(f"结果已导出: {os.path.basename(path)}")
except Exception as exc:
messagebox.showerror("导出失败", f"写入 CSV 失败: {exc}")
messagebox.showerror("导出失败", f"写入 CSV 失败: {exc}")
class SingleStepPanelMixin:
"""由 tools/refactor_to_mixins.py 自动生成。
把本模块的自由函数挂到 PQAutomationApp 上,便于 F12 跳转与类型推断。
"""
create_single_step_panel = create_single_step_panel
toggle_single_step_panel = toggle_single_step_panel
_load_default_samples = _load_default_samples
_refresh_sample_list = _refresh_sample_list
_on_sample_select = _on_sample_select
_select_sample = _select_sample
_import_samples_csv = _import_samples_csv
_delete_current_sample = _delete_current_sample
_upsert_sample = _upsert_sample
_build_color_patch = _build_color_patch
_send_current_patch = _send_current_patch
_measure_current_sample = _measure_current_sample
_commit_result = _commit_result
_clear_results = _clear_results
_export_results_csv = _export_results_csv