當前位置: 首頁>>代碼示例>>Python>>正文


Python param.Parameterized方法代碼示例

本文整理匯總了Python中param.Parameterized方法的典型用法代碼示例。如果您正苦於以下問題:Python param.Parameterized方法的具體用法?Python param.Parameterized怎麽用?Python param.Parameterized使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在param的用法示例。


在下文中一共展示了param.Parameterized方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: from_params

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def from_params(cls, params, **kwargs):
        """Returns Params streams given a dictionary of parameters

        Args:
            params (dict): Dictionary of parameters

        Returns:
            List of Params streams
        """
        key_fn = lambda x: id(x[1].owner)
        streams = []
        for _, group in groupby(sorted(params.items(), key=key_fn), key_fn):
            group = list(group)
            inst = [p.owner for _, p in group][0]
            if not isinstance(inst, param.Parameterized):
                continue
            names = [p.name for _, p in group]
            rename = {p.name: n for n, p in group}
            streams.append(cls(inst, names, rename=rename, **kwargs))
        return streams 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:22,代碼來源:streams.py

示例2: test_deep_apply_parameterized_method_with_dependency

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def test_deep_apply_parameterized_method_with_dependency(self):
        class Test(param.Parameterized):

            label = param.String(default='label')

            @param.depends('label')
            def relabel(self, obj):
                return obj.relabel(self.label.title())

        test = Test()
        fn = lambda i: Curve(np.arange(i))
        dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
        mapped = dmap.apply(test.relabel)
        curve = fn(10)
        self.assertEqual(mapped[10], curve.relabel('Label'))
        test.label = 'new label'
        self.assertEqual(mapped[10], curve.relabel('New Label')) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:19,代碼來源:testdynamic.py

示例3: test_deep_apply_parameterized_method_with_dependency_and_static_kwarg

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def test_deep_apply_parameterized_method_with_dependency_and_static_kwarg(self):
        class Test(param.Parameterized):

            label = param.String(default='label')

            @param.depends('label')
            def relabel(self, obj, group):
                return obj.relabel(self.label.title(), group)

        test = Test()
        fn = lambda i: Curve(np.arange(i))
        dmap = DynamicMap(fn, kdims=[Dimension('Test', range=(10, 20))])
        mapped = dmap.apply(test.relabel, group='Group')
        curve = fn(10)
        self.assertEqual(mapped[10], curve.relabel('Label', 'Group'))
        test.label = 'new label'
        self.assertEqual(mapped[10], curve.relabel('New Label', 'Group')) 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:19,代碼來源:testdynamic.py

示例4: is_param_method

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def is_param_method(obj, has_deps=False):
    """Whether the object is a method on a parameterized object.

    Args:
       obj: Object to check
       has_deps (boolean, optional): Check for dependencies
          Whether to also check whether the method has been annotated
          with param.depends

    Returns:
       A boolean value indicating whether the object is a method
       on a Parameterized object and if enabled whether it has any
       dependencies
    """
    parameterized = (inspect.ismethod(obj) and
                     isinstance(get_method_owner(obj), param.Parameterized))
    if parameterized and has_deps:
        return getattr(obj, "_dinfo", {}).get('dependencies')
    return parameterized 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:21,代碼來源:util.py

示例5: disable_constant

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def disable_constant(parameterized):
    """
    Temporarily set parameters on Parameterized object to
    constant=False.
    """
    params = parameterized.param.objects('existing').values()
    constants = [p.constant for p in params]
    for p in params:
        p.constant = False
    try:
        yield
    except:
        raise
    finally:
        for (p, const) in zip(params, constants):
            p.constant = const 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:18,代碼來源:util.py

示例6: __call__

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def __call__(self, obj, filter_fn=None):
        if filter_fn is None:
            return obj

        name = obj.__name__ if isinstance(obj,type) else obj.__class__.__name__
        class_proxy = type(name, (param.Parameterized,),
                      {k:v for k,v in obj.param.objects('existing').items()
                       if filter_fn(k,v)})

        if isinstance(obj,type):
            return class_proxy
        else:
            instance_params = obj.param.get_param_values()
            obj_proxy = class_proxy()
            filtered = {k:v for k,v in instance_params
                        if (k in obj_proxy.param)
                            and not obj_proxy.param.objects('existing')[k].constant}
            obj_proxy.param.set_param(**filtered)
            return obj_proxy 
開發者ID:holoviz,項目名稱:holoviews,代碼行數:21,代碼來源:pprint.py

示例7: edit_readonly

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def edit_readonly(parameterized):
    """
    Temporarily set parameters on Parameterized object to readonly=False
    to allow editing them.
    """
    params = parameterized.param.objects("existing").values()
    readonlys = [p.readonly for p in params]
    constants = [p.constant for p in params]
    for p in params:
        p.readonly = False
        p.constant = False
    try:
        yield
    except Exception:
        raise
    finally:
        for (p, readonly) in zip(params, readonlys):
            p.readonly = readonly
        for (p, constant) in zip(params, constants):
            p.constant = constant 
開發者ID:holoviz,項目名稱:panel,代碼行數:22,代碼來源:util.py

