def __init__(self, par):
        self.par = par

        # Define widgets.
        self.value_text = FloatText(description=par.name,
                                    min=self.par.min, max=self.par.max)
        self.min_text = FloatText(description='min', max=self.par.max)
        self.max_text = FloatText(description='max', min=self.par.min)
        self.min_checkbox = Checkbox(description='min')
        self.max_checkbox = Checkbox(description='max')
        self.vary_checkbox = Checkbox(description='vary')

        # Set widget values and visibility.
        if par.value is not None:
            self.value_text.value = self.par.value
        min_unset = self.par.min is None or self.par.min == -np.inf
        max_unset = self.par.max is None or self.par.max == np.inf
        self.min_checkbox.value = not min_unset
        self.min_text.visible = not min_unset
        self.min_text.value = self.par.min
        self.max_checkbox.value = not max_unset
        self.max_text.visible = not max_unset
        self.max_text.value = self.par.max
        self.vary_checkbox.value = self.par.vary

        # Configure widgets to sync with par attributes.
        self.value_text.on_trait_change(self._on_value_change, 'value')
        self.min_text.on_trait_change(self._on_min_value_change, 'value')
        self.max_text.on_trait_change(self._on_max_value_change, 'value')
        self.min_checkbox.on_trait_change(self._on_min_checkbox_change,
                                          'value')
        self.max_checkbox.on_trait_change(self._on_max_checkbox_change,
                                          'value')
        self.vary_checkbox.on_trait_change(self._on_vary_change, 'value')
Exemple #2
0
    def __init__(self, par):
        self.par = par

        # Define widgets.
        self.value_text = FloatText(description=par.name,
                                            min=self.par.min, max=self.par.max)
        self.min_text = FloatText(description='min', max=self.par.max)
        self.max_text = FloatText(description='max', min=self.par.min)
        self.min_checkbox = Checkbox(description='min')
        self.max_checkbox = Checkbox(description='max')
        self.vary_checkbox = Checkbox(description='vary')

        # Set widget values and visibility.
        if par.value is not None:
            self.value_text.value = self.par.value
        min_unset = self.par.min is None or self.par.min == -np.inf
        max_unset = self.par.max is None or self.par.max == np.inf
        self.min_checkbox.value = not min_unset
        self.min_text.visible = not min_unset
        self.min_text.value = self.par.min
        self.max_checkbox.value = not max_unset
        self.max_text.visible = not max_unset
        self.max_text.value = self.par.max
        self.vary_checkbox.value = self.par.vary

        # Configure widgets to sync with par attributes.
        self.value_text.on_trait_change(self._on_value_change, 'value')
        self.min_text.on_trait_change(self._on_min_value_change, 'value')
        self.max_text.on_trait_change(self._on_max_value_change, 'value')
        self.min_checkbox.on_trait_change(self._on_min_checkbox_change, 'value')
        self.max_checkbox.on_trait_change(self._on_max_checkbox_change, 'value')
        self.vary_checkbox.on_trait_change(self._on_vary_change, 'value')
 def update_info(self):
     controller = self.controller 
     html = HTML()
     html_string = '<b>Name:</b> ' + controller.name + '<br>'
     html_string += '<b>Case Number:</b> ' + self.case.case_number + '<br>'
     html_string += '<b>Case Signature:</b> (' + self.case.signature + ')<br>'
     html_string += '<b>Valid:</b> ' + str(self.case.is_valid()) + '<br>'
     html_string += '<b>Is Cyclical:</b> ' + str(self.case.is_cyclical) + '<br><hr>'
     check_box = Checkbox(description='Logarithmic coordinates', 
                                        value=self.log_coordinates)
     check_box.on_trait_change(self.change_logarithmic, 'value')
     html.value = html_string
     self.info.children = [html, check_box]
    def make_display_widget(self):
        controller = self.controller 
        if controller.ds is None:
            return
        self.info = VBox()
        self.constraints_widget = VBox()
        self.plot = HBox()
        self.log_coordinates = True
        self.global_tolerance = VBox()
        close_button = Button(description='Close Tab')
        close_button.on_click(self.close_widget)
        ss_options = ['log('+ i + ')' for i in controller.ds.dependent_variables]
        self.y_dropdown = Dropdown(description='y-axis',
                                   values=ss_options,
                                   options=ss_options,
                                   value=self.y_variable)
        self.make_plot = Button(description='Create Plot')
        self.make_plot.on_click(self.change_y_axis)
        self.make_plot.yaxis = self.y_dropdown
        self.make_plot.visible = True
        check_box = Checkbox(description='Logarithmic coordinates', 
                                           value=self.log_coordinates)
        check_box.on_trait_change(self.update_log, 'value')
        self.y_dropdown.visible = False
        if len(self.slice_variables) <= 3:
            ## self.make_plot.visible = True
            if len(self.slice_variables) == 1:
                self.y_dropdown.visible = True
            if len(self.slice_variables) == 3:
                self.y_dropdown = HTML(value='<font color="red">Warning 3D plots are experimental.</font>')
        wi = VBox(children=[self.info, 
                            self.constraints_widget,
                            check_box,
                            self.y_dropdown,
                            self.make_plot,
                            self.global_tolerance,
                            close_button])
        if old_ipython is True:
            wi.set_css('height', '400px')
        else:
            wi.height='400px'
            wi.overflow_x = 'auto'
            wi.overflow_y = 'auto'

        self.update_display()
        controller.update_child(self.name, wi)
