refactor(gui): 抽 refresh_high_value_rooms 到 components/high_value_view (4656 → 4635)
This commit is contained in:
1 parent
5329561b3a
commit
a07ef00b5e
2 files changed
+41
-23
No files matched your search
@@ -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}")
|
||||
+2
-23
@@ -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
|
||||
|
||||
Reference in new issue
Block a user