示例8: test_widget_from_param_instance_with_kwargs

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def test_widget_from_param_instance_with_kwargs():
    class Test(param.Parameterized):

        a = param.Number(default=3.14)

    test = Test()
    widget = FloatSlider.from_param(test.param.a, start=0.3, end=5.2)
    assert isinstance(widget, FloatSlider)
    assert widget.name == 'A'
    assert widget.start == 0.3
    assert widget.end == 5.2
    assert widget.value == 3.14

    test.a = 1.57
    assert widget.value == 1.57

    widget.value = 4.3
    assert test.a == 4.3 
開發者ID:holoviz,項目名稱:panel,代碼行數:20,代碼來源:test_base.py

示例9: test_action_param

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def test_action_param(document, comm):
    class Test(param.Parameterized):
        a = param.Action(lambda x: setattr(x, 'b', 2))
        b = param.Number(default=1)

    test = Test()
    test_pane = Pane(test)
    model = test_pane.get_root(document, comm=comm)

    button = model.children[1]
    assert isinstance(button, Button)

    # Check that the action is actually executed
    pn_button = test_pane.layout[1]
    pn_button.clicks = 1

    assert test.b == 2 
開發者ID:holoviz,項目名稱:panel,代碼行數:19,代碼來源:test_param.py

示例10: test_set_name

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def test_set_name(document, comm):
    class Test(param.Parameterized):
        a = param.Number(bounds=(0, 10))
        b = param.String(default='A')

    pane = Param(Test(), name='First')

    model = pane.get_root(document, comm=comm)

    assert len(model.children) == 3
    title, slider, text = model.children
    assert isinstance(title, Div)
    # Check setting name displays in as a title
    assert title.text == '<b>First</b>'
    assert isinstance(slider, Slider)
    assert isinstance(text, TextInput)

    pane.name = 'Second'

    assert len(model.children) == 3
    title, _, _ = model.children
    assert isinstance(title, Div)
    # Check the title updates with name
    assert title.text == '<b>Second</b>' 
開發者ID:holoviz,項目名稱:panel,代碼行數:26,代碼來源:test_param.py

示例11: test_set_parameters

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def test_set_parameters(document, comm):
    class Test(param.Parameterized):
        a = param.Number(bounds=(0, 10))
        b = param.String(default='A')

    pane = Param(Test())

    model = pane.get_root(document, comm=comm)

    assert len(model.children) == 3
    title, slider, text = model.children
    assert isinstance(title, Div)
    assert isinstance(slider, Slider)
    assert isinstance(text, TextInput)

    pane.parameters = ['b']

    assert len(model.children) == 2
    title, text = model.children
    assert isinstance(title, Div)
    assert isinstance(text, TextInput) 
開發者ID:holoviz,項目名稱:panel,代碼行數:23,代碼來源:test_param.py

示例12: test_set_show_name

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def test_set_show_name(document, comm):
    class Test(param.Parameterized):
        a = param.Number(bounds=(0, 10))

    pane = Param(Test())

    model = pane.get_root(document, comm=comm)

    assert len(model.children) == 2
    title, widget = model.children
    assert isinstance(title, Div)
    assert isinstance(widget, Slider)

    pane.show_name = False

    assert len(model.children) == 1
    assert isinstance(model.children[0], Slider) 
開發者ID:holoviz,項目名稱:panel,代碼行數:19,代碼來源:test_param.py

示例13: test_set_show_labels

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def test_set_show_labels(document, comm):
    class Test(param.Parameterized):
        a = param.Number(bounds=(0, 10))

    pane = Param(Test())

    model = pane.get_root(document, comm=comm)

    assert len(model.children) == 2
    title, widget = model.children
    assert isinstance(title, Div)
    assert isinstance(widget, Slider)
    assert widget.title == 'A'

    pane.show_labels = False

    assert len(model.children) == 2
    assert isinstance(model.children[1], Slider)
    assert model.children[1].title == '' 
開發者ID:holoviz,項目名稱:panel,代碼行數:21,代碼來源:test_param.py

示例14: test_expand_param_subobject_expand

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [as 別名]
def test_expand_param_subobject_expand(document, comm):
    class Test(param.Parameterized):
        a = param.Parameter()

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

    toggle = model.children[1].children[1]
    assert isinstance(toggle, Toggle)

    # Expand subpane
    assert len(model.children) == 3
    _, _, subpanel = test_pane.layout.objects
    col = model.children[2]
    assert isinstance(col, BkColumn)
    assert len(col.children) == 2
    div, widget = col.children
    assert div.text == '<b>Nested</b>'
    assert isinstance(widget, BkTextInput)

    # Collapse subpanel
    test_pane._widgets['a'][1].value = False
    assert len(model.children) == 2
    assert subpanel._models == {} 
開發者ID:holoviz,項目名稱:panel,代碼行數:27,代碼來源:test_param.py

示例15: test_param_subobject_expand_no_toggle

# 需要導入模塊: import param [as 別名]
# 或者: from param import Parameterized [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


注:本文中的param.Parameterized方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。