本文整理汇总了Python中traitlets.link函数的典型用法代码示例。如果您正苦于以下问题:Python link函数的具体用法?Python link怎么用?Python link使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了link函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:mwcraig,项目名称:reducer,代码行数:29,代码来源:gui.py
示例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])
开发者ID:vusd,项目名称:p55py,代码行数:28,代码来源:legacy.py
示例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>"""
开发者ID:getmolmap,项目名称:ipynb,代码行数:8,代码来源:gui.py
示例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'))
开发者ID:indigophillips,项目名称:pythreejs,代码行数:10,代码来源:Renderer.py
示例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")
开发者ID:jdlesage,项目名称:animation-widget,代码行数:11,代码来源:matplotlibanim.py
示例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")
开发者ID:hoburg,项目名称:gpkit,代码行数:52,代码来源:widgets.py
示例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()
开发者ID:saraedum,项目名称:sage-renamed,代码行数:52,代码来源:widgets.py
示例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
开发者ID:mwcraig,项目名称:reducer,代码行数:13,代码来源:astro_gui.py
示例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'))
开发者ID:cortner,项目名称:chemview,代码行数:14,代码来源:trajectory.py
示例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))))
开发者ID:Autodesk,项目名称:notebook-molecular-visualization,代码行数:15,代码来源:trajectory_viewer.py
示例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
开发者ID:galbramc,项目名称:gpkit,代码行数:48,代码来源:widgets.py
示例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
开发者ID:fish2000,项目名称:altair,代码行数:17,代码来源:view.py
示例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
开发者ID:anu-bioinfo,项目名称:jp_gene_viz,代码行数:17,代码来源:genome_wiggle.py
示例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
开发者ID:smartscheduling,项目名称:chatto-transform-open-source,代码行数:45,代码来源:mimic_widgets.py
示例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
开发者ID:smartscheduling,项目名称:chatto-transform-open-source,代码行数:18,代码来源:mimic_widgets.py
示例16: test_player_link_to_ipywidgets
def test_player_link_to_ipywidgets():
traj = pt.datafiles.load_tz2()
view = nv.show_pytraj(traj)
int_text = IntText(2)
float_text = BoundedFloatText(40, min=10)
HBox([int_text, float_text])
link((int_text, 'value'), (view.player, 'step'))
link((float_text, 'value'), (view.player, 'delay'))
assert view.player.step == 2
assert view.player.delay == 40
float_text.value = 100
assert view.player.delay == 100
float_text.value= 0.00
# we set min=10
assert view.player.delay == 10
开发者ID:marscher,项目名称:nglview,代码行数:19,代码来源:test_widget.py
示例17: interact
def interact(self, **kwargs):
c = []
for name, abbrev in kwargs.items():
default = getattr(self, name)
widget = _widget_from_abbrev(abbrev, default)
if not widget.description:
widget.description = name
widget.link = link((widget, 'value'), (self, name))
c.append(widget)
cont = Box(children=c)
return cont
开发者ID:rlugojr,项目名称:ipyleaflet,代码行数:11,代码来源:leaflet.py
示例18: __init__
def __init__(self, *args, **kwargs):
super(ExonExplorer, self).__init__(*args, **kwargs)
self.genome_zoom = genome_bar.GenomeBar()
z = self.zoom_svg = self.canvas()
z.watch_event = "mousemove"
z.default_event_callback = self.zoom_callback
self.genome_guide = genome_bar.GenomeBar()
g = self.guide_svg = self.canvas()
g.watch_event = "mousemove click"
g.default_event_callback = self.guide_callback
self.info = widgets.Text(value="", width=500)
self.assembly = widgets.VBox(children=[self.zoom_svg,
self.guide_svg,
self.info])
self.data = gtf_format.GTFData()
self.name_to_feature = {}
self.select_name = "SELECTION"
self.selected_svg_x = None
traitlets.link((self, "start_position"), (self.genome_zoom, "minLocation"))
traitlets.link((self, "end_position"), (self.genome_zoom, "maxLocation"))
开发者ID:anu-bioinfo,项目名称:jp_gene_viz,代码行数:20,代码来源:genome_guide.py
示例19: slider_link
def slider_link(obj, attr):
def link_fn(name, new_value):
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 is "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 is "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"))
开发者ID:galbramc,项目名称:gpkit,代码行数:20,代码来源:widgets.py
示例20: __init__
def __init__(self, mol):
super(ResidueSelector, self).__init__(mol)
self.selection_type = ipy.Dropdown(description='Clicks select:',value=self.viewer.selection_type,
options=('Atom', 'Residue', 'Chain'))
traitlets.link((self.selection_type, 'value'), (self.viewer, 'selection_type'))
self.residue_listname = ipy.HTML('<b>Selected residues:</b>')
self.residue_list = ipy.SelectMultiple(options=list(), height=150)
traitlets.directional_link((self.viewer, 'selected_atom_indices'), (self.residue_list, 'options'), self._atoms_to_residues)
self.residue_list.observe(self.remove_atomlist_highlight, 'value')
self.atom_list.observe(self.remove_reslist_highlight, 'value')
self.subtools.children = [ipy.HBox([self.select_all_atoms_button, self.select_none])]
self.toolpane.children = [self.selection_type,
self.atom_listname,
self.atom_list,
self.residue_listname,
self.residue_list]
开发者ID:drancom,项目名称:molecular-design-toolkit,代码行数:20,代码来源:selection.py
注:本文中的traitlets.link函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论