当前位置: 首页>>代码示例>>Python>>正文


Python param.Parameter方法代码示例

本文整理汇总了Python中param.Parameter方法的典型用法代码示例。如果您正苦于以下问题:Python param.Parameter方法的具体用法?Python param.Parameter怎么用?Python param.Parameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在param的用法示例。


在下文中一共展示了param.Parameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_dynamic_args

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def process_dynamic_args(x, y, kind, **kwds):
    dynamic = {}
    arg_deps = []
    arg_names = []

    for k, v in list(kwds.items()) + [('x', x), ('y', y), ('kind', kind)]:
        if isinstance(v, param.Parameter):
            dynamic[k] = v
        elif panel_available and isinstance(v, pn.widgets.Widget):
            if LooseVersion(pn.__version__) < '0.6.4':
                dynamic[k] = v.param.value
            else:
                dynamic[k] = v

    for k, v in kwds.items():
        if k not in dynamic and isinstance(v, FunctionType) and hasattr(v, '_dinfo'):
            deps = v._dinfo['dependencies']
            arg_deps += list(deps)
            arg_names += list(k) * len(deps)

    return dynamic, arg_deps, arg_names 
开发者ID:holoviz,项目名称:hvplot,代码行数:23,代码来源:util.py

示例2: __call__

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def __call__(self, element, **kwargs):
        params = dict(kwargs)
        for k, v in kwargs.items():
            if util.is_param_method(v, has_deps=True):
                params[k] = v()
            elif isinstance(v, param.Parameter) and isinstance(v.owner, param.Parameterized):
                params[k] = getattr(v.owner, v.name)
        self.p = param.ParamOverrides(self, params,
                                      allow_extra_keywords=self._allow_extra_keywords)
        if not self.p.dynamic:
            kwargs['dynamic'] = False
            if isinstance(element, HoloMap):
                # Backwards compatibility for key argument
                return element.clone([(k, self._apply(el, key=k))
                                      for k, el in element.items()])
            elif ((self._per_element and isinstance(element, Element)) or
                  (not self._per_element and isinstance(element, ViewableElement))):
                return self._apply(element)
        elif 'streams' not in kwargs:
            kwargs['streams'] = self.p.streams
        kwargs['per_element'] = self._per_element
        kwargs['link_dataset'] = self._propagate_dataset
        return element.apply(self, **kwargs) 
开发者ID:holoviz,项目名称:holoviews,代码行数:25,代码来源:operation.py

示例3: param_value_if_widget

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def param_value_if_widget(arg):
    if isinstance(arg, Widget):
        return arg.param.value

    from .pane.ipywidget import IPyWidget
    if IPyWidget.applies(arg) and hasattr(arg, 'value'):
        name = type(arg).__name__
        if name in ipywidget_classes:
            ipy_param = ipywidget_classes[name]
        else:
            ipy_param = param.parameterized_class(name, {'value': param.Parameter()})
        ipywidget_classes[name] = ipy_param
        ipy_inst = ipy_param(value=arg.value)
        arg.observe(lambda event: ipy_inst.set_param(value=event['new']), 'value')
        return ipy_inst.param.value
    return arg 
开发者ID:holoviz,项目名称:panel,代码行数:18,代码来源:depends.py

示例4: _validate_object

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def _validate_object(self):
        dependencies = getattr(self.object, '_dinfo', None)
        if not dependencies or not dependencies.get('watch'):
            return
        fn_type = 'method' if type(self) is ParamMethod else 'function'
        self.param.warning(f"The {fn_type} supplied for Panel to display "
                           "was declared with `watch=True`, which will "
                           f"cause the {fn_type} to be called twice for "
                           "any change in a dependent Parameter. "
                           "`watch` should be False when Panel is "
                           "responsible for displaying the result "
                           f"of the {fn_type} call, while `watch=True` "
                           f"should be reserved for {fn_type}s that work "
                           "via side-effects, e.g. by modifying internal  "
                           "state of a class or global state in an "
                           "application's namespace.")

    #----------------------------------------------------------------
    # Callback API
    #---------------------------------------------------------------- 
开发者ID:holoviz,项目名称:panel,代码行数:22,代码来源:param.py