class DisplaySystem(object):
    
    def __init__(self, controller):
        setattr(self, 'controller', controller)
        setattr(self, 'html', None)
        setattr(self, 'html_equations', None)
        setattr(self, 'latex', None)
        
    def create_system_widget(self):
        controller = self.controller 
        if controller.ds is None:
            return
        self.html = HTML()
        self.html_equations = HTML()
        self.latex = Latex()
        self.checkbox = Checkbox(description='Typeset Equations?',
                                 value=True)
        self.checkbox.on_trait_change(self.changed_check_box, 'value')
        wi = VBox(children=[self.html,
                                    self.checkbox,
                                    self.html_equations,
                                    self.latex])
        self.update_display()
        controller.update_child('System', wi)
        
    def update_display(self):
        controller = self.controller 
        html_string = '<b>Name:</b> ' + controller.name
        html_string += ' (<font color="darkred">v{0}</font>)<br>'.format(controller.version) if controller.version != '' else '<br>'
        html_string += '<b>Number of Cases:</b> ' + str(controller.ds.number_of_cases) + '<br>'
        html_string += '<b>System Signature:</b> [' + controller.ds.signature + ']<br><hr>'
        html_string += '<b>Equations:</b><br><br>'
        if self.checkbox.value is True:
            self.html_equations.value = ''
            latex_string = controller.ds.equations._repr_latex_()
        else:
            self.html_equations.value = '<br>'.join([str(i) for i in controller.ds.equations]) 
            latex_string = ''
        self.latex.value = latex_string
        self.html.value = html_string
    
    def changed_check_box(self, name, value):
        self.update_display()
        
 def function_2D_plot_widget(self):
     controller = self.controller
     zlim = controller.defaults('zlim')
     value = str(self.plot_type.value)
     log_linear_widget = Checkbox(description='Function is log linear',
                                                value=True)
     if value == 'Steady State Flux':
         flux_options = ['log(V_'+ i + ')' for i in controller.ds.dependent_variables]
         function_widget = Dropdown(values=flux_options,
                                    options=flux_options)
         self.title.value = 'System design space showing a steady state flux'
         self.caption.value = 'Steady state flux shown as a heat map on the z-axis.'
     elif value == 'Steady State Function':
         function_widget = Text(description='Function', value='')
         log_linear_widget.value = False
         self.title.value = 'System design space showing a function at steady state'
         self.caption.value = 'Steady state function shown as a heat map on the z-axis.'
     else:
         ss_options = ['log('+ i + ')' for i in controller.ds.dependent_variables]
         function_widget = Dropdown(values=ss_options,
                                    options=ss_options)
         self.title.value = 'System Design Space showing a steady state concentration'
         self.caption.value = 'Steady state concentration shown as a heat map on the z-axis.'
     resolution_widget = FloatText(description='Resolution', value=controller.defaults('resolution'))
     parallel_widget = Checkbox(description='Compute in Parallel', value=False)
     zlim_auto = (zlim is None)
     zlim_widget = Checkbox(description='Automatic Z-Lim', value=zlim_auto)
     if zlim_auto is True:
         zlim = [0., 0.]
     zmin_widget = FloatText(description='Z-Min', value=zlim[0])
     zmax_widget = FloatText(description='Z-Max', value=zlim[1])
     wi = VBox(children=[function_widget, resolution_widget,
                                            zlim_widget, zmin_widget, zmax_widget,
                                            parallel_widget, log_linear_widget])
     wi.function = function_widget
     wi.resolution = resolution_widget
     wi.parallel = parallel_widget
     wi.log_linear = log_linear_widget
     wi.zlim = zlim_widget
     wi.zmin = zmin_widget
     wi.zmax = zmax_widget
     self.plot_data.children = [wi]
     return
 def update_equations(self):
     controller = self.controller 
     case = self.case
     check_box = Checkbox(description='Show only dynamical system?', 
                                        value=self.dynamic_only)
     check_box.on_trait_change(self.change_dynamic_only, 'value')
     if self.case.ssystem.solution is None:
         check_box.disables = True            
     equations = Latex()
     if self.dynamic_only is False:
         equations.value = case.equations._repr_latex_()
     else:
         ssys = case.ssystem.remove_algebraic_constraints()
         equations.value = ssys.equations._repr_latex_()
     solution = Latex()
     conditions = Latex() 
     boundaries = Latex() 
     if self.log_coordinates is True:
         conditions.value = case.conditions_log._repr_latex_()
         solution_data = case.ssystem.solution_log
         boundary_data = case.boundaries_log
     else:
         conditions.value = case.conditions._repr_latex_()
         solution_data = case.ssystem.solution
         boundary_data = case.boundaries
     if solution_data is not None:
         solution.value = solution_data._repr_latex_()
         boundaries.value = boundary_data._repr_latex_()
     else:
         solution.value = 'S-System has no solution.'
         boundaries.value = 'S-System has no solution.'
     self.equations.children = [check_box,
                                HTML(value='<b>Equations:</b><br>'),
                                equations, 
                                HTML(value='<b>Conditions:</b><br>'),
                                conditions, 
                                HTML(value='<b>Solution:</b><br>'),
                                solution,
                                HTML(value='<b>Boundaries:</b><br>'),
                                boundaries]
