Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure playing starts when clicked after model param change #1851

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_reset():
reset_counter.value += 1

def do_set_playing(value):

Check warning on line 207 in mesa/experimental/jupyter_viz.py

View check run for this annotation

Codecov / codecov/patch

mesa/experimental/jupyter_viz.py#L207

Added line #L207 was not covered by tests
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)

Check warning on line 213 in mesa/experimental/jupyter_viz.py

View check run for this annotation

Codecov / codecov/patch

mesa/experimental/jupyter_viz.py#L212-L213

Added lines #L212 - L213 were not covered by tests

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 @@
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