我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用ipywidgets.Text()。
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))
def __init__(self, format=None, *args, **kwargs): description = kwargs.pop('description', 'FloatSlider') min = kwargs.setdefault('min', 0.0) max = kwargs.setdefault('max', 10.0) self.formatstring = format self.header = ipy.HTML() self.readout = ipy.Text(layout=ipy.Layout(width='100px')) self.readout.on_submit(self.parse_value) kwargs.setdefault('readout', False) self.slider = ipy.FloatSlider(*args, **process_widget_kwargs(kwargs)) self.minlabel = ipy.HTML(u'<font size=1.5>{}</font>'.format(self.formatstring.format(min))) self.maxlabel = ipy.HTML(u'<font size=1.5>{}</font>'.format(self.formatstring.format(max))) self.sliderbox = HBox([self.minlabel, self.slider, self.maxlabel]) traitlets.link((self, 'description'), (self.header, 'value')) traitlets.link((self, 'value'), (self.slider, 'value')) self.description = description self.update_readout() super().__init__([self.header, self.readout, self.sliderbox])
def task_search_bar(): task_search = widgets.Text( value="", placeholder="Task ID", description="Search for a task:", disabled=False ) display(task_search) def handle_submit(sender): pp = pprint.PrettyPrinter() pp.pprint(ray.global_state.task_table(task_search.value)) task_search.on_submit(handle_submit) # Hard limit on the number of tasks to return to the UI client at once
def __init__(self, initial_value='', default=''): if initial_value == '': try: initial_value = iris.sample_data_path('') except ValueError: initial_value = '' # Define the file system path for input files. self._path = ipywidgets.Text( description='Path:', value=initial_value, width="100%") # Observe the path. self._path.observe(self._handle_path, names='value') # Use default path value to initialise file options. options = [] if os.path.exists(self._path.value): options = glob.glob('{}/*'.format(self._path.value)) options.sort() default_list = [] for default_value in default.split(','): if default_value in options: default_list.append(default_value) default_tuple = tuple(default_list) # Defines the files selected to be loaded. self._files = ipywidgets.SelectMultiple( description='Files:', options=OrderedDict([(os.path.basename(f), f) for f in options]), value=default_tuple, width="100%" ) self.deleter = ipywidgets.Button(description='delete tab', height='32px', width='75px') hbox = ipywidgets.HBox(children=[self._files, self.deleter]) self._box = ipywidgets.Box(children=[self._path, hbox], width="100%")
def __init__(self): self.mpl_kwargs = {} # Defines the cube which is to be plotted. self.cube_picker = ipywidgets.Dropdown(description='Cubes:', options=('None', None), value=None, width='50%') # Define the type of cube browser plot required self.plot_type = ipywidgets.Dropdown( description='Plot type:', options={'pcolormesh': cube_browser.Pcolormesh, 'contour': cube_browser.Contour, 'contourf': cube_browser.Contourf}, value=cube_browser.Pcolormesh) self.x_coord = ipywidgets.Dropdown( description='X Coord', options=('None', None)) self.y_coord = ipywidgets.Dropdown( description='Y Coord', options=('None', None)) self.cmap = ipywidgets.Text( description='colour map') # Handle events: self.cube_picker.observe(self._handle_cube_selection, names='value') self.cmap.observe(self._handle_cmap, names='value') self.plot_type.observe(self._handle_plot_type, names='value') self._box = ipywidgets.Box(children=[self.cube_picker, self.plot_type, self.x_coord, self.y_coord, self.cmap])
def _controllers_for(opt): """ Give a string representing the parameter represented, find the appropriate command. """ colors = [None, 'blue', 'red', 'green', 'black'] controllers = {'type': widgets.Dropdown(options=['auto detect'] +\ _get_types(), description='type'), 'bin': widgets.Checkbox(description='bin'), 'aggregate': widgets.Dropdown(options=[None] +\ _get_functions(), description='aggregate'), 'zero': widgets.Checkbox(description='zero'), 'text': widgets.Text(description='text value'), 'scale': widgets.Dropdown(options=['linear', 'log'], description='scale'), 'color': widgets.Dropdown(options=colors, description='main color'), 'applyColorToBackground': widgets.Checkbox(description='applyColorToBackground'), 'shortTimeLabels': widgets.Checkbox(description='shortTimeLabels') } for title, controller in controllers.items(): controller.title = title if 'Checkbox' in str(controller): # traits = dir(controller.layout) # traits = [t for t in traits if t[0] != '_'] controller.layout.max_width = '200ex' # controller.layout.min_width = '100ex' # controller.layout.width = '150ex' return controllers[opt]
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): super().__init__( **process_widget_kwargs(dict(flex_flow='column'))) self.repo_field = ipy.Text(description='Image repository') self.version_field = ipy.Text(description='Image version') self._reset_config_button = ipy.Button(description='Reset', tooltip='Reset to current configuration') 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._pull_button = ipy.Button(description='Pull images', tooltip= 'Download all moldesign images to the compute engine') self.children = (HBox([self.repo_field, self.version_field]), HBox([self._reset_config_button, self._apply_changes_button, self._pull_button])) 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._test_button.on_click(self.test_connection)
def __init__(self, *args, **kwargs): super().__init__(*args, **process_widget_kwargs(kwargs)) self.textbox = ipy.Text() self.textbox.disabled = True self.children = [self.textbox]
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 create_custom_text(self, tup): """Create custom text based on config.FORM_TEXT_FIELDS tuple""" text = Text(value="", description=tup[0]) text._workattr = tup[1] self.custom_widgets.append(text) if tup[2]: if hasattr(self, tup[2]): warnings.warn("ArticleNavigator already has the attribute {}. Skipping".format(tup[2])) else: setattr(self, tup[2], text) return text
def object_search_bar(): object_search = widgets.Text( value="", placeholder="Object ID", description="Search for an object:", disabled=False ) display(object_search) def handle_submit(sender): pp = pprint.PrettyPrinter() pp.pprint(ray.global_state.object_table(object_search.value)) object_search.on_submit(handle_submit)
def define_site_description_image(self): '''Widgets for site description parameters''' self.w_latBut = widgets.Button(description='Browse Latitude Image') self.w_lat = widgets.Text( description='(Decimal degrees)', value='0', width=500) self.w_lonBut = widgets.Button(description='Browse Longitude Image') self.w_lon = widgets.Text( description='(Decimal degrees):', value='0', width=500) self.w_altBut = widgets.Button(description='Browse Altitude Image') self.w_alt = widgets.Text( description='(m):', value='0', width=500) self.w_stdlon_But = widgets.Button(description='Browse Standard Longitude Image') self.w_stdlon = widgets.Text( description='(Decimal degrees):', value='0', width=500) self.w_z_u_But = widgets.Button(description='Wind meas. height') self.w_z_u = widgets.Text( description='(m):', value=str(self.zu), width=500) self.w_z_T_But = widgets.Button(description='Air temp. meas. height') self.w_z_T = widgets.Text( description='(m):', value=str(self.zt), width=500) self.site_page = widgets.VBox([widgets.HTML('Select latitude image or type a constant value'), widgets.HBox([self.w_latBut, self.w_lat]), widgets.HTML('Select longitude image or type a constant value'), widgets.HBox([self.w_lonBut, self.w_lon]), widgets.HTML('Select altitude image or type a constant value'), widgets.HBox([self.w_altBut, self.w_alt]), widgets.HTML('Select standard longitude image or type a constant value'), widgets.HBox([self.w_stdlon_But, self.w_stdlon]), widgets.HTML('Select wind measurement height image or type a constant value'), widgets.HBox([self.w_z_u_But, self.w_z_u]), widgets.HTML('Select air temperature measurement height image or type a constant value'), widgets.HBox([self.w_z_T_But, self.w_z_T])]) self.w_latBut.on_click( lambda b: self._on_input_clicked(b, 'Latitude', self.w_lat)) self.w_lonBut.on_click( lambda b: self._on_input_clicked(b, 'Longitude', self.w_lon)) self.w_altBut.on_click( lambda b: self._on_input_clicked(b, 'Altitude', self.w_alt)) self.w_stdlon_But.on_click( lambda b: self._on_input_clicked(b, 'Standard Longitude', self.w_stdlon)) self.w_z_u_But.on_click( lambda b: self._on_input_clicked(b, 'Wind Measurement Height', self.w_z_u)) self.w_z_T_But.on_click( lambda b: self._on_input_clicked(b, 'Air Temperature Measurement Height', self.w_z_T))
def surface_properties_image(self): '''Widgets for canopy properties''' self.w_PT_But = widgets.Button( description='Browse Initial alphaPT Image') self.w_PT = widgets.Text(description=' ', value=str(self.max_PT), width=500) self.w_LAD_But = widgets.Button( description='Browse Leaf Angle Distribution Image') self.w_LAD = widgets.Text(description='(degrees)', value=str(self.x_LAD), width=500) self.w_leafwidth_But = widgets.Button( description='Browse Leaf Width Image') self.w_leafwidth = widgets.Text(description='(m)', value=str(self.leaf_width), width=500) self.w_zsoil_But = widgets.Button( description='Browse Soil Roughness Image') self.w_zsoil = widgets.Text(description='(m)', value=str(self.z0soil), width=500) self.w_lc_But = widgets.Button( description='Browse Land Cover Image') # Landcover classes and values come from IGBP Land Cover Type Classification self.w_lc = widgets.Dropdown( options={ 'CROP': 12, 'GRASS': 10, 'SHRUB': 6, 'CONIFER': 1, 'BROADLEAVED': 4}, value=self.landcover, description=" ", width=300) lcText = widgets.HTML(value='''Land cover information is used to estimate roughness. <BR> For shrubs, conifers and broadleaves we use the model of <BR> Schaudt & Dickinson (2000) Agricultural and Forest Meteorology. <BR> For crops and grasses we use a fixed ratio of canopy height<BR>''', width=600) self.calc_row_options() self.veg_page = widgets.VBox([widgets.HTML('Select alphaPT image or type a constant value'), widgets.HBox([self.w_PT_But, self.w_PT]), widgets.HTML('Select leaf angle distribution image or type a constant value'), widgets.HBox([self.w_LAD_But, self.w_LAD]), widgets.HTML('Select leaf width image or type a constant value'), widgets.HBox([self.w_leafwidth_But, self.w_leafwidth]), widgets.HTML('Select soil roughness image or type a constant value'), widgets.HBox([self.w_zsoil_But, self.w_zsoil]), widgets.HTML('Select landcover image or type a constant value'), widgets.HBox([self.w_lc_But, self.w_lc]), lcText, widgets.HBox([self.w_row, self.w_rowaz])], background_color='#EEE') self.w_PT_But.on_click( lambda b: self._on_input_clicked(b, 'Initial alphaPT', self.w_PT)) self.w_LAD_But.on_click( lambda b: self._on_input_clicked(b, 'Leaf Angle Distribution', self.w_LAD)) self.w_leafwidth_But.on_click( lambda b: self._on_input_clicked(b, 'Leaf Width', self.w_leafwidth)) self.w_zsoil_But.on_click( lambda b: self._on_input_clicked(b, 'Soil Roughness', self.w_zsoil)) self.w_lc_But.on_click( lambda b: self._input_dropdown_clicked(b, 'Land Cover', self.w_lc))
def resistances_image(self): '''Widgets for resistance model selection''' self.w_res = widgets.ToggleButtons( description='Select TSEB model to run:', options={ 'Kustas & Norman 1999': 0, 'Choudhury & Monteith 1988': 1, 'McNaughton & Van der Hurk': 2}, value=self.res, width=300) self.w_PT_But = widgets.Button( description='Browse Initial alphaPT Image') self.w_PT = widgets.Text(description=' ', value=str(self.max_PT), width=500) self.w_KN_b_But = widgets.Button( description = 'Browse Resistance Parameter b Image') self.w_KN_b = widgets.Text( value=str(self.KN_b), description=' ', width=500) self.w_KN_c_But = widgets.Button( description = ('Browse Resistance Parameter c image')) self.w_KN_c = widgets.Text( value=str(self.KN_c), description='(m s-1 K-1/3)', width=500) self.w_KN_C_dash_But = widgets.Button( description = ("Browse Resistance Parameter C' Image")) self.w_KN_C_dash = widgets.Text( value=str(self.KN_C_dash), description="s1/2 m-1", width=500) self.KN_params_box = widgets.VBox([widgets.HTML('Select resistance parameter b image or type a constant value'), widgets.HBox([self.w_KN_b_But, self.w_KN_b]), widgets.HTML('Select resistance parameter c image or type a constant value'), widgets.HBox([self.w_KN_c_But, self.w_KN_c]), widgets.HTML('Select resistance parameter C\' image or type a constant value'), widgets.HBox([self.w_KN_C_dash_But, self.w_KN_C_dash])], background_color='#EEE') self.res_page = widgets.VBox([self.w_res, self.KN_params_box], background_color='#EEE') self.w_KN_b_But.on_click( lambda b: self._on_input_clicked(b, 'Resistance Parameter b', self.w_KN_b)) self.w_KN_c_But.on_click( lambda b: self._on_input_clicked(b, 'Resistance Parameter c', self.w_KN_c)) self.w_KN_C_dash_But.on_click( lambda b: self._on_input_clicked(b, 'Resistance Parameter C\'', self.w_KN_C_dash))
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
def __init__(self, paramdef): super(ParamSelector, self).__init__(layout=ipy.Layout(display='flex', flex_flow='nowrap', align_content='stretch')) self.paramdef = paramdef children = [] self.name = ipy.HTML("<p style='text-align:right'>%s:</p>" % paramdef.displayname, layout=ipy.Layout(width='200px')) children.append(self.name) if paramdef.choices: self.selector = ipy.Dropdown(options=paramdef.choices, **self.WIDGETKWARGS) elif paramdef.type == bool: self.selector = ipy.ToggleButtons(options=[True, False], **self.WIDGETKWARGS) elif paramdef.units: self.selector = UnitText(units=paramdef.units, **self.WIDGETKWARGS) elif paramdef.type == float: self.selector = ipy.FloatText(**self.WIDGETKWARGS) elif paramdef.type == int: self.selector = ipy.IntText(**self.WIDGETKWARGS) elif paramdef.type == str: self.selector = ipy.Text(**self.WIDGETKWARGS) else: self.selector = ReadOnlyRepr(**self.WIDGETKWARGS) children.append(self.selector) children = [self.name, self.selector] self.default_button = None if paramdef.default: self.default_button = ipy.Button(description='Default', tooltip='Set to default: %s' % self.paramdef.default, layout=ipy.Layout(width='75px')) self.default_button.on_click(self.default) children.append(self.default_button) self.default() self.help_link = None if paramdef.help_url: self.help_link = ipy.HTML('<a href="%s" target="_blank">?</a>' % paramdef.help_url) children.append(self.help_link) self.children = children