From a2bfd6d12378032d22b47525f9c94e93ff593947 Mon Sep 17 00:00:00 2001 From: "xinzhu.yin" Date: Mon, 20 Apr 2026 17:33:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=8F=90=E5=8F=96=E9=83=A8?= =?UTF-8?q?=E5=88=86=E9=9D=A2=E6=9D=BF=E5=88=87=E6=8D=A2=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pqAutomationApp.py | 336 +++++++++++++++------------------------------ 1 file changed, 107 insertions(+), 229 deletions(-) diff --git a/pqAutomationApp.py b/pqAutomationApp.py index d6d2d7d..a296395 100644 --- a/pqAutomationApp.py +++ b/pqAutomationApp.py @@ -3651,272 +3651,150 @@ class PQAutomationApp: print(f"关闭窗口时出错: {str(e)}") self.root.destroy() - def on_screen_gamut_ref_changed(self, event=None): - """屏模组色域参考标准改变时的回调""" + # ---- gamut 参考标准改变回调(统一实现) ---- + _GAMUT_REF_CONFIGS = { + "screen_module": {"var_attr": "screen_gamut_ref_var", "label": "屏模组"}, + "sdr_movie": {"var_attr": "sdr_gamut_ref_var", "label": "SDR"}, + "hdr_movie": {"var_attr": "hdr_gamut_ref_var", "label": "HDR"}, + } + + def _on_gamut_ref_changed(self, test_type, event=None): + cfg = self._GAMUT_REF_CONFIGS[test_type] try: - new_ref = self.screen_gamut_ref_var.get() - self.log_gui.log(f"✓ 屏模组色域参考标准已更改为: {new_ref}") + new_ref = getattr(self, cfg["var_attr"]).get() + self.log_gui.log(f"✓ {cfg['label']} 色域参考标准已更改为: {new_ref}") - # 保存到配置 - if "screen_module" not in self.config.current_test_types: - self.config.current_test_types["screen_module"] = {} - - self.config.current_test_types["screen_module"]["gamut_reference"] = new_ref + 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"保存屏模组色域参考标准失败: {str(e)}") + self.log_gui.log(f"保存 {cfg['label']} 色域参考标准失败: {str(e)}") + + def on_screen_gamut_ref_changed(self, event=None): + self._on_gamut_ref_changed("screen_module", event) def on_sdr_gamut_ref_changed(self, event=None): - """SDR 色域参考标准改变时的回调""" - try: - new_ref = self.sdr_gamut_ref_var.get() - self.log_gui.log(f"✓ SDR 色域参考标准已更改为: {new_ref}") - - # 保存到配置 - if "sdr_movie" not in self.config.current_test_types: - self.config.current_test_types["sdr_movie"] = {} - - self.config.current_test_types["sdr_movie"]["gamut_reference"] = new_ref - self.save_pq_config() - - except Exception as e: - self.log_gui.log(f"保存 SDR 色域参考标准失败: {str(e)}") + self._on_gamut_ref_changed("sdr_movie", event) def on_hdr_gamut_ref_changed(self, event=None): - """HDR 色域参考标准改变时的回调""" - try: - new_ref = self.hdr_gamut_ref_var.get() - self.log_gui.log(f"✓ HDR 色域参考标准已更改为: {new_ref}") + self._on_gamut_ref_changed("hdr_movie", event) - # 保存到配置 - if "hdr_movie" not in self.config.current_test_types: - self.config.current_test_types["hdr_movie"] = {} + # ---- 单步调试面板(统一实现) ---- + _DEBUG_PANEL_CONFIGS = { + "screen_module": { + "window_attr": "debug_window", + "btn_attr": "screen_debug_btn", + "title": "🔧 单步调试面板", + "window_log_prefix": "", + "data_log_prefix": "屏模组", + "failure_data_label": "调试数据", + # (item_key, debug_key, (category, subkey), data_label, enable_desc) + "data_items": [ + ("gamma", "gamma", ("shared", "gray"), "灰阶", "Gamma 单步调试"), + ("gamut", "rgb", ("gamut", "rgb"), "RGB", "RGB 单步调试"), + ], + }, + "sdr_movie": { + "window_attr": "sdr_debug_window", + "btn_attr": "sdr_debug_btn", + "title": "🔧 SDR 单步调试面板", + "window_log_prefix": "SDR ", + "data_log_prefix": "SDR", + "failure_data_label": "SDR 调试数据", + "data_items": [ + ("gamma", "gamma", ("shared", "gray"), "灰阶", "Gamma 单步调试"), + ("accuracy", "accuracy", ("accuracy", "measured"), "色准", "色准单步调试"), + ("gamut", "rgb", ("gamut", "rgb"), "RGB", "RGB 单步调试"), + ], + }, + "hdr_movie": { + "window_attr": "hdr_debug_window", + "btn_attr": "hdr_debug_btn", + "title": "🔧 HDR 单步调试面板", + "window_log_prefix": "HDR ", + "data_log_prefix": "HDR", + "failure_data_label": "HDR 调试数据", + "data_items": [ + ("eotf", "eotf", ("shared", "gray"), "灰阶", "EOTF 单步调试"), + ("accuracy", "accuracy", ("accuracy", "measured"), "色准", "色准单步调试"), + ("gamut", "rgb", ("gamut", "rgb"), "RGB", "RGB 单步调试"), + ], + }, + } - self.config.current_test_types["hdr_movie"]["gamut_reference"] = new_ref - self.save_pq_config() + def _toggle_debug_panel(self, test_type): + """打开/关闭对应测试类型的单步调试面板(独立窗口)。""" + cfg = self._DEBUG_PANEL_CONFIGS[test_type] + win_attr = cfg["window_attr"] + btn = getattr(self, cfg["btn_attr"]) + wlp = cfg["window_log_prefix"] - except Exception as e: - self.log_gui.log(f"保存 HDR 色域参考标准失败: {str(e)}") - - def toggle_screen_debug_panel(self): - """打开/关闭屏模组单步调试面板(独立窗口)""" # 如果窗口已存在且可见,关闭它 - if hasattr(self, "debug_window") and self.debug_window.winfo_exists(): - self.debug_window.destroy() - self.screen_debug_btn.config(text="打开调试面板") - self.log_gui.log("✓ 单步调试面板已关闭") + existing = getattr(self, win_attr, None) + if existing is not None and existing.winfo_exists(): + existing.destroy() + btn.config(text="打开调试面板") + self.log_gui.log(f"✓ {wlp}单步调试面板已关闭") return # 创建新窗口 - self.debug_window = ttk.Toplevel(self.root) - self.debug_window.title("🔧 单步调试面板") - self.debug_window.geometry("900x400") - self.debug_window.transient(self.root) + win = ttk.Toplevel(self.root) + win.title(cfg["title"]) + win.geometry("900x400") + win.transient(self.root) + setattr(self, win_attr, win) - # 创建调试面板容器 - debug_container = ttk.Frame(self.debug_window, padding=10) - debug_container.pack(fill=tk.BOTH, expand=True) # ← 这个 pack 是对的 + # 调试面板容器 + debug_container = ttk.Frame(win, padding=10) + debug_container.pack(fill=tk.BOTH, expand=True) - # 创建调试面板实例 + # 创建调试面板实例(不要对它调用 pack) debug_panel_instance = PQDebugPanel(debug_container, self) - # ← 这里不应该有任何 pack 调用! - self.log_gui.log("✓ 单步调试面板实例已创建") + self.log_gui.log(f"✓ {wlp}单步调试面板实例已创建") # 重新启用调试(如果有数据) try: - test_type = self.config.current_test_type selected_items = self.get_selected_test_items() - - if test_type == "screen_module": - if "gamma" in selected_items: - gray_data = self.results.get_intermediate_data("shared", "gray") - if gray_data: - self.log_gui.log(f" → 加载 {len(gray_data)} 个灰阶数据点") - debug_panel_instance.enable_debug( - "screen_module", "gamma", gray_data - ) - self.log_gui.log("✓ 屏模组 Gamma 单步调试已重新启用") - else: + dlp = cfg["data_log_prefix"] + for item_key, debug_key, (cat, sub), data_label, enable_desc in cfg["data_items"]: + if item_key not in selected_items: + continue + data = self.results.get_intermediate_data(cat, sub) + if not data: + if test_type == "screen_module" and item_key == "gamma": self.log_gui.log(" ✗ 没有可用的灰阶数据") - - if "gamut" in selected_items: - rgb_data = self.results.get_intermediate_data("gamut", "rgb") - if rgb_data: - self.log_gui.log(f" → 加载 {len(rgb_data)} 个RGB数据点") - debug_panel_instance.enable_debug( - "screen_module", "rgb", rgb_data - ) - self.log_gui.log("✓ 屏模组 RGB 单步调试已重新启用") - + continue + self.log_gui.log(f" → 加载 {len(data)} 个{data_label}数据点") + debug_panel_instance.enable_debug(test_type, debug_key, data) + self.log_gui.log(f"✓ {dlp} {enable_desc}已重新启用") except Exception as e: - self.log_gui.log(f"⚠️ 加载调试数据失败: {str(e)}") + self.log_gui.log(f"⚠️ 加载{cfg['failure_data_label']}失败: {str(e)}") import traceback self.log_gui.log(traceback.format_exc()) - # 更新按钮文字 - self.screen_debug_btn.config(text="关闭调试面板") + btn.config(text="关闭调试面板") - # 窗口关闭时的回调 def on_closing(): - self.screen_debug_btn.config(text="打开调试面板") - self.debug_window.destroy() - self.log_gui.log("✓ 单步调试窗口已关闭") + btn.config(text="打开调试面板") + getattr(self, win_attr).destroy() + self.log_gui.log(f"✓ {wlp}单步调试窗口已关闭") - self.debug_window.protocol("WM_DELETE_WINDOW", on_closing) - self.debug_window.update_idletasks() + win.protocol("WM_DELETE_WINDOW", on_closing) + win.update_idletasks() - self.log_gui.log("✓ 单步调试面板已打开(独立窗口)") + self.log_gui.log(f"✓ {wlp}单步调试面板已打开(独立窗口)") + + def toggle_screen_debug_panel(self): + self._toggle_debug_panel("screen_module") def toggle_sdr_debug_panel(self): - """打开/关闭 SDR 单步调试面板(独立窗口)""" - # 如果窗口已存在且可见,关闭它 - if hasattr(self, "sdr_debug_window") and self.sdr_debug_window.winfo_exists(): - self.sdr_debug_window.destroy() - self.sdr_debug_btn.config(text="打开调试面板") - self.log_gui.log("✓ SDR 单步调试面板已关闭") - return - - # 创建新窗口 - self.sdr_debug_window = ttk.Toplevel(self.root) - self.sdr_debug_window.title("🔧 SDR 单步调试面板") - self.sdr_debug_window.geometry("900x400") - self.sdr_debug_window.transient(self.root) - - # 创建调试面板容器 - debug_container = ttk.Frame(self.sdr_debug_window, padding=10) - debug_container.pack(fill=tk.BOTH, expand=True) - - # ✅ 创建调试面板实例(不要对它调用 pack) - debug_panel_instance = PQDebugPanel(debug_container, self) - # ← 删除:debug_panel_instance.pack(...) - - self.log_gui.log("✓ SDR 单步调试面板实例已创建") - - # ✅ 重新启用调试(如果有数据) - try: - selected_items = self.get_selected_test_items() - - if "gamma" in selected_items: - gray_data = self.results.get_intermediate_data("shared", "gray") - if gray_data: - self.log_gui.log(f" → 加载 {len(gray_data)} 个灰阶数据点") - debug_panel_instance.enable_debug("sdr_movie", "gamma", gray_data) - self.log_gui.log("✓ SDR Gamma 单步调试已重新启用") - - if "accuracy" in selected_items: - accuracy_data = self.results.get_intermediate_data( - "accuracy", "measured" - ) - if accuracy_data: - self.log_gui.log(f" → 加载 {len(accuracy_data)} 个色准数据点") - debug_panel_instance.enable_debug( - "sdr_movie", "accuracy", accuracy_data - ) - self.log_gui.log("✓ SDR 色准单步调试已重新启用") - - if "gamut" in selected_items: - rgb_data = self.results.get_intermediate_data("gamut", "rgb") - if rgb_data: - self.log_gui.log(f" → 加载 {len(rgb_data)} 个RGB数据点") - debug_panel_instance.enable_debug("sdr_movie", "rgb", rgb_data) - self.log_gui.log("✓ SDR RGB 单步调试已重新启用") - - except Exception as e: - self.log_gui.log(f"⚠️ 加载 SDR 调试数据失败: {str(e)}") - import traceback - - self.log_gui.log(traceback.format_exc()) - - # 更新按钮文字 - self.sdr_debug_btn.config(text="关闭调试面板") - - # 窗口关闭时的回调 - def on_closing(): - self.sdr_debug_btn.config(text="打开调试面板") - self.sdr_debug_window.destroy() - self.log_gui.log("✓ SDR 单步调试窗口已关闭") - - self.sdr_debug_window.protocol("WM_DELETE_WINDOW", on_closing) - self.sdr_debug_window.update_idletasks() - - self.log_gui.log("✓ SDR 单步调试面板已打开(独立窗口)") + self._toggle_debug_panel("sdr_movie") def toggle_hdr_debug_panel(self): - """打开/关闭 HDR 单步调试面板(独立窗口)""" - # 如果窗口已存在且可见,关闭它 - if hasattr(self, "hdr_debug_window") and self.hdr_debug_window.winfo_exists(): - self.hdr_debug_window.destroy() - self.hdr_debug_btn.config(text="打开调试面板") - self.log_gui.log("✓ HDR 单步调试面板已关闭") - return - - # 创建新窗口 - self.hdr_debug_window = ttk.Toplevel(self.root) - self.hdr_debug_window.title("🔧 HDR 单步调试面板") - self.hdr_debug_window.geometry("900x400") - self.hdr_debug_window.transient(self.root) - - # 创建调试面板容器 - debug_container = ttk.Frame(self.hdr_debug_window, padding=10) - debug_container.pack(fill=tk.BOTH, expand=True) - - # ✅ 创建调试面板实例(不要对它调用 pack) - debug_panel_instance = PQDebugPanel(debug_container, self) - # ← 删除:debug_panel_instance.pack(...) - - self.log_gui.log("✓ HDR 单步调试面板实例已创建") - - # ✅ 重新启用调试(如果有数据) - try: - selected_items = self.get_selected_test_items() - - if "eotf" in selected_items: - gray_data = self.results.get_intermediate_data("shared", "gray") - if gray_data: - self.log_gui.log(f" → 加载 {len(gray_data)} 个灰阶数据点") - debug_panel_instance.enable_debug("hdr_movie", "eotf", gray_data) - self.log_gui.log("✓ HDR EOTF 单步调试已重新启用") - - if "accuracy" in selected_items: - accuracy_data = self.results.get_intermediate_data( - "accuracy", "measured" - ) - if accuracy_data: - self.log_gui.log(f" → 加载 {len(accuracy_data)} 个色准数据点") - debug_panel_instance.enable_debug( - "hdr_movie", "accuracy", accuracy_data - ) - self.log_gui.log("✓ HDR 色准单步调试已重新启用") - - if "gamut" in selected_items: - rgb_data = self.results.get_intermediate_data("gamut", "rgb") - if rgb_data: - self.log_gui.log(f" → 加载 {len(rgb_data)} 个RGB数据点") - debug_panel_instance.enable_debug("hdr_movie", "rgb", rgb_data) - self.log_gui.log("✓ HDR RGB 单步调试已重新启用") - - except Exception as e: - self.log_gui.log(f"⚠️ 加载 HDR 调试数据失败: {str(e)}") - import traceback - - self.log_gui.log(traceback.format_exc()) - - # 更新按钮文字 - self.hdr_debug_btn.config(text="关闭调试面板") - - # 窗口关闭时的回调 - def on_closing(): - self.hdr_debug_btn.config(text="打开调试面板") - self.hdr_debug_window.destroy() - self.log_gui.log("✓ HDR 单步调试窗口已关闭") - - self.hdr_debug_window.protocol("WM_DELETE_WINDOW", on_closing) - self.hdr_debug_window.update_idletasks() - - self.log_gui.log("✓ HDR 单步调试面板已打开(独立窗口)") + self._toggle_debug_panel("hdr_movie") clear_config_file = _cfg_clear_config_file start_local_dimming_test = _ld_start_local_dimming_test