修改引用逻辑、新增Pattern更改界面、新增Calman灰阶界面
This commit is contained in:
@@ -11,11 +11,17 @@ from tkinter import filedialog, messagebox
|
||||
|
||||
import ttkbootstrap as ttk
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from pqAutomationApp import PQAutomationApp
|
||||
|
||||
|
||||
|
||||
_TEMPLATE_FILE = "pantone_2670_colors.xlsx"
|
||||
|
||||
|
||||
def create_pantone_baseline_panel(self):
|
||||
def create_pantone_baseline_panel(self: "PQAutomationApp"):
|
||||
"""创建 Pantone 认证摸底测试面板。"""
|
||||
frame = ttk.Frame(self.content_frame)
|
||||
self.pantone_baseline_frame = frame
|
||||
@@ -149,12 +155,12 @@ def create_pantone_baseline_panel(self):
|
||||
_set_button_states(self)
|
||||
|
||||
|
||||
def toggle_pantone_baseline_panel(self):
|
||||
def toggle_pantone_baseline_panel(self: "PQAutomationApp"):
|
||||
"""切换 Pantone 认证摸底测试面板。"""
|
||||
self.show_panel("pantone_baseline")
|
||||
|
||||
|
||||
def _get_settings_dir(self):
|
||||
def _get_settings_dir(self: "PQAutomationApp"):
|
||||
"""返回 settings 绝对目录,避免依赖当前工作目录。"""
|
||||
if getattr(self, "config_file", None):
|
||||
return os.path.dirname(self.config_file)
|
||||
@@ -168,7 +174,7 @@ def _get_settings_dir(self):
|
||||
return os.path.join(base_dir, "settings")
|
||||
|
||||
|
||||
def _load_patterns(self):
|
||||
def _load_patterns(self: "PQAutomationApp"):
|
||||
path = os.path.join(_get_settings_dir(self), _TEMPLATE_FILE)
|
||||
if not os.path.isfile(path):
|
||||
raise FileNotFoundError(f"未找到模板文件: {path}")
|
||||
@@ -201,7 +207,7 @@ def _load_patterns(self):
|
||||
return patterns
|
||||
|
||||
|
||||
def _start_pantone_baseline(self):
|
||||
def _start_pantone_baseline(self: "PQAutomationApp"):
|
||||
if self._pantone_running:
|
||||
messagebox.showinfo("提示", "Pantone 任务正在执行")
|
||||
return
|
||||
@@ -247,7 +253,7 @@ def _start_pantone_baseline(self):
|
||||
_launch_worker(self, start_index=0, settle=settle)
|
||||
|
||||
|
||||
def _resume_pantone_baseline(self):
|
||||
def _resume_pantone_baseline(self: "PQAutomationApp"):
|
||||
if self._pantone_running:
|
||||
messagebox.showinfo("提示", "Pantone 任务正在执行")
|
||||
return
|
||||
@@ -291,7 +297,7 @@ def _resume_pantone_baseline(self):
|
||||
_launch_worker(self, start_index=self._pantone_next_index, settle=settle)
|
||||
|
||||
|
||||
def _launch_worker(self, start_index, settle):
|
||||
def _launch_worker(self: "PQAutomationApp", start_index, settle):
|
||||
total = self._pantone_target_count or len(self.pantone_patterns)
|
||||
|
||||
def worker():
|
||||
@@ -401,7 +407,7 @@ def _launch_worker(self, start_index, settle):
|
||||
threading.Thread(target=worker, daemon=True).start()
|
||||
|
||||
|
||||
def _append_result_row(self, record, total):
|
||||
def _append_result_row(self: "PQAutomationApp", record, total):
|
||||
self.pantone_tree.insert(
|
||||
"",
|
||||
tk.END,
|
||||
@@ -423,7 +429,7 @@ def _append_result_row(self, record, total):
|
||||
self.pantone_tree.see(children[-1])
|
||||
|
||||
|
||||
def _pause_pantone_baseline(self):
|
||||
def _pause_pantone_baseline(self: "PQAutomationApp"):
|
||||
if not self._pantone_running:
|
||||
messagebox.showinfo("提示", "当前没有运行中的任务")
|
||||
return
|
||||
@@ -433,7 +439,7 @@ def _pause_pantone_baseline(self):
|
||||
self._pantone_control_event.set()
|
||||
|
||||
|
||||
def _end_pantone_baseline(self):
|
||||
def _end_pantone_baseline(self: "PQAutomationApp"):
|
||||
if self._pantone_running:
|
||||
self._pantone_stop_requested = True
|
||||
self.pantone_status_var.set("结束中...")
|
||||
@@ -448,7 +454,7 @@ def _end_pantone_baseline(self):
|
||||
_set_button_states(self)
|
||||
|
||||
|
||||
def _clear_results(self):
|
||||
def _clear_results(self: "PQAutomationApp"):
|
||||
if self._pantone_running:
|
||||
messagebox.showinfo("提示", "任务执行中,无法清空")
|
||||
return
|
||||
@@ -463,7 +469,7 @@ def _clear_results(self):
|
||||
_set_button_states(self)
|
||||
|
||||
|
||||
def _set_button_states(self):
|
||||
def _set_button_states(self: "PQAutomationApp"):
|
||||
if self._pantone_running:
|
||||
self.pantone_start_btn.configure(state=tk.DISABLED)
|
||||
self.pantone_pause_btn.configure(state=tk.NORMAL)
|
||||
@@ -479,7 +485,7 @@ def _set_button_states(self):
|
||||
self.pantone_resume_btn.configure(state=tk.NORMAL if can_resume else tk.DISABLED)
|
||||
|
||||
|
||||
def _save_as_template(self):
|
||||
def _save_as_template(self: "PQAutomationApp"):
|
||||
if not self.pantone_results:
|
||||
messagebox.showinfo("提示", "暂无可导出的结果")
|
||||
return
|
||||
@@ -502,7 +508,7 @@ def _save_as_template(self):
|
||||
messagebox.showerror("保存失败", f"写入 xlsx 失败: {exc}")
|
||||
|
||||
|
||||
def _resolve_results_dir(self):
|
||||
def _resolve_results_dir(self: "PQAutomationApp"):
|
||||
if getattr(self, "config_file", None):
|
||||
root_dir = os.path.dirname(os.path.dirname(self.config_file))
|
||||
else:
|
||||
@@ -514,7 +520,7 @@ def _resolve_results_dir(self):
|
||||
return results_dir
|
||||
|
||||
|
||||
def _auto_save_template(self):
|
||||
def _auto_save_template(self: "PQAutomationApp"):
|
||||
results_dir = _resolve_results_dir(self)
|
||||
target_count = len(self.pantone_results)
|
||||
filename = (
|
||||
@@ -526,7 +532,7 @@ def _auto_save_template(self):
|
||||
return path
|
||||
|
||||
|
||||
def _write_template_xlsx(self, path):
|
||||
def _write_template_xlsx(self: "PQAutomationApp", path):
|
||||
# 优先复制 settings 模板,再覆盖数据区;没有模板时自动创建同结构表。
|
||||
template_path = os.path.join(_get_settings_dir(self), _TEMPLATE_FILE)
|
||||
from openpyxl import load_workbook, Workbook
|
||||
@@ -560,3 +566,25 @@ def _write_template_xlsx(self, path):
|
||||
ws.cell(row=idx, column=6, value=float(item["y"]))
|
||||
|
||||
wb.save(path)
|
||||
|
||||
|
||||
class PantoneBaselinePanelMixin:
|
||||
"""由 tools/refactor_to_mixins.py 自动生成。
|
||||
把本模块的自由函数挂到 PQAutomationApp 上,便于 F12 跳转与类型推断。
|
||||
"""
|
||||
create_pantone_baseline_panel = create_pantone_baseline_panel
|
||||
toggle_pantone_baseline_panel = toggle_pantone_baseline_panel
|
||||
_get_settings_dir = _get_settings_dir
|
||||
_load_patterns = _load_patterns
|
||||
_start_pantone_baseline = _start_pantone_baseline
|
||||
_resume_pantone_baseline = _resume_pantone_baseline
|
||||
_launch_worker = _launch_worker
|
||||
_append_result_row = _append_result_row
|
||||
_pause_pantone_baseline = _pause_pantone_baseline
|
||||
_end_pantone_baseline = _end_pantone_baseline
|
||||
_clear_results = _clear_results
|
||||
_set_button_states = _set_button_states
|
||||
_save_as_template = _save_as_template
|
||||
_resolve_results_dir = _resolve_results_dir
|
||||
_auto_save_template = _auto_save_template
|
||||
_write_template_xlsx = _write_template_xlsx
|
||||
|
||||
Reference in New Issue
Block a user