import os 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) # 抽离:ADB/配置/参数结构体到 gui_core.py(便于后续模块化) from gui.gui_core import ( RunParams, read_config, write_config, ) from douyin.core.path_config import get_logs_dir from gui.components.wifi_adb_scan_dialog import open_scan_dialog # noqa: F401 re-export from gui.components.preview_view import ( async_refresh_preview as _async_refresh_preview_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, # noqa: F401 re-export save_ui_to_config as _save_ui_to_config_impl, # noqa: F401 re-export ) from gui.components.simple_tabs import ( setup_simple_text_tab, # noqa: F401 re-export ) from gui.components.config_vars import build_config_vars from gui.components.top_device_bar import setup_top_device_bar from gui.components.top_buttons import setup_top_buttons from gui.components.log_pipeline import setup_log_pipeline from gui.components.root_window import setup_root_window from gui.components.left_config_area import setup_left_config_area from gui.components.right_main_area import setup_right_main_area from gui.components.periodic_refreshers import ( setup_periodic_refreshers, setup_close_handler, ) # 抑制 PyTorch DataLoader 的 pin_memory 警告(当没有 GPU 时,EasyOCR 会触发此警告) warnings.filterwarnings("ignore", message=".*pin_memory.*", category=UserWarning) warnings.filterwarnings("ignore", message=".*accelerator.*", category=UserWarning) # 兼容旧调用方:format_gui_log_line 现在由 log_pipeline 内部调用,这里仅作 re-export def format_gui_log_line(line: str) -> str: # noqa: F401 re-export for backward compat from gui.components.log_pipeline import _format_gui_log_line return _format_gui_log_line(line) def main(): _bundle = setup_root_window(read_config=read_config) root = _bundle.root ScrolledText = _bundle.ScrolledText import tkinter as tk from tkinter import ttk try: from ttkbootstrap.constants import X except ImportError: from tkinter.constants import X # type: ignore[assignment] q, _log_writer, on_line, runner = setup_log_pipeline() # 顶部:设备选择 + Y偏移(其余运行参数放到左侧分组,避免重复) top = ttk.Frame(root) top.pack(fill=X, padx=12, pady=10) # 配置区(提前读取配置,供后续使用) cfg = read_config() _vars_ = build_config_vars(cfg) gui_theme_var = _vars_["gui_theme_var"] y_var = _vars_["y_var"] theme_getter = lambda: str(gui_theme_var.get() or "litera") _top_bar = setup_top_device_bar(top, root=root, on_line=on_line, y_var=y_var) device_var = _top_bar.device_var refresh_devices = _top_bar.refresh_devices _left_area = setup_left_config_area( root, vars_=_vars_, cfg=cfg, ScrolledText_cls=ScrolledText, read_config=read_config, write_config=write_config, on_line=on_line, ) right = _left_area.right_frame save_ui_to_config = _left_area.save_ui_to_config def get_params() -> RunParams: return _get_params_impl({**_vars_, "device_var": device_var}) _right = setup_right_main_area( right, root=root, cfg=cfg, runner=runner, on_line=on_line, log_queue=q, device_var=device_var, save_ui_to_config=save_ui_to_config, get_params_from_vars=get_params, ScrolledText_cls=ScrolledText, theme_getter=theme_getter, logs_dir_getter=get_logs_dir, read_config=read_config, ) # 顶部常驻按钮(image_var/update_ocr_results/refresh_preview 都已就绪) setup_top_buttons( top, device_var=device_var, y_var=y_var, image_var=_right.image_var, on_line=on_line, root=root, on_save_ui_to_config=save_ui_to_config, on_ocr_results=_right.update_ocr_results, on_refresh_preview=_right.refresh_preview, ) setup_periodic_refreshers( root, image_var=_right.image_var, async_refresh_preview_impl=_async_refresh_preview_impl, preview_view=_right.preview_view, refresh_stats=_right.refresh_stats, refresh_reservations=_right.refresh_reservations, refresh_high_value_rooms=_right.refresh_high_value_rooms, refresh_actions_log=_right.refresh_actions_log, refresh_win_record=_right.refresh_win_record, runner=runner, ) setup_close_handler(root, runner=runner) 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()