From a07ef00b5e0ba425ac7b8f6f5f4bc21555797791 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 30 May 2026 13:56:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor(gui):=20=E6=8A=BD=20refresh=5Fhigh=5Fv?= =?UTF-8?q?alue=5Frooms=20=E5=88=B0=20components/high=5Fvalue=5Fview=20(46?= =?UTF-8?q?56=20=E2=86=92=204635)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui/components/high_value_view.py | 39 +++++++++++++++++++++++++++++++ gui/gui_app.py | 25 ++------------------ 2 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 gui/components/high_value_view.py diff --git a/gui/components/high_value_view.py b/gui/components/high_value_view.py new file mode 100644 index 0000000..5cb7411 --- /dev/null +++ b/gui/components/high_value_view.py @@ -0,0 +1,39 @@ +"""高价值房间 Tab 视图刷新逻辑。 + +从 ``gui/gui_app.py`` 抽出。原本是 ``main()`` 内的闭包 ``refresh_high_value_rooms``, +负责读 ``state/high_value_rooms.json`` 并以 JSON 格式渲染到 Tab。 + +依赖通过显式参数注入:``text_widget`` (展示用的 ScrolledText/Text widget)。 +""" + +from __future__ import annotations + +import json +import os +import tkinter as tk + + +def refresh_high_value_rooms(text_widget: tk.Text) -> None: + try: + from douyin.core.path_config import get_high_value_rooms_path + + path = get_high_value_rooms_path() + except Exception: + # 回退到旧路径(向后兼容) + from douyin.core import path_config + + path = path_config.get_high_value_rooms_path() + try: + if os.path.exists(path): + with open(path, "r", encoding="utf-8") as f: + data = json.load(f) + text_widget.delete("1.0", "end") + text_widget.insert( + "1.0", json.dumps(data, ensure_ascii=False, indent=2) + ) + else: + text_widget.delete("1.0", "end") + text_widget.insert("1.0", "暂无高价值房间数据") + except Exception as e: + text_widget.delete("1.0", "end") + text_widget.insert("1.0", f"读取高价值房间失败:{e}") diff --git a/gui/gui_app.py b/gui/gui_app.py index c6aa69c..88c694a 100644 --- a/gui/gui_app.py +++ b/gui/gui_app.py @@ -48,6 +48,7 @@ from gui.components.mapping_table import create_mapping_tab from gui.components.wifi_adb_scan_dialog import open_scan_dialog 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 # 导入日志颜色配置模块 try: @@ -3983,29 +3984,7 @@ def main(): pass def refresh_high_value_rooms(): - try: - from douyin.core.path_config import get_high_value_rooms_path - - path = get_high_value_rooms_path() - except Exception: - # 回退到旧路径(向后兼容) - from douyin.core import path_config - - path = path_config.get_high_value_rooms_path() - try: - if os.path.exists(path): - with open(path, "r", encoding="utf-8") as f: - data = json.load(f) - high_value_text.delete("1.0", "end") - high_value_text.insert( - "1.0", json.dumps(data, ensure_ascii=False, indent=2) - ) - else: - high_value_text.delete("1.0", "end") - high_value_text.insert("1.0", "暂无高价值房间数据") - except Exception as e: - high_value_text.delete("1.0", "end") - high_value_text.insert("1.0", f"读取高价值房间失败:{e}") + _refresh_high_value_rooms_impl(high_value_text) ttk.Button(high_value_top, text="刷新", command=refresh_high_value_rooms).pack( side=LEFT