优化日志显示

This commit is contained in:
xinzhu.yin
2026-04-21 15:31:48 +08:00
parent 6cc3e55ebb
commit e27312d0a3
22 changed files with 684 additions and 553 deletions

View File

@@ -1,4 +1,4 @@
"""CCT 参数面板及其处理函数(与主文件重构版本保持同步)。"""
"""CCT 参数面板及其处理函数(与主文件重构版本保持同步)。"""
import time
import traceback
@@ -10,7 +10,7 @@ import algorithm.pq_algorithm as pq_algorithm
def create_cct_params_frame(self):
"""创建色度参数设置区域 - 屏模组、SDR、HDR 独立(增加色域参考标准选择 + 单步调试按钮)"""
"""创建色度参数设置区域 - 屏模组、SDR、HDR 独立(增加色域参考标准选择 + 单步调试按钮)"""
# ==================== 屏模组色度参数 Frame ====================
self.cct_params_frame = ttk.LabelFrame(
@@ -84,7 +84,7 @@ def create_cct_params_frame(self):
)
self.screen_gamut_combo = screen_gamut_combo
# ==================== 单步调试按钮(右侧第二行)====================
# ==================== 单步调试按钮(右侧第二行)====================
ttk.Label(self.cct_params_frame, text="单步调试:").grid(
row=1, column=2, sticky=tk.W, padx=(20, 5), pady=3
)
@@ -94,7 +94,7 @@ def create_cct_params_frame(self):
text="打开调试面板",
command=self.toggle_screen_debug_panel,
bootstyle="info-outline",
state=tk.DISABLED, # 初始禁用
# state=tk.DISABLED, # 初始禁用
width=15,
)
self.screen_debug_btn.grid(row=1, column=3, sticky=tk.W, padx=5, pady=3)
@@ -201,7 +201,7 @@ def create_cct_params_frame(self):
sdr_gamut_combo.bind("<<ComboboxSelected>>", self.on_sdr_gamut_ref_changed)
self.sdr_gamut_combo = sdr_gamut_combo
# ==================== SDR 单步调试按钮(右侧第二行)====================
# ==================== SDR 单步调试按钮(右侧第二行)====================
ttk.Label(self.sdr_cct_params_frame, text="单步调试:").grid(
row=1, column=2, sticky=tk.W, padx=(20, 5), pady=3
)
@@ -211,7 +211,7 @@ def create_cct_params_frame(self):
text="打开调试面板",
command=self.toggle_sdr_debug_panel,
bootstyle="info-outline",
state=tk.DISABLED, # 初始禁用
# state=tk.DISABLED, # 初始禁用
width=15,
)
self.sdr_debug_btn.grid(row=1, column=3, sticky=tk.W, padx=5, pady=3)
@@ -318,7 +318,7 @@ def create_cct_params_frame(self):
hdr_gamut_combo.bind("<<ComboboxSelected>>", self.on_hdr_gamut_ref_changed)
self.hdr_gamut_combo = hdr_gamut_combo
# ==================== HDR 单步调试按钮(右侧第二行)====================
# ==================== HDR 单步调试按钮(右侧第二行)====================
ttk.Label(self.hdr_cct_params_frame, text="单步调试:").grid(
row=1, column=2, sticky=tk.W, padx=(20, 5), pady=3
)
@@ -328,7 +328,7 @@ def create_cct_params_frame(self):
text="打开调试面板",
command=self.toggle_hdr_debug_panel,
bootstyle="info-outline",
state=tk.DISABLED, # 初始禁用
# state=tk.DISABLED, # 初始禁用
width=15,
)
self.hdr_debug_btn.grid(row=1, column=3, sticky=tk.W, padx=5, pady=3)
@@ -427,7 +427,7 @@ def _handle_cct_focus_out(self, var, default_value, save_func, label):
if value == "":
var.set(str(default_value))
if hasattr(self, "log_gui"):
self.log_gui.log(f"{label} 参数为空,恢复默认值: {default_value}")
self.log_gui.log(f"{label} 参数为空,恢复默认值: {default_value}", level="success")
else:
try:
float_val = float(value)
@@ -435,19 +435,19 @@ def _handle_cct_focus_out(self, var, default_value, save_func, label):
var.set(str(default_value))
if hasattr(self, "log_gui"):
self.log_gui.log(
f"⚠️ {label} 参数超出范围,恢复默认值: {default_value}"
)
f"{label} 参数超出范围,恢复默认值: {default_value}"
, level="error")
except ValueError:
var.set(str(default_value))
if hasattr(self, "log_gui"):
self.log_gui.log(
f"⚠️ {label} 参数无效,恢复默认值: {default_value}"
)
f"{label} 参数无效,恢复默认值: {default_value}"
, level="error")
save_func()
except Exception as e:
if hasattr(self, "log_gui"):
self.log_gui.log(f"处理 {label} 参数失败: {str(e)}")
self.log_gui.log(f"处理 {label} 参数失败: {str(e)}", level="error")
def on_sdr_cct_param_focus_out(self, var, default_value):
@@ -475,7 +475,7 @@ def recalculate_cct(self):
try:
# 1. 保存新参数
self.save_cct_params()
self.log_gui.log("色度参数已更新")
self.log_gui.log("色度参数已更新", level="success")
# 2. 收起配置项
if hasattr(self, "config_panel_frame"):
@@ -493,7 +493,7 @@ def recalculate_cct(self):
# 4. 检查是否有数据
if not hasattr(self, "results") or not self.results:
self.log_gui.log("⚠️ 没有测试数据,无法重新绘制")
self.log_gui.log("没有测试数据,无法重新绘制", level="error")
messagebox.showwarning("警告", "请先完成测试后再重新计算")
return
@@ -503,14 +503,14 @@ def recalculate_cct(self):
gray_data = self.results.get_intermediate_data("cct", "gray")
if not gray_data or len(gray_data) < 2:
self.log_gui.log("⚠️ 没有可用的灰阶数据")
self.log_gui.log("没有可用的灰阶数据", level="error")
messagebox.showwarning("警告", "没有找到色度测试数据")
return
# 6. 重新计算 CCT
self.log_gui.log("=" * 50)
self.log_gui.log("开始重新计算色度一致性...")
self.log_gui.log("=" * 50)
self.log_gui.log("=" * 50, level="separator")
self.log_gui.log("开始重新计算色度一致性...", level="info")
self.log_gui.log("=" * 50, level="separator")
cct_values = pq_algorithm.calculate_cct_from_results(gray_data)
@@ -521,14 +521,14 @@ def recalculate_cct(self):
test_type = self.config.current_test_type
self.plot_cct(test_type)
self.log_gui.log("色度图已重新绘制")
self.log_gui.log("=" * 50)
self.log_gui.log("色度图已重新绘制", level="success")
self.log_gui.log("=" * 50, level="separator")
messagebox.showinfo("成功", "色度图已根据新参数重新绘制!")
except Exception as e:
self.log_gui.log(f" 重新计算失败: {str(e)}")
self.log_gui.log(traceback.format_exc())
self.log_gui.log(f"[Error] 重新计算失败: {str(e)}", level="error")
self.log_gui.log(traceback.format_exc(), level="error")
messagebox.showerror("错误", f"重新计算失败: {str(e)}")
@@ -551,7 +551,7 @@ def recalculate_gamut(self):
# 3. 检查是否有数据
if not hasattr(self, "results") or not self.results:
self.log_gui.log("⚠️ 没有测试数据,无法重新绘制")
self.log_gui.log("没有测试数据,无法重新绘制", level="error")
messagebox.showwarning("警告", "请先完成测试后再重新计算")
return
@@ -559,7 +559,7 @@ def recalculate_gamut(self):
rgb_data = self.results.get_intermediate_data("gamut", "rgb")
if not rgb_data or len(rgb_data) < 3:
self.log_gui.log("⚠️ 没有可用的色域数据")
self.log_gui.log("没有可用的色域数据", level="error")
messagebox.showwarning("警告", "没有找到色域测试数据")
return
@@ -576,9 +576,9 @@ def recalculate_gamut(self):
else:
reference_standard = "DCI-P3"
self.log_gui.log("=" * 50)
self.log_gui.log(f"开始重新计算色域(参考标准: {reference_standard}...")
self.log_gui.log("=" * 50)
self.log_gui.log("=" * 50, level="separator")
self.log_gui.log(f"开始重新计算色域(参考标准: {reference_standard}...", level="info")
self.log_gui.log("=" * 50, level="separator")
# 7. 重新计算 XY 色域覆盖率
xy_points = [[result[0], result[1]] for result in rgb_data]
@@ -602,10 +602,10 @@ def recalculate_gamut(self):
)
reference_standard = "DCI-P3"
self.log_gui.log(f"参考标准: {reference_standard}")
self.log_gui.log(f"XY 色域覆盖率: {coverage_xy:.1f}%")
self.log_gui.log(f"参考标准: {reference_standard}", level="success")
self.log_gui.log(f"XY 色域覆盖率: {coverage_xy:.1f}%", level="success")
# ========== ✅✅8. 重新计算 UV 色域覆盖率 ==========
# ========== ✅✅8. 重新计算 UV 色域覆盖率 ==========
# 将 XY 坐标转换为 UV 坐标
uv_points = []
for x, y in xy_points:
@@ -621,7 +621,7 @@ def recalculate_gamut(self):
except ZeroDivisionError:
continue
self.log_gui.log(f"转换后的 UV 点数量: {len(uv_points)}")
self.log_gui.log(f"转换后的 UV 点数量: {len(uv_points)}", level="success")
# 根据参考标准计算 UV 覆盖率
if reference_standard == "BT.2020":
@@ -641,10 +641,10 @@ def recalculate_gamut(self):
uv_points
)
self.log_gui.log(f"UV 色域覆盖率: {coverage_uv:.1f}%")
self.log_gui.log(f"UV 色域覆盖率: {coverage_uv:.1f}%", level="success")
# ========================================================
# 9. 更新结果(同时保存 XY 和 UV 覆盖率)
# 9. 更新结果(同时保存 XY 和 UV 覆盖率)
self.results.set_test_item_result(
"gamut",
{
@@ -659,13 +659,13 @@ def recalculate_gamut(self):
},
)
self.log_gui.log("测试结果已更新到 results 对象")
self.log_gui.log("测试结果已更新到 results 对象", level="success")
# 10. 重新绘制色域图
self.plot_gamut(rgb_data, coverage_xy, test_type)
self.log_gui.log("色域图已重新绘制")
self.log_gui.log("=" * 50)
self.log_gui.log("色域图已重新绘制", level="success")
self.log_gui.log("=" * 50, level="separator")
messagebox.showinfo(
"成功",
@@ -675,8 +675,8 @@ def recalculate_gamut(self):
)
except Exception as e:
self.log_gui.log(f" 重新计算失败: {str(e)}")
self.log_gui.log(traceback.format_exc())
self.log_gui.log(f"[Error] 重新计算失败: {str(e)}", level="error")
self.log_gui.log(traceback.format_exc(), level="error")
messagebox.showerror("错误", f"重新计算失败: {str(e)}")
@@ -709,7 +709,7 @@ def reload_cct_params(self):
except Exception as e:
if hasattr(self, "log_gui"):
self.log_gui.log(f"重新加载色度参数失败: {str(e)}")
self.log_gui.log(f"重新加载色度参数失败: {str(e)}", level="error")
def toggle_cct_params_frame(self):
@@ -743,7 +743,7 @@ def toggle_cct_params_frame(self):
self.hdr_cct_params_frame.pack(fill=tk.X, padx=5, pady=5)
else:
if hasattr(self, "log_gui"):
self.log_gui.log("[ERROR] HDR 色度参数框尚未创建")
self.log_gui.log("[ERROR] HDR 色度参数框尚未创建", level="error")
# ---- gamut 参考标准改变回调(统一实现) ----
@@ -758,14 +758,14 @@ def _on_gamut_ref_changed(self, test_type, event=None):
cfg = _GAMUT_REF_CONFIGS[test_type]
try:
new_ref = getattr(self, cfg["var_attr"]).get()
self.log_gui.log(f"{cfg['label']} 色域参考标准已更改为: {new_ref}")
self.log_gui.log(f"{cfg['label']} 色域参考标准已更改为: {new_ref}", level="success")
if test_type not in self.config.current_test_types:
self.config.current_test_types[test_type] = {}
self.config.current_test_types[test_type]["gamut_reference"] = new_ref
self.save_pq_config()
except Exception as e:
self.log_gui.log(f"保存 {cfg['label']} 色域参考标准失败: {str(e)}")
self.log_gui.log(f"保存 {cfg['label']} 色域参考标准失败: {str(e)}", level="error")
def on_screen_gamut_ref_changed(self, event=None):