예제 #1
0
 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')
예제 #2
0
 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)
예제 #3
0
 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')
예제 #4
0
 def _repr_html_(self):
     display(self.models_menu)
     button_box = HBox()
     button_box.children = [self.fit_button, self.guess_button]
     display(button_box)
     for pw in self.param_widgets:
         display(pw)
     self.plot()
예제 #5
0
def interactive(__interact_f, **kwargs):
    """Build a group of widgets to interact with a function."""
    f = __interact_f
    co = kwargs.pop('clear_output', True)
    kwargs_widgets = []
    container = ContainerWidget()
    container.result = None
    container.args = []
    container.kwargs = dict()
    kwargs = kwargs.copy()

    new_kwargs = _find_abbreviations(f, kwargs)
    # Before we proceed, let's make sure that the user has passed a set of args+kwargs
    # that will lead to a valid call of the function. This protects against unspecified
    # and doubly-specified arguments.
    getcallargs(f, **{n: v for n, v in new_kwargs})
    # Now build the widgets from the abbreviations.
    kwargs_widgets.extend(_widgets_from_abbreviations(new_kwargs))
    kwargs_widgets.extend(
        _widgets_from_abbreviations(sorted(kwargs.items(),
                                           key=lambda x: x[0])))

    # This has to be done as an assignment, not using container.children.append,
    # so that traitlets notices the update. We skip any objects (such as fixed) that
    # are not DOMWidgets.
    c = [w for w in kwargs_widgets if isinstance(w, DOMWidget)]
    container.children = c

    # Build the callback
    def call_f(name, old, new):
        container.kwargs = {}
        for widget in kwargs_widgets:
            value = widget.value
            container.kwargs[widget.description] = value
        if co:
            clear_output(wait=True)
        try:
            container.result = f(**container.kwargs)
        except Exception as e:
            ip = get_ipython()
            if ip is None:
                container.log.warn("Exception in interact callback: %s",
                                   e,
                                   exc_info=True)
            else:
                ip.showtraceback()

    # Wire up the widgets
    for widget in kwargs_widgets:
        widget.on_trait_change(call_f, 'value')

    container.on_displayed(lambda _: call_f(None, None, None))

    return container
예제 #6
0
def interactive(__interact_f, **kwargs):
    """Build a group of widgets to interact with a function."""
    f = __interact_f
    co = kwargs.pop('clear_output', True)
    kwargs_widgets = []
    container = ContainerWidget()
    container.result = None
    container.args = []
    container.kwargs = dict()
    kwargs = kwargs.copy()

    new_kwargs = _find_abbreviations(f, kwargs)
    # Before we proceed, let's make sure that the user has passed a set of args+kwargs
    # that will lead to a valid call of the function. This protects against unspecified
    # and doubly-specified arguments.
    getcallargs(f, **{n:v for n,v in new_kwargs})
    # Now build the widgets from the abbreviations.
    kwargs_widgets.extend(_widgets_from_abbreviations(new_kwargs))
    kwargs_widgets.extend(_widgets_from_abbreviations(sorted(kwargs.items(), key = lambda x: x[0])))

    # This has to be done as an assignment, not using container.children.append,
    # so that traitlets notices the update. We skip any objects (such as fixed) that
    # are not DOMWidgets.
    c = [w for w in kwargs_widgets if isinstance(w, DOMWidget)]
    container.children = c

    # Build the callback
    def call_f(name, old, new):
        container.kwargs = {}
        for widget in kwargs_widgets:
            value = widget.value
            container.kwargs[widget.description] = value
        if co:
            clear_output(wait=True)
        try:
            container.result = f(**container.kwargs)
        except Exception as e:
            ip = get_ipython()
            if ip is None:
                container.log.warn("Exception in interact callback: %s", e, exc_info=True)
            else:
                ip.showtraceback()

    # Wire up the widgets
    for widget in kwargs_widgets:
        widget.on_trait_change(call_f, 'value')

    container.on_displayed(lambda _: call_f(None, None, None))

    return container
 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)