feat: 添加确保输入框获得焦点的选项,优化文本粘贴功能
This commit is contained in:
1 parent
a3b15e3965
commit
df96e5fc83
4 files changed
+172
-21
No files matched your search
+72
-1
@@ -1077,7 +1077,78 @@ def main():
|
||||
width=8,
|
||||
).pack(side=LEFT)
|
||||
|
||||
# 标签页4:养号设置
|
||||
# 新增:映射表标签页(用于查看运行时/持久化的 room_pos -> title 映射)
|
||||
mapping_tab = ttk.Frame(left_notebook)
|
||||
left_notebook.add(mapping_tab, text="映射表")
|
||||
|
||||
map_box = ttk.LabelFrame(mapping_tab, text="运行时映射表(room_pos -> (title, title_raw))")
|
||||
map_box.pack(fill=X, padx=10, pady=(10, 10))
|
||||
|
||||
map_ctrl = ttk.Frame(map_box)
|
||||
map_ctrl.pack(fill=X, padx=10, pady=(8, 6))
|
||||
|
||||
map_auto_refresh_var = tk.BooleanVar(value=False)
|
||||
ttk.Checkbutton(map_ctrl, text="自动刷新(5s)", variable=map_auto_refresh_var).pack(
|
||||
side=LEFT
|
||||
)
|
||||
ttk.Button(map_ctrl, text="刷新映射表", width=12).pack(side=LEFT, padx=(8, 6))
|
||||
|
||||
# 映射内容显示区
|
||||
map_view = ScrolledText(mapping_tab, wrap="none", height=12)
|
||||
map_view.pack(fill=BOTH, expand=True, padx=10, pady=(6, 10))
|
||||
|
||||
# 加载映射表的函数(尝试多个可能的路径)
|
||||
def _load_mapping_to_view():
|
||||
map_view.delete("1.0", "end")
|
||||
possible_paths = [
|
||||
os.path.join(os.getcwd(), "douyin", "core", "state", "room_pos_map.json"),
|
||||
os.path.join(os.getcwd(), "douyin", "core", "state", "reservations.json"),
|
||||
os.path.join(os.getcwd(), "douyin", "state", "room_pos_map.json"),
|
||||
]
|
||||
found = False
|
||||
for p in possible_paths:
|
||||
try:
|
||||
if os.path.exists(p):
|
||||
with open(p, "r", encoding="utf-8") as f:
|
||||
data = f.read()
|
||||
# 尝试格式化 JSON,否则原样显示
|
||||
try:
|
||||
import json as _json
|
||||
|
||||
parsed = _json.loads(data)
|
||||
pretty = _json.dumps(parsed, ensure_ascii=False, indent=2)
|
||||
map_view.insert("end", f"# 从: {p}\n")
|
||||
map_view.insert("end", pretty)
|
||||
except Exception:
|
||||
map_view.insert("end", f"# 从: {p}(非JSON,原始内容)\n")
|
||||
map_view.insert("end", data)
|
||||
found = True
|
||||
break
|
||||
except Exception as e:
|
||||
map_view.insert("end", f"读取 {p} 失败: {e}\n")
|
||||
if not found:
|
||||
map_view.insert(
|
||||
"end",
|
||||
"未找到映射表文件。可在运行端将 '_room_pos_to_title_map' 序列化到 'douyin/core/state/room_pos_map.json',然后点击刷新以查看内容。",
|
||||
)
|
||||
|
||||
# 绑定刷新按钮与自动刷新
|
||||
btns = map_ctrl.winfo_children()
|
||||
if btns and isinstance(btns[-1], ttk.Button):
|
||||
btns[-1].config(command=_load_mapping_to_view)
|
||||
|
||||
def _maybe_auto_refresh():
|
||||
if map_auto_refresh_var.get():
|
||||
try:
|
||||
_load_mapping_to_view()
|
||||
except Exception:
|
||||
pass
|
||||
root.after(5000, _maybe_auto_refresh)
|
||||
|
||||
# 启动自动刷新轮询(无害,如果开关关闭不会频繁IO)
|
||||
root.after(5000, _maybe_auto_refresh)
|
||||
|
||||
# 养号设置标签(后续代码)
|
||||
yanghao_tab = ttk.Frame(left_notebook)
|
||||
left_notebook.add(yanghao_tab, text="养号设置")
|
||||
|
||||
|
||||
Reference in new issue
Block a user