style: format all Python files with Black

Apply Black formatter to the entire codebase for consistent code style.

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-02-26 22:44:03 +08:00
parent 1b16842a2c
commit 3b7c00377f
46 changed files with 1488 additions and 974 deletions

View File

@@ -70,10 +70,12 @@ class DataExtractionTab(BaseTab):
input_group.pack(fill=tk.BOTH, expand=True)
self.production_id_input = ProductionIdInput(
input_group,
placeholder="每行输入一个 Production ID\n\n示例:\n26B848\n26B849"
placeholder="每行输入一个 Production ID\n\n示例:\n26B848\n26B849",
)
self.production_id_input.pack(fill=tk.BOTH, expand=True)
self.production_id_input.text_widget.bind("<FocusOut>", self._on_production_ids_changed)
self.production_id_input.text_widget.bind(
"<FocusOut>", self._on_production_ids_changed
)
def _create_right_panel(self, parent):
main_paned = ttk.PanedWindow(parent, orient=tk.VERTICAL)
@@ -89,7 +91,9 @@ class DataExtractionTab(BaseTab):
output_group = ttk.LabelFrame(parent, text="输出文件", padding=10)
output_group.pack(fill=tk.X, pady=5)
self.output_file_selector = FileSelector(
output_group, label_text="保存为:", file_type="file",
output_group,
label_text="保存为:",
file_type="file",
file_types=[("Excel 文件", "*.xlsx"), ("所有文件", "*.*")],
initial_dir=self.config.get("paths.data_dir", "data/"),
)
@@ -103,20 +107,28 @@ class DataExtractionTab(BaseTab):
options_group = ttk.LabelFrame(parent, text="提取选项", padding=10)
options_group.pack(fill=tk.X, pady=5)
self.headless_var = tk.BooleanVar(value=self.config.get("erp.headless", True))
ttk.Checkbutton(options_group, text="无头模式", variable=self.headless_var).grid(row=0, column=0, sticky="w", padx=5)
ttk.Checkbutton(
options_group, text="无头模式", variable=self.headless_var
).grid(row=0, column=0, sticky="w", padx=5)
progress_group = ttk.LabelFrame(parent, text="进度", padding=10)
progress_group.pack(fill=tk.X, pady=5)
self.progress_bar = ttk.Progressbar(progress_group, mode="determinate")
self.progress_bar.pack(fill=tk.X, pady=5)
self.status_label = ttk.Label(progress_group, text="就绪", relief=tk.SUNKEN, anchor=tk.W)
self.status_label = ttk.Label(
progress_group, text="就绪", relief=tk.SUNKEN, anchor=tk.W
)
self.status_label.pack(fill=tk.X)
button_frame = ttk.Frame(parent)
button_frame.pack(fill=tk.X, pady=10)
self.start_button = ttk.Button(button_frame, text="开始提取", command=self.start_extraction)
self.start_button = ttk.Button(
button_frame, text="开始提取", command=self.start_extraction
)
self.start_button.pack(side=tk.LEFT, padx=5)
self.stop_button = ttk.Button(button_frame, text="停止", command=self.stop_extraction, state=tk.DISABLED)
self.stop_button = ttk.Button(
button_frame, text="停止", command=self.stop_extraction, state=tk.DISABLED
)
self.stop_button.pack(side=tk.LEFT, padx=5)
def _create_log_panel(self, parent):
@@ -125,10 +137,11 @@ class DataExtractionTab(BaseTab):
# 设置 GUI 日志处理器,将 logging 输出桥接到 LogText 组件
self._gui_handler = GuiTextHandler(self.log_text)
self._gui_handler.setFormatter(logging.Formatter(
'%(asctime)s [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
))
self._gui_handler.setFormatter(
logging.Formatter(
"%(asctime)s [%(levelname)s] %(message)s", datefmt="%Y-%m-%d %H:%M:%S"
)
)
self.logger.addHandler(self._gui_handler)
def _apply_ui_config(self):
@@ -136,7 +149,7 @@ class DataExtractionTab(BaseTab):
font_family = self.config.get("ui.font_family", "Microsoft YaHei UI")
font_size = self.config.get("ui.font_size", 10)
self.production_id_input.apply_font(font_family, font_size)
if hasattr(self.log_text, 'apply_font'):
if hasattr(self.log_text, "apply_font"):
self.log_text.apply_font(font_family, font_size)
except Exception as e:
self.logger.debug(f"应用 UI 配置失败: {e}")
@@ -163,7 +176,9 @@ class DataExtractionTab(BaseTab):
self.status_label.config(text="正在初始化...")
self.log_text.clear()
self.extraction_thread = threading.Thread(
target=self._extraction_worker, args=(production_ids, output_file), daemon=True
target=self._extraction_worker,
args=(production_ids, output_file),
daemon=True,
)
self.extraction_thread.start()
@@ -174,20 +189,28 @@ class DataExtractionTab(BaseTab):
def _extraction_worker(self, production_ids: list[str], output_file: str):
import tempfile
temp_file = None
try:
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False, encoding='utf-8') as f:
with tempfile.NamedTemporaryFile(
mode="w", suffix=".txt", delete=False, encoding="utf-8"
) as f:
temp_file = f.name
f.write('\n'.join(production_ids))
f.write("\n".join(production_ids))
from utils.discrete_material_plan_extractor import (
DiscreteMaterialPlanExtractor,
)
from utils.discrete_material_plan_extractor import DiscreteMaterialPlanExtractor
self.extractor = DiscreteMaterialPlanExtractor(
username=self.config.get("erp.username"),
password=self.config.get("erp.password"),
headless=self.headless_var.get(),
verbose=self.config.get("extraction.verbose", True),
batch_size=self.config.get("extraction.batch_size", 100),
enable_db_persistence=self.config.get("extraction.enable_db_persistence", False),
enable_db_persistence=self.config.get(
"extraction.enable_db_persistence", False
),
)
# 修复:直接调用标准的 _update_log不再传入 add_timestamp 参数
@@ -196,11 +219,15 @@ class DataExtractionTab(BaseTab):
level = progress_info.detail.get("log_level", "INFO").upper()
self._update_log(progress_info.message, level)
else:
percent = self.progress_calculator.calculate_overall_percent(progress_info)
percent = self.progress_calculator.calculate_overall_percent(
progress_info
)
self._update_progress(percent, progress_info.message)
result = self.extractor.extract(
production_id_file=temp_file, output_file=output_file, progress_callback=progress_callback
production_id_file=temp_file,
output_file=output_file,
progress_callback=progress_callback,
)
if result and self.extracting:
@@ -246,8 +273,10 @@ class DataExtractionTab(BaseTab):
def _on_production_ids_changed(self, event=None):
if self.main_window:
self.main_window.update_shared_production_ids(self.production_id_input.get())
self.main_window.update_shared_production_ids(
self.production_id_input.get()
)
def reload_config(self):
self._apply_ui_config()
self._on_production_ids_changed()
self._on_production_ids_changed()