631 lines
22 KiB
Python
631 lines
22 KiB
Python
import logging
|
||
import os
|
||
import queue
|
||
import re
|
||
import sys
|
||
import warnings
|
||
|
||
# 确保项目根目录在 Python 路径中(支持直接运行 gui/gui_app.py)
|
||
_script_dir = os.path.dirname(os.path.abspath(__file__))
|
||
_project_root = os.path.dirname(_script_dir)
|
||
if _project_root not in sys.path:
|
||
sys.path.insert(0, _project_root)
|
||
|
||
from PIL import ImageTk # type: ignore[import]
|
||
|
||
# 抽离:ADB/配置/参数结构体到 gui_core.py(便于后续模块化)
|
||
from gui.gui_core import (
|
||
RunParams,
|
||
Runner,
|
||
find_adb_executable,
|
||
list_adb_devices,
|
||
enable_wifi_adb,
|
||
connect_wifi_adb,
|
||
disconnect_wifi_adb,
|
||
get_device_ip,
|
||
auto_connect_wifi_adb,
|
||
is_device_wifi_connected,
|
||
get_connected_wifi_devices,
|
||
read_config,
|
||
write_config,
|
||
)
|
||
from gui.gui_core_pkg import (
|
||
DiscoveredDevice,
|
||
clear_last_wifi_target,
|
||
discover_adb_devices,
|
||
get_last_wifi_target,
|
||
get_local_subnet,
|
||
pick_best_match,
|
||
set_last_wifi_target,
|
||
)
|
||
from gui.gui_core_pkg.wifi_adb_scan import verify_adb_target, query_device_model # noqa: F401 re-export
|
||
from douyin.core.path_config import get_logs_dir
|
||
from gui.components.mapping_table import create_mapping_tab
|
||
from gui.components.wifi_adb_scan_dialog import open_scan_dialog # noqa: F401 re-export
|
||
from gui.components.wifi_adb_dialog import open_wifi_adb_dialog as _open_wifi_adb_dialog
|
||
from gui.components.reservations_view import refresh_reservations as _refresh_reservations_impl
|
||
from gui.components.high_value_view import refresh_high_value_rooms as _refresh_high_value_rooms_impl
|
||
from gui.components.screenshot_action import do_screenshot as _do_screenshot_impl
|
||
from gui.components.actions_log_view import (
|
||
configure_actions_log_colors as _configure_actions_log_colors_impl,
|
||
refresh_actions_log as _refresh_actions_log_impl,
|
||
)
|
||
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
|
||
from gui.components.log_pump import pump_logs as _pump_logs_impl
|
||
from gui.components.win_record_view import (
|
||
WinRecordView as _WinRecordView,
|
||
refresh_win_record as _refresh_win_record_impl,
|
||
on_win_list_select as _on_win_list_select_impl,
|
||
open_win_folder as _open_win_folder_impl,
|
||
load_false_positives as _load_false_positives_impl,
|
||
save_false_positives as _save_false_positives_impl,
|
||
)
|
||
from gui.components.preview_view import (
|
||
PreviewView as _PreviewView,
|
||
scan_image_files as _scan_image_files_impl,
|
||
update_image_list as _update_image_list_impl,
|
||
refresh_preview as _refresh_preview_impl,
|
||
_load_and_fit_image as _load_and_fit_image_impl,
|
||
open_pic_folder as _open_pic_folder_impl,
|
||
async_refresh_preview as _async_refresh_preview_impl,
|
||
)
|
||
from gui.components.wifi_adb_one_click_scan import (
|
||
on_scan_one_click as _on_scan_one_click_impl,
|
||
_handle_scan_result as _handle_scan_result_impl,
|
||
)
|
||
from gui.components.run_log_view import refresh_run_log as _refresh_run_log_impl # noqa: F401 re-export
|
||
from gui.components.text_search import generic_search_widget as _generic_search_widget_impl # noqa: F401 re-export
|
||
from gui.components.logging_config_io import save_logging_config as _save_logging_config_impl
|
||
from gui.components.run_params_builder import get_params as _get_params_impl
|
||
from gui.components.config_io import (
|
||
load_config_to_ui as _load_config_to_ui_impl,
|
||
save_ui_to_config as _save_ui_to_config_impl,
|
||
)
|
||
from gui.components.debug_tab import setup_debug_tab
|
||
from gui.components.logging_tab import setup_logging_tab
|
||
from gui.components.yanghao_tab import setup_yanghao_tab
|
||
from gui.components.reservation_tab import setup_reservation_tab
|
||
from gui.components.run_tab import setup_run_tab
|
||
from gui.components.filter_tab import setup_filter_tab
|
||
from gui.components.realtime_tab import setup_realtime_tab
|
||
from gui.components.log_text_colors import configure_log_text_colors
|
||
from gui.components.log_search_toolbar import setup_log_search_toolbar
|
||
from gui.components.win_record_tab import setup_win_record_tab
|
||
from gui.components.actions_log_toolbar import setup_actions_log_toolbar
|
||
from gui.components.simple_tabs import setup_simple_text_tab
|
||
from gui.components.preview_tab import setup_preview_tab
|
||
from gui.components.keywords_tab import setup_keywords_tab
|
||
from gui.components.main_notebook import setup_main_notebook
|
||
from gui.components.action_buttons import setup_action_buttons
|
||
from gui.components.config_vars import build_config_vars
|
||
|
||
# 导入日志颜色配置模块
|
||
try:
|
||
from gui.components.log_color_config import (
|
||
get_color_config,
|
||
apply_operation_color,
|
||
get_operation_type,
|
||
)
|
||
except ImportError:
|
||
# 如果模块不存在,使用空函数作为回退
|
||
def get_color_config(theme: str = "litera"):
|
||
return {}
|
||
|
||
def apply_operation_color(*args, **kwargs):
|
||
pass
|
||
|
||
def get_operation_type(line: str) -> str | None:
|
||
return None
|
||
|
||
|
||
# 抑制 PyTorch DataLoader 的 pin_memory 警告(当没有 GPU 时,EasyOCR 会触发此警告)
|
||
warnings.filterwarnings("ignore", message=".*pin_memory.*", category=UserWarning)
|
||
warnings.filterwarnings("ignore", message=".*accelerator.*", category=UserWarning)
|
||
|
||
# 模块级 logger:内部"日志写入失败 / pump_logs 异常"等错误统一走 logging
|
||
_LOGGER = logging.getLogger("gui.gui_app")
|
||
|
||
|
||
def format_gui_log_line(line: str) -> str:
|
||
"""将完整日志行转换为 GUI 显示用的精简版本。
|
||
|
||
实际实现位于 gui.components.log_viewer,此处仅作 re-export,
|
||
失败时回退到原始字符串。
|
||
"""
|
||
try:
|
||
from gui.components.log_viewer import format_gui_log_line as _impl
|
||
|
||
return _impl(line)
|
||
except Exception:
|
||
return (line or "").rstrip("\n")
|
||
|
||
|
||
def main():
|
||
# 主题优先级:使用 config 中的 gui.theme(若有),否则使用默认明亮主题 'litera'
|
||
cfg_theme = "darkly"
|
||
try:
|
||
cfg_theme = read_config().get("gui", {}).get("theme", "litera") or "litera"
|
||
except Exception:
|
||
cfg_theme = "litera"
|
||
|
||
# ttkbootstrap 优先(更美观);没装则回退到原生 tkinter
|
||
try:
|
||
import ttkbootstrap as tb
|
||
from ttkbootstrap.scrolled import ScrolledText
|
||
|
||
import tkinter as tk
|
||
from tkinter import ttk
|
||
from ttkbootstrap.constants import LEFT, RIGHT, BOTH, X, Y
|
||
|
||
# 使用 config 中指定的主题名
|
||
root = tb.Window(themename=cfg_theme)
|
||
except Exception:
|
||
import tkinter as tk
|
||
from tkinter import ttk
|
||
from tkinter.constants import LEFT, RIGHT, BOTH, X, Y # type: ignore[assignment]
|
||
from tkinter.scrolledtext import ScrolledText
|
||
|
||
root = tk.Tk()
|
||
|
||
# 常量兜底:部分主题常量未提供时使用字符串
|
||
BOTTOM = "bottom"
|
||
# W 常量在部分导入路径中可能不存在,兜底为 'w'(grid sticky 使用)
|
||
W = "w"
|
||
|
||
root.title("抖音福袋挂机 - 可视化控制台")
|
||
root.geometry("1400x900") # 增大窗口尺寸,提供更多空间
|
||
|
||
q: queue.Queue[str] = queue.Queue()
|
||
|
||
# 线程安全的日志文件写入器(已抽到 gui/components/log_writer)
|
||
from gui.components.log_writer import ThreadSafeLogWriter
|
||
log_writer = ThreadSafeLogWriter()
|
||
|
||
# 日志格式化已移至模块级别函数 format_gui_log_line()
|
||
|
||
def on_line(line: str):
|
||
"""处理日志行:GUI 显示用精简版本,文件写入用完整版本"""
|
||
# GUI 显示:使用精简后的版本
|
||
try:
|
||
display_line = format_gui_log_line(line)
|
||
except Exception:
|
||
display_line = line
|
||
q.put(display_line)
|
||
|
||
# 文件:写入完整日志行(不做精简处理)
|
||
try:
|
||
log_writer.write(line)
|
||
except Exception:
|
||
pass # 文件写入失败不应影响GUI显示
|
||
|
||
runner = Runner(on_line=on_line)
|
||
|
||
# 顶部:设备选择 + Y偏移(其余运行参数放到左侧分组,避免重复)
|
||
top = ttk.Frame(root)
|
||
top.pack(fill=X, padx=12, pady=10)
|
||
|
||
adb_exe = find_adb_executable()
|
||
devices = list_adb_devices(adb_exe)
|
||
device_var = tk.StringVar(value=(devices[0] if devices else ""))
|
||
|
||
ttk.Label(top, text="设备:").pack(side=LEFT)
|
||
device_combo = ttk.Combobox(top, textvariable=device_var, values=devices, width=28)
|
||
device_combo.pack(side=LEFT, padx=(0, 10))
|
||
|
||
def refresh_devices():
|
||
nonlocal adb_exe
|
||
adb_exe = find_adb_executable()
|
||
devs = list_adb_devices(adb_exe)
|
||
device_combo["values"] = devs
|
||
if devs and not device_var.get():
|
||
device_var.set(devs[0])
|
||
if not adb_exe:
|
||
on_line("[设备] 未找到 adb.exe(请确认已安装 platform-tools)")
|
||
elif not devs:
|
||
on_line("[设备] adb 可用,但未发现 device 状态设备(可能未授权/未连接)")
|
||
|
||
def save_logging_config():
|
||
_save_logging_config_impl(
|
||
vars_=_vars_,
|
||
read_config=read_config,
|
||
write_config=write_config,
|
||
on_line=on_line,
|
||
)
|
||
refresh_devices_btn = ttk.Button(top, text="刷新设备", command=refresh_devices)
|
||
refresh_devices_btn.pack(side=LEFT, padx=(0, 8))
|
||
|
||
# 一键扫描局域网 ADB 设备并自动连接(同 WiFi 下设备已开 5555 / 已授权时无需 USB)
|
||
scan_connect_btn = ttk.Button(top, text="扫描 WiFi")
|
||
scan_connect_btn.pack(side=LEFT, padx=(0, 20))
|
||
_scan_busy = {"flag": False}
|
||
|
||
def _try_reconnect_last_wifi():
|
||
_try_reconnect_last_wifi_impl(
|
||
root,
|
||
adb_exe=adb_exe,
|
||
device_var=device_var,
|
||
on_line=on_line,
|
||
refresh_devices=refresh_devices,
|
||
)
|
||
# 启动时延迟一点,等界面创建完成再尝试重连
|
||
root.after(300, _try_reconnect_last_wifi)
|
||
|
||
def _on_scan_one_click():
|
||
_on_scan_one_click_impl(
|
||
adb_exe=adb_exe,
|
||
scan_btn=scan_connect_btn,
|
||
scan_busy=_scan_busy,
|
||
root=root,
|
||
on_line=on_line,
|
||
device_var=device_var,
|
||
refresh_devices=refresh_devices,
|
||
open_pick_dialog=_open_scan_pick_dialog,
|
||
)
|
||
|
||
def _handle_scan_result(devs):
|
||
_handle_scan_result_impl(
|
||
devs,
|
||
on_line=on_line,
|
||
device_var=device_var,
|
||
refresh_devices=refresh_devices,
|
||
open_pick_dialog=_open_scan_pick_dialog,
|
||
)
|
||
|
||
def _open_scan_pick_dialog(devs):
|
||
_open_scan_pick_dialog_impl(
|
||
root,
|
||
devs,
|
||
device_var=device_var,
|
||
on_line=on_line,
|
||
refresh_devices=refresh_devices,
|
||
)
|
||
|
||
scan_connect_btn.config(command=_on_scan_one_click)
|
||
|
||
# WiFi ADB 功能
|
||
wifi_adb_btn = ttk.Button(
|
||
top,
|
||
text="WiFi ADB",
|
||
command=lambda: _open_wifi_adb_dialog(
|
||
root,
|
||
adb_exe=adb_exe,
|
||
on_line=on_line,
|
||
refresh_devices=refresh_devices,
|
||
),
|
||
)
|
||
wifi_adb_btn.pack(side=LEFT, padx=(0, 20))
|
||
|
||
# 配置区(提前读取配置,供后续使用)
|
||
cfg = read_config()
|
||
|
||
_vars_ = build_config_vars(cfg)
|
||
gui_theme_var = _vars_["gui_theme_var"]
|
||
y_var = _vars_["y_var"]
|
||
|
||
ttk.Label(top, text="Y偏移:").pack(side=LEFT)
|
||
ttk.Spinbox(top, from_=-200, to=200, textvariable=y_var, width=6).pack(
|
||
side=LEFT, padx=(0, 12)
|
||
)
|
||
|
||
# 中部:左侧配置(使用Notebook标签页)+ 右侧日志/预览(支持拖拽调整宽度)
|
||
mid = ttk.PanedWindow(root, orient="horizontal")
|
||
mid.pack(fill=BOTH, expand=True, padx=12, pady=(0, 12))
|
||
|
||
left_wrap = ttk.Frame(mid)
|
||
right = ttk.Frame(mid)
|
||
mid.add(left_wrap, weight=0) # 左侧配置区域
|
||
mid.add(right, weight=1) # 右侧日志/预览区域
|
||
|
||
# 左侧使用Notebook标签页组织配置
|
||
left_notebook = ttk.Notebook(left_wrap)
|
||
left_notebook.pack(fill=BOTH, expand=True)
|
||
|
||
# 创建左侧配置标签页
|
||
setup_run_tab(left_notebook, vars_=_vars_)
|
||
setup_filter_tab(left_notebook, vars_=_vars_)
|
||
setup_reservation_tab(left_notebook, vars_=_vars_)
|
||
_, yg_comment_texts, yg_like_keywords_text, yg_fav_keywords_text = setup_yanghao_tab(left_notebook, vars_=_vars_)
|
||
setup_debug_tab(left_notebook, vars_=_vars_)
|
||
setup_logging_tab(left_notebook, vars_=_vars_, on_save_logging=save_logging_config)
|
||
want_text, not_want_text = setup_keywords_tab(left_notebook, ScrolledText_cls=ScrolledText)
|
||
_config_io_texts = {
|
||
"not_want_text": not_want_text,
|
||
"want_text": want_text,
|
||
"yg_comment_texts": yg_comment_texts,
|
||
"yg_fav_keywords_text": yg_fav_keywords_text,
|
||
"yg_like_keywords_text": yg_like_keywords_text,
|
||
}
|
||
|
||
def load_config_to_ui():
|
||
nonlocal cfg
|
||
cfg = _load_config_to_ui_impl(
|
||
vars_=_vars_,
|
||
texts_=_config_io_texts,
|
||
read_config=read_config,
|
||
)
|
||
|
||
def save_ui_to_config():
|
||
_save_ui_to_config_impl(
|
||
vars_=_vars_,
|
||
texts_=_config_io_texts,
|
||
cfg=cfg,
|
||
read_config=read_config,
|
||
write_config=write_config,
|
||
on_line=on_line,
|
||
)
|
||
load_config_to_ui()
|
||
|
||
# 顶部常驻按钮区域(与设备选择同一行,不随左侧滚动)
|
||
top_btns = ttk.Frame(top)
|
||
top_btns.pack(side=RIGHT, padx=(20, 0))
|
||
ttk.Button(top_btns, text="保存配置", command=save_ui_to_config).pack(
|
||
side=LEFT, padx=(0, 8)
|
||
)
|
||
# 截图+OCR 按钮也放在顶部,方便随时使用
|
||
# 具体回调在后文定义,这里先占位,通过 lambda 延迟绑定
|
||
screenshot_btn = ttk.Button(
|
||
top_btns,
|
||
text="截图+OCR",
|
||
command=lambda: _do_screenshot_impl(
|
||
device_id=device_var.get().strip(),
|
||
y_offset=int(y_var.get() or 0),
|
||
image_var=image_var,
|
||
on_line=on_line,
|
||
root=root,
|
||
on_ocr_results=update_ocr_results,
|
||
on_refresh_preview=refresh_preview,
|
||
),
|
||
)
|
||
screenshot_btn.pack(side=LEFT, padx=(0, 8))
|
||
|
||
# 右侧:操作按钮区域(先创建,放在底部)
|
||
actions = ttk.Frame(right)
|
||
|
||
# 右侧:Notebook(日志 / 截图预览 / 统计信息 / 预约队列 / 高价值房间)
|
||
_main_nb = setup_main_notebook(
|
||
right,
|
||
on_open_realtime_viewer=lambda: (
|
||
_open_realtime_viewer_impl()
|
||
if callable(_open_realtime_viewer_impl)
|
||
else None
|
||
),
|
||
)
|
||
notebook = _main_nb.notebook
|
||
log_tab = _main_nb.log_tab
|
||
preview_tab = _main_nb.preview_tab
|
||
stats_tab = _main_nb.stats_tab
|
||
reservation_tab = _main_nb.reservation_tab
|
||
high_value_tab = _main_nb.high_value_tab
|
||
actions_log_tab = _main_nb.actions_log_tab
|
||
realtime_tab = _main_nb.realtime_tab
|
||
ocr_results_tab = _main_nb.ocr_results_tab
|
||
win_record_tab = _main_nb.win_record_tab
|
||
show_actions_var = _main_nb.show_actions_var
|
||
show_screenshot_var = _main_nb.show_screenshot_var
|
||
auto_scroll_var = _main_nb.auto_scroll_var
|
||
# forward-declare handler to satisfy linters; real function defined later
|
||
_open_realtime_viewer_impl = None
|
||
# 使用模块化组件创建映射表并加入 Notebook
|
||
mapping_tab = create_mapping_tab(root, notebook, cfg)
|
||
notebook.add(mapping_tab, text="映射表")
|
||
|
||
# 日志区
|
||
log_box = ttk.Frame(log_tab)
|
||
log_box.pack(fill=BOTH, expand=True)
|
||
|
||
setup_realtime_tab(
|
||
realtime_tab,
|
||
vars_={
|
||
"show_actions_var": show_actions_var,
|
||
"show_screenshot_var": show_screenshot_var,
|
||
"auto_scroll_var": auto_scroll_var,
|
||
},
|
||
root=root,
|
||
ScrolledText_cls=ScrolledText,
|
||
logs_dir_getter=get_logs_dir,
|
||
read_config=read_config,
|
||
)
|
||
|
||
# --------- 实时查看弹窗(紧凑视图) ---------
|
||
def _open_realtime_viewer_impl():
|
||
"""委托到 gui/components/realtime_viewer.open_realtime_viewer。"""
|
||
from gui.components.realtime_viewer import open_realtime_viewer
|
||
open_realtime_viewer(root)
|
||
|
||
log_text = ScrolledText(log_box)
|
||
try:
|
||
log_text.configure(font=("Consolas", 10))
|
||
except Exception:
|
||
pass
|
||
log_text.pack(fill=BOTH, expand=True, padx=10, pady=(0, 10))
|
||
|
||
# 搜索工具栏
|
||
_log_search_handles = setup_log_search_toolbar(
|
||
log_box,
|
||
log_text=log_text,
|
||
runner=runner,
|
||
theme_getter=lambda: str(gui_theme_var.get() or "litera"),
|
||
)
|
||
log_filter_var = _log_search_handles.log_filter_var
|
||
refresh_run_log = _log_search_handles.refresh_run_log
|
||
|
||
|
||
configure_log_text_colors(
|
||
log_text,
|
||
theme_getter=lambda: str(gui_theme_var.get() or "litera"),
|
||
)
|
||
|
||
_preview_handles = setup_preview_tab(
|
||
preview_tab,
|
||
on_line=on_line,
|
||
root=root,
|
||
)
|
||
_preview_view = _preview_handles.preview_view
|
||
image_var = _preview_handles.image_var
|
||
refresh_preview = _preview_handles.refresh_preview
|
||
|
||
status_var = tk.StringVar(value="就绪")
|
||
|
||
def get_params() -> RunParams:
|
||
return _get_params_impl({**_vars_, "device_var": device_var})
|
||
# 先打包 actions 到底部(不 expand,固定在底部)
|
||
actions.pack(fill=X, pady=(10, 0), padx=12, side="bottom")
|
||
# 然后打包 notebook 填充剩余空间(在 actions 之上)
|
||
notebook.pack(fill=BOTH, expand=True)
|
||
|
||
setup_action_buttons(
|
||
actions,
|
||
runner=runner,
|
||
status_var=status_var,
|
||
device_var=device_var,
|
||
on_line=on_line,
|
||
save_ui_to_config=save_ui_to_config,
|
||
get_params=get_params,
|
||
)
|
||
|
||
def pump_logs():
|
||
_pump_logs_impl(
|
||
q,
|
||
text_widget=log_text,
|
||
filter_getter=lambda: log_filter_var.get().strip(),
|
||
theme_getter=lambda: str(gui_theme_var.get() or "litera"),
|
||
root=root,
|
||
is_running_getter=runner.is_running,
|
||
status_getter=status_var.get,
|
||
status_setter=status_var.set,
|
||
)
|
||
# 统计信息显示
|
||
stats_top, stats_text = setup_simple_text_tab(stats_tab, ScrolledText_cls=ScrolledText)
|
||
|
||
def refresh_stats():
|
||
"""委托给 gui/components/stats_formatter.format_stats(纯字符串构建)。"""
|
||
try:
|
||
from gui.components.stats_formatter import format_stats
|
||
stats = runner.get_stats()
|
||
stats_text.delete("1.0", "end")
|
||
stats_text.insert("1.0", "\n".join(format_stats(stats)))
|
||
except Exception as e:
|
||
import traceback
|
||
|
||
stats_text.delete("1.0", "end")
|
||
error_detail = traceback.format_exc()
|
||
stats_text.insert(
|
||
"1.0", f"刷新统计信息失败:{e}\n\n详细信息:\n{error_detail}"
|
||
)
|
||
|
||
ttk.Button(stats_top, text="刷新", command=refresh_stats).pack(side=LEFT)
|
||
|
||
# 预约队列显示
|
||
reservation_top, reservation_text = setup_simple_text_tab(reservation_tab, ScrolledText_cls=ScrolledText)
|
||
|
||
def refresh_reservations():
|
||
_refresh_reservations_impl(reservation_text)
|
||
|
||
ttk.Button(reservation_top, text="刷新", command=refresh_reservations).pack(
|
||
side=LEFT
|
||
)
|
||
|
||
# 高价值房间显示
|
||
high_value_top, high_value_text = setup_simple_text_tab(high_value_tab, ScrolledText_cls=ScrolledText)
|
||
|
||
def refresh_high_value_rooms():
|
||
_refresh_high_value_rooms_impl(high_value_text)
|
||
|
||
ttk.Button(high_value_top, text="刷新", command=refresh_high_value_rooms).pack(
|
||
side=LEFT
|
||
)
|
||
|
||
# 行为日志显示(点击/识别/耗时)
|
||
actions_log_top, actions_log_text = setup_simple_text_tab(actions_log_tab, ScrolledText_cls=ScrolledText)
|
||
|
||
_actions_log_handles = setup_actions_log_toolbar(
|
||
actions_log_top,
|
||
actions_log_text=actions_log_text,
|
||
theme_getter=lambda: str(gui_theme_var.get() or "litera"),
|
||
)
|
||
refresh_actions_log = _actions_log_handles.refresh_actions_log
|
||
|
||
# OCR结果显示
|
||
ocr_results_top, ocr_results_text = setup_simple_text_tab(ocr_results_tab, ScrolledText_cls=ScrolledText)
|
||
|
||
def update_ocr_results(results):
|
||
_update_ocr_results_impl(ocr_results_text, results)
|
||
ttk.Button(
|
||
ocr_results_top, text="刷新", command=lambda: update_ocr_results([])
|
||
).pack(side=LEFT)
|
||
ttk.Label(ocr_results_top, text='(点击"截图+OCR"按钮自动更新)').pack(
|
||
side=LEFT, padx=(10, 0)
|
||
)
|
||
|
||
_win_record_handles = setup_win_record_tab(
|
||
win_record_tab,
|
||
on_line=on_line,
|
||
ScrolledText_cls=ScrolledText,
|
||
open_realtime_viewer=lambda: (
|
||
_open_realtime_viewer_impl()
|
||
if callable(_open_realtime_viewer_impl)
|
||
else None
|
||
),
|
||
)
|
||
refresh_win_record = _win_record_handles.refresh_win_record
|
||
|
||
pump_logs()
|
||
|
||
def delayed_refresh_preview() -> None:
|
||
if image_var.get():
|
||
_async_refresh_preview()
|
||
|
||
def _async_refresh_preview() -> None:
|
||
_async_refresh_preview_impl(_preview_view)
|
||
|
||
root.after(3000, delayed_refresh_preview) # type: ignore[arg-type]
|
||
root.after(500, refresh_stats) # type: ignore[arg-type]
|
||
root.after(500, refresh_reservations) # type: ignore[arg-type]
|
||
root.after(500, refresh_high_value_rooms) # type: ignore[arg-type]
|
||
root.after(500, refresh_actions_log) # type: ignore[arg-type]
|
||
root.after(500, refresh_win_record) # type: ignore[arg-type]
|
||
|
||
# 定期刷新行为日志(每2秒)
|
||
def auto_refresh_actions_log() -> None:
|
||
refresh_actions_log()
|
||
root.after(2000, auto_refresh_actions_log) # type: ignore[arg-type]
|
||
|
||
# 定期刷新预约队列(每5秒)
|
||
def auto_refresh_reservations() -> None:
|
||
refresh_reservations()
|
||
root.after(5000, auto_refresh_reservations) # type: ignore[arg-type]
|
||
|
||
root.after(2000, auto_refresh_actions_log) # type: ignore[arg-type]
|
||
root.after(5000, auto_refresh_reservations) # type: ignore[arg-type]
|
||
|
||
# 定期刷新统计信息(每3秒)
|
||
def auto_refresh_stats() -> None:
|
||
if runner.is_running():
|
||
refresh_stats()
|
||
root.after(3000, auto_refresh_stats) # type: ignore[arg-type]
|
||
|
||
auto_refresh_stats()
|
||
|
||
def on_close():
|
||
try:
|
||
runner.stop()
|
||
except Exception:
|
||
pass
|
||
root.destroy()
|
||
|
||
root.protocol("WM_DELETE_WINDOW", on_close)
|
||
refresh_devices()
|
||
root.mainloop()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
try:
|
||
from douyin.core.version import print_version_banner
|
||
|
||
print_version_banner("gui_app")
|
||
except Exception:
|
||
pass
|
||
main()
|