本文整理汇总了Python中param.ObjectSelector方法的典型用法代码示例。如果您正苦于以下问题:Python param.ObjectSelector方法的具体用法?Python param.ObjectSelector怎么用?Python param.ObjectSelector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类param
的用法示例。
在下文中一共展示了param.ObjectSelector方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_layout_with_param_setitem
# 需要导入模块: import param [as 别名]
# 或者: from param import ObjectSelector [as 别名]
def test_layout_with_param_setitem(document, comm):
import param
class TestClass(param.Parameterized):
select = param.ObjectSelector(default=0, objects=[0,1])
def __init__(self, **params):
super(TestClass, self).__init__(**params)
self._layout = Row(Param(self.param, parameters=['select']),
self.select)
@param.depends('select', watch=True)
def _load(self):
self._layout[-1] = self.select
test = TestClass()
model = test._layout.get_root(document, comm=comm)
test.select = 1
assert model.children[1].text == '<pre>1</pre>'
示例2: test_object_selector_param
# 需要导入模块: import param [as 别名]
# 或者: from param import ObjectSelector [as 别名]
def test_object_selector_param(document, comm):
class Test(param.Parameterized):
a = param.ObjectSelector(default='b', objects=[1, 'b', 'c'])
test = Test()
test_pane = Pane(test)
model = test_pane.get_root(document, comm=comm)
select = model.children[1]
assert isinstance(select, Select)
assert select.options == [('1','1'), ('b','b'), ('c','c')]
assert select.value == 'b'
assert select.disabled == False
# Check changing param value updates widget
test.a = 1
assert select.value == '1'
# Check changing param attribute updates widget
a_param = test.param['a']
a_param.objects = ['c', 'd', 1]
assert select.options == [('c','c'), ('d','d'), ('1','1')]
a_param.constant = True
assert select.disabled == True
# Ensure cleanup works
test_pane._cleanup(model)
a_param.constant = False
a_param.objects = [1, 'c', 'd']
test.a = 'd'
assert select.value == '1'
assert select.options == [('c','c'), ('d','d'), ('1','1')]
assert select.disabled == True
示例3: test_switch_param_subobject
# 需要导入模块: import param [as 别名]
# 或者: from param import ObjectSelector [as 别名]
def test_switch_param_subobject(document, comm):
class Test(param.Parameterized):
a = param.ObjectSelector()
o1 = Test(name='Subobject 1')
o2 = Test(name='Subobject 2')
Test.param['a'].objects = [o1, o2, 3]
test = Test(a=o1, name='Nested')
test_pane = Pane(test)
model = test_pane.get_root(document, comm=comm)
toggle = model.children[1].children[1]
assert isinstance(toggle, Toggle)
# Expand subpane
test_pane._widgets['a'][1].value = True
assert len(model.children) == 3
_, _, subpanel = test_pane.layout.objects
col = model.children[2]
assert isinstance(col, BkColumn)
assert len(col.children) == 2
div, row = col.children
assert div.text == '<b>Subobject 1</b>'
assert isinstance(row.children[0], Select)
# Switch subobject
test_pane._widgets['a'][0].value = o2
_, _, subpanel = test_pane.layout.objects
col = model.children[2]
assert isinstance(col, BkColumn)
assert len(col.children) == 2
div, row = col.children
assert div.text == '<b>Subobject 2</b>'
assert isinstance(row.children[0], Select)
# Collapse subpanel
test_pane._widgets['a'][1].value = False
assert len(model.children) == 2
assert subpanel._models == {}