继续优化色准测试结果显示模块
This commit is contained in:
@@ -408,20 +408,27 @@ def init_contrast_chart(self: "PQAutomationApp"):
|
||||
def init_accuracy_chart(self: "PQAutomationApp"):
|
||||
"""初始化色准图表 - 固定大小,居中显示"""
|
||||
container = ttk.Frame(self.accuracy_chart_frame)
|
||||
container.pack(expand=True)
|
||||
container.pack(expand=True, fill=tk.BOTH)
|
||||
container.grid_rowconfigure(0, weight=1)
|
||||
container.grid_rowconfigure(1, weight=0, minsize=220)
|
||||
container.grid_columnconfigure(0, weight=1)
|
||||
|
||||
# 上方图表优先显示;下方表格固定高度,避免挤占图表区域。
|
||||
plot_container = ttk.Frame(container)
|
||||
plot_container.grid(row=0, column=0, sticky="nsew")
|
||||
|
||||
table_container = ttk.LabelFrame(container, text="色准明细")
|
||||
table_container.grid(row=1, column=0, sticky="ew", padx=4, pady=(2, 4))
|
||||
|
||||
self.accuracy_fig = plt.Figure(
|
||||
figsize=(10, 6),
|
||||
dpi=100,
|
||||
tight_layout=False,
|
||||
)
|
||||
self.accuracy_canvas = FigureCanvasTkAgg(self.accuracy_fig, master=container)
|
||||
self.accuracy_canvas = FigureCanvasTkAgg(self.accuracy_fig, master=plot_container)
|
||||
|
||||
canvas_widget = self.accuracy_canvas.get_tk_widget()
|
||||
canvas_widget.pack()
|
||||
|
||||
canvas_widget.config(width=1000, height=600)
|
||||
canvas_widget.pack_propagate(False)
|
||||
canvas_widget.pack(fill=tk.BOTH, expand=True)
|
||||
|
||||
self.accuracy_ax = self.accuracy_fig.add_subplot(111)
|
||||
self.accuracy_ax.set_xlim(0, 1)
|
||||
@@ -439,6 +446,134 @@ def init_accuracy_chart(self: "PQAutomationApp"):
|
||||
)
|
||||
|
||||
self.accuracy_canvas.draw()
|
||||
self._init_accuracy_result_table(table_container)
|
||||
|
||||
|
||||
def _init_accuracy_result_table(self: "PQAutomationApp", parent):
|
||||
"""创建色准结果表格(支持横向/纵向滚动)。"""
|
||||
table_wrap = ttk.Frame(parent)
|
||||
table_wrap.pack(fill=tk.BOTH, expand=True, padx=2, pady=2)
|
||||
|
||||
self.accuracy_result_table = ttk.Treeview(
|
||||
table_wrap,
|
||||
show="headings",
|
||||
height=7,
|
||||
)
|
||||
|
||||
x_scroll = ttk.Scrollbar(
|
||||
table_wrap,
|
||||
orient=tk.HORIZONTAL,
|
||||
command=self.accuracy_result_table.xview,
|
||||
)
|
||||
y_scroll = ttk.Scrollbar(
|
||||
table_wrap,
|
||||
orient=tk.VERTICAL,
|
||||
command=self.accuracy_result_table.yview,
|
||||
)
|
||||
self.accuracy_result_table.configure(
|
||||
xscrollcommand=x_scroll.set,
|
||||
yscrollcommand=y_scroll.set,
|
||||
)
|
||||
|
||||
self.accuracy_result_table.grid(row=0, column=0, sticky="nsew")
|
||||
y_scroll.grid(row=0, column=1, sticky="ns")
|
||||
x_scroll.grid(row=1, column=0, sticky="ew")
|
||||
table_wrap.grid_rowconfigure(0, weight=1)
|
||||
table_wrap.grid_columnconfigure(0, weight=1)
|
||||
|
||||
self.clear_accuracy_result_table()
|
||||
|
||||
|
||||
def clear_accuracy_result_table(self: "PQAutomationApp"):
|
||||
"""清空色准表格并恢复占位内容。"""
|
||||
if not hasattr(self, "accuracy_result_table"):
|
||||
return
|
||||
|
||||
tree = self.accuracy_result_table
|
||||
tree.delete(*tree.get_children())
|
||||
|
||||
columns = ("metric", "value")
|
||||
tree.configure(columns=columns)
|
||||
tree.heading("metric", text="项目")
|
||||
tree.heading("value", text="值")
|
||||
tree.column("metric", width=150, anchor="w", stretch=False)
|
||||
tree.column("value", width=300, anchor="w", stretch=True)
|
||||
|
||||
tree.insert("", tk.END, values=("状态", "等待色准测试数据..."))
|
||||
|
||||
|
||||
def update_accuracy_result_table(self: "PQAutomationApp", accuracy_data, standards):
|
||||
"""更新色准表格:按指标行 + 色块列展示,可横向滚动浏览。"""
|
||||
if not hasattr(self, "accuracy_result_table"):
|
||||
return
|
||||
|
||||
tree = self.accuracy_result_table
|
||||
tree.delete(*tree.get_children())
|
||||
|
||||
color_patches = accuracy_data.get("color_patches", []) or []
|
||||
measurements = accuracy_data.get("color_measurements", []) or []
|
||||
delta_e_values = accuracy_data.get("delta_e_values", []) or []
|
||||
delta_e_itp_values = accuracy_data.get("delta_e_itp_values", []) or []
|
||||
|
||||
if not color_patches:
|
||||
self.clear_accuracy_result_table()
|
||||
return
|
||||
|
||||
columns = ["metric"] + [f"c{i}" for i in range(len(color_patches))]
|
||||
tree.configure(columns=columns)
|
||||
|
||||
tree.heading("metric", text="项目")
|
||||
tree.column("metric", width=140, anchor="w", stretch=False)
|
||||
|
||||
for i, name in enumerate(color_patches):
|
||||
col = f"c{i}"
|
||||
tree.heading(col, text=name)
|
||||
tree.column(col, width=96, anchor="center", stretch=False)
|
||||
|
||||
def fmt(v, digits=4):
|
||||
if isinstance(v, (int, float)):
|
||||
return f"{v:.{digits}f}"
|
||||
return "N/A"
|
||||
|
||||
row_x = ["x: CIE31"]
|
||||
row_y = ["y: CIE31"]
|
||||
row_Y = ["Y"]
|
||||
row_tx = ["Target x:CIE31"]
|
||||
row_ty = ["Target y:CIE31"]
|
||||
row_de2000 = ["ΔE 2000"]
|
||||
|
||||
include_itp = bool(delta_e_itp_values)
|
||||
row_deitp = ["ΔE ITP"] if include_itp else None
|
||||
|
||||
for i, name in enumerate(color_patches):
|
||||
m = measurements[i] if i < len(measurements) else None
|
||||
sx, sy = standards.get(name, (None, None))
|
||||
|
||||
if m is not None and len(m) >= 3:
|
||||
row_x.append(fmt(m[0], 4))
|
||||
row_y.append(fmt(m[1], 4))
|
||||
row_Y.append(fmt(m[2], 4))
|
||||
else:
|
||||
row_x.append("N/A")
|
||||
row_y.append("N/A")
|
||||
row_Y.append("N/A")
|
||||
|
||||
row_tx.append(fmt(sx, 4))
|
||||
row_ty.append(fmt(sy, 4))
|
||||
|
||||
de = delta_e_values[i] if i < len(delta_e_values) else None
|
||||
row_de2000.append(fmt(de, 4))
|
||||
|
||||
if include_itp and row_deitp is not None:
|
||||
ditp = delta_e_itp_values[i] if i < len(delta_e_itp_values) else None
|
||||
row_deitp.append(fmt(ditp, 4))
|
||||
|
||||
rows = [row_x, row_y, row_Y, row_tx, row_ty, row_de2000]
|
||||
if include_itp and row_deitp is not None:
|
||||
rows.append(row_deitp)
|
||||
|
||||
for row in rows:
|
||||
tree.insert("", tk.END, values=row)
|
||||
|
||||
def clear_chart(self: "PQAutomationApp"):
|
||||
"""清空所有图表"""
|
||||
@@ -735,6 +870,9 @@ def clear_chart(self: "PQAutomationApp"):
|
||||
|
||||
self.accuracy_canvas.draw()
|
||||
|
||||
# 清空色准明细表格
|
||||
self.clear_accuracy_result_table()
|
||||
|
||||
def update_chart_tabs_state(self: "PQAutomationApp"):
|
||||
"""根据测试项目复选框状态动态增删图表 Tab(保持规范顺序)。
|
||||
|
||||
@@ -888,6 +1026,9 @@ class ChartFrameMixin:
|
||||
init_cct_chart = init_cct_chart
|
||||
init_contrast_chart = init_contrast_chart
|
||||
init_accuracy_chart = init_accuracy_chart
|
||||
_init_accuracy_result_table = _init_accuracy_result_table
|
||||
clear_accuracy_result_table = clear_accuracy_result_table
|
||||
update_accuracy_result_table = update_accuracy_result_table
|
||||
clear_chart = clear_chart
|
||||
update_chart_tabs_state = update_chart_tabs_state
|
||||
create_result_chart_frame = create_result_chart_frame
|
||||
|
||||
@@ -634,16 +634,6 @@ def recalculate_gamut(self: "PQAutomationApp"):
|
||||
# 10. 重新绘制色域图
|
||||
self.plot_gamut(rgb_data, coverage_xy, test_type)
|
||||
|
||||
self.log_gui.log("色域图已重新绘制", level="success")
|
||||
self.log_gui.log("=" * 50, level="separator")
|
||||
|
||||
messagebox.showinfo(
|
||||
"成功",
|
||||
f"色域图已根据新参考标准 {reference_standard} 重新绘制!\n\n"
|
||||
f"XY 覆盖率: {coverage_xy:.1f}%\n"
|
||||
f"UV 覆盖率: {coverage_uv:.1f}%",
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"重新计算失败: {str(e)}", level="error")
|
||||
self.log_gui.log(traceback.format_exc(), level="error")
|
||||
|
||||
@@ -590,6 +590,14 @@ def create_operation_frame(self: "PQAutomationApp"):
|
||||
)
|
||||
self.start_btn.pack(side=tk.LEFT, padx=5)
|
||||
|
||||
self.simulate_btn = ttk.Button(
|
||||
operation_frame,
|
||||
text="模拟测试",
|
||||
command=self.run_simulation_test,
|
||||
style="warning.TButton",
|
||||
)
|
||||
self.simulate_btn.pack(side=tk.LEFT, padx=5)
|
||||
|
||||
self.stop_btn = ttk.Button(
|
||||
operation_frame,
|
||||
text="停止测试",
|
||||
|
||||
Reference in New Issue
Block a user