Skip to content

Commit

Permalink
fix: Ensure playing starts when clicked after model param change
Browse files Browse the repository at this point in the history
Fixes: #1845
  • Loading branch information
rht authored and tpike3 committed Nov 3, 2023
1 parent 4ec7433 commit 0f196e5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mesa/experimental/jupyter_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0f196e5

Please sign in to comment.