79 lines
2.5 KiB
Python
79 lines
2.5 KiB
Python
"""GUI 周期性刷新调度 + 关闭处理。
|
|
|
|
从 ``gui/gui_app.py`` 抽出。包括:
|
|
- 启动时延迟一次性刷新各 Tab 内容(预览/统计/预约/高价值房间/操作日志/中奖记录)
|
|
- 周期性刷新(操作日志 2s / 预约 5s / 统计 3s)
|
|
- 窗口关闭时停止 runner
|
|
|
|
依赖通过显式参数注入。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tkinter as tk
|
|
from typing import Any, Callable
|
|
|
|
|
|
def setup_periodic_refreshers(
|
|
root: tk.Misc,
|
|
*,
|
|
image_var: tk.StringVar,
|
|
async_refresh_preview_impl: Callable[[Any], None],
|
|
preview_view: Any,
|
|
refresh_stats: Callable[[], None],
|
|
refresh_reservations: Callable[[], None],
|
|
refresh_high_value_rooms: Callable[[], None],
|
|
refresh_actions_log: Callable[[], None],
|
|
refresh_win_record: Callable[[], None],
|
|
runner: Any,
|
|
) -> None:
|
|
"""启动延迟刷新 + 周期刷新调度。"""
|
|
|
|
def delayed_refresh_preview() -> None:
|
|
if image_var.get():
|
|
async_refresh_preview_impl(preview_view)
|
|
|
|
root.after(3000, delayed_refresh_preview) # type: ignore[arg-type]
|
|
root.after(500, refresh_stats) # type: ignore[arg-type]
|
|
root.after(500, refresh_reservations) # type: ignore[arg-type]
|
|
root.after(500, refresh_high_value_rooms) # type: ignore[arg-type]
|
|
root.after(500, refresh_actions_log) # type: ignore[arg-type]
|
|
root.after(500, refresh_win_record) # type: ignore[arg-type]
|
|
|
|
# 定期刷新行为日志(每2秒)
|
|
def auto_refresh_actions_log() -> None:
|
|
refresh_actions_log()
|
|
root.after(2000, auto_refresh_actions_log) # type: ignore[arg-type]
|
|
|
|
# 定期刷新预约队列(每5秒)
|
|
def auto_refresh_reservations() -> None:
|
|
refresh_reservations()
|
|
root.after(5000, auto_refresh_reservations) # type: ignore[arg-type]
|
|
|
|
root.after(2000, auto_refresh_actions_log) # type: ignore[arg-type]
|
|
root.after(5000, auto_refresh_reservations) # type: ignore[arg-type]
|
|
|
|
# 定期刷新统计信息(每3秒)
|
|
def auto_refresh_stats() -> None:
|
|
if runner.is_running():
|
|
refresh_stats()
|
|
root.after(3000, auto_refresh_stats) # type: ignore[arg-type]
|
|
|
|
auto_refresh_stats()
|
|
|
|
|
|
def setup_close_handler(
|
|
root: tk.Misc,
|
|
*,
|
|
runner: Any,
|
|
) -> None:
|
|
"""绑定窗口关闭(WM_DELETE_WINDOW)→ 停止 runner + 销毁 root。"""
|
|
def on_close():
|
|
try:
|
|
runner.stop()
|
|
except Exception:
|
|
pass
|
|
root.destroy()
|
|
|
|
root.protocol("WM_DELETE_WINDOW", on_close)
|