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

Added text boxes to edit the initial conditions in the GUI. #333

Merged
merged 6 commits into from
Mar 9, 2016
Merged
Changes from 1 commit
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
Next Next commit
Added text boxes to edit the initial conditions in the GUI.
  • Loading branch information
moorepants committed Mar 6, 2016
commit e154483028446c38a323144e9643f8a8a49338bb
43 changes: 36 additions & 7 deletions pydy/viz/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,12 @@ def _rerun_button_callback(self, btn):
original_scene_file = self._scene_json_file
original_sim_file = self._simulation_json_file
original_constants = self.system.constants.copy()
original_initial_conditions = self.system.initial_conditions.copy()
try:
self.system.constants = {s: w.value for s, w in
self._constants_text_widgets.items()}
self.system.initial_conditions = {s: w.value for s, w in
self._initial_conditions_text_widgets.items()}
pydy_dir = os.path.join(os.getcwd(), self.pydy_directory)
self._generate_json(directory=pydy_dir)
except:
Expand All @@ -669,7 +672,9 @@ def _rerun_button_callback(self, btn):
self._scene_json_file = original_scene_file
self._simulation_json_file = original_sim_file
self.system.constants = original_constants
self.system.initial_conditions = original_initial_conditions
self._fill_constants_widgets()
self._fill_initial_conditions_widgets()

js_tmp = 'jQuery("#json-input").val("{}/{}");'
js = js_tmp.format(self.pydy_directory, self._scene_json_file)
Expand All @@ -690,9 +695,26 @@ def _fill_constants_widgets(self):

text_widget = widgets.FloatText(value=init_val,
description=desc)
# NOTE : These widgets overlap each other in the HBox and this
# width setting (the default) keeps them from overlapping.
text_widget.width = 'auto'

self._constants_text_widgets[sym] = text_widget

def _fill_initial_conditions_widgets(self):

for sym, val in self._system.initial_conditions.items():

desc = latex(sym, mode='inline')

text_widget = widgets.FloatText(value=val,
description=desc)
# NOTE : These widgets overlap each other in the HBox and this
# width setting (the default) keeps them from overlapping.
text_widget.width = 'auto'

self._initial_conditions_text_widgets[sym] = text_widget

def _initialize_rerun_button(self):
"""Construct a button for controlling rerunning the simulations."""

Expand Down Expand Up @@ -727,20 +749,27 @@ def display_ipython(self):
# button if the scene was generated with a System.
if self._system is not None:

# Construct a container that holds all of the constants input
# text widgets.
self._constants_container = widgets.Box()
self._constants_container._css = [("canvas", "width", "100%")]
self._initial_conditions_container = widgets.Box()
self._initial_conditions_text_widgets = OrderedDict()
self._fill_initial_conditions_widgets()
self._initial_conditions_container.children = \
((widgets.HTML('<strong>Initial Conditions</strong>'), ) +
tuple(v for v in self._initial_conditions_text_widgets.values()))

self._constants_container = widgets.Box()
self._constants_text_widgets = OrderedDict()
self._fill_constants_widgets()
# Add all of the constants widgets to the container.
self._constants_container.children = \
tuple(v for v in self._constants_text_widgets.values())
((widgets.HTML('<strong>Constants</strong>'), ) +
tuple(v for v in self._constants_text_widgets.values()))

self._initialize_rerun_button()

display(self._constants_container)
parameter_input_container = \
widgets.HBox(children=(self._initial_conditions_container,
self._constants_container))

display(parameter_input_container)
display(self._rerun_button)

ipython_static_url = os.path.relpath(self.pydy_directory, os.getcwd())
Expand Down