Esempio n. 1
0
 def _validate(self):
     if not self.param.validate_btn.constant:
         self.param.validate_btn.constant = True
         self.pre_validate()
         is_valid = self.validate()
         self.validated = is_valid
         if is_valid:
             param.depends(
                 'environment_variables',
                 'load_modules',
                 'unload_modules',
                 watch=True)(self.un_validate)  # TODO: this is not working
         else:
             self.param.validate_btn.constant = False
             self.param.trigger('validated')
Esempio n. 2
0
def depends(*args, **kwargs):
    """
    Python decorator annotating a function or Parameterized method to
    express its dependencies on a set of Parameters. This declaration
    allows Panel to watch those dependencies and then invoke the
    function or method to get an updated output when one of the
    dependencies changes.

    This function is the same as the corresponding param.depends
    decorator, but extended so that if widgets are provided as
    dependencies, the underlying `value` Parameter of the widget is
    extracted as the actual dependency. This extension is solely for
    syntactic convenience, allowing the widget to be passed in as a
    synonym for the underlying parameter. Apart from that extension,
    this decorator otherwise behaves the same as the underlying Param
    depends decorator.
    
    For the Panel version of the decorator, the specified dependencies
    can either be Parameter instances, Panel or ipywidgets widgets,
    or, if a Parameterized method is supplied rather than a function,
    they can be defined either as string names of Parameters of this
    object or as Parameter objects of this object's subobjects (i.e.,
    Parameterized objects that are values of this object's
    Parameters). See the docs for the corresponding param.depends
    decorator for further details.
    """
    updated_args = [param_value_if_widget(a) for a in args]
    updated_kwargs = {k: param_value_if_widget(v) for k, v in kwargs.items()}
    return param.depends(*updated_args, **updated_kwargs)
Esempio n. 3
0
def test_get_param_function_pane_type():
    test = View()

    def view(a):
        return Div(text='%d' % a)

    assert PaneBase.get_pane_type(view) is not ParamFunction
    assert PaneBase.get_pane_type(param.depends(test.param.a)(view)) is ParamFunction
Esempio n. 4
0
 def _validate(self):
     if not self.param.validate_btn.constant:
         self.param.validate_btn.constant = True
         self.pre_validate()
         is_valid = self.validate()
         self.validated = is_valid
         if is_valid:
             param.depends(
                 self.param.job_name,
                 self.param.environment_variables,
                 self.param.modules_to_load,
                 self.param.modules_to_unload,
                 watch=True
             )(self.un_validate)
         else:
             self.param.validate_btn.constant = False
             self.param.trigger('validated')
Esempio n. 5
0
def depends(*args, **kwargs):
    updated_args = [param_value_if_widget(a) for a in args]
    updated_kwargs = {k: param_value_if_widget(v) for k, v in kwargs.items()}

    return param.depends(*updated_args, **updated_kwargs)
    def __init__(self,
                 user,
                 lang,
                 agent_type=None,
                 doc=None,
                 fav_charts_widget=None,
                 theme_name='',
                 **params):
        self.user = user
        self.agent_type = agent_type
        self.lang = lang
        self.doc = doc
        self.fav_charts_widget = fav_charts_widget
        self._active_style = theme_name
        if self.show_initial_table:
            toggle_label = _('Hide table')
        else:
            toggle_label = _('View table')
        self.queryset_widgets_objs = {}
        self.toggle_widget = pn.widgets.Toggle(name=toggle_label,
                                               value=self.show_initial_table,
                                               max_width=30)
        self.fav_chart_1_widget = pn.widgets.Checkbox(name='1',
                                                      width_policy='min',
                                                      align='start',
                                                      height_policy='min',
                                                      css_classes=[
                                                          'fav-checkbox',
                                                      ])
        self.fav_chart_2_widget = pn.widgets.Checkbox(name='2',
                                                      width_policy='min',
                                                      align='start',
                                                      height_policy='min',
                                                      css_classes=[
                                                          'fav-checkbox',
                                                      ])

        if self.fav_charts_widget:
            self.fav_charts_widget.param.watch(self.on_fav_charts_changed,
                                               'value')

        super().__init__(**params)
        common_dependencies = []
        self.init_queryset_widgets(common_dependencies)
        self.widgets = {
            widget_name: widget()
            for widget_name, widget in self.widgets_cls.items()
        }
        for _name, _inst in self.widgets.items():
            self.param._add_parameter(_name, _inst.param)
            common_dependencies.append(_name)
        self.param._add_parameter(
            'new_theme_name',
            param.String(default=self._active_style, precedence=-1))
        self.param._add_parameter(
            'show_table',
            param.Boolean(default=self.show_initial_table, precedence=-1))
        self.col = None
        chart_dependencies = common_dependencies + ['new_theme_name']
        table_dependencies = common_dependencies + ['show_table']
        param.depends(self.render_chart, chart_dependencies, watch=False)
        self.toggle_widget.link(
            self, callbacks={'value': self.table_toggle_callback})
        self.fav_chart_1_widget.link(
            self, callbacks={'value': partial(self.fav_chart_callback, 1)})
        self.fav_chart_2_widget.link(
            self, callbacks={'value': partial(self.fav_chart_callback, 2)})

        code = {'value': 'target.disabled = true;'}
        self.fav_chart_1_widget.jslink(self.fav_chart_2_widget, code=code)
        self.fav_chart_2_widget.jslink(self.fav_chart_1_widget, code=code)

        if self.fav_charts_widget:
            self._setup_fav_chart_widgets(self.fav_charts_widget.value)
        if common_dependencies:
            param.depends(self.table, table_dependencies, watch=False)