Skip to content

Commit

Permalink
Added refresh button
Browse files Browse the repository at this point in the history
  • Loading branch information
dsblank committed Jan 10, 2018
1 parent 53e72a5 commit be1a967
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions jyro/simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ def __init__(self, robot=None, worldf=None, size=None, gamepad=False,
self.size = size if size else (400, 400)
self.trace = trace
self.canvas = self.makeCanvas()
self.reset()
self.widgets = {}
self.reset()
self.physics.draw(self.canvas, trace=self.trace)
self.widget = self.create_widgets(gamepad)
if self.widget:
Expand All @@ -614,6 +614,8 @@ def reset(self):
for robot in self.robots:
robot.reset()
self.physics.addRobot(robot)
if self.widgets:
self.update_gui()

def create_widgets(self, gamepad=False):
pass
Expand Down Expand Up @@ -810,6 +812,7 @@ def create_widgets(self, gamepad=False):
step = ipywidgets.Button(icon="fa-step-forward")
clear = ipywidgets.Button(description="Clear Output")
play = ipywidgets.Play(max=1000000, show_repeat=False, layout={"width": "100%"})
refresh_button = Button(icon="refresh", layout=Layout(width="25%"))
time = ipywidgets.Text(description="Time:", value="0.0 seconds")
html_canvas = ipywidgets.HTML(value=self.canvas._repr_svg_())
output = ipywidgets.Output()
Expand Down Expand Up @@ -837,9 +840,10 @@ def init_gamepad(data):
row1.append(gamepad)
horz = ipywidgets.HBox(row1)
title = ipywidgets.VBox([ipywidgets.HBox([update, trace, time]), horz])
controls = ipywidgets.HBox([step, play, clear])
controls = ipywidgets.HBox([step, play, clear, refresh_button])
vbox = ipywidgets.VBox([title, controls, output])
play.observe(self.step, 'value')
refresh_button.on_click(lambda widget: self.reset())
step.on_click(lambda data: self.step({"new": -1})) # signal to step once
clear.on_click(lambda data: self.widgets["output"].clear_output())
update.observe(self.update_gui, 'value')
Expand All @@ -854,6 +858,7 @@ def init_gamepad(data):
self.widgets.update({
"step": step,
"play": play,
"refresh": refresh_button,
"time": time,
"html_canvas": html_canvas,
"output": output,
Expand Down Expand Up @@ -908,7 +913,6 @@ def update_gui(self, data=None, set_angle=True):
self.widgets["pan"].value = 100 - ((a % (math.pi * 2))/(math.pi * 2)) * 100

def step(self, data={"new": 1}, run_brain=True):
## Update Simulator:
if data["new"] == 0:
self.reset()
self.physics.time = 0.0
Expand Down

0 comments on commit be1a967

Please sign in to comment.