def __init__(self, value, **kwargs): self.value = value self.__text = Text(value, description='value') self.__text.continuous_update = False self.__text.observe(self.__on_text_changed, names='value') kwargs['children'] = [self.__text] super().__init__(**kwargs)
def __init__(self, lp, filename='', **kwargs): self.__lp = lp self.filename = filename self.__accordion = Accordion() self.__auto_apply_cbx = Checkbox(description='Auto apply') self.__auto_save_cbx = Checkbox(description='Auto save') self.__apply_btn = Button(description='Apply changes') self.__save_btn = Button(description='Save changes') self.__add_category_btn = Button(description='Add category') self.__add_category_txt = Text(placeholder='category name') self.__initialize() super().__init__([ VBox([ HBox([ HBox((self.__apply_btn, self.__auto_apply_cbx)), HBox((self.__save_btn, self.__auto_save_cbx)), HBox((self.__add_category_btn, self.__add_category_txt)) ], layout=Layout(flex_flow='row wrap', margin='5px')), self.__accordion ], layout=Layout(margin='5px')) ], **kwargs)
def __init__(self): plt.close("all") self.backend = TextInputLoop(use_widget=True) self.highlighter = SentimentHighlighter(self.backend) self.backend.add_interface(self.highlighter) self.backend.start() self.cwd_label = Label( value="Working directory: {}".format(Path.cwd()), layout=dict(margin="2px 0px 0px 20px"), ) self.save_path = Text( value=str(Path("saved_html.html")), description='Save path:', disabled=False, layout=dict(width="50%"), ) self.save_button = Button( value=False, description='Save to HTML', disabled=False, button_style= 'success', # 'success', 'info', 'warning', 'danger' or '' tooltip='', icon='', layout=Layout(width='18%', margin="2px 0px 0px 20px"), ) self.progress_label = Label( value="", layout=dict(margin="2px 0px 0px 20px"), ) self.full_contrast = Checkbox(value=False, description='Full Contrast', disabled=False) self.do_highlighting = Checkbox(value=True, description='Do Highlighting', disabled=False) box1 = HBox( (self.do_highlighting, self.full_contrast), layout=Layout(align_content="flex-start"), ) box2 = HBox( (self.save_path, self.save_button), layout=Layout(align_content="flex-start"), ) self.storage_dashboard = VBox( (box1, self.cwd_label, box2, self.progress_label)) # Set observers self.save_button.on_click(self._save) self.full_contrast.observe(self._special_options) self.do_highlighting.observe(self._special_options) # noinspection PyTypeChecker display(self.storage_dashboard)
def packageWidgets(self): ''' 打包组件 :return: ''' debug.out('package request widgets') self.paramWidgets = {} self.txtBody = None for param, ptype in self.interface['params'].items(): value = self.cf.readConf(self.default['interface'], param) if ptype == 'int': pw = IntText(description = param + ':', value = value if value is not None else 0, layout = Layout(width = '90%')) elif ptype == 'date': pw = DatePicker(description = param + ':', value = value if value is not None else '', layout = Layout(width = '90%')) elif ptype == 'companyId': pw = Text(description = param + ':', value = value if value is not None else self.env.tester['companyId'], layout = Layout(width = '90%')) elif ptype == 'openId': pw = Text(description = param + ':', value = value if value is not None else self.env.tester['openId'], layout = Layout(width = '90%')) else: pw = Text(description = param + ':', value = value if value is not None else '', layout = Layout(width = '90%')) pw.observe(self.on_param_change) self.paramWidgets[param] = pw self.txtBody = Textarea(description = 'body data:', value = '') self.txtBody.layout = Layout(display = 'none') debug.out(self.interface.get('body', False)) if self.interface.get('body', False) != False: debug.out('interface have body data to package widget') value = self.cf.readConf(self.default['interface'], 'body') self.txtBody.value = value if value is not None else '' self.txtBody.layout = Layout(width = '90%', height = '200px') tmpWds = [wd for wd in self.paramWidgets.values()] tmpWds.append(self.txtBody) self.boxParams.children = tmpWds
def __init__(self, name, validator=None, no_name=False, **kwargs): self.name = name self.__validator = validator if validator is not None else lambda x: True self.__text = Text(name, description='name') self.__text.continuous_update = False self.__text.observe(self.__on_name_changed, names='value') if no_name: kwargs['children'] = kwargs['children'] else: kwargs['children'] = (self.__text, *kwargs['children']) kwargs['layout'] = Layout(margin='10px 10px') super().__init__(**kwargs)
def __init__(self): self.start_button = Button( value=False, description='Start Camera', disabled=False, button_style= 'success', # 'success', 'info', 'warning', 'danger' or '' tooltip='Start the camera and the recognition algorithm.', icon='') self.select_network = Dropdown( options=KerasDetector.available_models, value=KerasDetector.available_models[0], description='Algorithm:', disabled=False, ) self.label_names = Text( value='', placeholder='separated by commas', description='Labels', disabled=False, ) self.num_pictures = IntText(value=2.0, description='#pictures', disabled=False, layout=Layout(width='18%')) self.text = Label(value='', layout=Layout(justify_content='space-around', )) self.widget_box = VBox((HBox( (self.start_button, self.label_names, self.num_pictures, self.select_network), layout=Layout(justify_content="space-around")), self.text)) # Initialize field self.collector = None self.start_button.on_click(self._start_video)
disabled=False) use_my_own_location = Accordion( children=[VBox([check_own, input_lat, input_lon])]) #Upload shapefile: check_shapefile = Checkbox( value=False, description='Use shapefile from shapefile_input folder:', disabled=False, indent=False, style={'description_width': 'initial'}) shapefile_loc = Text( value='shapefile_inputs/', placeholder='Enter the name of the shapefile in the folder', description='Name of shapefile:', disabled=False, style={'description_width': 'initial'}) upload_shapefile = Accordion(children=[VBox([check_shapefile, shapefile_loc])]) # Select representative gauge: gauge_num = Text(value='409025', placeholder='Enter gauge number', description='', disabled=False) # What water threshold cloud_threshold = BoundedFloatText(value=5, min=0, max=100,
def __init__(self): self.start_button = Button( value=False, description='Start Camera', disabled=False, button_style= 'success', # 'success', 'info', 'warning', 'danger' or '' tooltip='Start the camera to take pictures for classifier ', icon='', layout=Layout(width='25%'), ) self.save_button = Button( value=False, description='Save images', disabled=True, button_style= 'danger', # 'success', 'info', 'warning', 'danger' or '' tooltip='Save images to folder ', icon='', layout=Layout(width='18%', margin="2px 0px 0px 20px"), ) self.load_button = Button( value=False, description='Load images', disabled=False, button_style= 'success', # 'success', 'info', 'warning', 'danger' or '' tooltip='Load images from folder ', icon='', layout=Layout(width='18%', margin="2px 0px 0px 20px"), ) self.save_path = Text( value=str(Path("path", "to", "directory")), description='Save path:', disabled=False, ) self.num_pictures = FloatText( value=12, description='#pictures:', disabled=False, layout=Layout(width='20%'), ) self.use_augmentation = Checkbox( value=False, description='Augmentation', disabled=False, tooltip='Use Augmentation', icon='check', ) self.progress_text = Label( value='', layout=Layout(margin="5px 0px 5px 20px"), ) self.widget_box = VBox(( HBox( (self.num_pictures, self.use_augmentation, self.start_button), layout=Layout(align_content="flex-start"), ), HBox( (self.progress_text, ), layout=Layout(align_content="flex-start"), ), HBox( (self.save_path, self.save_button, self.load_button), layout=Layout(align_content="flex-start"), ), )) self.start_button.on_click(self._start_video) self.save_button.on_click(self._save_images) self.load_button.on_click(self._load_images) self.collector = ImageCollector()
from ipywidgets.widgets import Dropdown, Text, Button, HBox, VBox from IPython.display import display, clear_output import pandas as pd from FileValidator.app import TheValidator def get_clicked(b): clear_output() #resets output every time you click the button csv_to_dataframe = pd.read_csv(FILE_PATH.value) validate_app = TheValidator(csv_to_dataframe, FUNCTION.value) output = validate_app.main() output.to_csv(FILE_PATH.value.replace('.csv', '_validated.csv'), sep=',') print('Validated! Please verify the output') FILE_PATH = Text(placeholder='Path to file') VALIDATE_BUTTON = Button(description="Validate!", button_style="primary") FUNCTION = Dropdown(description="Select a File Type", options=['FileType1']) VALIDATE_BUTTON.on_click(get_clicked) FILE_PATH.layout.width = '75%' display(FILE_PATH, FUNCTION) display(VALIDATE_BUTTON)
def __init__(self, logviews=None): if logviews is None: logviews = [] line = Text(value='', placeholder='log filters', layout=Layout(width='200px'), disabled=False) icon_info = ToolButton(value=True, toggleable=True, button_color='#bdbdbd', pressed_color='#eee', icon='info-circle', color='#2176ff') def info_color(value): icon_info.color = '#2176ff' if value else '#333' icon_info.on_value_changed(info_color) icon_warn = ToolButton(value=True, toggleable=True, button_color='#bdbdbd', pressed_color='#eee', icon='exclamation-triangle', color='#eba427') def warn_color(value): icon_warn.color = '#eba427' if value else '#333' icon_warn.on_value_changed(warn_color) icon_error = ToolButton(value=True, toggleable=True, button_color='#bdbdbd', pressed_color='#eee', icon='exclamation-circle', color='#c71e1e') def error_color(value): icon_error.color = '#c71e1e' if value else '#333' icon_error.on_value_changed(error_color) icon_debug = ToolButton(value=True, toggleable=True, button_color='#bdbdbd', pressed_color='#eee', icon='code', color='#111') def debug_color(value): icon_debug.color = '#111' if value else '#333' icon_debug.on_value_changed(debug_color) space = HTML(layout=Layout(width='25px')) case_sensitive = HTMLButton(value=True, html='Aa', size=40, button_color='#bdbdbd', pressed_color='#eee', toggleable=True) super(LogToolBar, self).__init__([ icon_info, icon_warn, icon_error, icon_debug, space, line, case_sensitive ]) self.info = icon_info self.warn = icon_warn self.error = icon_error self.debug = icon_debug self.filter = line self.case = case_sensitive if not isinstance(logviews, list): logviews = [logviews] self._logviews = [] for logview in logviews: self.link_to(logview)
def __init__(self, df: pd.DataFrame, col_name: str, df_name: str, page_size: int): self._clusterer = Clusterer(df, col_name, df_name) self._clusterer.cluster("fingerprint") self._page_size = page_size # clustering dropdown and export code checkbox, used in the top row self._clustering_method_label = Label( " Clustering Method: ", layout=Layout(margin="2px 0 0 20px")) self._clustering_method_drop = Dropdown( options=[ "fingerprint", "ngram-fingerprint", "phonetic-fingerprint", "levenshtein" ], layout=Layout(width="150px", margin="0 0 0 10px"), ) self._clustering_method_drop.observe(self._cluster_method_change, names="value") self._export_code = Checkbox( value=True, description="export code", layout=Layout(width="165px", margin="0 0 0 482px"), style={"description_width": "initial"}, ) self._dropds = HBox( [ self._clustering_method_label, self._clustering_method_drop, self._export_code, ], layout=Layout(height="35px", margin="10px 0 0 0"), ) # text boxes for clustering parameters used in the top row self._ngram_text = Text( value=DEFAULT_NGRAM, description="n-gram", layout=Layout(width="130px"), continuous_update=False, ) self._radius_text = Text( value=DEFAULT_RADIUS, description="Radius", layout=Layout(width="130px"), continuous_update=False, ) self._block_chars_text = Text( value=DEFAULT_BLOCK_SIZE, description="Block Chars", layout=Layout(width="130px"), continuous_update=False, ) self._ngram_text.observe(self._param_recluster, names="value") self._radius_text.observe(self._param_recluster, names="value") self._block_chars_text.observe(self._param_recluster, names="value") # create header labels, second row headers = HBox( [ Label("Distinct values", layout=Layout(margin="0 0 0 10px")), Label("Total values", layout=Layout(margin="0 0 0 35px")), Label("Cluster values", layout=Layout(margin="0 0 0 95px")), Label("Merge?", layout=Layout(margin="0 0 0 295px")), Label("Representative value", layout=Layout(margin="0 0 0 50px")), ], layout=Layout(margin="10px"), ) # create buttons for bottom row self._sel_all = Checkbox(description="Select all", layout=Layout(width="165px")) self._sel_all.observe(self._select_all, names="value") merge_and_recluster = Button(description="Merge and Re-Cluster", layout=Layout(margin="0 0 0 466px", width="150px")) merge_and_recluster.on_click(self._execute_merge) finish = Button(description="Finish", layout=Layout(margin="0 0 0 10px")) finish.on_click(self._close) # next and previous page buttons self._next_button = Button(description="Next") self._next_button.on_click(self._next_page) self._prev_button = Button(description="Previous", layout=Layout(margin="0 0 0 20px")) self._prev_button.on_click(self._prev_page) # an index in the clusters Series indicating the start of the current page self._page_pos = 0 # loading label, displayed when re-clustering or next page load self._loading_label = Label("Loading...", layout=Layout(margin="170px 0 0 440px")) # displayed when the user enters a non integer value into a clustering parameter text box self._invalid_param_label = Label( "Invalid clustering parameter, please enter an integer", layout=Layout(margin="170px 0 0 350px"), ) self._reprs = [ Text(layout=Layout(width="200px", margin="0 10px 0 40px")) for _ in range(self._page_size) ] self._checks = [ Checkbox(indent=False, layout=Layout(width="auto", margin="0 0 0 20px")) for _ in range(self._page_size) ] # VBox containing a VBox with all the clusters in the first row and an optional # second row containing next and previous page buttons self._cluster_and_next_prev = VBox() self._cluster_vbox = VBox( layout=Layout(height="450px", flex_flow="row wrap")) footer = HBox([self._sel_all, merge_and_recluster, finish]) box_children = [ self._dropds, headers, self._cluster_and_next_prev, footer ] box_layout = Layout(display="flex", flex_flow="column", align_items="stretch", border="solid") self._box = Box(children=box_children, layout=box_layout) self._update_clusters()
def __init__(self, model, *args, **kwargs): self.model = model self._fields = {field: Text() for field in self.model.fields} self.radio_button_group = RadioButtons( description="When:", options=[ "All", "30 Days", "24 Hours", "1 Year", "1 Week", "1 Hour" ], ) self.refresh_button = Button(description="Refresh") date_buttons = VBox([self.radio_button_group, self.refresh_button]) self.since_widget = DatetimePicker() self.until_widget = DatetimePicker() date_range = HBox([ Label(value="Date range:"), self.since_widget, Label(value="-"), self.until_widget, ]) grid_children = [] for field, text in self._fields.items(): grid_children.append(Label(value=f"{field}:")) grid_children.append(text) text_grid = GridBox(children=grid_children, layout=Layout(grid_template_columns="30% 70%")) text_input = VBox([date_range, text_grid]) children = (date_buttons, text_input) if self.model.text_search_supported: full_text_label = Label("Full Text Search:") self.text_search_input = Text() text_grid.children += (full_text_label, self.text_search_input) self.text_search_input.observe(self._on_text_view_changed, "value") self.model.events.text.connect(self._on_text_model_changed) super().__init__(children, **kwargs) self.radio_button_group.observe(self._on_radio_button_changed, "value") self.refresh_button.on_click(self._on_reload_request) self.model.events.reload.connect(self._on_reload) self.model.events.query.connect(self._on_reload) self.since_widget.observe(self._on_since_view_changed, "value") self.model.events.since.connect(self._on_since_model_changed) self.until_widget.observe(self._on_until_view_changed, "value") self.model.events.until.connect(self._on_until_model_changed) # Set these values here so the model picks the values up self.model.since = GRACE_HOPPER_BIRTHDAY self.model.until = timedelta() self.radio_button_group.index = self.radio_button_group.options.index( "All") for field, text in zip(self.model.fields, self._fields.values()): def on_field_text_changed(change, field=field): self.model.field_search.update({field: change["new"]}) text.observe(on_field_text_changed, "value") self.model.events.field_search_updated.connect( self._on_field_search_updated)
def __init__(self): self.start_button = Button( value=False, description='Start Camera', disabled=False, button_style= 'success', # 'success', 'info', 'warning', 'danger' or '' tooltip='Start the camera and the recognition algorithm.', icon='') self.use_recorded = RadioButtons( options=['Webcam', 'MP4'], value='Webcam', description='Input', disabled=False, layout=Layout(width='320px'), style={'description_width': '150px'}, ) self.video_path = Text( value='', placeholder=str(Path("path", "to", "video.mp4")), description='Video path:', disabled=True, layout=Layout(width='320px'), style={'description_width': '150px'}, ) self.select_network = Dropdown( options=KerasDetector.available_models, value=KerasDetector.available_models[0], description='Algorithm:', disabled=False, layout=Layout(width='220px'), style={'description_width': '100px'}, ) self.select_frontend = Dropdown( options=["opencv", "matplotlib"], value="opencv", description='Frontend:', disabled=False, layout=Layout(width='220px', padding='8px 0 0 0'), style={'description_width': '100px'}, ) self.video_length = FloatText( value=12.0, description='Video length [s]:', disabled=False, layout=Layout(width='250px'), style={'description_width': '130px'}, ) self.select_framerate = Dropdown( options=[3, 5, 10, 15, 24], value=15, description='Frame rate:', disabled=False, layout=Layout(width='250px', padding='8px 0 0 0'), style={'description_width': '130px'}, ) self.static_text = Label( value="Working directory: {}".format(Path.cwd()), layout=Layout(margin='30px 0 0 0'), ) self.progress_text = Label(value='', ) self.text_box = VBox((self.static_text, self.progress_text), layout=Layout(justify_content="flex-start")) self.widget_box = VBox( (HBox((VBox((self.start_button, ), layout=Layout(justify_content="space-around")), VBox((self.use_recorded, self.video_path), layout=Layout(justify_content="space-around")), VBox((self.video_length, self.select_framerate), layout=Layout(justify_content="space-around")), VBox((self.select_network, self.select_frontend), layout=Layout(justify_content="space-around"))), ), HBox((self.text_box, ), layout=Layout(justify_content="flex-start"))), ) self.start_button.on_click(self._start_video) self.use_recorded.observe(self.refresh_state)