style: normalize code formatting across the codebase
- Standardize quote style (single to double quotes) - Improve code formatting consistency - Apply formatting to utilities, GUI components, and tools - Update imports and docstrings for consistency Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -76,7 +76,7 @@ class MaterialValidationTab(ttk.Frame):
|
||||
text="使用现有 Excel 文件",
|
||||
variable=self.source_mode,
|
||||
value="existing",
|
||||
command=self._on_source_mode_change
|
||||
command=self._on_source_mode_change,
|
||||
).grid(row=0, column=0, sticky="w", padx=5)
|
||||
|
||||
ttk.Radiobutton(
|
||||
@@ -84,7 +84,7 @@ class MaterialValidationTab(ttk.Frame):
|
||||
text="完整工作流 (提取 + 校验)",
|
||||
variable=self.source_mode,
|
||||
value="full",
|
||||
command=self._on_source_mode_change
|
||||
command=self._on_source_mode_change,
|
||||
).grid(row=0, column=1, sticky="w", padx=5)
|
||||
|
||||
# 文件选择
|
||||
@@ -100,7 +100,7 @@ class MaterialValidationTab(ttk.Frame):
|
||||
label_text="现有 Excel 文件:",
|
||||
file_type="file",
|
||||
file_types=[("Excel 文件", "*.xlsx"), ("所有文件", "*.*")],
|
||||
initial_dir=self.config.get('paths.data_dir', 'data/')
|
||||
initial_dir=self.config.get("paths.data_dir", "data/"),
|
||||
)
|
||||
self.existing_excel_selector.pack(fill=tk.X)
|
||||
|
||||
@@ -113,7 +113,7 @@ class MaterialValidationTab(ttk.Frame):
|
||||
label_text="ProductionID 文件:",
|
||||
file_type="file",
|
||||
file_types=[("文本文件", "*.txt"), ("所有文件", "*.*")],
|
||||
initial_dir="D:/python/playwrite/"
|
||||
initial_dir="D:/python/playwrite/",
|
||||
)
|
||||
self.production_id_selector.pack(fill=tk.X)
|
||||
|
||||
@@ -126,14 +126,14 @@ class MaterialValidationTab(ttk.Frame):
|
||||
label_text="输出文件:",
|
||||
file_type="file",
|
||||
file_types=[("Excel 文件", "*.xlsx"), ("所有文件", "*.*")],
|
||||
initial_dir=self.config.get('paths.data_dir', 'data/')
|
||||
initial_dir=self.config.get("paths.data_dir", "data/"),
|
||||
)
|
||||
self.output_file_selector.pack(fill=tk.X)
|
||||
|
||||
# 设置默认输出
|
||||
default_output = os.path.join(
|
||||
self.config.get('paths.data_dir', 'data/'),
|
||||
self.config.get('paths.validation_output', '物料状态校验结果.xlsx')
|
||||
self.config.get("paths.data_dir", "data/"),
|
||||
self.config.get("paths.validation_output", "物料状态校验结果.xlsx"),
|
||||
)
|
||||
self.output_file_selector.set(default_output)
|
||||
|
||||
@@ -141,10 +141,17 @@ class MaterialValidationTab(ttk.Frame):
|
||||
button_frame = ttk.Frame(parent)
|
||||
button_frame.pack(fill=tk.X, pady=10)
|
||||
|
||||
self.start_button = ttk.Button(button_frame, text="开始校验", command=self.start_validation)
|
||||
self.start_button = ttk.Button(
|
||||
button_frame, text="开始校验", command=self.start_validation
|
||||
)
|
||||
self.start_button.pack(side=tk.LEFT, padx=5)
|
||||
|
||||
self.export_button = ttk.Button(button_frame, text="导出结果", command=self.export_results, state=tk.DISABLED)
|
||||
self.export_button = ttk.Button(
|
||||
button_frame,
|
||||
text="导出结果",
|
||||
command=self.export_results,
|
||||
state=tk.DISABLED,
|
||||
)
|
||||
self.export_button.pack(side=tk.LEFT, padx=5)
|
||||
|
||||
def _create_result_table(self, parent):
|
||||
@@ -166,9 +173,13 @@ class MaterialValidationTab(ttk.Frame):
|
||||
|
||||
# 添加滚动条
|
||||
scrollbar_y = ttk.Scrollbar(parent, orient=tk.VERTICAL, command=self.tree.yview)
|
||||
scrollbar_x = ttk.Scrollbar(parent, orient=tk.HORIZONTAL, command=self.tree.xview)
|
||||
scrollbar_x = ttk.Scrollbar(
|
||||
parent, orient=tk.HORIZONTAL, command=self.tree.xview
|
||||
)
|
||||
|
||||
self.tree.configure(yscrollcommand=scrollbar_y.set, xscrollcommand=scrollbar_x.set)
|
||||
self.tree.configure(
|
||||
yscrollcommand=scrollbar_y.set, xscrollcommand=scrollbar_x.set
|
||||
)
|
||||
|
||||
# 布局
|
||||
self.tree.grid(row=0, column=0, sticky="nsew")
|
||||
@@ -239,11 +250,13 @@ class MaterialValidationTab(ttk.Frame):
|
||||
validation_thread = threading.Thread(
|
||||
target=self._validation_worker,
|
||||
args=(input_file, production_id_file, output_file),
|
||||
daemon=True
|
||||
daemon=True,
|
||||
)
|
||||
validation_thread.start()
|
||||
|
||||
def _validation_worker(self, input_file: str, production_id_file: str, output_file: str):
|
||||
def _validation_worker(
|
||||
self, input_file: str, production_id_file: str, output_file: str
|
||||
):
|
||||
"""校验工作线程"""
|
||||
try:
|
||||
# 导入校验器
|
||||
@@ -251,10 +264,10 @@ class MaterialValidationTab(ttk.Frame):
|
||||
|
||||
# 创建校验器实例(需要 ERP 凭据,因为可能需要登录系统)
|
||||
validator = MaterialStatusValidator(
|
||||
username=self.config.get('erp.username'),
|
||||
password=self.config.get('erp.password'),
|
||||
headless=self.config.get('erp.headless', True),
|
||||
verbose=True
|
||||
username=self.config.get("erp.username"),
|
||||
password=self.config.get("erp.password"),
|
||||
headless=self.config.get("erp.headless", True),
|
||||
verbose=True,
|
||||
)
|
||||
|
||||
# 捕获 stdout 输出
|
||||
@@ -264,20 +277,19 @@ class MaterialValidationTab(ttk.Frame):
|
||||
with redirect_stdout(captured_output):
|
||||
if self.source_mode.get() == "existing":
|
||||
result = validator.validate_from_existing_excel(
|
||||
excel_file=input_file,
|
||||
output_file=output_file
|
||||
excel_file=input_file, output_file=output_file
|
||||
)
|
||||
else:
|
||||
result = validator.validate(
|
||||
production_id_file=production_id_file,
|
||||
merged_excel_file=None, # 将在内部生成
|
||||
output_file=output_file
|
||||
output_file=output_file,
|
||||
)
|
||||
|
||||
# 获取捕获的输出并显示到日志
|
||||
output_text = captured_output.getvalue()
|
||||
if output_text:
|
||||
for line in output_text.split('\n'):
|
||||
for line in output_text.split("\n"):
|
||||
if line.strip():
|
||||
self._update_log(line, "INFO")
|
||||
|
||||
@@ -307,12 +319,16 @@ class MaterialValidationTab(ttk.Frame):
|
||||
# 在主线程中更新表格
|
||||
def update_table():
|
||||
for _, row in df.iterrows():
|
||||
self.tree.insert("", tk.END, values=(
|
||||
row.get('材料名称', ''),
|
||||
row.get('匹配的MaterialName', ''),
|
||||
row.get('负责人', ''),
|
||||
row.get('匹配状态', '')
|
||||
))
|
||||
self.tree.insert(
|
||||
"",
|
||||
tk.END,
|
||||
values=(
|
||||
row.get("材料名称", ""),
|
||||
row.get("匹配的MaterialName", ""),
|
||||
row.get("负责人", ""),
|
||||
row.get("匹配状态", ""),
|
||||
),
|
||||
)
|
||||
|
||||
if len(df) > 0:
|
||||
self.export_button.config(state=tk.NORMAL)
|
||||
@@ -325,6 +341,7 @@ class MaterialValidationTab(ttk.Frame):
|
||||
|
||||
def _update_log(self, message: str, level: str = "INFO"):
|
||||
"""线程安全的日志更新"""
|
||||
|
||||
def update():
|
||||
if level == "INFO":
|
||||
self.log_text.info(message)
|
||||
@@ -345,7 +362,7 @@ class MaterialValidationTab(ttk.Frame):
|
||||
output_file = filedialog.asksaveasfilename(
|
||||
title="保存结果",
|
||||
defaultextension=".xlsx",
|
||||
filetypes=[("Excel 文件", "*.xlsx"), ("所有文件", "*.*")]
|
||||
filetypes=[("Excel 文件", "*.xlsx"), ("所有文件", "*.*")],
|
||||
)
|
||||
|
||||
if not output_file:
|
||||
@@ -355,7 +372,7 @@ class MaterialValidationTab(ttk.Frame):
|
||||
# 收集表格数据
|
||||
data = []
|
||||
for item in self.tree.get_children():
|
||||
values = self.tree.item(item)['values']
|
||||
values = self.tree.item(item)["values"]
|
||||
data.append(values)
|
||||
|
||||
if not data:
|
||||
@@ -363,7 +380,9 @@ class MaterialValidationTab(ttk.Frame):
|
||||
return
|
||||
|
||||
# 创建 DataFrame 并保存
|
||||
df = pd.DataFrame(data, columns=["材料名称", "匹配的MaterialName", "负责人", "匹配状态"])
|
||||
df = pd.DataFrame(
|
||||
data, columns=["材料名称", "匹配的MaterialName", "负责人", "匹配状态"]
|
||||
)
|
||||
df.to_excel(output_file, index=False)
|
||||
|
||||
messagebox.showinfo("成功", f"结果已导出到:{output_file}")
|
||||
|
||||
Reference in New Issue
Block a user