Exemple #8
0
def _widget_abbrev_single_value(o):
    """Make widgets from single values, which can be used as parameter defaults."""
    if isinstance(o, string_types):
        return TextWidget(value=unicode_type(o))
    elif isinstance(o, dict):
        return DropdownWidget(values=o)
    elif isinstance(o, bool):
        return CheckboxWidget(value=o)
    elif isinstance(o, float):
        min, max, value = _get_min_max_value(None, None, o)
        return FloatSliderWidget(value=o, min=min, max=max)
    elif isinstance(o, int):
        min, max, value = _get_min_max_value(None, None, o)
        return IntSliderWidget(value=o, min=min, max=max)
    else:
        return None
 def create_system_widget(self):
     controller = self.controller 
     if controller.ds is None:
         return
     self.html = HTML()
     self.html_equations = HTML()
     self.latex = Latex()
     self.checkbox = Checkbox(description='Typeset Equations?',
                              value=True)
     self.checkbox.on_trait_change(self.changed_check_box, 'value')
     wi = VBox(children=[self.html,
                                 self.checkbox,
                                 self.html_equations,
                                 self.latex])
     self.update_display()
     controller.update_child('System', wi)
Exemple #10
0
class ParameterWidgetGroup(object):
    """Construct several widgets that together represent a Parameter.

    This will only be used if IPython is available."""
    def __init__(self, par):
        self.par = par

        # Define widgets.
        self.value_text = FloatText(description=par.name,
                                            min=self.par.min, max=self.par.max)
        self.min_text = FloatText(description='min', max=self.par.max)
        self.max_text = FloatText(description='max', min=self.par.min)
        self.min_checkbox = Checkbox(description='min')
        self.max_checkbox = Checkbox(description='max')
        self.vary_checkbox = Checkbox(description='vary')

        # Set widget values and visibility.
        if par.value is not None:
            self.value_text.value = self.par.value
        min_unset = self.par.min is None or self.par.min == -np.inf
        max_unset = self.par.max is None or self.par.max == np.inf
        self.min_checkbox.value = not min_unset
        self.min_text.visible = not min_unset
        self.min_text.value = self.par.min
        self.max_checkbox.value = not max_unset
        self.max_text.visible = not max_unset
        self.max_text.value = self.par.max
        self.vary_checkbox.value = self.par.vary

        # Configure widgets to sync with par attributes.
        self.value_text.on_trait_change(self._on_value_change, 'value')
        self.min_text.on_trait_change(self._on_min_value_change, 'value')
        self.max_text.on_trait_change(self._on_max_value_change, 'value')
        self.min_checkbox.on_trait_change(self._on_min_checkbox_change, 'value')
        self.max_checkbox.on_trait_change(self._on_max_checkbox_change, 'value')
        self.vary_checkbox.on_trait_change(self._on_vary_change, 'value')

    def _on_value_change(self, name, value):
        self.par.value = value

    def _on_min_checkbox_change(self, name, value):
        self.min_text.visible = value
        if value:
            min_unset = self.par.min is None or self.par.min == -np.inf
            # -np.inf does not play well with a numerical text field,
            # so set min to 1 if activated (and back to -inf if deactivated).
            self.min_text.value = -1 
            self.par.min = self.min_text.value 
            self.value_text.min = self.min_text.value
        else:
            self.par.min = None

    def _on_max_checkbox_change(self, name, value):
        self.max_text.visible = value
        if value:
            # np.inf does not play well with a numerical text field,
            # so set max to 1 if activated (and back to inf if deactivated).
            max_unset = self.par.max is None or self.par.max == np.inf
            self.max_text.value = 1
            self.par.max = self.max_text.value
            self.value_text.max = self.max_text.value
        else:
            self.par.max = None

    def _on_min_value_change(self, name, value):
        self.par.min = value
        self.value_text.min = value
        self.max_text.min = value

    def _on_max_value_change(self, name, value):
        self.par.max = value
        self.value_text.max = value
        self.min_text.max = value

    def _on_vary_change(self, name, value):
        self.par.vary = value
        self.value_text.disabled = not value

    def close(self):
        # one convenience method to close (i.e., hide and disconnect) all
        # widgets in this group
        self.value_text.close()
        self.min_text.close()
        self.max_text.close()
        self.vary_checkbox.close()
        self.min_checkbox.close()
        self.max_checkbox.close()

    def _repr_html_(self):
        box = Box()
        box.children = [self.value_text, self.vary_checkbox, 
                        self.min_text, self.min_checkbox,
                        self.max_text, self.max_checkbox]
        display(box)
        box.add_class('hbox')

    # Make it easy to set the widget attributes directly.
    @property
    def value(self):
        return self.value_text.value

    @value.setter
    def value(self, value):
        self.value_text.value = value

    @property
    def vary(self):
        return self.vary_checkbox.value

    @vary.setter
    def vary(self, value):
        self.vary_checkbox.value = value

    @property
    def min(self):
        return self.min_text.value

    @min.setter
    def min(self, value):
        self.min_text.value = value

    @property
    def max(self):
        return self.max_text.value

    @min.setter
    def max(self, value):
        self.max_text.value = value

    @property
    def name(self):
       return self.par.name
