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}")
|
||||
Reference in new issue
Block a user