def _make_general_box(self): if self.widget_general is None: step_slide = IntSlider(value=self.step, min=-100, max=100, description='step') delay_text = IntSlider(value=self.delay, min=10, max=1000, description='delay') toggle_button_interpolate = ToggleButton( self.interpolate, description='Smoothing', tooltip='smoothing trajectory') link((toggle_button_interpolate, 'value'), (self, 'interpolate')) background_color_picker = ColorPicker(value='white', description='background') camera_type = Dropdown(value=self.camera, options=['perspective', 'orthographic'], description='camera') link((step_slide, 'value'), (self, 'step')) link((delay_text, 'value'), (self, 'delay')) link((toggle_button_interpolate, 'value'), (self, 'interpolate')) link((camera_type, 'value'), (self, 'camera')) link((background_color_picker, 'value'), (self._view, 'background')) center_button = self._make_button_center() render_button = self._show_download_image() center_render_hbox = _make_autofit( HBox([ toggle_button_interpolate, center_button, render_button, ])) v0_left = VBox([ step_slide, delay_text, background_color_picker, camera_type, center_render_hbox, ]) v0_left = _relayout_master(v0_left, width='100%') self.widget_general = v0_left return self.widget_general
def _make_repr_playground(self): vbox = VBox() children = [] rep_names = REPRESENTATION_NAMES[:] excluded_names = ['ball+stick', 'distance'] for name in excluded_names: rep_names.remove(name) repr_selection = Text(value='*') repr_selection.layout.width = default.DEFAULT_TEXT_WIDTH repr_selection_box = HBox([Label('selection'), repr_selection]) setattr(repr_selection_box, 'value', repr_selection.value) for index, name in enumerate(rep_names): button = ToggleButton(description=name) def make_func(): def on_toggle_button_value_change(change, button=button): selection = repr_selection.value new = change['new'] # True/False if new: self._view.add_representation(button.description, selection=selection) else: self._view._remove_representations_by_name( button.description) return on_toggle_button_value_change button.observe(make_func(), names='value') children.append(button) button_clear = Button(description='clear', button_style='info', icon='fa-eraser') @button_clear.on_click def on_clear(button_clear): self._view.clear() for kid in children: # unselect kid.value = False vbox.children = children + [repr_selection, button_clear] _make_autofit(vbox) self.widget_quick_repr = vbox return self.widget_quick_repr
def _(*_): self.buttons = [ ToggleButton(description=label, layout=Layout(margin='1', width='auto')) for label in self._selection_obj._options_labels ] self.label = Label( self.description, layout=Layout( width=self.style.get('description_width', '100px'))) self.children = [self.label] + self.buttons @observer(self.buttons, 'value') def _(*_): self.value = tuple(value for btn, value in zip( self.buttons, self._selection_obj._options_values) if btn.value)
def __init__(self, querier, debug=False): from snowballing.selenium_scholar import URLQuery reload() self.querier = querier self.query = None self.search_text_widget = Text(value="", layout=Layout(width="99%")) self.do_search_widget = Button(description="Search", icon="fa-search") self.navigator = ArticleNavigator(force_citation_file=False) 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.do_search_widget.on_click(self.search) self.search_text_widget.on_submit(self.search) self.tab_widget = 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 = VBox([ self.search_text_widget, self.do_search_widget, self.tab_widget ]) self.tab_widget.set_title(0, "Page") self.tab_widget.set_title(1, "Article")
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, name: str = "Network", **opts): super().__init__(name=name, **opts) self.network: ipycytoscape.CytoscapeWidget = None self._view: Output = Output() self._node_spacing: IntSlider = IntSlider(description='', min=3, max=500, value=50, layout={'width': '200px'}) self._edge_length_val: IntSlider = IntSlider( description='', min=3, max=500, value=50, layout={'width': '200px'} ) self._padding: IntSlider = IntSlider(description='', min=3, max=500, value=50, layout={'width': '200px'}) self._label: HTML = HTML(value=' ', layout={'width': '200px'}) self._network_layout = Dropdown( description='', options=['cola', 'klay', 'circle', 'concentric'], value='cola', layout={'width': '115px'}, ) self._relayout = Button( description="Continue", button_style='Info', layout=Layout(width='115px', background_color='blue') ) self._animate: Checkbox = ToggleButton( description="Animate", icon='check', value=True, layout={'width': '115px'}, ) self._curve_style = Dropdown( description='', options=[ ('Straight line', 'haystack'), ('Curve, Bezier', 'bezier'), ('Curve, Bezier*', 'unbundled-bezier'), ], value='haystack', layout={'width': '115px'}, ) self._custom_styles: dict = None self._buzy: bool = False
def controls(self): get_supercell = ToggleButton(value=False, description='Get supercell', disabled=False, button_style='', tooltip='Click to show supercell') get_supercell.observe(self.supercell_callback, 'value') run_command = Button(description='Run Command', disabled=False) run_command.on_click(self.run_cmd_callback) self.command_text = Text(value='spin on', placeholder='spin on', description='Command:', disabled=False) data_filter_vbox = VBox( [HBox([get_supercell]), HBox([self.command_text, run_command])]) return data_filter_vbox
def on_selector_change(self, change): if self.image_selector.value in self.image_dict: self.change_image(self.image_dict[self.image_selector.value]) self.widget.children = [self.selector_box, self.display_box] else: self.upload_widget = FileUpload(accept='image/*', multiple=False) self.name_widget = Text(description='<b>Image Name</b>', style={'description_width': 'initial'}) self.ok_widget = ToggleButton( value=False, description='Add', disabled=False, button_style='success', tooltip='Description', icon='check') self.add_widget = HBox(children=[self.upload_widget, self.name_widget, self.ok_widget], layout=Layout(justify_content='space-around')) self.widget.children = [self.selector_box, self.add_widget] self.upload_widget.observe(self.on_upload, 'value') self.ok_widget.observe(self.on_add, 'value')
def interact_gravity_sphere(): Q = interactive( drawfunction, delta_rho=FloatSlider( description=r"$\Delta\rho$", min=-5.0, max=5.0, step=0.1, value=1.0, continuous_update=False, ), a=FloatSlider(min=0.1, max=4.0, step=0.1, value=1.0, continuous_update=False), z=FloatSlider(min=0.1, max=5.0, step=0.1, value=1.0, continuous_update=False), stationSpacing=FloatSlider( description="Step", min=0.005, max=0.1, step=0.005, value=0.01, continuous_update=False, readout_format=".3f", ), B=ToggleButton( value=True, description="keep previous plots", disabled=False, button_style="", tooltip="Click me", layout=Layout(width="20%"), ), ) return Q
def create_category(self, name, attr, value, color, font_color): """Create category widget""" VIS = ["none", ""] widget = self.toggle_widgets[attr] = ToggleButton(value=value, description=name) wcolor = self.color_widgets[attr] = ColorPicker(value=color, description=name, width="180px") wfont_color = self.font_color_widgets[attr] = ColorPicker( value=font_color, width="110px") def visibility(*args): """" Toggles visibility of category """ self._display_stack += 1 wcolor.layout.display = VIS[int(widget.value)] wfont_color.layout.display = VIS[int(widget.value)] self.display() widget.observe(visibility, "value") wcolor.observe(self.update_widget, "value") wfont_color.observe(self.update_widget, "value") visibility()
def __init__(self, data, dimensions, **kwargs): self.data = data self.options = {} self.margins = {} self.dimensions = dimensions self.debug = kwargs.get('debug', None) self.modal = kwargs.get('modal', True) self.only_subsets = kwargs.get('only_subsets', False) self.output_cont = Output() self.output_cont.layout.width = '100%' self.options_cont = Output() self.margins_cont = Output() self.option_tab = Tab() self.option_tab.children = [self.options_cont, self.margins_cont] self.option_tab.set_title(0, "Plot") self.option_tab.set_title(1, "Layout") self.option_tab.layout.display = 'none' self.options_check = ToggleButton(value=False, description="Options", icon='cog') self.options_check.observe(lambda v: self.showWidget(v["new"]), names='value') self.tab = HBox() self.tab.children = [self.option_tab, self.output_cont] init_notebook_mode(connected=True) if (self.window == None): if (self.modal == True): title = kwargs.get('title', "") mode = kwargs.get('mode', "") self.window = Floatview(title=title, mode=mode) else: self.window = Output() display(self.window) self.DefaultMargins() self.displayWindow()
def create_tab(self): def change(visible): with self.figure: if visible: ipv.style.axes_on() ipv.style.box_on() else: ipv.style.axes_off() ipv.style.box_off() self.state.add_callback('visible_axes', change) self.widget_show_movie_maker = ToggleButton(value=False, description="Show movie maker") self.movie_maker = ipv.moviemaker.MovieMaker(self.figure, self.figure.camera) dlink((self.widget_show_movie_maker, 'value'), (self.movie_maker.widget_main.layout, 'display'), lambda value: None if value else 'none') self.tab_general = VBox([]) self.tab_general.children += self._options_cls(self.state).children self.tab_general.children += (self.widget_show_movie_maker, self.movie_maker.widget_main) children = [self.tab_general] self.tab = Tab(children) self.tab.set_title(0, "General") self.tab.set_title(1, "Axes")
def __init__(self, viewer_state): self.state = viewer_state self.widget_reference_data = LinkedDropdown(self.state, 'reference_data', label='reference') self.widget_axis_x = LinkedDropdown(self.state, 'x_att', label='x axis') self.widget_function = LinkedDropdown(self.state, 'function', label='function') self.button_normalize = ToggleButton(value=False, description='normalize', tooltip='Normalize profiles') link((self.button_normalize, 'value'), (self.state, 'normalize')) super().__init__([ self.widget_reference_data, self.widget_axis_x, self.widget_function, self.button_normalize ])
def _(*_): self.buttons = [] for label in self._selection_obj._options_labels: short_label = short_label_map.get(label, label) self.buttons.append( ToggleButton( description=short_label if len(short_label) < 15 else short_label[:12] + "…", tooltip=label, layout=Layout( margin='1', width='auto', ), )) if self.description: self.label = Label( self.description, layout=Layout( width=self.style.get('description_width', '100px'))) else: self.label = Label( self.description, layout=Layout( width=self.style.get('description_width', '0px'))) self.children = [self.label] + self.buttons @observer(self.buttons, 'value') def _(*_): proposed_value = tuple(value for btn, value in zip( self.buttons, self._selection_obj._options_values) if btn.value) # When nothing is selected, treat as if everything is selected. if len(proposed_value) == 0: proposed_value = tuple(value for btn, value in zip( self.buttons, self._selection_obj._options_values)) self.value = proposed_value
def __init__(self, *, bundle: Bundle, default_token_filter: str = None, **kwargs): global CURRENT_BUNDLE CURRENT_BUNDLE = bundle """Alternative implementation that uses VectorizedCorpus""" self.bundle: Bundle = bundle self.co_occurrences: pd.DataFrame = None self.pivot_column_name: str = 'time_period' if not isinstance(bundle.token2id, Token2Id): raise ValueError( f"Expected Token2Id, found {type(bundle.token2id)}") if not isinstance(bundle.compute_options, dict): raise ValueError( "Expected Compute Options in bundle but found no such thing.") """Current processed corpus""" self.corpus: VectorizedCorpus = bundle.corpus """Properties that changes current corpus""" self._pivot: Dropdown = Dropdown( options=["year", "lustrum", "decade"], value="decade", placeholder='Group by', layout=Layout(width='auto'), ) """"Keyness source""" self._keyness_source: Dropdown = Dropdown( options={ "Full corpus": KeynessMetricSource.Full, "Concept corpus": KeynessMetricSource.Concept, "Weighed corpus": KeynessMetricSource.Weighed, } if bundle.concept_corpus is not None else { "Full corpus": KeynessMetricSource.Full, }, value=KeynessMetricSource.Weighed if bundle.concept_corpus is not None else KeynessMetricSource.Full, layout=Layout(width='auto'), ) """Properties that changes current corpus""" self._keyness: Dropdown = Dropdown( options={ "TF": KeynessMetric.TF, "TF (norm)": KeynessMetric.TF_normalized, "TF-IDF": KeynessMetric.TF_IDF, "HAL CWR": KeynessMetric.HAL_cwr, "PPMI": KeynessMetric.PPMI, "LLR": KeynessMetric.LLR, "LLR(Z)": KeynessMetric.LLR_Z, "LLR(N)": KeynessMetric.LLR_N, "DICE": KeynessMetric.DICE, }, value=KeynessMetric.TF, layout=Layout(width='auto'), ) """Properties that don't change current corpus""" self._token_filter: Text = Text(value=default_token_filter, placeholder='token match', layout=Layout(width='auto')) self._global_threshold_filter: Dropdown = Dropdown( options={ f'>= {i}': i for i in (1, 2, 3, 4, 5, 10, 25, 50, 100, 250, 500) }, value=5, layout=Layout(width='auto'), ) self.concepts: Set[str] = set(self.bundle.context_opts.concept or []) self._largest: Dropdown = Dropdown( options=[10**i for i in range(0, 7)], value=10000, layout=Layout(width='auto'), ) self._show_concept = ToggleButton( description='Show concept', value=False, icon='', layout=Layout(width='auto'), ) self._message: HTML = HTML() self._compute: Button = Button(description="Compute", button_style='success', layout=Layout(width='auto')) self._save = Button(description='Save', layout=Layout(width='auto')) self._download = Button(description='Download', layout=Layout(width='auto')) self._download_output: Output = Output() self._table_view = TableViewerClass(data=empty_data()) self._button_bar = HBox( children=[ VBox([HTML("<b>Token match</b>"), self._token_filter]), VBox([HTML("<b>Source</b>"), self._keyness_source]), VBox([HTML("<b>Keyness</b>"), self._keyness]), VBox([HTML("🙂"), self._show_concept]), VBox([HTML("<b>Group by</b>"), self._pivot]), VBox([HTML("<b>Threshold</b>"), self._global_threshold_filter]), VBox([HTML("<b>Group limit</b>"), self._largest]), VBox([self._save, self._download]), VBox([self._compute, self._message]), self._download_output, ], layout=Layout(width='auto'), ) super().__init__( children=[self._button_bar, self._table_view.container], layout=Layout(width='auto'), **kwargs) self._save.on_click(self.save) self._download.on_click(self.download) self.start_observe()
def create_param_widget(self, param, value): from ipywidgets import Layout, HBox children = (HBox(),) if isinstance(value, bool): from ipywidgets import Label, ToggleButton p = Label(value=param, layout=Layout(width='10%')) t = ToggleButton(description=str(value), value=value) def on_bool_change(change): t.description = str(change['new']) self.params[self._method][param] = change['new'] self.replot_peaks() t.observe(on_bool_change, names='value') children = (p, t) elif isinstance(value, float): from ipywidgets import FloatSlider, FloatText, BoundedFloatText, \ Label from traitlets import link p = Label(value=param, layout=Layout(flex='0 1 auto', width='10%')) b = BoundedFloatText(value=0, min=1e-10, layout=Layout(flex='0 1 auto', width='10%'), font_weight='bold') a = FloatText(value=2 * value, layout=Layout(flex='0 1 auto', width='10%')) f = FloatSlider(value=value, min=b.value, max=a.value, step=np.abs(a.value - b.value) * 0.01, layout=Layout(flex='1 1 auto', width='60%')) l = FloatText(value=f.value, layout=Layout(flex='0 1 auto', width='10%'), disabled=True) link((f, 'value'), (l, 'value')) def on_min_change(change): if f.max > change['new']: f.min = change['new'] f.step = np.abs(f.max - f.min) * 0.01 def on_max_change(change): if f.min < change['new']: f.max = change['new'] f.step = np.abs(f.max - f.min) * 0.01 def on_param_change(change): self.params[self._method][param] = change['new'] self.replot_peaks() b.observe(on_min_change, names='value') f.observe(on_param_change, names='value') a.observe(on_max_change, names='value') children = (p, l, b, f, a) elif isinstance(value, int): from ipywidgets import IntSlider, IntText, BoundedIntText, \ Label from traitlets import link p = Label(value=param, layout=Layout(flex='0 1 auto', width='10%')) b = BoundedIntText(value=0, min=1e-10, layout=Layout(flex='0 1 auto', width='10%'), font_weight='bold') a = IntText(value=2 * value, layout=Layout(flex='0 1 auto', width='10%')) f = IntSlider(value=value, min=b.value, max=a.value, step=1, layout=Layout(flex='1 1 auto', width='60%')) l = IntText(value=f.value, layout=Layout(flex='0 1 auto', width='10%'), disabled=True) link((f, 'value'), (l, 'value')) def on_min_change(change): if f.max > change['new']: f.min = change['new'] f.step = 1 def on_max_change(change): if f.min < change['new']: f.max = change['new'] f.step = 1 def on_param_change(change): self.params[self._method][param] = change['new'] self.replot_peaks() b.observe(on_min_change, names='value') f.observe(on_param_change, names='value') a.observe(on_max_change, names='value') children = (p, l, b, f, a) container = HBox(children) return container
def interact_gravity_Dike(): s1 = FloatSlider( description=r"$\Delta\rho$", min=-5.0, max=5.0, step=0.1, value=1.0, continuous_update=False, ) s2 = FloatSlider( description=r"$z_1$", min=0.1, max=4.0, step=0.1, value=1 / 3, continuous_update=False, ) s3 = FloatSlider( description=r"$z_2$", min=0.1, max=5.0, step=0.1, value=4 / 3, continuous_update=False, ) s4 = FloatSlider(description="b", min=0.1, max=5.0, step=0.1, value=1.0, continuous_update=False) s5 = FloatSlider( description=r"$\beta$", min=-85, max=85, step=5, value=45, continuous_update=False, ) s6 = FloatSlider( description="Step", min=0.005, max=0.10, step=0.005, value=0.01, continuous_update=False, readout_format=".3f", ) b1 = ToggleButton( value=True, description="keep previous plots", disabled=False, button_style="", # 'success', 'info', 'warning', 'danger' or '' tooltip="Click me", layout=Layout(width="20%"), ) v1 = VBox([s1, s2, s3]) v2 = VBox([s4, s5, s6]) out1 = HBox([v1, v2, b1]) out = interactive_output( drawfunction, { "delta_rho": s1, "z1": s2, "z2": s3, "b": s4, "beta": s5, "stationSpacing": s6, "B": b1, }, ) return VBox([out1, out])
def __init__(self, name="graph", delayed=False, **kwargs): self._display_stack = 1 self._display_categories = set() self._filter_in = None self._filter_out = None self._svg_name = "" self._initial = kwargs self.delayed = delayed self.graph_name = name self.toggle_widgets = OrderedDict() self.color_widgets = OrderedDict() self.font_color_widgets = OrderedDict() self.filter_in_widget = Text(description="Filter In", value=kwargs.get("filter_in", "")) self.filter_out_widget = Text(description="Filter Out", value=kwargs.get("filter_out", "")) self.r_widget = self.slider("R", "r", 5, 70, 1, 21, fn=self.update_r_widget) self.margin_widget = self.slider("Margin", "margin", 5, 170, 1, 59) self.margin_left_widget = self.slider("M. Left", "margin_left", 5, 170, 1, 21) self.dist_x_widget = self.slider("Dist. X", "dist_x", 5, 170, 1, 76) self.dist_y_widget = self.slider("Dist. Y", "dist_y", 5, 170, 1, 76) self.letters_widget = self.slider("Letters", "letters", 1, 40, 1, 7) self.by_year_widget = self.slider("By Year", "max_by_year", 0, 50, 1, 5) self.places_widget = ToggleButton(description="Places", value=kwargs.get("places", False)) self.references_widget = ToggleButton(description="References", value=kwargs.get( "references", True)) self.delayed_widget = Button(description="Draw") self.output_widget = Output() self.filter_in_widget.observe(self.update_widget, "value") self.filter_out_widget.observe(self.update_widget, "value") self.places_widget.observe(self.update_widget, "value") self.references_widget.observe(self.update_widget, "value") self.delayed_widget.on_click(self.delayed_draw) self.create_widgets() self.update_r_widget() super(Graph, self).__init__([ HBox([ VBox([self.filter_in_widget, self.filter_out_widget] + list(self.toggle_widgets.values()) + [ HBox([w1, w2]) for w1, w2 in zip(self.color_widgets.values(), self.font_color_widgets.values()) ] + [self.places_widget, self.references_widget] + ([self.delayed_widget] if delayed else [])), VBox([ self.r_widget, self.margin_widget, self.margin_left_widget, self.dist_x_widget, self.dist_y_widget, self.letters_widget, self.by_year_widget, ]), ]), self.output_widget ]) self.layout.display = "flex" self.layout.align_items = "stretch" self.delayed_draw()
def __init__(self, position: str = "bottomleft", attr_name: str = "style", kind: str = "stroke", orientation: str = "horizontal", transparent: bool = False, a_map: Map = None, layer: Layer = None, place_control: bool = True): """Add a widget to the map that allows styling some given layer. At the moment only the stroke color, opacity and weight can be changed using a color picker and sliders. Dash array might follow later. :param m: The map object to which to add a styling widget. :param layer: The layer object which is to be styled. :param attr_name: The layer's attribute name storing the style object. This is usually one of: "style", "hover_style", and "point_style" :param kind: The kind of style, either "stroke" or "fill". :param orientation: The orientation of the UI elements, either "horizontal" (default) or "vertical". :param transparent: A flag to indicate if the widget background should be transparent (default: ``False``). :param position: The map corner where this widget will be placed. TODO: The UI elements should reflect changes to the layer triggered by others. """ assert kind in ["stroke", "fill"] assert orientation in ["horizontal", "vertical"] def restyle(change): if change["type"] != "change": return owner = change["owner"] style_copy = copy.copy(getattr(layer, attr_name)) attr_map = { p: "color" if kind == "stroke" else "fillColor", o: "opacity" if kind == "stroke" else "fillOpacity", w: "weight" } if owner in [p, o, w]: style_copy[attr_map[owner]] = owner.value setattr(layer, attr_name, style_copy) def close(button): a_map.remove_control(wc) attr = getattr(layer, attr_name) style = getattr(layer, "style") b = ToggleButton(description="Stroke", value=True, tooltip="Stroke or not?") dummy = ToggleButton(value=not b.value) b.layout.width = "80px" name = "color" if kind == "stroke" else "fillColor" p = ColorPicker(value=attr.get(name, style.get(name, "#3885ff"))) p.layout.width = "100px" name = "opacity" if kind == "stroke" else "fillOpacity" o = FloatSlider(min=0, max=1, value=attr.get(name, style.get(name, 0.5))) o.layout.width = "200px" w = IntSlider(min=0, max=50, value=attr.get("weight", style.get("weight", 5))) w.layout.width = "200px" layout = Layout(width="28px", height="28px", padding="0px 0px 0px 4px") q = Button(tooltip="Close", icon="close", button_style="info", layout=layout) for el in [p, o, w] if kind == "stroke" else [p, o]: link((dummy, "value"), (el, "disabled")) p.observe(restyle) o.observe(restyle) if kind == "stroke": w.observe(restyle) else: w.disabled = True q.on_click(close) desc = HTML(f"{kind} {attr_name}") if orientation == "horizontal": self.widget = HBox([desc, p, w, o, q]) elif orientation == "vertical": self.widget = VBox([HBox([desc, q]), p, w, o]) wc = WidgetControl(widget=self.widget, position=position, transparent_bg=transparent) a_map.add_control(wc)
def create_toggle_button(**kwargs): return ToggleButton(**kwargs, style=label_style)
def __init__(self, database_path='./'): VBox.__init__(self, layout=Layout(width="100%", min_height="800px")) self.database_path = database_path dbs = Dropdown(description='DB', layout=Layout(width="auto")) dbs.observe(lambda event, this=self: this.loadFields(event), "value") self.current = "Database" layout = { "Database": { 'action': (lambda this=self: this.toDatabase()), 'click': (lambda event, this=self: this.clickPanel("Database")), 'children': { "list": dbs, "fields": VBox(layout=Layout(width="100%", border="1px solid #6666")) }, }, "Filters": { 'action': (lambda this=self: this.toFilters()), 'click': (lambda event, this=self: this.clickPanel("Filters")), 'children': { "grid": VBox() }, }, "Exploration": { 'action': (lambda this=self: this.toExploration()), 'click': (lambda event, this=self: this.clickPanel("Exploration")), 'children': { "grid": HBox() }, }, "Visualization": { 'action': (lambda this=self: this.toVisualization()), 'click': (lambda event, this=self: this.clickPanel("Visualization")), 'children': { "main_view": Output(), "secondary_view": Output() }, }, } self.ui = self.createDefaultLayout(layout) content = [] for i, k in enumerate(self.ui.keys()): if 'container' in self.ui[k]: content.append(self.ui[k]["container"]) tabs = [] for i, k in enumerate(self.ui.keys()): if 'container' in self.ui[k]: self.ui[k]["tab"] = ToggleButton(value=False, description=k, layout=Layout(width="auto"), disabled=True) self.ui[k]["tab"].observe( lambda a, b=k, c=self: self.eventPanel(a, b), "value") tabs.append(self.ui[k]["tab"]) self.children = [ HBox(tabs, layout=Layout(width="auto")), VBox(content, layout=Layout(width="auto")) ] self.clickPanel(self.current)
value=0, description='center_x', **kws) dw['center_y'] = FloatText(min=-300, max=300, value=0, description='center_y', **kws) dw['rotation'] = FloatText(min=-90, max=90, value=0, description='rotation', **kws) dw['focal'] = FloatText(min=5, max=100, value=32, description='focal', **kws) dw['steer_only'] = ToggleButton(False, description='steer_only', **kws) dw['dark_all'] = ToggleButton(False, description='dark_all', **kws) dw['grid'] = ToggleButton(False, description='grid', **kws) dw['test_pattern'] = ToggleButton(False, description='test_pattern', **kws) dw['steer_horiz'] = ToggleButton(True, description='steer_horiz', **kws) dw['steer_lw'] = IntText(min=1, max=25, value=1, description='steer_lw', **kws) dw['steer_pad'] = IntText(min=1, max=50, value=1, description='steer_pad', **kws) dw['steer_vmax'] = IntText(min=0, max=255, description='steer_vmax', **kws) dw['stretch'] = ToggleButton(False, description='stretch', **kws) dw['ref_spot'] = IntText(min=0,
def setup_widgets(self, image_folder='data/images'): image_folder = self.base_path + '/' + image_folder self.image_list = os.listdir(image_folder) # Data Filter Setup reset_plot = Button( description='Reset', disabled=False, tooltip='Reset the colors of the plot' ) xy_check = Button( description='Show X-Y axes', disabled=False, button_style='', tooltip='Click to show X-Y axes' ) show_success_hull = ToggleButton( value=True, description='Show sucess hull', disabled=False, button_style='', tooltip='Toggle to show/hide success hull', icon='check' ) unique_inchis = self.full_perovskite_data['_rxn_organic-inchikey'].unique( ) self.select_amine = Dropdown( options=[row['Chemical Name'] for i, row in self.inchis.iterrows() if row['InChI Key (ID)'] in unique_inchis], description='Amine:', disabled=False, ) reset_plot.on_click(self.reset_plot_callback) xy_check.on_click(self.set_xy_camera) show_success_hull.observe(self.toggle_success_mesh, 'value') self.select_amine.observe(self.select_amine_callback, 'value') # Experiment data tab setup self.experiment_table = HTML() self.experiment_table.value = "Please click on a point" "to explore experiment details" self.image_data = {} for img_filename in os.listdir(image_folder): with open("{}/{}".format(image_folder, img_filename), "rb") as f: b = f.read() self.image_data[img_filename] = b self.image_widget = Image( value=self.image_data['not_found.png'], layout=Layout(height='400px', width='650px') ) experiment_view_vbox = VBox( [HBox([self.experiment_table, self.image_widget])]) plot_tabs = Tab([VBox([self.fig, HBox([self.select_amine]), HBox([xy_check, show_success_hull, reset_plot])]), ]) plot_tabs.set_title(0, 'Chemical Space') self.full_widget = VBox([plot_tabs, experiment_view_vbox]) self.full_widget.layout.align_items = 'center'
def MT1D_app(): app = widgetify( PlotAppRes3Layers_wrapper, fmin=FloatText(min=1e-5, max=1e5, value=1e-5, continuous_update=False), fmax=FloatText(min=1e-5, max=1e5, value=1e5, continuous_update=False), nbdata=IntSlider(min=10, max=100, value=100, step=10, continuous_update=False), h1=FloatSlider(min=0.0, max=10000.0, step=50.0, value=500.0, continuous_update=False), h2=FloatSlider(min=0.0, max=10000.0, step=50.0, value=1000.0, continuous_update=False), rhol1=FloatText( min=1e-8, max=1e8, value=100.0, continuous_update=False, description="$\\rho_1$", ), rhol2=FloatText( min=1e-8, max=1e8, value=1000.0, continuous_update=False, description="$\\rho_2$", ), rhol3=FloatText( min=1e-8, max=1e8, value=10.0, continuous_update=False, description="$\\rho_3$", ), mul1=FloatSlider( min=1.0, max=1.2, step=0.01, value=1.0, continuous_update=False, description="$\\mu_1$", ), mul2=FloatSlider( min=1.0, max=1.2, step=0.01, value=1.0, continuous_update=False, description="$\\mu_2$", ), mul3=FloatSlider( min=1.0, max=1.2, step=0.01, value=1.0, continuous_update=False, description="$\\mu_3$", ), epsl1=FloatSlider( min=1.0, max=80.0, step=1.0, value=1.0, continuous_update=False, description="$\\varepsilon_1$", ), epsl2=FloatSlider( min=1.0, max=80.0, step=1, value=1.0, continuous_update=False, description="$\\varepsilon_2$", ), epsl3=FloatSlider( min=1.0, max=80.0, step=1.0, value=1.0, continuous_update=False, description="$\\varepsilon_3$", ), PlotEnvelope=ToggleButton(options=True, description="Plot Envelope fields"), F_Envelope=FloatText(min=1e-5, max=1e5, value=1e4, continuous_update=False, description="F"), ) return app
def __init__(self, **kwargs): super(TaskManager, self).__init__(**kwargs) # Header self.checkbox = Checkbox(indent=False, layout=Layout(flex='1 1 20', width='auto')) self.cancel_selected = Button(description='Cancel Selected', tooltip='Cancel all selected tasks') self.cancel_all = Button(description='Cancell All', tooltip='Cancel all tasks') self.refresh = Button(description='Refresh', tooltip='Refresh Tasks List') self.autorefresh = ToggleButton( description='auto-refresh', tooltip='click to enable/disable autorefresh') self.slider = IntSlider(min=1, max=10, step=1, value=5) self.hbox = HBox([ self.checkbox, self.refresh, self.cancel_selected, self.cancel_all, self.autorefresh, self.slider ]) # Tabs for COMPLETED, FAILED, etc self.tabs = Tab() # Tabs index self.tab_index = { 0: 'RUNNING', 1: 'COMPLETED', 2: 'FAILED', 3: 'CANCELED', 4: 'UNKNOWN' } self.taskVBox = VBox() self.runningVBox = VBox() self.completedVBox = VBox() self.failedVBox = VBox() self.canceledVBox = VBox() self.unknownVBox = VBox() self.tab_widgets_rel = { 'RUNNING': self.runningVBox, 'COMPLETED': self.completedVBox, 'FAILED': self.failedVBox, 'CANCELED': self.canceledVBox, 'UNKNOWN': self.unknownVBox } # Create Tabs self.tab_widgets = [] for key, val in self.tab_index.items(): widget = self.tab_widgets_rel[val] self.tab_widgets.append(widget) self.tabs.children = self.tab_widgets self.tabs.set_title(key, val) ''' autorefresh def update_task_list(widget): # widget is a VBox tasklist = ee.data.getTaskList() widlist = [] for task in tasklist: accordion = create_accordion(task) if task.has_key('description'): name = '{} ({})'.format(task['description'], task['state']) else: name = '{} ({})'.format(task['output_url'][0].split('/')[-1], task['state']) mainacc = Accordion(children=(accordion, )) mainacc.set_title(0, name) mainacc.selected_index = None wid = CheckRow(mainacc) #wid = CheckRow(accordion) widlist.append(wid) widget.children = tuple(widlist) ''' def loop(widget): while True: self.update_task_list()(self.refresh) time.sleep(self.slider.value) # First widget self.update_task_list(vbox=self.runningVBox)(self.refresh) # self.children = (self.hbox, self.taskVBox) self.children = (self.hbox, self.tabs) # Set on_click for refresh button self.refresh.on_click(self.update_task_list(vbox=self.selected_tab())) ''' autorefresh thread = threading.Thread(target=loop, args=(self.taskVBox,)) thread.start() ''' # Set on_clicks self.cancel_all.on_click(self.cancel_all_click) self.cancel_selected.on_click(self.cancel_selected_click)
x for x in json.loads(self.output_widget.value) if x != "Incomplete" ] def browser(self): """ Presents the widget """ return self.view def _ipython_display_(self): """ Displays widget """ display(self.view) WIDGET_CLS = { "text": lambda x: Text(value=x[3] or "", description=x[1]), "toggle": lambda x: ToggleButton(value=x[3] or False, description=x[1]), "dropdown": lambda x: Dropdown(options=x[4], value=x[3] or "", description=x[1]), "button": lambda x: Button(description=x[1]), } class EventRunner: def __init__(self, navigator, info=None): self.widgets = navigator.widgets self.widgets_empty = navigator.widgets_empty self.navigator = navigator self.info = info self.operations = { "if": self.op_if, "and": self.op_and,
def __init__(self, volume=None, default_directory=os.getcwd(), title='', enhancement_steps=1000, **kwargs): def on_chosen_path_change(old_path, new_path): self.dataset = FolderDataset(new_path) # TODO: If the path doesn't contain images, display a warning # A widget for changing the image folder self.pathchooser = PathChooser( chosen_path_desc='Image folder:', default_directory=default_directory, on_chosen_path_change=on_chosen_path_change, ) self.pathchooser.layout.margin = '0 0 10px 0' # The number of increments of the min/max slider self.enhancement_steps = enhancement_steps self.scales = { 'x': LinearScale(), 'y': LinearScale(), } # The currently displayed image will be in bytes at `self.image_plot.image.value` self.image_plot = BQImage( image=IPyImage(), scales=self.scales, ) self.figure = Figure( marks=[self.image_plot], padding_x=0, padding_y=0, animation_duration=1000, fig_margin={ 'top': 0, 'right': 0, 'bottom': 0, 'left': 0, }, layout=Layout( grid_area='figure', margin='0', width='320px', height='320px', ), ) # Custom toolbar toolbar_width = '100%' toolbar_margin = '0px 0 2px 0' self.pan_zoom = PanZoom(scales={ 'x': [self.scales['x']], 'y': [self.scales['y']], }, ) self.save_button = Button( description='Save Image', tooltip='Save Image', icon='save', layout=Layout( width=toolbar_width, # flex='1 1 auto', margin=toolbar_margin, ), ) self.save_button.on_click(self.save_current_image) self.hide_button = Button( description='Hide Image', tooltip='Hide Image', icon='eye-slash', layout=Layout( width=toolbar_width, # flex='1 1 auto', margin=toolbar_margin, )) self.hide_button.on_click(self.hide_current_image) self.pan_zoom_toggle_button = ToggleButton( description='Pan / Zoom', tooltip='Pan/Zoom', icon='arrows', layout=Layout( width=toolbar_width, # flex='1 1 auto', margin=toolbar_margin, ), ) self.pan_zoom_toggle_button.observe(self.on_pan_zoom_toggle, names='value') self.reset_pan_zoom_button = Button( description='Undo Zoom', tooltip='Reset pan/zoom', icon='refresh', layout=Layout( width=toolbar_width, # flex='1 1 auto', margin=toolbar_margin, ), ) self.reset_pan_zoom_button.on_click(self.reset_pan_zoom) self.reset_enhancements_button = Button( description='Un-Enhance', tooltip='Reset enhancements', icon='ban', layout=Layout( width=toolbar_width, # flex='1 1 auto', margin=toolbar_margin, ), ) self.reset_enhancements_button.on_click(self.reset_enhancements) self.mini_map = IPyImage(layout=Layout( grid_area='mini-map', margin='0', )) self.mini_map.width = 180 self.mini_map.height = 180 # PERFORMANCE CONCERN # Ideally instead of four observations, this would observe 'scales' on `self.pan_zoom` # However, it doesn't fire updates # Ref: https://github.com/bloomberg/bqplot/issues/800 self.image_plot.scales['x'].observe(self.on_pan_zoom_change('x_min'), names='min') self.image_plot.scales['x'].observe(self.on_pan_zoom_change('x_max'), names='max') self.image_plot.scales['y'].observe(self.on_pan_zoom_change('y_min'), names='min') self.image_plot.scales['y'].observe(self.on_pan_zoom_change('y_max'), names='max') self.plane_toggle = ToggleButtons( options=['yz', 'xz', 'xy'], description='', disabled=False, button_style='', tooltips=[ 'Step in x direction', 'Step in y direction', 'Step in z direction' ], layout=Layout( width='200px', # flex='1 1 auto', margin='7px 0 auto auto', ), ) self.plane_toggle.style.button_width = 'auto' self.plane_toggle.observe(self.on_plane_change, names='value') self.toolbar = VBox( children=[ self.save_button, self.hide_button, self.pan_zoom_toggle_button, self.reset_pan_zoom_button, self.reset_enhancements_button, ], layout=Layout( grid_area='toolbar', margin='0', ), ) # Image enhancements self.min_max_slider = FloatRangeSlider( value=[0, 255], min=0, max=255, step=255 / self.enhancement_steps, description='Min/Max:', orientation='horizontal', readout=True, readout_format='.1f', continuous_update=True, layout=Layout( grid_area='min-max-slider', margin='10px 0 10px -10px', width='100%', ), ) self.min_max_slider.observe(self.on_min_max_change, names='value') self.index_slider = IntSlider( value=0, min=0, max=1, step=1, description='Index:', orientation='horizontal', readout=True, readout_format='d', continuous_update=True, layout=Layout( grid_area='index-slider', margin='8px -20px 10px -36px', width='100%', ), ) self.index_slider.observe(self.on_image_index_change, names='value') # Animation self.play = Play( value=self.index_slider.value, min=self.index_slider.min, max=self.index_slider.max, step=self.index_slider.step, ) jslink((self.play, 'value'), (self.index_slider, 'value')) # Keep 'max' in sync as well self.index_slider.observe(self.on_index_slider_max_change, names='max') self.bottom_bar = HBox( children=[ self.play, self.index_slider, self.plane_toggle, ], layout=Layout( grid_area='bottom-bar', margin=f'10px -20px 0 0', # overflow='hidden', )) # Layout self.gridbox = GridBox(children=[ self.figure, self.toolbar, self.mini_map, self.min_max_slider, self.bottom_bar, ], ) # Initially hidden without data self.gridbox.layout.display = 'none' self._dataset = None if volume is not None: self.dataset = VolumeDataset(volume) # Hide pathchooser when using a volume self.pathchooser.layout.display = 'none' # Call VBox super class __init__ super().__init__( children=[ self.pathchooser, self.gridbox, ], layout=Layout(width='auto'), **kwargs, )
def __init__(self): # Stores the respective line number and variable changes for each # exection step self._tracer = TimeTravelTracer() self._current_state = None self._debugger = None self._code_output = HTML() self._var_output = Output() self._watchpoint_output = Output() self._breakpoint_output = Output() self._diff_slider = IntSlider( min=1, readout=False, layout=Layout(width="99%"), tooltip="Execution timeline", ) self._diff_slider.observe(self._handle_diff_slider, names="value") self._autoplay = Play( tooltip="Automatic playback of the execution", layout=Layout(height="30px"), ) self._auto_link = jsdlink((self._autoplay, "value"), (self._diff_slider, "value")) self._speed_slider = IntSlider(description="Delay (ms)", min=100, max=1000, step=100, value=500) self._speed_link = jsdlink((self._speed_slider, "value"), (self._autoplay, "interval")) self._reverse_autoplay = ToggleButton( value=False, icon="history", tooltip="Reverse autoplay", layout=Layout(width="40px"), ) self._reverse_autoplay.observe(self._handle_reverse_button) self._watchpoint_input = Text( layout=Layout(width="150px"), placeholder="Watch expression", ) self._add_watchpoint = Button( icon="plus", tooltip="Add an expression or variable to watch", layout=Layout(width="50px"), ) self._add_watchpoint.on_click(self.watch_command) self._watchpoint_dropdown = Dropdown(layout=Layout(width="150px"), ) self._remove_watchpoint = Button( icon="trash", tooltip="Remove a watchpoint", layout=Layout(width="50px"), ) self._remove_watchpoint.on_click(self.unwatch_command) self._breakpoint_layout = GridspecLayout(3, 1) self._add_breakpoint = Button( icon="plus", tooltip="Add a breakpoint", name="breakpoint_button", layout=Layout(width="40px"), ) self._add_breakpoint.on_click(self._handle_breakpoint) self._disable_breakpoint_button = Button( icon="eye-slash", tooltip="Disable breakpoint", layout=Layout(width="50px"), ) self._disable_breakpoint_button.on_click(self.disable_command) self._remove_breakpoint_button = Button( icon="trash", tooltip="Remove breakpoint", layout=Layout(width="50px"), ) self._remove_breakpoint_button.on_click(self.delete_command) self._breakpoint_dropdown = Dropdown(layout=Layout(width="70px")) self._function_dropdown = Dropdown(layout=Layout(width="200px")) self._function_dropdown.disabled = True self._breakpoint_type = Dropdown( options=["Line", "Function", "Conditional"], value="Line", layout=Layout(width="100px"), ) self._breakpoint_type.observe(self._handle_breakpoint_type, names="value") self._condition_input = Text(placeholder="Enter condition", layout=Layout(width="200px")) self._condition_input.disabled = True self._line_input = Text( placeholder="Line Number", name="line_input", layout=Layout(width="100px"), ) self._breakpoint_layout = VBox([ HBox([ self._add_breakpoint, self._breakpoint_type, self._function_dropdown, self._line_input, self._condition_input, self._breakpoint_dropdown, self._remove_breakpoint_button, self._disable_breakpoint_button, ]), self._breakpoint_output, ]) self._search_input = Text(placeholder="Search...") self._search_input.observe(self._handle_search_input, names="value") self._search_results = Output() self._search_layout = VBox([ self._search_input, self._search_results, ]) # Remove shadows from scrolling style = """ <style> .jupyter-widgets-output-area .output_scroll { border-radius: unset !important; -webkit-box-shadow: unset !important; box-shadow: unset !important; } </style> """ display(HTML(style)) for key, item in self._BUTTONS.items(): self.register_button(key, **item) self._code_layout = GridspecLayout(4, 4, grid_gap="20px") self._code_layout[0:4, 0:3] = HBox( [self._code_output], layout=Layout(height="500px", overflow_y="scroll", border="2px solid black"), ) self._code_layout[0:2, 3] = self._var_output self._code_layout[2:4, 3] = VBox([ HBox([self._add_watchpoint, self._watchpoint_input]), HBox([self._remove_watchpoint, self._watchpoint_dropdown]), self._watchpoint_output, ]) self._code_nav_layout = VBox([ HBox([ *self.get_buttons(), self._autoplay, self._reverse_autoplay, self._speed_slider, ]), self._diff_slider, self._code_layout, ]) self._main_layout = Tab( [ self._code_nav_layout, self._breakpoint_layout, self._search_layout, ], layout=Layout(height="650px"), ) self._main_layout.set_title(0, "Code") self._main_layout.set_title(1, "Breakpoints") self._main_layout.set_title(2, "Search") display(self._main_layout)
def annotate(examples, task_type='classification', options=None, shuffle=False, include_skip=True, include_back=False, use_dropdown=False, buttons_in_a_row=4, reset_buttons_after_click=False, example_process_fn=None, final_process_fn=None, display_fn=display): """ Build an interactive widget for annotating a list of input examples. Parameters ---------- examples : list(any), list of items to annotate task_type : possible options are: - classification - multilabel-classification - captioning options : depending on the task this can be: - list of options - tuple with a range for regression tasks shuffle : bool, shuffle the examples before annotating include_skip: bool, include option to skip example while annotating include_back: bool, include option to navigate to previous example use_dropdown: use a dropdown or buttons during classification buttons_in_a_row: number of buttons in a row during classification reset_buttons_after_click: reset multi-label buttons after each click example_process_fn: hooked function to call after each example fn(ix, labels) final_process_fn: hooked function to call after annotation is done fn(annotations) display_fn : func, function for displaying an example to the user Returns ------- annotations : list of tuples, list of annotated examples (example, label(s)) """ examples = list(examples) if shuffle: random.shuffle(examples) annotations = {} current_index = -1 def set_label_text(index): nonlocal count_label count_label.value = f'{len(annotations)} of {len(examples)} Examples annotated, Current Position: {index + 1} ' def render(index): set_label_text(index) if index >= len(examples): print('Annotation done.') if final_process_fn is not None: final_process_fn(list(annotations.items())) for btn in buttons: btn.disabled = True count_label.value = f'{len(annotations)} of {len(annotations)} Examples annotated, Current Position: {len(annotations)} ' return for btn in buttons: if btn.description == 'prev': btn.disabled = index <= 0 elif btn.description == 'skip': btn.disabled = index >= len(examples) - 1 elif examples[index] in annotations: if isinstance(annotations[examples[index]], list): btn.value = btn.description in annotations[examples[index]] else: btn.value = btn.description == annotations[examples[index]] def add_annotation(annotation): annotations[examples[current_index]] = annotation if example_process_fn is not None: example_process_fn(examples[current_index], annotation) next_example() def next_example(btn=None): nonlocal current_index if current_index < len(examples): current_index += 1 render(current_index) def prev_example(btn=None): nonlocal current_index if current_index > 0: current_index -= 1 render(current_index) count_label = HTML() set_label_text(current_index) display(count_label) buttons = [] if task_type == 'classification': if use_dropdown: dd = Dropdown(options=options) display(dd) btn = Button(description='submit') def on_click(btn): add_annotation(dd.value) btn.on_click(on_click) buttons.append(btn) else: for label in options: btn = Button(description=label) def on_click(label, btn): add_annotation(label) btn.on_click(functools.partial(on_click, label)) buttons.append(btn) elif task_type == 'multilabel-classification': for label in options: tgl = ToggleButton(description=label) buttons.append(tgl) btn = Button(description='submit', button_style='info') def on_click(btn): labels_on = [] for tgl in buttons: if (isinstance(tgl, ToggleButton)): if (tgl.value == True): labels_on.append(tgl.description) if (reset_buttons_after_click): tgl.value = False add_annotation(labels_on) btn.on_click(on_click) buttons.append(btn) elif task_type == 'regression': target_type = type(options[0]) if target_type == int: cls = IntSlider else: cls = FloatSlider if len(options) == 2: min_val, max_val = options slider = cls(min=min_val, max=max_val) else: min_val, max_val, step_val = options slider = cls(min=min_val, max=max_val, step=step_val) display(slider) btn = Button(description='submit', value='submit') def on_click(btn): add_annotation(slider.value) btn.on_click(on_click) buttons.append(btn) elif task_type == 'captioning': ta = Textarea() display(ta) btn = Button(description='submit') def on_click(btn): add_annotation(ta.value) btn.on_click(on_click) buttons.append(btn) else: raise ValueError('invalid task type') if include_back: btn = Button(description='prev', button_style='info') btn.on_click(prev_example) buttons.append(btn) if include_skip: btn = Button(description='skip', button_style='info') btn.on_click(next_example) buttons.append(btn) if len(buttons) > buttons_in_a_row: box = VBox([ HBox(buttons[x:x + buttons_in_a_row]) for x in range(0, len(buttons), buttons_in_a_row) ]) else: box = HBox(buttons) display(box) out = Output() display(out) next_example() return annotations
def __init__( self, default_corpus_path: str = None, default_corpus_filename: str = '', default_data_folder: str = None ): self.default_corpus_path: str = default_corpus_path self.default_corpus_filename: str = os.path.basename(default_corpus_filename or '') self.default_data_folder: str = default_data_folder self._config: CorpusConfig = None self._corpus_filename: notebook_utility.FileChooserExt2 = None self._target_folder: notebook_utility.FileChooserExt2 = None self._corpus_tag: Text = Text( value='', placeholder='Tag to prepend output files', description='', disabled=False, layout=default_layout, ) self._pos_includes: SelectMultiple = SelectMultiple( options=[], value=[], rows=8, description='', disabled=False, layout=Layout(width='160px'), ) self._pos_paddings: SelectMultiple = SelectMultiple( options=[], value=[], rows=8, description='', disabled=False, layout=Layout(width='160px'), ) self._pos_excludes: SelectMultiple = SelectMultiple( options=[], value=[], rows=8, description='', disabled=False, layout=Layout(width='160px'), ) self._filename_fields: Text = Text( value="", placeholder='Fields to extract from filename (regex)', description='', disabled=True, layout=default_layout, ) self._create_subfolder: ToggleButton = ToggleButton( value=True, description='Create folder', icon='check', layout=button_layout ) self._ignore_checkpoints: ToggleButton = ToggleButton( value=False, description='Force', icon='', layout=button_layout ) self._lemmatize: ToggleButton = ToggleButton( value=True, description='Lemmatize', icon='check', layout=button_layout ) self._to_lowercase: ToggleButton = ToggleButton( value=True, description='To lower', icon='check', layout=button_layout ) self._remove_stopwords: ToggleButton = ToggleButton( value=False, description='No stopwords', icon='', layout=button_layout ) self._only_alphabetic: ToggleButton = ToggleButton( value=False, description='Only alpha', icon='', layout=button_layout ) self._only_any_alphanumeric: ToggleButton = ToggleButton( value=False, description='Only alphanum', icon='', layout=button_layout ) self._extra_stopwords: Textarea = Textarea( value='', placeholder='Enter extra stop words', description='', disabled=False, rows=8, layout=Layout(width='140px'), ) self._tf_threshold: IntSlider = IntSlider( description='', min=1, max=1000, step=1, value=10, layout=default_layout ) self._tf_threshold_mask: ToggleButton = ToggleButton( value=False, description='Mask low-TF', icon='', layout=button_layout ) self._use_pos_groupings: ToggleButton = ToggleButton( value=True, description='PoS groups', icon='check', layout=button_layout ) self._append_pos_tag: ToggleButton = ToggleButton( value=False, description='Append PoS', icon='', layout=button_layout ) self._phrases = Text( value='', placeholder='Enter phrases, use semicolon (;) as phrase delimiter', description='', disabled=False, layout=Layout(width='480px'), ) self._compute_button: Button = Button( description='Compute!', button_style='Success', layout=button_layout, ) self._cli_button: Button = Button(description='CLI', button_style='Success', layout=button_layout) self.extra_placeholder: HBox = HBox() self.buttons_placeholder: VBox = VBox() self._corpus_type: Dropdown = Dropdown( description='', options={ 'Text': CorpusType.Text, 'Pipeline': CorpusType.Pipeline, 'Sparv4-CSV': CorpusType.SparvCSV, }, value=CorpusType.Pipeline, layout=default_layout, ) self.compute_callback: Callable[[interface.ComputeOpts, CorpusConfig], Any] = None self.done_callback: Callable[[Any, interface.ComputeOpts], None] = None