Update: Refactor to absolute imports, fix QPS limits, and enhance Gitea sync with SQLite support

This commit is contained in:
2026-07-21 10:25:29 +08:00
parent ef04fc5627
commit 97d9d98b4c
67 changed files with 1691 additions and 457 deletions
+39 -103
View File
@@ -27,6 +27,27 @@ from .command_runner import get_running_task, set_running_task
from .file_operations import select_file, select_excel_file, validate_unit_price_against_item_data
def _get_missing_barcodes_callback(log_widget):
"""创建并返回缺失条码的回调函数"""
def callback(missing_barcodes):
if not missing_barcodes:
return
msg = f"发现以下条码不在商品资料中,已记录到数据库:\n\n" + "\n".join([f"{bc}" for bc in missing_barcodes])
# 在主线程中弹出对话框
def show_msg():
messagebox.showwarning("发现缺失条码", msg)
# 尝试使用 log_widget 的 winfo_toplevel() 来调用 after,确保在 UI 线程执行
try:
log_widget.after(0, show_msg)
except Exception:
# 降级处理
show_msg()
return callback
def _ask_and_merge_purchase_orders(order_service, log_widget, add_to_recent=False):
"""弹窗询问是否合并采购单,返回合并结果路径或 None。
@@ -138,108 +159,23 @@ def process_single_image_with_status(log_widget, status_bar):
def run_pipeline_directly(log_widget, status_bar):
"""直接运行完整处理流程"""
"""运行完整处理流程:先选择图片,再执行 OCR+Excel 处理"""
if get_running_task() is not None:
messagebox.showinfo("任务进行中", "请等待当前任务完成后再执行新的操作。")
return
def run_in_thread():
set_running_task("pipeline")
# 先选择图片
file_path = select_file(
log_widget,
[("支持文件", "*.jpg *.jpeg *.png *.bmp *.xlsx *.xls"), ("图片文件", "*.jpg *.jpeg *.png *.bmp"), ("Excel文件", "*.xlsx *.xls"), ("所有文件", "*.*")],
"选择待处理文件"
)
if not file_path:
add_to_log(log_widget, "未选择文件,一键处理已取消\n", "warning")
return
if status_bar:
status_bar.set_running(True)
status_bar.set_status("开始完整处理流程...")
start_time = datetime.datetime.now()
start_perf = time.perf_counter()
log_widget.configure(state=tk.NORMAL)
log_widget.delete(1.0, tk.END)
log_widget.insert(tk.END, "执行命令: 完整处理流程\n", "command")
log_widget.insert(tk.END, f"开始时间: {start_time.strftime('%Y-%m-%d %H:%M:%S')}\n", "time")
log_widget.insert(tk.END, "=" * 50 + "\n\n", "separator")
log_widget.configure(state=tk.DISABLED)
try:
config = ConfigManager()
gui_handler = init_gui_logger(log_widget)
ocr_service = OCRService(config)
order_service = OrderService(config)
reporter = ProgressReporter(status_bar)
reporter.running()
reporter.set("开始OCR批量处理...", 10)
total, success = ocr_service.batch_process(progress_cb=lambda p: reporter.set("OCR处理中...", p))
if total == 0:
add_to_log(log_widget, "没有找到需要处理的图片\n", "warning")
if status_bar:
status_bar.set_status("未找到图片文件")
return
elif success == 0:
add_to_log(log_widget, "OCR处理没有成功处理任何新文件\n", "warning")
else:
add_to_log(log_widget, f"OCR处理完成,共处理 {success}/{total} 个文件\n", "success")
try:
processed_map = {}
config = ConfigManager()
pjson = config.get('Paths', 'processed_record', fallback='data/processed_files.json')
if os.path.exists(pjson):
with open(pjson, 'r', encoding='utf-8') as f:
processed_map = json.load(f)
outputs = list(processed_map.values())
for p in outputs[-10:]:
if p:
add_recent_file(os.path.abspath(p))
except Exception as e:
logger.debug(f"加载已处理文件记录失败: {e}")
reporter.set("开始Excel处理...", 92)
add_to_log(log_widget, "开始Excel处理...\n", "info")
result = order_service.process_excel()
if not result:
add_to_log(log_widget, "Excel处理失败\n", "error")
else:
add_to_log(log_widget, "Excel处理完成\n", "success")
try:
add_recent_file(result)
except Exception as e:
logger.debug(f"添加最近文件失败: {e}")
try:
validate_unit_price_against_item_data(result, log_widget)
except Exception as e:
logger.debug(f"单价校验失败: {e}")
reporter.set("检查是否需要合并采购单...", 80)
_ask_and_merge_purchase_orders(order_service, log_widget, add_to_recent=True)
end_time = datetime.datetime.now()
duration_sec = max(0.0, time.perf_counter() - start_perf)
add_to_log(log_widget, f"\n{'=' * 50}\n", "separator")
add_to_log(log_widget, "完整处理流程执行完毕!\n", "success")
add_to_log(log_widget, f"结束时间: {end_time.strftime('%Y-%m-%d %H:%M:%S')}\n", "time")
add_to_log(log_widget, f"耗时: {duration_sec:.2f}\n", "time")
reporter.set("处理完成", 100)
except Exception as e:
add_to_log(log_widget, f"执行过程中发生错误: {str(e)}\n", "error")
import traceback
add_to_log(log_widget, f"详细错误信息: {traceback.format_exc()}\n", "error")
finally:
dispose_gui_logger()
reporter.done()
set_running_task(None)
if status_bar:
status_bar.set_running(False)
status_bar.set_status("就绪")
thread = Thread(target=run_in_thread)
thread.daemon = True
thread.start()
# 复用拖拽处理的逻辑,实现“先选图,后全流程”
process_dropped_file(log_widget, status_bar, file_path)
def batch_ocr_with_status(log_widget, status_bar):
@@ -318,7 +254,7 @@ def batch_process_all_inputs(log_widget, status_bar):
from .memory_editor import show_memory_editor # noqa: F401 触发 import 顺序
cfg = ConfigManager()
svc = BatchService(cfg)
svc = BatchService(cfg, missing_barcodes_cb=_get_missing_barcodes_callback(log_widget))
def progress(done, total, entry):
pct = int(done / total * 100) if total else 100
@@ -404,7 +340,7 @@ def batch_process_orders_with_status(log_widget, status_bar):
init_gui_logger(log_widget)
order_service = OrderService()
order_service = OrderService(missing_barcodes_cb=_get_missing_barcodes_callback(log_widget))
add_to_log(log_widget, "开始Excel处理...\n", "info")
try:
@@ -461,7 +397,7 @@ def merge_orders_with_status(log_widget, status_bar):
init_gui_logger(log_widget)
order_service = OrderService()
order_service = OrderService(missing_barcodes_cb=_get_missing_barcodes_callback(log_widget))
result = order_service.merge_all_purchase_orders(progress_cb=lambda p: reporter.set("合并处理中...", p))
@@ -511,7 +447,7 @@ def process_excel_file_with_status(log_widget, status_bar):
init_gui_logger(log_widget)
order_service = OrderService()
order_service = OrderService(missing_barcodes_cb=_get_missing_barcodes_callback(log_widget))
if file_path:
try:
@@ -589,7 +525,7 @@ def process_dropped_file(log_widget, status_bar, file_path):
# 步骤2: Excel处理
reporter.set("Excel处理中...", 40)
order_service = OrderService()
order_service = OrderService(missing_barcodes_cb=_get_missing_barcodes_callback(log_widget))
result = order_service.process_excel(excel_path, progress_cb=lambda p: reporter.set("Excel处理中...", p))
if not result:
add_to_log(log_widget, "Excel处理失败\n", "error")
@@ -622,7 +558,7 @@ def process_dropped_file(log_widget, status_bar, file_path):
reporter = ProgressReporter(status_bar)
reporter.running()
init_gui_logger(log_widget)
order_service = OrderService()
order_service = OrderService(missing_barcodes_cb=_get_missing_barcodes_callback(log_widget))
add_to_log(log_widget, f"开始一键处理Excel文件: {file_path}\n", "info")
try:
add_recent_file(file_path)
+1 -1
View File
@@ -7,7 +7,7 @@ from tkinter import messagebox
from app.core.excel.converter import UnitConverter
from app.core.utils.dialog_utils import show_barcode_mapping_dialog
from .logging_ui import add_to_log
from app.ui.logging_ui import add_to_log
def edit_barcode_mappings(log_widget):
+2 -2
View File
@@ -12,8 +12,8 @@ import tkinter as tk
from tkinter import messagebox
from threading import Thread
from .logging_ui import LogRedirector
from .result_previews import show_result_preview
from app.ui.logging_ui import LogRedirector
from app.ui.result_previews import show_result_preview
# 任务状态跟踪
_RUNNING_TASK = None
+2 -2
View File
@@ -8,8 +8,8 @@ from tkinter import messagebox, filedialog, ttk
from app.config.settings import ConfigManager
from .user_settings import load_user_settings, save_user_settings
from .ui_widgets import center_window
from app.ui.user_settings import load_user_settings, save_user_settings
from app.ui.ui_widgets import center_window
from app.core.utils.dialog_utils import show_cloud_sync_dialog
+264
View File
@@ -0,0 +1,264 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""数据库内容查看器模块"""
import os
import tkinter as tk
from tkinter import ttk, messagebox
import sqlite3
from datetime import datetime
from typing import Optional, Dict, List, Any
from app.config.settings import ConfigManager
from app.ui.ui_widgets import center_window
from app.ui.theme import THEMES, get_theme_mode
class DatabaseViewer:
"""通用数据库查看器,支持多表切换"""
def __init__(self, root, config: Optional[ConfigManager] = None):
self.root = root
self.config = config or ConfigManager()
self.db_path = self.config.get_path('Paths', 'product_db', fallback='data/product_cache.db')
# 确保路径是绝对路径
if not os.path.isabs(self.db_path):
app_root = getattr(self.config, 'app_root', os.getcwd())
self.db_path = os.path.join(app_root, self.db_path)
self.dlg = tk.Toplevel(root)
self.dlg.title("数据库内容查看器")
self.dlg.geometry("1000x600")
center_window(self.dlg)
theme = THEMES[get_theme_mode()]
self.dlg.configure(bg=theme["bg"])
# 使用 Notebook 实现多表切换
self.notebook = ttk.Notebook(self.dlg)
self.notebook.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# 定义要查看的表及其列信息
self.table_configs = {
"order_metadata": {
"title": "订单记录",
"columns": {
"bill_date": ("单据日期", 100),
"supplier": ("供应商", 200),
"total_amount": ("总金额", 80),
"updated_at": ("处理时间", 150),
"source_image": ("原始图片", 250),
"file_hash": ("Hash", 120)
},
"query": "SELECT * FROM order_metadata ORDER BY updated_at DESC"
},
"missing_barcodes": {
"title": "缺失条码",
"columns": {
"barcode": ("条码", 150),
"name": ("商品名称", 200),
"count": ("出现次数", 80),
"last_seen": ("最后发现", 150),
"source_file": ("来源文件", 250)
},
"query": "SELECT * FROM missing_barcodes ORDER BY last_seen DESC"
},
"products": {
"title": "商品记忆库",
"columns": {
"barcode": ("条码", 120),
"name": ("名称", 180),
"specification": ("规格", 80),
"unit": ("单位", 50),
"price": ("单价", 70),
"confidence": ("置信度", 60),
"usage_count": ("使用次数", 70),
"last_seen": ("最后使用", 140)
},
"query": "SELECT * FROM products ORDER BY last_seen DESC"
}
}
self.trees = {}
self._init_tabs()
# 底部按钮
btn_frame = ttk.Frame(self.dlg)
btn_frame.pack(fill=tk.X, padx=10, pady=(0, 10))
ttk.Button(btn_frame, text="刷新当前表", command=self.refresh_current_tab).pack(side=tk.LEFT, padx=5)
ttk.Button(btn_frame, text="清空记录 (慎用)", command=self.clear_current_table).pack(side=tk.LEFT, padx=5)
ttk.Button(btn_frame, text="关闭", command=self.dlg.destroy).pack(side=tk.RIGHT, padx=5)
def _init_tabs(self):
"""初始化各个标签页"""
for table_id, config in self.table_configs.items():
frame = ttk.Frame(self.notebook)
self.notebook.add(frame, text=config["title"])
# 搜索栏
search_frame = ttk.Frame(frame)
search_frame.pack(fill=tk.X, padx=5, pady=5)
ttk.Label(search_frame, text="搜索:").pack(side=tk.LEFT)
search_var = tk.StringVar()
search_entry = ttk.Entry(search_frame, textvariable=search_var, width=30)
search_entry.pack(side=tk.LEFT, padx=5)
# Treeview
cols = list(config["columns"].keys())
tree = ttk.Treeview(frame, columns=cols, show="headings")
for col, (text, width) in config["columns"].items():
tree.heading(col, text=text)
tree.column(col, width=width, anchor="center")
scrollbar = ttk.Scrollbar(frame, orient=tk.VERTICAL, command=tree.yview)
tree.configure(yscrollcommand=scrollbar.set)
tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# 双击复制单元格内容
tree.bind("<Double-1>", lambda e, tid=table_id: self.copy_cell_value(e, tid))
self.trees[table_id] = {
"tree": tree,
"search_var": search_var,
"config": config
}
# 绑定搜索事件
search_var.trace_add("write", lambda *args, tid=table_id: self.load_table_data(tid))
# 初始加载数据
self.load_table_data(table_id)
def load_table_data(self, table_id):
"""加载指定表的数据"""
if not os.path.exists(self.db_path):
return
info = self.trees[table_id]
tree = info["tree"]
config = info["config"]
search_text = info["search_var"].get().lower()
# 清空现有数据
for item in tree.get_children():
tree.delete(item)
try:
conn = sqlite3.connect(self.db_path)
conn.row_factory = sqlite3.Row
cursor = conn.cursor()
# 检查表是否存在
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?", (table_id,))
if not cursor.fetchone():
conn.close()
return
cursor.execute(config["query"])
rows = cursor.fetchall()
cols = list(config["columns"].keys())
for row in rows:
vals = [row[c] if c in row.keys() else "" for c in cols]
# 简单搜索过滤
if search_text:
match = False
for val in vals:
if search_text in str(val).lower():
match = True
break
if not match:
continue
# 格式化金额
if "total_amount" in row.keys():
idx = cols.index("total_amount")
try:
vals[idx] = f"{float(vals[idx]):.2f}"
except:
pass
tree.insert("", tk.END, values=vals)
conn.close()
# 自动调整列宽
self.auto_resize_columns(table_id)
except Exception as e:
print(f"加载表 {table_id} 数据失败: {e}")
def auto_resize_columns(self, table_id):
"""根据内容自动调整列宽"""
info = self.trees[table_id]
tree = info["tree"]
config = info["config"]
for col in list(config["columns"].keys()):
# 获取表头宽度
header_text = config["columns"][col][0]
max_w = len(header_text) * 12 + 20
# 获取内容宽度(检查前 20 行)
for item in tree.get_children()[:20]:
val = str(tree.set(item, col))
w = len(val) * 8 + 20
if w > max_w:
max_w = w
# 限制最大宽度
max_w = min(max_w, 400)
tree.column(col, width=max_w)
def copy_cell_value(self, event, table_id):
"""双击复制单元格内容到剪贴板"""
tree = self.trees[table_id]["tree"]
region = tree.identify_region(event.x, event.y)
if region == "cell":
column = tree.identify_column(event.x)
item = tree.identify_row(event.y)
value = tree.set(item, column)
self.root.clipboard_clear()
self.root.clipboard_append(value)
messagebox.showinfo("成功", f"内容已复制到剪贴板:\n{value}")
def refresh_current_tab(self):
"""刷新当前选中的标签页"""
current_tab_idx = self.notebook.index(self.notebook.select())
table_ids = list(self.table_configs.keys())
if current_tab_idx < len(table_ids):
self.load_table_data(table_ids[current_tab_idx])
def clear_current_table(self):
"""清空当前表的记录"""
current_tab_idx = self.notebook.index(self.notebook.select())
table_ids = list(self.table_configs.keys())
if current_tab_idx >= len(table_ids):
return
table_id = table_ids[current_tab_idx]
title = self.table_configs[table_id]["title"]
if not messagebox.askyesno("警告", f"确定要永久清空表 '{title}' 的所有记录吗?此操作不可恢复!"):
return
try:
conn = sqlite3.connect(self.db_path)
conn.execute(f"DELETE FROM {table_id}")
conn.commit()
conn.close()
self.load_table_data(table_id)
messagebox.showinfo("成功", f"'{title}' 已清空")
except Exception as e:
messagebox.showerror("错误", f"清空表失败: {e}")
def show_db_viewer(root, config: Optional[ConfigManager] = None):
"""显示数据库查看器"""
DatabaseViewer(root, config=config)
+11 -1
View File
@@ -16,7 +16,17 @@ def select_file(log_widget, file_types=None, title="选择文件"):
"""通用文件选择对话框"""
if file_types is None:
file_types = [("所有文件", "*.*")]
file_path = filedialog.askopenfilename(title=title, filetypes=file_types)
# 获取默认输入目录
try:
config = ConfigManager()
initial_dir = config.get_path('Paths', 'input_folder', fallback='data/input')
if not os.path.exists(initial_dir):
initial_dir = os.getcwd()
except Exception:
initial_dir = os.getcwd()
file_path = filedialog.askopenfilename(title=title, filetypes=file_types, initialdir=initial_dir)
if file_path:
add_to_log(log_widget, f"已选择文件: {file_path}\n", "info")
return file_path
+19 -10
View File
@@ -13,7 +13,7 @@ from app.core.utils.log_utils import set_log_level
from .theme import THEMES, get_theme_mode, set_theme_mode, create_modern_button, create_card_frame
from .logging_ui import add_to_log, poll_log_queue
from .ui_widgets import StatusBar
from .ui_widgets import StatusBar, ToolTip
from .user_settings import (
load_user_settings, save_user_settings, refresh_recent_list_widget,
_extract_path_from_recent_item, clear_recent_files, RECENT_LIST_WIDGET,
@@ -33,6 +33,7 @@ from .config_dialog import show_config_dialog
from .barcode_editor import edit_barcode_mappings
from .shortcuts import bind_keyboard_shortcuts
from app.core.utils.dialog_utils import show_cloud_sync_dialog
from .db_viewer import show_db_viewer
def _init_window():
@@ -100,8 +101,14 @@ def _create_left_panel(content_frame, theme, log_text, status_bar):
pipeline_section.pack(fill=tk.X, pady=(0, 8))
pipeline_frame = tk.Frame(pipeline_section, bg=theme["card_bg"])
pipeline_frame.pack(fill=tk.X, padx=8, pady=6)
create_modern_button(pipeline_frame, "一键处理", lambda: run_pipeline_directly(log_text, status_bar), "primary", px_width=150, px_height=32).pack(anchor='w', pady=3)
create_modern_button(pipeline_frame, "一键处理全部图片", lambda: batch_process_all_inputs(log_text, status_bar), "primary", px_width=180, px_height=32).pack(anchor='w', pady=3)
btn_onekey = create_modern_button(pipeline_frame, "一键处理", lambda: run_pipeline_directly(log_text, status_bar), "primary", px_width=150, px_height=32)
btn_onekey.pack(anchor='w', pady=3)
ToolTip(btn_onekey.winfo_children()[0], "选择图片或Excel,自动完成OCR识别和采购单生成全流程")
btn_batch = create_modern_button(pipeline_frame, "批量处理", lambda: batch_process_all_inputs(log_text, status_bar), "primary", px_width=150, px_height=32)
btn_batch.pack(anchor='w', pady=3)
ToolTip(btn_batch.winfo_children()[0], "扫描 data/input 文件夹,处理所有未识别的图片")
# OCR处理区
core_section = tk.LabelFrame(
@@ -220,7 +227,7 @@ def _create_recent_files_section(parent, theme, log_text):
create_modern_button(rf_btns, "清理无效", purge_invalid, "primary", px_width=72, px_height=32).pack(side=tk.LEFT, padx=(3, 0))
def _create_right_panel(content_frame, theme, log_text, root):
def _create_right_panel(content_frame, theme, log_text, root, status_bar, config):
"""创建右侧面板:快捷操作、系统设置"""
right_panel = create_card_frame(content_frame)
right_panel.pack(side=tk.RIGHT, fill=tk.BOTH, expand=False, padx=(5, 0), pady=5)
@@ -240,12 +247,13 @@ def _create_right_panel(content_frame, theme, log_text, root):
tk.Frame(tools_buttons_frame, bg=theme["card_bg"]).pack(fill=tk.X, pady=3)
create_modern_button(tools_buttons_frame, "打开结果目录", lambda: open_result_directory(), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(tools_buttons_frame, "打开输出目录", lambda: os.startfile(ConfigManager().get_path('Paths', 'output_folder', fallback='data/output', create=True)), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(tools_buttons_frame, "打开输入目录", lambda: os.startfile(ConfigManager().get_path('Paths', 'input_folder', fallback='data/input', create=True)), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(tools_buttons_frame, "合并订单", lambda: merge_orders_with_status(log_text, StatusBar(root)), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(tools_buttons_frame, "打开输出目录", lambda: os.startfile(config.get_path('Paths', 'output_folder', fallback='data/output', create=True)), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(tools_buttons_frame, "打开输入目录", lambda: os.startfile(config.get_path('Paths', 'input_folder', fallback='data/input', create=True)), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(tools_buttons_frame, "合并订单", lambda: merge_orders_with_status(log_text, status_bar), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(tools_buttons_frame, "数据库内容", lambda: show_db_viewer(root, config=config), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(tools_buttons_frame, "清除缓存", lambda: clean_cache(log_text), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(tools_buttons_frame, "清理input/out文件", lambda: clean_data_files(log_text), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(tools_buttons_frame, "清理result文件", lambda: clean_result_files(log_text), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(tools_buttons_frame, "清理结果文件", lambda: clean_result_files(log_text), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
# 系统设置区
settings_section = tk.LabelFrame(
@@ -255,7 +263,7 @@ def _create_right_panel(content_frame, theme, log_text, root):
settings_section.pack(fill=tk.X, pady=(0, 8))
settings_buttons_frame = tk.Frame(settings_section, bg=theme["card_bg"])
settings_buttons_frame.pack(fill=tk.X, padx=8, pady=6)
create_modern_button(settings_buttons_frame, "系统设置", lambda: show_config_dialog(root, ConfigManager()), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(settings_buttons_frame, "系统设置", lambda: show_config_dialog(root, config), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(settings_buttons_frame, "条码映射", lambda: edit_barcode_mappings(log_text), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(settings_buttons_frame, "云端同步", lambda: show_cloud_sync_dialog(root), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
create_modern_button(settings_buttons_frame, "商品记忆库", lambda: show_memory_editor(root), "primary", px_width=132, px_height=32).pack(anchor='w', pady=3)
@@ -448,6 +456,7 @@ def main():
"""主函数"""
try:
root, theme, settings, dnd_supported = _init_window()
config = ConfigManager()
# 主容器
main_container = tk.Frame(root, bg=theme["bg"])
@@ -469,7 +478,7 @@ def main():
_create_left_panel(content_frame, theme, log_text, status_bar)
# 右侧面板
_create_right_panel(content_frame, theme, log_text, root)
_create_right_panel(content_frame, theme, log_text, root, status_bar, config)
# 拖拽区域
_setup_drag_area(mid_container, theme, dnd_supported, log_text, status_bar)
+1 -1
View File
@@ -6,7 +6,7 @@ from tkinter import ttk, messagebox, simpledialog
from app.config.settings import ConfigManager
from app.core.db.product_db import ProductDatabase
from .ui_widgets import center_window
from app.ui.ui_widgets import center_window
def _get_product_db():
+2 -2
View File
@@ -8,8 +8,8 @@ import datetime
import tkinter as tk
from tkinter import messagebox, scrolledtext
from .theme import THEMES, get_theme_mode, apply_theme
from .ui_widgets import center_window
from app.ui.theme import THEMES, get_theme_mode, apply_theme
from app.ui.ui_widgets import center_window
from app.core.utils.file_utils import format_file_size
from app.config.settings import ConfigManager
+3 -3
View File
@@ -5,15 +5,15 @@
import tkinter as tk
from tkinter import messagebox
from .ui_widgets import center_window
from .action_handlers import (
from app.ui.ui_widgets import center_window
from app.ui.action_handlers import (
process_single_image_with_status,
process_excel_file_with_status,
batch_ocr_with_status,
run_pipeline_directly,
merge_orders_with_status,
)
from .file_operations import clean_cache
from app.ui.file_operations import clean_cache
def bind_keyboard_shortcuts(root, log_widget, status_bar):
+30
View File
@@ -74,6 +74,36 @@ class ProgressReporter:
pass
class ToolTip:
"""给组件添加悬停提示"""
def __init__(self, widget, text):
self.widget = widget
self.text = text
self.tip_window = None
self.widget.bind("<Enter>", self.show_tip)
self.widget.bind("<Leave>", self.hide_tip)
def show_tip(self, event=None):
if self.tip_window or not self.text:
return
x, y, _cx, cy = self.widget.bbox("insert")
x = x + self.widget.winfo_rootx() + 27
y = y + cy + self.widget.winfo_rooty() + 27
self.tip_window = tw = tk.Toplevel(self.widget)
tw.wm_overrideredirect(1)
tw.wm_geometry("+%d+%d" % (x, y))
label = tk.Label(tw, text=self.text, justify=tk.LEFT,
background="#ffffe0", relief=tk.SOLID, borderwidth=1,
font=("tahoma", "8", "normal"), padx=4, pady=2)
label.pack(ipadx=1)
def hide_tip(self, event=None):
tw = self.tip_window
self.tip_window = None
if tw:
tw.destroy()
def create_collapsible_frame(parent, title, initial_state=True):
"""创建可折叠的面板"""
frame = tk.Frame(parent)