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
  • Loading branch information
rht committed Oct 30, 2023
1 parent adc5549 commit adb9a3e
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 @@ -130,6 +130,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 @@ -148,7 +156,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)
solara.Markdown(md_text=f"**Step:** {current_step}")
Expand Down

0 comments on commit adb9a3e

Please sign in to comment.