feat: 添加提取耗时悬浮计时器,并修复无表格时引发的 IndexError

This commit is contained in:
HONOR
2026-09-16 13:36:20 +08:00
parent edb390e4f8
commit 8f87562feb
2 changed files with 39 additions and 16 deletions
+18
View File
@@ -7,6 +7,7 @@ from tkinter import filedialog, messagebox, ttk
import pythoncom
import windnd
import datetime
import time
from utils.config import CONFIG_FILE, APP_DIR
from core.extractor import detect_and_create_apps, export_single_doc_tables
@@ -174,6 +175,10 @@ class BatchTableExtractorApp:
sb.pack(side=tk.RIGHT, fill=tk.Y)
self.txt.config(yscrollcommand=sb.set)
# 添加耗时悬浮标签
self.lbl_timer = tk.Label(self.txt, text="00:00:00.000", font=("Consolas", 10), bg="white", fg="gray")
self.lbl_timer.place(relx=1.0, rely=0.0, anchor=tk.NE, x=-10, y=5)
def _on_debug_toggle(self):
if self.debug_var.get():
messagebox.showinfo("Debug 模式说明", "开启 Debug 模式后,程序在提取表格时将强制显示 Office/WPS 窗口。\n\n这主要用于排查程序“卡死”的问题。例如:当文档被加密或需要修复时,Office 会在后台弹窗等待用户点击。开启此模式可让你看到这些弹窗并手动处理。")
@@ -282,6 +287,16 @@ class BatchTableExtractorApp:
self._save_config()
self.root.destroy()
def _update_timer(self):
if getattr(self, '_is_running', False):
elapsed = time.time() - getattr(self, '_start_time', time.time())
hours, rem = divmod(elapsed, 3600)
minutes, seconds = divmod(rem, 60)
ms = int((elapsed - int(elapsed)) * 1000)
time_str = f"{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}.{ms:03d}"
self.lbl_timer.config(text=time_str)
self.root.after(50, self._update_timer)
def _start(self):
self._save_config()
src = self.src_path_var.get().strip()
@@ -332,6 +347,9 @@ class BatchTableExtractorApp:
self.log(f"\n===== 开始任务: 共扫描到 {len(files_to_process)} 个文件 =====")
self._start_time = time.time()
self._update_timer()
threading.Thread(
target=self._worker,
args=(files_to_process, out),