refactor(gui): 抽 update_ocr_results 到 components/ocr_results_view (4148 → 4117)
This commit is contained in:
1 parent
b3380042b8
commit
c5df7a05d2
2 files changed
+50
-33
No files matched your search
@@ -0,0 +1,48 @@
|
||||
"""OCR 结果展示 Tab 的更新逻辑。
|
||||
|
||||
从 ``gui/gui_app.py`` 抽出。原本是 ``main()`` 内的闭包 ``update_ocr_results``,
|
||||
被 ``do_screenshot`` 在 OCR 完成后通过 ``root.after`` 调用。
|
||||
|
||||
依赖通过显式参数注入:``text_widget`` (展示用的 ScrolledText/Text widget)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import tkinter as tk
|
||||
from typing import Sequence, Tuple
|
||||
|
||||
|
||||
def update_ocr_results(text_widget: tk.Text, results: Sequence[Tuple[str, str, str, str]]) -> None:
|
||||
"""更新OCR结果标签页的显示"""
|
||||
try:
|
||||
lines = []
|
||||
lines.append("=" * 80)
|
||||
lines.append("OCR识别结果(基于最新截图)")
|
||||
lines.append("=" * 80)
|
||||
lines.append("")
|
||||
|
||||
if not results:
|
||||
lines.append('暂无OCR结果,请先点击"截图+OCR"按钮')
|
||||
else:
|
||||
# 按区域名称分组显示
|
||||
for region_name, desc, text_result, status in results:
|
||||
lines.append(f"【{region_name}】{desc}")
|
||||
lines.append(f" 状态: {status}")
|
||||
if text_result:
|
||||
# 如果文本较长,分行显示
|
||||
if len(text_result) > 100:
|
||||
lines.append(f" 识别文本: {text_result[:100]}...")
|
||||
lines.append(f" (完整文本: {text_result})")
|
||||
else:
|
||||
lines.append(f" 识别文本: {text_result}")
|
||||
else:
|
||||
lines.append(" 识别文本: (空)")
|
||||
lines.append("")
|
||||
|
||||
text_widget.delete("1.0", "end")
|
||||
text_widget.insert("1.0", "\n".join(lines))
|
||||
text_widget.see("1.0")
|
||||
except Exception as e:
|
||||
text_widget.delete("1.0", "end")
|
||||
text_widget.insert("1.0", f"更新OCR结果失败:{e}")
|
||||
|
||||
+2
-33
@@ -56,6 +56,7 @@ from gui.components.actions_log_view import (
|
||||
)
|
||||
from gui.components.wifi_adb_pick_dialog import open_scan_pick_dialog as _open_scan_pick_dialog_impl
|
||||
from gui.components.wifi_adb_reconnect import try_reconnect_last_wifi as _try_reconnect_last_wifi_impl
|
||||
from gui.components.ocr_results_view import update_ocr_results as _update_ocr_results_impl
|
||||
|
||||
# 导入日志颜色配置模块
|
||||
try:
|
||||
@@ -3740,39 +3741,7 @@ def main():
|
||||
pass
|
||||
|
||||
def update_ocr_results(results):
|
||||
"""更新OCR结果标签页的显示"""
|
||||
try:
|
||||
lines = []
|
||||
lines.append("=" * 80)
|
||||
lines.append("OCR识别结果(基于最新截图)")
|
||||
lines.append("=" * 80)
|
||||
lines.append("")
|
||||
|
||||
if not results:
|
||||
lines.append('暂无OCR结果,请先点击"截图+OCR"按钮')
|
||||
else:
|
||||
# 按区域名称分组显示
|
||||
for region_name, desc, text_result, status in results:
|
||||
lines.append(f"【{region_name}】{desc}")
|
||||
lines.append(f" 状态: {status}")
|
||||
if text_result:
|
||||
# 如果文本较长,分行显示
|
||||
if len(text_result) > 100:
|
||||
lines.append(f" 识别文本: {text_result[:100]}...")
|
||||
lines.append(f" (完整文本: {text_result})")
|
||||
else:
|
||||
lines.append(f" 识别文本: {text_result}")
|
||||
else:
|
||||
lines.append(" 识别文本: (空)")
|
||||
lines.append("")
|
||||
|
||||
ocr_results_text.delete("1.0", "end")
|
||||
ocr_results_text.insert("1.0", "\n".join(lines))
|
||||
ocr_results_text.see("1.0")
|
||||
except Exception as e:
|
||||
ocr_results_text.delete("1.0", "end")
|
||||
ocr_results_text.insert("1.0", f"更新OCR结果失败:{e}")
|
||||
|
||||
_update_ocr_results_impl(ocr_results_text, results)
|
||||
ttk.Button(
|
||||
ocr_results_top, text="刷新", command=lambda: update_ocr_results([])
|
||||
).pack(side=LEFT)
|
||||
|
||||
Reference in new issue
Block a user