本文整理匯總了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