add pause resume controls to ui

This commit is contained in:
Your Name committed 2026-06-23 02:38:08 +08:00
1 parent 3c7cb45bec
commit d81e00ddbc
13 files changed
+367 -12

No files matched your search

+17 -2
View File
@@ -1,4 +1,4 @@
"""底部操作按钮区(开始运行 / 停止 / 强制停止 / 发送返回键 / 状态标签)。
"""底部操作按钮区(开始运行 / 暂停继续 / 停止 / 强制停止 / 发送返回键 / 状态标签)。
从 ``gui/gui_app.py`` 抽出。原本是 ``main()`` 内的 widget 创建段 + 4 个按钮回调
(``start_run`` / ``stop_run`` / ``force_stop_run`` / ``send_back_key``)。
@@ -24,7 +24,7 @@ def setup_action_buttons(
save_ui_to_config: Callable[[], None],
get_params: Callable[[], Any],
) -> None:
"""构建底部操作按钮区(开始/停止/强制停止/发送返回键 + 状态标签)。"""
"""构建底部操作按钮区(开始/暂停继续/停止/强制停止/发送返回键 + 状态标签)。"""
def start_run() -> None:
if runner.is_running():
@@ -65,6 +65,18 @@ def setup_action_buttons(
runner.stop()
status_var.set("已停止")
def pause_resume_run() -> None:
if not runner.is_running():
on_line("[暂停] 当前没有正在运行的进程")
status_var.set("未运行")
return
if getattr(runner, "is_paused", lambda: False)():
ok = runner.resume()
status_var.set("运行中" if ok else "继续失败")
else:
ok = runner.pause()
status_var.set("已暂停" if ok else "暂停失败")
def force_stop_run() -> None:
"""强制终止后台进程(包括可能残留的子进程)。"""
runner.force_stop()
@@ -78,6 +90,9 @@ def setup_action_buttons(
on_line(f"[错误] 发送返回键失败: {e}")
ttk.Button(actions, text="开始运行", command=start_run).pack(side=LEFT, padx=(0, 8))
ttk.Button(actions, text="暂停/继续", command=pause_resume_run).pack(
side=LEFT, padx=(0, 4)
)
ttk.Button(actions, text="停止", command=stop_run).pack(side=LEFT, padx=(0, 4))
ttk.Button(actions, text="强制停止", command=force_stop_run).pack(
side=LEFT, padx=(0, 8)