本文整理汇总了Python中param.Action方法的典型用法代码示例。如果您正苦于以下问题:Python param.Action方法的具体用法?Python param.Action怎么用?Python param.Action使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类param
的用法示例。
在下文中一共展示了param.Action方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_action_param
# 需要导入模块: import param [as 别名]
# 或者: from param import Action [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
示例2: test_param_label
# 需要导入模块: import param [as 别名]
# 或者: from param import Action [as 别名]
def test_param_label(document, comm):
class Test(param.Parameterized):
a = param.Number(default=1.2, bounds=(0, 5), label='A')
b = param.Action(label='B')
test = Test()
test_pane = Pane(test)
# Check updating label changes widget name
a_param = test.param['a']
a_param.label = 'B'
assert test_pane._widgets['a'].name == 'B'
b_param = test.param['b']
b_param.label = 'C'
assert test_pane._widgets['b'].name == 'C'
示例3: test_param_js_callbacks
# 需要导入模块: import param [as 别名]
# 或者: from param import Action [as 别名]
def test_param_js_callbacks(document, comm):
class JsButton(param.Parameterized):
param_btn = param.Action(lambda self: print('Action Python Response'), label='Action')
param_button = Param(JsButton())
code = "console.log('Action button clicked')"
param_button[1].js_on_click(code=code)
model = param_button.get_root(document, comm=comm)
button = model.children[1]
assert len(button.js_event_callbacks) == 1
callbacks = button.js_event_callbacks
assert 'button_click' in callbacks
assert len(callbacks['button_click']) == 1
assert code in callbacks['button_click'][0].code
示例4: ActionButton
# 需要导入模块: import param [as 别名]
# 或者: from param import Action [as 别名]
def ActionButton(*args, **kw):
"""Returns a ipywidgets.Button executing a paramnb.Action."""
kw['description'] = str(kw['name'])
value = kw["value"]
w = ipywidgets.Button(*args,**kw)
if value: w.on_click(value)
return w
示例5: on_msg
# 需要导入模块: import param [as 别名]
# 或者: from param import Action [as 别名]
def on_msg(self, msg):
p_name = msg['p_name']
p_obj = self.parameterized.params(p_name)
if isinstance(p_obj, param.Action):
getattr(self.parameterized, p_name)(self.parameterized)
return
w = self._widgets[p_name]
self._queue.append((w, p_obj, p_name, None, None, msg['value']))
self.change_event()
示例6: setUp
# 需要导入模块: import param [as 别名]
# 或者: from param import Action [as 别名]
def setUp(self):
super(TestParamsStream, self).setUp()
class Inner(param.Parameterized):
x = param.Number(default = 0)
y = param.Number(default = 0)
class InnerAction(Inner):
action = param.Action(lambda o: o.param.trigger('action'))
self.inner = Inner
self.inner_action = InnerAction
示例7: widgets
# 需要导入模块: import param [as 别名]
# 或者: from param import Action [as 别名]
def widgets(self):
"""Return name,widget boxes for all parameters (i.e., a property sheet)"""
params = self.parameterized.params().items()
key_fn = lambda x: x[1].precedence if x[1].precedence is not None else self.p.default_precedence
sorted_precedence = sorted(params, key=key_fn)
outputs = [k for k, p in sorted_precedence if isinstance(p, _View)]
filtered = [(k,p) for (k,p) in sorted_precedence
if ((p.precedence is None) or (p.precedence >= self.p.display_threshold))
and k not in outputs]
groups = itertools.groupby(filtered, key=key_fn)
sorted_groups = [sorted(grp) for (k,grp) in groups]
ordered_params = [el[0] for group in sorted_groups for el in group]
# Format name specially
ordered_params.pop(ordered_params.index('name'))
widgets = [Div(text='<b>{0}</b>'.format(self.parameterized.name))]
def format_name(pname):
p = self.parameterized.params(pname)
# omit name for buttons, which already show the name on the button
name = "" if issubclass(type(p),param.Action) else pname
return Div(text=name)
if self.p.show_labels:
widgets += [self.widget(pname) for pname in ordered_params]
else:
widgets += [self.widget(pname) for pname in ordered_params]
if self.p.button and not (self.p.callback is None and self.p.next_n==0):
display_button = Button(label=self.p.button_text)
def click_cb():
# Execute and clear changes since last button press
try:
self.execute(self._changed)
except Exception as e:
self._changed.clear()
raise e
self._changed.clear()
display_button.on_click(click_cb)
widgets.append(display_button)
outputs = [self.widget(pname) for pname in outputs]
return widgets, outputs