1 2
from __future__ import absolute_import, division, unicode_literals
2

3 2
import param
4

5 2
from .widgets import Widget
6

7 2
ipywidget_classes = {}
8

9

10 2
def param_value_if_widget(arg):
11 2
    if isinstance(arg, Widget):
12 2
        return arg.param.value
13

14 0
    from .pane.ipywidget import IPyWidget
15 0
    if IPyWidget.applies(arg) and hasattr(arg, 'value'):
16 0
        name = type(arg).__name__
17 0
        if name in ipywidget_classes:
18 0
            ipy_param = ipywidget_classes[name]
19
        else:
20 0
            ipy_param = param.parameterized_class(name, {'value': param.Parameter()})
21 0
        ipywidget_classes[name] = ipy_param
22 0
        ipy_inst = ipy_param(value=arg.value)
23 0
        arg.observe(lambda event: ipy_inst.param.set_param(value=event['new']), 'value')
24 0
        return ipy_inst.param.value
25 0
    return arg
26

27

28 2
def depends(*args, **kwargs):
29 2
    updated_args = [param_value_if_widget(a) for a in  args]
30 2
    updated_kwargs = {k: param_value_if_widget(v) for k, v in kwargs.items()}
31

32 2
    return param.depends(*updated_args, **updated_kwargs)

Read our documentation on viewing source code .

Loading