本文整理汇总了Python中traitlets.link函数的典型用法代码示例。如果您正苦于以下问题:Python link函数的具体用法?Python link怎么用?Python link使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了link函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *arg, **kwd):
box_first = kwd.pop('box_first', False)
description = kwd.pop('description', '')
super(CheckboxPlus, self).__init__(*arg, **kwd)
# Set the description to an empty string to ensure no space
# is left for it.
self._check = widgets.Checkbox(description='',
style={'description_width': 'initial'})
self._description = widgets.Label(value=description)
children = [self._check, self._description]
if not box_first:
children.reverse()
# Make this a flex-box
self.layout.display = 'flex'
# This ensures vertical alignment between the checkbox and its label.
self.layout.align_items = 'center'
# Keep the checkbox and description close together
self.layout.justify_content = 'flex-start'
# Tie this widget's value to the value of the actual checkbox.
link((self, 'value'), (self._check, 'value'))
# Tie this widget's disabled state to that of the actual checkbox.
link((self, 'disabled'), (self._check, 'disabled'))
self.children = children
示例2: __init__
def __init__(self, width=320, height=320, setupfn=empty_function, drawfn=empty_function, stepfn=empty_function, renderfn=empty_function):
self.setup_func = setupfn
self.draw_func = drawfn
self.step_func = stepfn
self.render_func = renderfn
self.redrawFreq = 1
self.randomSeed = int(calendar.timegm(time.gmtime()))
self.incSeedOnStop = True
self.settings_pane = None
self.randomSeedWidget = None
self.play = widgets.Play()
self.p55_widget = P55CanvasWidget()
self.p55_widget.canvas_width = width
self.p55_widget.canvas_height = height
self.p55_widget.value = 0
self.reset_widget();
self.step_label = widgets.Label(u"0", description='step');
play_observer = get_p55_play_observer(self)
self.p55_widget.observe(play_observer, names='value')
traitlets.link((self.play, 'value'), (self.p55_widget, 'value'))
label_observer = get_label_changer(self)
self.p55_widget.observe(label_observer, names='value')
self.play_row = widgets.HBox([self.play, self.step_label])
self.display_pane = widgets.VBox([self.p55_widget, self.play_row])
self.widget = widgets.HBox([self.display_pane])
示例3: output_panel
def output_panel(self):
download_link = HTML(value="")
link((self, "download_link"), (download_link, "value"))
results_table = HTML(value="")
link((self, "results_table"), (results_table, "value"))
content = VBox(children=[download_link, results_table])
return ControlPanel(title="Results:", children=[content], border_width=2, border_radius=4, margin=10, padding=0)
"""<div style="height:100px;width:200px;overflow:auto;border:8px solid yellowgreen;padding:2%">This </div>"""
示例4: __init__
def __init__(self, scene, camera, controls=None, antialias=False, alpha=False, **kwargs):
super(Renderer, self).__init__(
scene=scene,
camera=camera,
controls=controls or [],
_antialias=antialias,
_alpha=alpha,
**kwargs)
link((self, 'width'), (self, '_width'))
link((self, 'height'), (self, '_height'))
示例5: gen_widget
def gen_widget(anim):
viewer = AnimationViewer(anim)
clear_output(True)
anim_widget = AnimationWidget()
anim_widget.loop = True
button = ToggleButton(description="run", default=False)
link((button, 'value'), (anim_widget, 'run'))
display(anim_widget)
display(viewer.image)
display(button)
anim_widget.observe(lambda value: viewer.update(value["new"]), names="value")
示例6: create_settings
def create_settings(box):
"Creates a widget Container for settings and info of a particular slider."
_, slider, sl_units = box.children
enable = widgets.Checkbox(value=box.visible, width="3ex")
link((box, 'visible'), (enable, 'value'))
def slider_link(obj, attr):
"Function to link one object to an attr of the slider."
# pylint: disable=unused-argument
def link_fn(name, new_value):
"How to update the object's value given min/max on the slider. "
if new_value >= slider.max:
slider.max = new_value
# if any value is greater than the max, the max slides up
# however, this is not held true for the minimum, because
# during typing the max or value will grow, and we don't want
# to permanently anchor the minimum to unfinished typing
if attr == "max" and new_value <= slider.value:
if slider.max >= slider.min:
slider.value = new_value
else:
pass # bounds nonsensical, probably because we picked up
# a small value during user typing.
elif attr == "min" and new_value >= slider.value:
slider.value = new_value
setattr(slider, attr, new_value)
slider.step = (slider.max - slider.min)/24.0
obj.on_trait_change(link_fn, "value")
link((slider, attr), (obj, "value"))
text_html = "<span class='form-control' style='width: auto;'>"
setvalue = widgets.FloatText(value=slider.value,
description=slider.description)
slider_link(setvalue, "value")
fromlabel = widgets.HTML(text_html + "from")
setmin = widgets.FloatText(value=slider.min, width="10ex")
slider_link(setmin, "min")
tolabel = widgets.HTML(text_html + "to")
setmax = widgets.FloatText(value=slider.max, width="10ex")
slider_link(setmax, "max")
units = widgets.Label()
units.width = "6ex"
units.font_size = "1.165em"
link((sl_units, 'value'), (units, 'value'))
descr = widgets.HTML(text_html + slider.varkey.descr.get("label", ""))
descr.width = "40ex"
return widgets.HBox(children=[enable, setvalue, units, descr,
fromlabel, setmin, tolabel, setmax],
width="105ex")
示例7: __init__
def __init__(self, nrows, ncols, make_widget, description=u"", transform=None):
"""
Create a :class:`Grid` widget.
INPUT:
- ``nrows``, ``ncols`` -- number of rows and columns in the grid
- ``make_widget`` -- a function of two arguments ``(i,j)``
returning the widget to be placed at position ``(i,j)``.
- ``description`` -- an optional label.
- ``transform`` -- an optional transformation, see :class:`TransformWidget`.
EXAMPLES::
sage: from sage.repl.ipython_kernel.widgets import Grid, EvalText
sage: w = Grid(2, 2, lambda i,j: EvalText(str(j+4*i)),
....: description="2x2 matrix", transform=matrix)
sage: w
Grid(value=[[0, 1], [4, 5]], children=(Label(value=u'2x2 matrix'), VBox(children=(EvalText(value=u'0'), EvalText(value=u'4'))), VBox(children=(EvalText(value=u'1'), EvalText(value=u'5')))))
sage: w.get_interact_value()
[0 1]
[4 5]
TESTS::
sage: w = Grid(0, 1, lambda i,j: EvalText())
Traceback (most recent call last):
...
ValueError: Grid requires a positive number of rows and columns
"""
if nrows < 1 or ncols < 1:
raise ValueError("Grid requires a positive number of rows and columns")
super(Grid, self).__init__(transform=transform)
label = Label(description)
link((label, "value"), (self, "description"))
self.cols = []
for j in range(ncols):
col = VBox()
widgets = []
for i in range(nrows):
w = make_widget(i, j)
w.observe(self._update, names="value")
widgets.append(w)
col.children = widgets
self.cols.append(col)
self.children = [label] + self.cols
self._update()
示例8: _make_pre_widget
def _make_pre_widget(self, description, values):
box = widgets.HBox()
box.description = description
text = widgets.Label(value=description)
style = {'button_width': 'initial'}
toggles = widgets.ToggleButtons(options=values, style=style)
# Vertically align text and toggles.
box.layout.align_items = 'center'
box.children = [text, toggles]
box.add_traits(value=Any(sync=True, default_value=toggles.value))
link((box, 'value'), (toggles, 'value'))
return box
示例9: __init__
def __init__(self, coordinate_frames, topology, width=500, height=500):
'''Display a trajectory in the IPython notebook.
:param list coordinate_frames: A list containing the positions of the atoms (as np.ndarray) for each frame.
:param dict topology: A dictionary specifying the topology
.. seealso:: :class:`MolecularViewer`
'''
self.coordinate_frames = coordinate_frames
super(TrajectoryViewer, self).__init__(coordinate_frames[0], topology, width=width, height=height)
self.controls = TrajectoryControls(len(coordinate_frames))
link((self, 'frame'), (self.controls, 'frame'))
示例10: make_controls
def make_controls(self):
self.playbutton = ipy.Play(value=0,
min=0,
max=self.traj.num_frames-1)
self.slider = ipy.IntSlider(value_selects='framenum', value=0,
description='Frame:', min=0, max=len(self.traj)-1,
readout=False)
self.readout = ipy.HTML(value='/%d' % (self.traj.num_frames - 1))
self.annotation = ipy.HTML()
traitlets.link((self.playbutton, 'value'), (self.slider, 'value'))
traitlets.link((self.slider, 'value'), (self, 'current_frame'))
return VBox((self.annotation,
HBox((self.playbutton, self.slider, self.readout))))
示例11: modelcontrolpanel
def modelcontrolpanel(model, *args, **kwargs):
"""Easy model control in IPython / Jupyter
Like interact(), but with the ability to control sliders and their ranges
live. args and kwargs are passed on to interact()
"""
sliders = model.interact(*args, **kwargs)
sliderboxes = []
for sl in sliders.children:
cb = widgets.Checkbox(value=True)
unit_latex = sl.varkey.unitstr
if unit_latex:
unit_latex = "$\scriptsize"+unit_latex+"$"
units = widgets.Latex(value=unit_latex)
units.font_size = "1.16em"
box = widgets.HBox(children=[cb, sl, units])
link((box, 'visible'), (cb, 'value'))
sliderboxes.append(box)
widgets_css = widgets.HTML("""<style>
[style="font-size: 1.16em;"] { padding-top: 0.25em; }
[style="width: 3ex; font-size: 1.165em;"] { padding-top: 0.2em; }
.widget-numeric-text { width: auto; }
.widget-numeric-text .widget-label { width: 20ex; }
.widget-numeric-text .form-control { background: #fbfbfb; width: 8.5ex; }
.widget-slider .widget-label { width: 20ex; }
.widget-checkbox .widget-label { width: 15ex; }
.form-control { border: none; box-shadow: none; }
</style>""")
settings = [widgets_css]
for sliderbox in sliderboxes:
settings.append(create_settings(sliderbox))
# model_latex = "$"+model.latex(show_subs=False)+"$"
# model_eq = widgets.Latex(model_latex)
tabs = widgets.Tab(children=[widgets.Box(children=sliderboxes,
padding="1.25ex"),
widgets.Box(children=settings,
padding="1.25ex")])
# TODO: fix model equation display
# widgets.Box(children=[model_eq],
# padding="1.25ex")])
tabs.set_title(0, 'Variable Sliders')
tabs.set_title(1, 'Slider Settings')
#tabs.set_title(2, 'Model Equations')
return tabs
示例12: create_shelf_view
def create_shelf_view(model, columns, types):
opts = list(zip(["-"] + columns, [""] + columns))
column_view = w.Dropdown(options=opts, description=model.shelf_name, value="")
type_view = w.Dropdown(options={"Q": "Q", "T": "T", "O": "O", "N": "N"}, value="Q")
shelf_view = w.HBox([column_view, type_view])
def on_column_changed(name, value):
if value == "":
type_view.value = "Q"
else:
index = columns.index(value)
type_view.value = types[index]
column_view.on_trait_change(on_column_changed, "value")
T.link((model, "name"), (column_view, "value"))
T.link((type_view, "value"), (model, "type"))
return shelf_view
示例13: assemble
def assemble(self):
guide = self.guide
wigs = self.wigs
vertical = []
for wig in wigs:
svg = wig.svg = canvas.SVGCanvasWidget()
vertical.append(svg)
svg.width = self.width
svg.height = self.height
svg.set_view_box(0, 0, self.width, self.height)
svg.add_style("background-color", "cyan")
traitlets.link((guide, "start_position"), (wig, "start_position"))
traitlets.link((guide, "end_position"), (wig, "end_position"))
vertical.append(self.guide.assembly)
self.assembly = widgets.VBox(children=vertical)
wig.on_trait_change(self.draw, "start_position")
self.assembled = True
示例14: multi_text_match
def multi_text_match():
t = widgets.Text()
submitted = []
s_box = widgets.VBox()
def update_s_box():
s_box.children = tuple(map(list_entry, submitted))
@t.on_submit
def on_submit(sender):
if not t.value:
return
submitted.append(t.value)
update_s_box()
t.value = ''
def list_entry(value):
e = widgets.HTML(
html.escape(value),
padding='5px',
background_color='gray',
color='white')
rm_button = widgets.Button(
description='✖',
margin='5px',
padding='1px')
traitlets.link((t, 'disabled'), (rm_button, 'disabled'))
le = widgets.HBox(children=[e, rm_button])
@rm_button.on_click
def remove(b):
submitted.remove(value)
update_s_box()
return le
root = widgets.VBox(children=[s_box, t])
root.add_traits(
value=traitlets.Any(),
disabled=traitlets.Any(),
filter_type=traitlets.Any())
root.value = submitted
root.disabled = False
root.filter_type = 'text'
traitlets.link((root, 'disabled'), (t, 'disabled'))
return root
示例15: list_entry
def list_entry(value):
e = widgets.HTML(
html.escape(value),
padding='5px',
background_color='gray',
color='white')
rm_button = widgets.Button(
description='✖',
margin='5px',
padding='1px')
traitlets.link((t, 'disabled'), (rm_button, 'disabled'))
le = widgets.HBox(children=[e, rm_button])
@rm_button.on_click
def remove(b):
submitted.remove(value)
update_s_box()
return le