def idisplay(*args, label=True):
"""Display multiple values using ipywidget HBox
Arguments:
* `*args` -- list of values
Keyword arguments:
* `label` -- create a Label widget instead of a Text widget, if value is
not a widget
"""
new_widget = lambda x: Label(x) if label else Text(value=x)
args = [
arg if isinstance(arg, DOMWidget) else new_widget(arg)
for arg in args
]
display(HBox(args))
python类Label()的实例源码
def __init__(self, mol):
super().__init__(mol)
self._bondset = collections.OrderedDict()
self._drawn_bond_state = set()
self.bond_listname = ipy.Label('Selected bonds:', layout=ipy.Layout(width='100%'))
self.bond_list = ipy.SelectMultiple(options=list(),
layout=ipy.Layout(height='150px'))
self.viewer.observe(self._update_bondlist, 'selected_atom_indices')
self.atom_list.observe(self.remove_bondlist_highlight, 'value')
self.subtools.children = [HBox([self.select_all_atoms_button,
self.select_none])]
self.toolpane.children = (self.atom_listname,
self.atom_list,
self.bond_listname,
self.bond_list)
def __init__(self, mol):
super().__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.Label('Selected residues:', layout=ipy.Layout(width='100%'))
self.residue_list = ipy.SelectMultiple(options=list(), height='150px')
self.viewer.observe(self._update_reslist, 'selected_atom_indices')
self.residue_list.observe(self.remove_atomlist_highlight, 'value')
self.atom_list.observe(self.remove_reslist_highlight, 'value')
self.subtools.children = [self.representation_buttons]
self.subtools.layout.flex_flow = 'column'
self.toolpane.children = [self.selection_type,
HBox([self.select_all_atoms_button, self.select_none]),
self.atom_listname,
self.atom_list,
self.residue_listname,
self.residue_list]
def __init__(self):
self.client = None
self.warning = ipy.HTML(description='<b>Engine status:</b>', value=SPINNER)
self.devmode_label = ipy.Label('Use local docker images (developer mode)',
layout=ipy.Layout(width='100%'))
self.devmode_button = ipy.Checkbox(value=mdt.compute.config.devmode,
layout=ipy.Layout(width='15px'))
self.devmode_button.observe(self.set_devmode, 'value')
self.engine_config_description = ipy.HTML('Docker host with protocol and port'
' (e.g., <code>http://localhost:2375</code>).'
' If blank, this'
' defaults to the docker engine configured at '
'your command line.',
layout=ipy.Layout(width='100%'))
self.engine_config_value = ipy.Text('blank', layout=ipy.Layout(width='100%'))
self.engine_config_value.add_class('nbv-monospace')
self.image_box = ipy.Box()
self._reset_config_button = ipy.Button(description='Reset',
tooltip='Reset to applied value')
self._apply_changes_button = ipy.Button(description='Apply',
tooltip='Apply for this session')
self._save_changes_button = ipy.Button(description='Make default',
tooltip='Make this the default for new sessions')
self._reset_config_button.on_click(self.reset_config)
self._apply_changes_button.on_click(self.apply_config)
self._save_changes_button.on_click(self.save_config)
self.children = [self.warning,
VBox([self.engine_config_description,
self.engine_config_value]),
HBox([self._reset_config_button,
self._apply_changes_button,
self._save_changes_button]),
HBox([self.devmode_button, self.devmode_label]),
self.image_box]
self.reset_config()
super().__init__(children=self.children)
self.connect_to_engine()
def __init__(self, mol):
super().__init__(mol)
self._atomset = collections.OrderedDict()
self.atom_listname = ipy.Label('Selected atoms:', layout=ipy.Layout(width='100%'))
self.atom_list = ipy.SelectMultiple(options=list(self.viewer.selected_atom_indices),
layout=ipy.Layout(height='150px'))
traitlets.directional_link(
(self.viewer, 'selected_atom_indices'),
(self.atom_list, 'options'),
self._atom_indices_to_atoms
)
self.select_all_atoms_button = ipy.Button(description='Select all atoms')
self.select_all_atoms_button.on_click(self.select_all_atoms)
self.select_none = ipy.Button(description='Clear all selections')
self.select_none.on_click(self.clear_selections)
self.representation_buttons = ipy.ToggleButtons(options=['stick','ribbon', 'auto', 'vdw'],
value='auto')
self.representation_buttons.observe(self._change_representation, 'value')
def __init__(self, mode="text"):
self.mode_widget = Dropdown(
options={
'BibTeX': 'bibtex',
'Text': 'text',
'[N] author name place other year': 'citation',
'Quoted': 'quoted',
},
value=mode
)
self.button_widget = Button(
description="Set article_list variable",
disabled=mode not in ("citation", "bibtex")
)
self.frompdf_widget = Textarea()
self.output_widget = Textarea()
self.label_widget = Label()
self.frompdf_widget.observe(self.write)
self.mode_widget.observe(self.select)
self.button_widget.on_click(self.set_variable)
self.view = VBox([
HBox([self.mode_widget, self.button_widget, self.label_widget]),
HBox([self.frompdf_widget, self.output_widget])
])
self.frompdf_widget.layout.height = "500px"
self.output_widget.layout.height = "500px"
self.frompdf_widget.layout.width = "50%"
self.output_widget.layout.width = "50%"
self.backup = ""
self.ipython = get_ipython()
def __init__(self, querier, citation_var, citation_file=None, debug=False, start=None, load=True):
from .selenium_scholar import URLQuery
reload()
self.querier = querier
work = work_by_varname(citation_var)
citation_file = citation_file or getattr(work, "citation_file", citation_var)
self.navigator = ArticleNavigator(citation_var, citation_file, backward=False, force_citation_file=False)
self.query = URLQuery(self.navigator.work.scholar, start)
self.next_page_widget = Button(description='Next Page', icon='fa-arrow-right')
self.reload_widget = Button(description='Reload', icon='fa-refresh')
self.previous_page_widget = Button(description='Previous Page', icon='fa-arrow-left')
self.debug_widget = ToggleButton(value=debug, description="Debug")
self.page_number_widget = Label(value="")
self.next_page_widget.on_click(self.next_page)
self.reload_widget.on_click(self.reload)
self.previous_page_widget.on_click(self.previous_page)
self.view = Tab([
VBox([
HBox([
self.previous_page_widget,
self.reload_widget,
self.next_page_widget,
self.debug_widget,
self.page_number_widget
]),
self.navigator.output_widget,
]),
self.navigator.view
])
self.view.set_title(0, "Page")
self.view.set_title(1, "Article")
if load:
self.reload(None)
def __init__(self, querier, worklist, force=False, debug=False, index=0):
reload()
self.worklist = worklist
self.force = force
self.querier = querier
self.next_page_widget = Button(description='Next Work', icon='fa-arrow-right')
self.reload_widget = Button(description='Reload', icon='fa-refresh')
self.previous_page_widget = Button(description='Previous Work', icon='fa-arrow-left')
self.debug_widget = ToggleButton(value=debug, description="Debug")
self.textarea_widget = ToggleButton(value=False, description="TextArea")
self.page_number_widget = Label(value="")
self.output_widget = Output()
self.next_page_widget.on_click(self.next_page)
self.reload_widget.on_click(self.reload)
self.previous_page_widget.on_click(self.previous_page)
self.textarea_widget.observe(self.show)
self.view = VBox([
HBox([
self.previous_page_widget,
self.reload_widget,
self.next_page_widget,
self.debug_widget,
self.textarea_widget,
self.page_number_widget
]),
self.output_widget
])
self.index = index
self.varname = ""
self.work = None
self.articles = []
self.reload(show=False)
def __init__(self, plots):
"""
Compiles non-axis coordinates into sliders, the values from which are
used to reconstruct plots upon movement of slider.
Args:
* plot
cube_browser plot instance to display with slider.
"""
if not isinstance(plots, Iterable):
plots = [plots]
self.plots = plots
# Mapping of coordinate/alias name to axis.
self._axis_by_name = {}
# Mapping of cube-id to shared cache.
self._cache_by_cube_id = {}
# Mapping of plot-id to coordinate/alias name.
self._names_by_plot_id = {}
# Mapping of coordinate/alias name to plots.
self._plots_by_name = {}
self._build_mappings()
self._slider_by_name = {}
self._name_by_slider_id = {}
if self._axis_by_name:
name_len = max([len(name) for name in self._axis_by_name])
children = []
for axis in self._axis_by_name.values():
if hasattr(axis, 'coord') and axis.coord.units.is_time_reference():
pairs = [(axis.coord.units.num2date(axis.coord.points[i]), i)
for i in range(axis.size)]
elif hasattr(axis, 'coord'):
pairs = [(axis.coord.points[i], i) for i in range(axis.size)]
else:
pairs = [(i, i) for i in range(axis.size)]
options = OrderedDict(pairs)
slider = ipywidgets.SelectionSlider(options=options)
slider.observe(self.on_change, names='value')
self._slider_by_name[axis.name] = slider
self._name_by_slider_id[id(slider)] = axis.name
# Explicitly control the slider label in order to avoid
# fix width widget description label wrapping issues.
# XXX: Adjust px/em scale-factor dynamically based on font-size.
scale_factor = .65
width = u'{}em'.format(int(name_len * scale_factor))
label = ipywidgets.Label(axis.name, padding=u'0.3em', width=width)
hbox = ipywidgets.HBox(children=[label, slider])
children.append(hbox)
# Layout the sliders in a consitent order.
self.form = ipywidgets.VBox()
key = lambda hbox: hbox.children[0].value
self.form.children = sorted(children, key=key)
orbital_viewer.py 文件源码
项目:notebook-molecular-visualization
作者: Autodesk
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def _make_ui_pane(self, hostheight):
layout = ipy.Layout(width='325px',
height=str(int(hostheight.rstrip('px')) - 50) + 'px')
#element_height = str(int(hostheight.rstrip('px')) - 125) + 'px'
element_height = None
# NOTE - element_height was used for the listbox-style orblist.
# HOWEVER ipywidgets 6.0 only displays those as a dropdown.
# This is therefore disabled until we can display listboxes again. -- AMV 7/16
# Orbital set selector
self.status_element = ipy.HTML(layout=ipy.Layout(width='inherit', height='20px'))
orbtype_label = ipy.Label("Orbital set:")
self.type_dropdown = ipy.Dropdown(options=list(self.wfn.orbitals.keys()))
initialtype = 'canonical'
if initialtype not in self.type_dropdown.options:
initialtype = next(iter(self.type_dropdown.options.keys()))
self.type_dropdown.value = initialtype
self.type_dropdown.observe(self.new_orb_type, 'value')
# List of orbitals in this set
orblist_label = ipy.Label("Orbital:")
self.orblist = ipy.Dropdown(options={None: None},
layout=ipy.Layout(width=layout.width, height=element_height))
traitlets.link((self.orblist, 'value'), (self, 'current_orbital'))
# Isovalue selector
isoval_label = ipy.Label('Isovalue:')
self.isoval_selector = ipy.FloatSlider(min=0.0, max=0.075,
value=0.01, step=0.00075,
readout_format='.4f',
layout=ipy.Layout(width=layout.width))
traitlets.link((self.isoval_selector, 'value'), (self, 'isoval'))
# Opacity selector
opacity_label = ipy.Label('Opacity:')
self.opacity_selector = ipy.FloatSlider(min=0.0, max=1.0,
value=0.8, step=0.01,
readout_format='.2f',
layout=ipy.Layout(width=layout.width))
traitlets.link((self.opacity_selector, 'value'), (self, 'orb_opacity'))
# Resolution selector
resolution_label = ipy.Label("Grid resolution:", layout=ipy.Layout(width=layout.width))
self.orb_resolution = ipy.Text(layout=ipy.Layout(width='75px',
positioning='bottom'))
self.orb_resolution.value = str(self.numpoints)
self.resolution_button = ipy.Button(description='Update resolution')
self.resolution_button.on_click(self.change_resolution)
traitlets.directional_link((self, 'numpoints'), (self.orb_resolution, 'value'),
transform=str)
self.uipane = ipy.VBox([self.status_element,
orbtype_label, self.type_dropdown,
orblist_label, self.orblist,
isoval_label, self.isoval_selector,
opacity_label, self.opacity_selector,
resolution_label, self.orb_resolution, self.resolution_button])
self.new_orb_type()
self.type_dropdown.observe(self.new_orb_type, 'value')
return self.uipane