示例5: test_param_subobject_expand_no_toggle

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def test_param_subobject_expand_no_toggle(document, comm):
    class Test(param.Parameterized):
        a = param.Parameter()

    test = Test(a=Test(name='Nested'))
    test_pane = Pane(test, expand=True,
                     expand_button=False)
    model = test_pane.get_root(document, comm=comm)

    # Assert no toggle was added
    assert len(model.children) == 3

    # Expand subpane
    _, _, subpanel = test_pane.layout.objects
    div, widget = model.children[2].children
    assert div.text == '<b>Nested</b>'
    assert isinstance(widget, BkTextInput) 
开发者ID:holoviz,项目名称:panel,代码行数:19,代码来源:test_param.py

示例6: test_param_rename

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def test_param_rename():
    "Test that Reactive renames params and properties"

    class ReactiveRename(Reactive):

        a = param.Parameter()
    
        _rename = {'a': 'b'}

    obj = ReactiveRename()

    params = obj._process_property_change({'b': 1})
    assert params == {'a': 1}

    properties = obj._process_param_change({'a': 1})
    assert properties == {'b': 1} 
开发者ID:holoviz,项目名称:panel,代码行数:18,代码来源:test_reactive.py

示例7: define

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def define(cls, name, **kwargs):
        """
        Utility to quickly and easily declare Stream classes. Designed
        for interactive use such as notebooks and shouldn't replace
        parameterized class definitions in source code that is imported.

        Takes a stream class name and a set of keywords where each
        keyword becomes a parameter. If the value is already a
        parameter, it is simply used otherwise the appropriate parameter
        type is inferred and declared, using the value as the default.

        Supported types: bool, int, float, str, dict, tuple and list
        """
        params = {'name': param.String(default=name)}
        for k, v in kwargs.items():
            kws = dict(default=v, constant=True)
            if isinstance(v, param.Parameter):
                params[k] = v
            elif isinstance(v, bool):
                params[k] = param.Boolean(**kws)
            elif isinstance(v, int):
                params[k] = param.Integer(**kws)
            elif isinstance(v, float):
                params[k] = param.Number(**kws)
            elif isinstance(v, str):
                params[k] = param.String(**kws)
            elif isinstance(v, dict):
                params[k] = param.Dict(**kws)
            elif isinstance(v, tuple):
                params[k] = param.Tuple(**kws)
            elif isinstance(v, list):
                params[k] = param.List(**kws)
            elif isinstance(v, np.ndarray):
                params[k] = param.Array(**kws)
            else:
                params[k] = param.Parameter(**kws)

        # Dynamic class creation using type
        return type(name, (Stream,), params) 
开发者ID:holoviz,项目名称:holoviews,代码行数:41,代码来源:streams.py

示例8: __init__

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def __init__(self, parameterized=None, parameters=None, watch=True, watch_only=False, **params):
        if util.param_version < '1.8.0' and watch:
            raise RuntimeError('Params stream requires param version >= 1.8.0, '
                               'to support watching parameters.')
        if parameters is None:
            parameters = [parameterized.param[p] for p in parameterized.param if p != 'name']
        else:
            parameters = [p if isinstance(p, param.Parameter) else parameterized.param[p]
                          for p in parameters]

        if 'rename' in params:
            rename = {}
            owners = [p.owner for p in parameters]
            for k, v in params['rename'].items():
                if isinstance(k, tuple):
                    rename[k] = v
                else:
                    rename.update({(o, k): v for o in owners})
            params['rename'] = rename

        self._watch_only = watch_only
        super(Params, self).__init__(parameterized=parameterized, parameters=parameters, **params)
        self._memoize_counter = 0
        self._events = []
        self._watchers = []
        if watch:
            # Subscribe to parameters
            keyfn = lambda x: id(x.owner)
            for _, group in groupby(sorted(parameters, key=keyfn)):
                group = list(group)
                watcher = group[0].owner.param.watch(self._watcher, [p.name for p in group])
                self._watchers.append(watcher) 
开发者ID:holoviz,项目名称:holoviews,代码行数:34,代码来源:streams.py

示例9: test_all_stream_parameters_constant

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def test_all_stream_parameters_constant():
    all_stream_cls = [v for v in globals().values() if
                      isinstance(v, type) and issubclass(v, Stream)]
    for stream_cls in all_stream_cls:
        for name, p in stream_cls.param.params().items():
            if name == 'name': continue
            if p.constant != True:
                raise TypeError('Parameter %s of stream %s not declared constant'
                                % (name, stream_cls.__name__)) 
开发者ID:holoviz,项目名称:holoviews,代码行数:11,代码来源:teststreams.py