Exemple #11
0
class ParameterWidgetGroup(object):
    """Construct several widgets that together represent a Parameter.

    This will only be used if IPython is available."""
    def __init__(self, par):
        self.par = par

        # Define widgets.
        self.value_text = FloatText(description=par.name,
                                    min=self.par.min,
                                    max=self.par.max)
        self.value_text.width = 100
        self.min_text = FloatText(description='min', max=self.par.max)
        self.min_text.width = 100
        self.max_text = FloatText(description='max', min=self.par.min)
        self.max_text.width = 100
        self.min_checkbox = Checkbox(description='min')
        self.max_checkbox = Checkbox(description='max')
        self.vary_checkbox = Checkbox(description='vary')

        # Set widget values and visibility.
        if par.value is not None:
            self.value_text.value = self.par.value
        min_unset = self.par.min is None or self.par.min == -np.inf
        max_unset = self.par.max is None or self.par.max == np.inf
        self.min_checkbox.value = not min_unset
        self.min_text.visible = not min_unset
        self.min_text.value = self.par.min
        self.max_checkbox.value = not max_unset
        self.max_text.visible = not max_unset
        self.max_text.value = self.par.max
        self.vary_checkbox.value = self.par.vary

        # Configure widgets to sync with par attributes.
        self.value_text.on_trait_change(self._on_value_change, 'value')
        self.min_text.on_trait_change(self._on_min_value_change, 'value')
        self.max_text.on_trait_change(self._on_max_value_change, 'value')
        self.min_checkbox.on_trait_change(self._on_min_checkbox_change,
                                          'value')
        self.max_checkbox.on_trait_change(self._on_max_checkbox_change,
                                          'value')
        self.vary_checkbox.on_trait_change(self._on_vary_change, 'value')

    def _on_value_change(self, name, value):
        self.par.value = value

    def _on_min_checkbox_change(self, name, value):
        self.min_text.visible = value
        if value:
            # -np.inf does not play well with a numerical text field,
            # so set min to -1 if activated (and back to -inf if deactivated).
            self.min_text.value = -1
            self.par.min = self.min_text.value
            self.value_text.min = self.min_text.value
        else:
            self.par.min = None

    def _on_max_checkbox_change(self, name, value):
        self.max_text.visible = value
        if value:
            # np.inf does not play well with a numerical text field,
            # so set max to 1 if activated (and back to inf if deactivated).
            self.max_text.value = 1
            self.par.max = self.max_text.value
            self.value_text.max = self.max_text.value
        else:
            self.par.max = None

    def _on_min_value_change(self, name, value):
        self.par.min = value
        self.value_text.min = value
        self.max_text.min = value

    def _on_max_value_change(self, name, value):
        self.par.max = value
        self.value_text.max = value
        self.min_text.max = value

    def _on_vary_change(self, name, value):
        self.par.vary = value
        # self.value_text.disabled = not value

    def close(self):
        # one convenience method to close (i.e., hide and disconnect) all
        # widgets in this group
        self.value_text.close()
        self.min_text.close()
        self.max_text.close()
        self.vary_checkbox.close()
        self.min_checkbox.close()
        self.max_checkbox.close()

    def _repr_html_(self):
        box = HBox()
        box.children = [
            self.value_text, self.vary_checkbox, self.min_checkbox,
            self.min_text, self.max_checkbox, self.max_text
        ]
        display(box)

    # Make it easy to set the widget attributes directly.
    @property
    def value(self):
        return self.value_text.value

    @value.setter
    def value(self, value):
        self.value_text.value = value

    @property
    def vary(self):
        return self.vary_checkbox.value

    @vary.setter
    def vary(self, value):
        self.vary_checkbox.value = value

    @property
    def min(self):
        return self.min_text.value

    @min.setter
    def min(self, value):
        self.min_text.value = value

    @property
    def max(self):
        return self.max_text.value

    @max.setter
    def max(self, value):
        self.max_text.value = value

    @property
    def name(self):
        return self.par.name