From 0f196e5e50b8b4000c55bf8015e277242b657035 Mon Sep 17 00:00:00 2001 From: rht Date: Mon, 30 Oct 2023 03:47:18 -0400 Subject: [PATCH] fix: Ensure playing starts when clicked after model param change Fixes: #1845 --- mesa/experimental/jupyter_viz.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mesa/experimental/jupyter_viz.py b/mesa/experimental/jupyter_viz.py index 2405c38ec98..de12a08374e 100644 --- a/mesa/experimental/jupyter_viz.py +++ b/mesa/experimental/jupyter_viz.py @@ -204,6 +204,14 @@ def do_pause(): def do_reset(): reset_counter.value += 1 + def do_set_playing(value): + if current_step == 0: + # This means the model has been recreated, and the step resets to + # 0. We want to avoid triggering the playing.value = False in the + # on_value_play function. + previous_step.value = current_step + playing.set(value) + with solara.Row(): solara.Button(label="Step", color="primary", on_click=do_step) # This style is necessary so that the play widget has almost the same @@ -222,7 +230,7 @@ def do_reset(): show_repeat=False, on_value=on_value_play, playing=playing.value, - on_playing=playing.set, + on_playing=do_set_playing, ) solara.Button(label="Reset", color="primary", on_click=do_reset) # threaded_do_play is not used for now because it