示例10: test_XY_set_invalid_class_y

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def test_XY_set_invalid_class_y(self):
        regexp = "Parameter 'y' only takes numeric values"
        with self.assertRaisesRegexp(ValueError, regexp):
            self.XY.y = 'string' 
开发者ID:holoviz,项目名称:holoviews,代码行数:6,代码来源:teststreams.py

示例11: test_XY_set_invalid_instance_x

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def test_XY_set_invalid_instance_x(self):
        xy = self.XY(x=1,y=2)
        regexp = "Parameter 'x' only takes numeric values"
        with self.assertRaisesRegexp(ValueError, regexp):
            xy.x = 'string' 
开发者ID:holoviz,项目名称:holoviews,代码行数:7,代码来源:teststreams.py

示例12: test_XY_set_invalid_instance_y

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def test_XY_set_invalid_instance_y(self):
        xy = self.XY(x=1,y=2)
        regexp = "Parameter 'y' only takes numeric values"
        with self.assertRaisesRegexp(ValueError, regexp):
            xy.y = 'string' 
开发者ID:holoviz,项目名称:holoviews,代码行数:7,代码来源:teststreams.py

示例13: params

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def params(self):
        params = {}
        for op in self.ops:
            op_args = list(op['args'])+list(op['kwargs'].values())
            for op_arg in op_args:
                if 'panel' in sys.modules:
                    from panel.widgets.base import Widget
                    if isinstance(op_arg, Widget):
                        op_arg = op_arg.param.value
                if (isinstance(op_arg, param.Parameter) and
                    isinstance(op_arg.owner, param.Parameterized)):
                    params[op_arg.name+str(id(op))] = op_arg
        return params

    # Namespace properties 
开发者ID:holoviz,项目名称:holoviews,代码行数:17,代码来源:transform.py

示例14: _update_backend

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def _update_backend(cls, backend):

        if cls.__original_docstring__ is None:
            cls.__original_docstring__ = cls.__doc__

        all_keywords = set()
        element_keywords = cls._element_keywords(backend)
        for element, keywords in element_keywords.items():
            with param.logging_level('CRITICAL'):
                all_keywords |= set(keywords)
                setattr(cls, element,
                        cls._create_builder(element, keywords))

        filtered_keywords = [k for k in all_keywords if k not in cls._no_completion]
        sorted_kw_set = sorted(set(filtered_keywords))
        if sys.version_info.major == 2:
            kws = ', '.join('{opt}=None'.format(opt=opt) for opt in sorted_kw_set)
            old_doc = cls.__original_docstring__.replace(
                'params(strict=Boolean, name=String)','')
            cls.__doc__ = '\n    opts({kws})'.format(kws=kws) + old_doc
        else:
            from inspect import Parameter, Signature
            signature = Signature([Parameter('args', Parameter.VAR_POSITIONAL)]
                                  + [Parameter(kw, Parameter.KEYWORD_ONLY)
                                     for kw in sorted_kw_set])
            cls.__init__.__signature__ = signature 
开发者ID:holoviz,项目名称:holoviews,代码行数:28,代码来源:__init__.py

示例15: resolve_dependent_value

# 需要导入模块: import param [as 别名]
# 或者: from param import Parameter [as 别名]
def resolve_dependent_value(value):
    """Resolves parameter dependencies on the supplied value

    Resolves parameter values, Parameterized instance methods and
    parameterized functions with dependencies on the supplied value.

    Args:
       value: A value which will be resolved

    Returns:
       A new dictionary where any parameter dependencies have been
       resolved.
    """
    if 'panel' in sys.modules:
        from panel.widgets.base import Widget
        if isinstance(value, Widget):
            value = value.param.value
    if is_param_method(value, has_deps=True):
        value = value()
    elif isinstance(value, param.Parameter) and isinstance(value.owner, param.Parameterized):
        value = getattr(value.owner, value.name)
    elif isinstance(value, FunctionType) and hasattr(value, '_dinfo'):
        deps = value._dinfo
        args = (getattr(p.owner, p.name) for p in deps.get('dependencies', []))
        kwargs = {k: getattr(p.owner, p.name) for k, p in deps.get('kw', {}).items()}
        value = value(*args, **kwargs)
    return value 
开发者ID:holoviz,项目名称:holoviews,代码行数:29,代码来源:util.py


注:本文中的param.Parameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。