优化日志显示
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import ttkbootstrap as ttk
|
||||
import ttkbootstrap as ttk
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox, filedialog
|
||||
import sys
|
||||
@@ -246,7 +246,7 @@ class PQAutomationApp:
|
||||
self.change_test_type("screen_module")
|
||||
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")
|
||||
|
||||
get_config_path = _cfg_get_config_path
|
||||
load_pq_config = _cfg_load_pq_config
|
||||
@@ -360,7 +360,7 @@ class PQAutomationApp:
|
||||
if not swallow_errors:
|
||||
raise
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log(f"保存参数失败: {str(e)}")
|
||||
self.log_gui.log(f"保存参数失败: {str(e)}", level="error")
|
||||
|
||||
def _save_cct_params_before_test_type_switch(self):
|
||||
"""切换测试类型前,按当前类型保存色度参数。"""
|
||||
@@ -376,10 +376,10 @@ class PQAutomationApp:
|
||||
if combo is not None:
|
||||
combo.configure(state=state)
|
||||
if success_msg and hasattr(self, "log_gui"):
|
||||
self.log_gui.log(success_msg)
|
||||
self.log_gui.log(success_msg, level="success")
|
||||
except Exception as e:
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log(f"{error_prefix}: {str(e)}")
|
||||
self.log_gui.log(f"{error_prefix}: {str(e)}", level="error")
|
||||
|
||||
def _hide_recalc_buttons(self, include_gamut=False):
|
||||
"""隐藏重新计算按钮。include_gamut=True 时同时隐藏色域重算按钮。"""
|
||||
@@ -403,15 +403,15 @@ class PQAutomationApp:
|
||||
if hasattr(self, "debug_panel"):
|
||||
try:
|
||||
self.debug_panel.disable_all_debug()
|
||||
self.log_gui.log("✓ 单步调试已禁用")
|
||||
self.log_gui.log("单步调试已禁用", level="success")
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"[Error] 禁用单步调试失败: {str(e)}")
|
||||
self.log_gui.log(f"[Error] 禁用单步调试失败: {str(e)}", level="error")
|
||||
if hasattr(self, "debug_container"):
|
||||
try:
|
||||
self.debug_container.pack_forget()
|
||||
self.log_gui.log("✓ 单步调试面板已隐藏")
|
||||
self.log_gui.log("单步调试面板已隐藏", level="success")
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"[Error] 隐藏调试面板失败: {str(e)}")
|
||||
self.log_gui.log(f"[Error] 隐藏调试面板失败: {str(e)}", level="error")
|
||||
|
||||
def _set_config_panel_btn_state(self, state):
|
||||
"""统一设置配置面板按钮状态(disabled/normal)。"""
|
||||
@@ -428,13 +428,13 @@ class PQAutomationApp:
|
||||
if hasattr(self, "config") and hasattr(self.config, "set_current_test_type"):
|
||||
success = self.config.set_current_test_type(test_type)
|
||||
if not success and hasattr(self, "log_gui"):
|
||||
self.log_gui.log(f"切换测试类型失败: {test_type}")
|
||||
self.log_gui.log(f"切换测试类型失败: {test_type}", level="error")
|
||||
|
||||
def _switch_signal_format_tabs(self, test_type):
|
||||
"""切换信号格式 Tab 到目标测试类型。"""
|
||||
if not hasattr(self, "signal_tabs"):
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log("[Error] signal_tabs 尚未创建")
|
||||
self.log_gui.log("[Error] signal_tabs 尚未创建", level="error")
|
||||
return
|
||||
|
||||
try:
|
||||
@@ -465,10 +465,10 @@ class PQAutomationApp:
|
||||
|
||||
if hasattr(self, "log_gui"):
|
||||
tab_names = ["屏模组测试", "SDR测试", "HDR"]
|
||||
self.log_gui.log(f"✓ 已切换到 {tab_names[target_tab]} 信号格式")
|
||||
self.log_gui.log(f"已切换到 {tab_names[target_tab]} 信号格式", level="success")
|
||||
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 _switch_chart_tabs_by_test_type(self, test_type):
|
||||
"""按测试类型切换 Gamma/EOTF 与客户模板结果 Tab。"""
|
||||
@@ -485,23 +485,23 @@ class PQAutomationApp:
|
||||
gamma_index = current_tabs.index(gamma_tab_id)
|
||||
self.chart_notebook.forget(gamma_index)
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log("✓ 已隐藏 Gamma 曲线 Tab")
|
||||
self.log_gui.log("已隐藏 Gamma 曲线 Tab", level="success")
|
||||
|
||||
if eotf_tab_id not in current_tabs:
|
||||
self.chart_notebook.insert(1, self.eotf_chart_frame, text="EOTF 曲线")
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log("✓ 已显示 EOTF 曲线 Tab")
|
||||
self.log_gui.log("已显示 EOTF 曲线 Tab", level="success")
|
||||
else:
|
||||
if eotf_tab_id in current_tabs:
|
||||
eotf_index = current_tabs.index(eotf_tab_id)
|
||||
self.chart_notebook.forget(eotf_index)
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log("✓ 已隐藏 EOTF 曲线 Tab")
|
||||
self.log_gui.log("已隐藏 EOTF 曲线 Tab", level="success")
|
||||
|
||||
if gamma_tab_id not in current_tabs:
|
||||
self.chart_notebook.insert(1, self.gamma_chart_frame, text="Gamma 曲线")
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log("✓ 已显示 Gamma 曲线 Tab")
|
||||
self.log_gui.log("已显示 Gamma 曲线 Tab", level="success")
|
||||
|
||||
custom_tab_id = str(self.custom_template_tab_frame)
|
||||
current_tabs = list(self.chart_notebook.tabs())
|
||||
@@ -510,17 +510,17 @@ class PQAutomationApp:
|
||||
if custom_tab_id not in current_tabs:
|
||||
self.chart_notebook.add(self.custom_template_tab_frame, text="客户模板结果显示")
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log("✓ 已显示客户模板结果 Tab")
|
||||
self.log_gui.log("已显示客户模板结果 Tab", level="success")
|
||||
else:
|
||||
if custom_tab_id in current_tabs:
|
||||
self.chart_notebook.forget(self.custom_template_tab_frame)
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log("✓ 已隐藏客户模板结果 Tab")
|
||||
self.log_gui.log("已隐藏客户模板结果 Tab", level="success")
|
||||
|
||||
self.chart_notebook.update_idletasks()
|
||||
except Exception as e:
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log(f"切换 Gamma/EOTF Tab 失败: {str(e)}")
|
||||
self.log_gui.log(f"切换 Gamma/EOTF Tab 失败: {str(e)}", level="error")
|
||||
|
||||
def change_test_type(self, test_type):
|
||||
"""切换测试类型"""
|
||||
@@ -637,9 +637,9 @@ class PQAutomationApp:
|
||||
def _signal_stop_and_update_ui(self):
|
||||
"""设置停止标志并立即更新 UI 以反馈给用户。"""
|
||||
self.testing = False
|
||||
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")
|
||||
self.stop_btn.config(state=tk.DISABLED)
|
||||
self.status_var.set("正在停止测试,请稍候...")
|
||||
self.root.update()
|
||||
@@ -648,24 +648,24 @@ class PQAutomationApp:
|
||||
"""等待测试线程结束,最多 timeout_seconds 秒,同时保持 UI 响应。"""
|
||||
if not (self.test_thread and self.test_thread.is_alive()):
|
||||
return
|
||||
self.log_gui.log("等待测试线程结束...")
|
||||
self.log_gui.log("等待测试线程结束...", level="info")
|
||||
for _ in range(int(timeout_seconds * 10)):
|
||||
if not self.test_thread.is_alive():
|
||||
break
|
||||
time.sleep(0.1)
|
||||
self.root.update()
|
||||
if self.test_thread.is_alive():
|
||||
self.log_gui.log("[Error] 测试线程未能正常结束,将在后台继续等待")
|
||||
self.log_gui.log("[Error] 测试线程未能正常结束,将在后台继续等待", level="error")
|
||||
else:
|
||||
self.log_gui.log("✓ 测试线程已结束")
|
||||
self.log_gui.log("测试线程已结束", level="success")
|
||||
|
||||
def _clear_test_data(self):
|
||||
"""清空测试结果对象与中间数据缓存。"""
|
||||
try:
|
||||
self.log_gui.log("清理测试数据...")
|
||||
self.log_gui.log("清理测试数据...", level="info")
|
||||
if hasattr(self, "results"):
|
||||
self.results = None
|
||||
self.log_gui.log(" ✓ 测试结果对象已清空")
|
||||
self.log_gui.log(" 测试结果对象已清空", level="success")
|
||||
for attr in [
|
||||
"gamut_results",
|
||||
"gamma_results",
|
||||
@@ -675,28 +675,28 @@ class PQAutomationApp:
|
||||
]:
|
||||
if hasattr(self, attr):
|
||||
setattr(self, attr, None)
|
||||
self.log_gui.log(" ✓ 所有中间数据已清空")
|
||||
self.log_gui.log(" 所有中间数据已清空", level="success")
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"[Error] 清理数据时出错: {str(e)}")
|
||||
self.log_gui.log(f"[Error] 清理数据时出错: {str(e)}", level="error")
|
||||
|
||||
def _clear_charts_and_tables(self):
|
||||
"""清空图表与客户模板结果表格,并跳转到色域图 Tab。"""
|
||||
try:
|
||||
self.clear_chart()
|
||||
self.log_gui.log("✓ 图表已清空")
|
||||
self.log_gui.log("图表已清空", level="success")
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"[Error] 清空图表时出错: {str(e)}")
|
||||
self.log_gui.log(f"[Error] 清空图表时出错: {str(e)}", level="error")
|
||||
try:
|
||||
self.clear_custom_template_results()
|
||||
self.log_gui.log("✓ 客户模板结果表格已清空")
|
||||
self.log_gui.log("客户模板结果表格已清空", level="success")
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"[Error] 清空客户模板结果表格失败: {str(e)}")
|
||||
self.log_gui.log(f"[Error] 清空客户模板结果表格失败: {str(e)}", level="error")
|
||||
try:
|
||||
if hasattr(self, "chart_notebook"):
|
||||
self.chart_notebook.select(self.gamut_chart_frame)
|
||||
self.root.update_idletasks()
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"[Error] 跳转到色域图失败: {str(e)}")
|
||||
self.log_gui.log(f"[Error] 跳转到色域图失败: {str(e)}", level="error")
|
||||
|
||||
def _restore_ui_after_stop(self):
|
||||
"""恢复主按钮与状态栏到非测试态。"""
|
||||
@@ -718,16 +718,16 @@ class PQAutomationApp:
|
||||
self._restore_ui_after_stop()
|
||||
self._set_gamut_combos_state(
|
||||
"disabled",
|
||||
success_msg="✓ 色域参考标准已禁用",
|
||||
success_msg="色域参考标准已禁用",
|
||||
error_prefix="禁用色域参考标准失败",
|
||||
)
|
||||
hidden = self._hide_recalc_buttons(include_gamut=True)
|
||||
if hidden > 0:
|
||||
self.log_gui.log(f"✓ 已隐藏 {hidden} 个重新计算按钮")
|
||||
self.log_gui.log(f"已隐藏 {hidden} 个重新计算按钮", level="success")
|
||||
self._disable_debug_panel()
|
||||
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="success")
|
||||
self.log_gui.log("=" * 50, level="separator")
|
||||
messagebox.showinfo(
|
||||
"测试已停止",
|
||||
"测试已停止,本次测试数据已清空。\n\n可以重新开始新的测试。",
|
||||
@@ -760,8 +760,8 @@ class PQAutomationApp:
|
||||
selected_items = self.get_selected_test_items()
|
||||
log = self.log_gui.log
|
||||
|
||||
log(f"保存测试类型: {current_test_type}")
|
||||
log(f"已选测试项: {selected_items}")
|
||||
log(f"保存测试类型: {current_test_type}", level="info")
|
||||
log(f"已选测试项: {selected_items}", level="info")
|
||||
|
||||
# 1) 图片
|
||||
_save_result_images_impl(
|
||||
@@ -779,16 +779,16 @@ class PQAutomationApp:
|
||||
)
|
||||
|
||||
# 3) 成功提示
|
||||
log("=" * 50)
|
||||
log(f"测试结果已保存到目录: {result_dir}")
|
||||
log("=" * 50)
|
||||
log("=" * 50, level="separator")
|
||||
log(f"测试结果已保存到目录: {result_dir}", level="success")
|
||||
log("=" * 50, level="separator")
|
||||
messagebox.showinfo("成功", f"测试结果已保存到目录:\n{result_dir}")
|
||||
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"[Error] 保存测试结果失败: {str(e)}")
|
||||
self.log_gui.log(f"[Error] 保存测试结果失败: {str(e)}", level="error")
|
||||
import traceback
|
||||
|
||||
self.log_gui.log(traceback.format_exc())
|
||||
self.log_gui.log(traceback.format_exc(), level="error")
|
||||
messagebox.showerror("错误", f"保存测试结果失败: {str(e)}")
|
||||
|
||||
new_pq_results = _run_new_pq_results
|
||||
@@ -862,7 +862,7 @@ class PQAutomationApp:
|
||||
self.save_pq_config()
|
||||
|
||||
except Exception as e:
|
||||
self.log_gui.log(f"[Error] 更新配置失败: {str(e)}")
|
||||
self.log_gui.log(f"[Error] 更新配置失败: {str(e)}", level="error")
|
||||
|
||||
def update_config_and_tabs(self):
|
||||
"""更新配置并同步Tab状态"""
|
||||
@@ -879,7 +879,7 @@ class PQAutomationApp:
|
||||
def on_closing(self):
|
||||
"""窗口关闭时的处理"""
|
||||
try:
|
||||
# ✅ 检查是否清理了配置
|
||||
# 检查是否清理了配置
|
||||
if not self.config_cleared:
|
||||
# 保存配置
|
||||
self.save_pq_config()
|
||||
|
||||
Reference in New Issue
Block a user