def __init__(self, label="Thresholds"): # hidden textfield to save the v_model # the v_model will be stored as json self.save = v.TextField(v_model=None) # create the inputs self.text_fields = [ v.TextField(placeholder=f'threshold {i+1}', v_model=None, type="number", class_='ml-1 mr-1', hint=cm.acc.res_hint) for i in range(5) ] # title title = v.Html(tag='h4', children=[label]) for w in self.text_fields: w.observe(self._on_change, 'v_model') w.on_event('focusout', self._on_focus_out) super().__init__( class_="ma-5", row=True, children=[title, v.Layout(row=True, children=self.text_fields)])
def __init__(self, label="Thresholds"): # hidden textfield to save the v_model # the v_model will be stored as json self.save = v.TextField(v_model=None) # create the inputs self.text_fields = [ v.TextField(placeholder=cm.frag.window_lbl.format(i + 1), v_model=None, type="number", class_='ml-1 mr-1', hint=cm.frag.invalid_window) for i in range(10) ] # title title = v.Html(tag='h4', children=[label]) # add js behaviour for w in self.text_fields: w.observe(self._on_change, 'v_model') w.on_event('focusout', self._on_focusout) super().__init__( class_="ma-5", row=True, children=[title, v.Layout(row=True, children=self.text_fields)])
def initialize(self): """ All ipyvuetify widgets to display for the title and the input / output file """ self.title = v.TextField( v_model=self.titlef, label="Title :", outlined=True, clearable=True, style_="margin-top:20px", ) self.input = v.TextField( v_model=self.inputf, label="Input_file :", suffix=".xml", outlined=True, clearable=True, style_="margin-top:5px", ) self.output = v.TextField( v_model=self.outputf, label="Output_file :", suffix=".xml", outlined=True, clearable=True, style_="margin-top:5px", ) display(self.title, self.input, self.output)
def __init__(self, aoi_vew, model): # save the model self.model = model # listen to the aoi_vew to update the map self.view = aoi_vew self.init_layer = "" self.id = "" self.index = None # add all the standard placeholder, they will be replaced when a layer will be selected self.title = v.CardTitle(children=["Layer name"]) self.text = v.CardText(children=[""]) self.layer = v.TextField(class_="ma-5", v_model=None, color="warning", outlined=True, label="Layer") self.unit = v.TextField(class_="ma-5", v_model=None, color="warning", outlined=True, label="Unit") # add a map to display the layers self.m = sm.SepalMap() self.m.layout.height = "40vh" self.m.layout.margin = "2em" # two button will be placed at the bottom of the panel self.cancel = sw.Btn(cm.dial.cancel, color="primary", outlined=True) self.save = sw.Btn(cm.dial.save, color="primary") # create the init card self.card = v.Card(children=[ self.title, self.text, self.layer, self.unit, self.m, v.CardActions(class_="ma-5", children=[self.cancel, self.save]), ]) # init the dialog super().__init__(persistent=True, value=False, max_width="50vw", children=[self.card]) # js behaviours self.layer.on_event("blur", self._on_layer_change) self.cancel.on_event("click", self._cancel_click) self.save.on_event("click", self._save_click) self.view.observe(self._update_aoi, "updated")
def __init__(self, byte_map=None): header = v.Html( tag="thead", children=[ v.Html( tag="tr", children=[ v.Html(tag="th", children=["old value"]), v.Html(tag="th", children=["new value"]), ], ) ], ) self.tbody = v.Html(tag="tbody", children=[]) # add a hidden textfield to save the json self.save = v.TextField(v_model=json.dumps({i: i for i in range(256)})) # load the body self.reload_body(byte_map) # create the actual table super().__init__(children=[header, self.tbody], class_="mb-5")
def reload_body(self, raster): """dynamically change the body of the widget according to the raster file""" # empty the tbody children self.tbody.children = [] # get the file features : features = cs.unique(raster) # create 1 line for each feature tmp_children = [] for i in features: # create a textField field = v.TextField(placeholder="any value in [0, 256[", type='number', v_model=None, value=i) # js link to the global widget field.observe(self._on_change, 'v_model') # wrap it in a row row = v.Html(tag='tr', children=[ v.Html(tag='td', children=[str(i)]), v.Html(tag='td', children=[field]) ]) # add the row to the tbody tmp_children += [row] self.tbody.children += tmp_children return self
def __init__(self, label="Date", **kwargs): date_picker = v.DatePicker(no_title=True, v_model=None, scrollable=True) date_text = v.TextField(v_model=None, label=label, hint="YYYY-MM-DD format", persistent_hint=True, prepend_icon="event", readonly=True, v_on='menuData.on') menu = v.Menu(transition="scale-transition", offset_y=True, v_slots=[{ 'name': 'activator', 'variable': 'menuData', 'children': date_text, }], children=[date_picker]) super().__init__(v_model=None, row=True, class_='pa-5', align_center=True, children=[v.Flex(xs10=True, children=[menu])], **kwargs) jslink((date_picker, 'v_model'), (date_text, 'v_model')) jslink((date_picker, 'v_model'), (self, 'v_model'))
def __init__(self, aoi_tile): self.aoi_tile = aoi_tile self.title = v.CardTitle(children=['Copy this link to you clipboard']) self.text = v.CardText( children=["click on the link then 'ctrl+a' and then 'ctrl+c'"]) self.link = v.TextField(class_="ma-5", v_model='je suis un link', outlined=True, label='link', readonly=True, append_icon='mdi-clipboard-outline') self.card = v.Card(children=[ self.title, self.text, self.link, ]) super().__init__(value=False, max_width='600px', children=[self.card]) # self.link.on_event('click', self.select_all) self.aoi_tile.aoi_select_btn.observe(self.fire_dialog, 'loading')
def __init__(self): self.label = v.TextField(label='label', v_model='') self.line_style = v.Select(label='Line style', items=[{ 'text': v, 'value': k } for k, v in Line2D.lineStyles.items()], v_model=plot_config['linestyle']) self.line_width = IntField(label='linewidth', v_model=plot_config['linewidth']) self.marker = v.Select(label='Marker', items=[{ 'text': v, 'value': k } for k, v in Line2D.markers.items()], v_model=plot_config['marker']) self.marker_size = IntField(label='Marker size', v_model=plot_config['markersize']) self.alpha = FloatField(label='alpha', v_model=plot_config['alpha']) self.color = v.ColorPicker(v_model=plot_config['colors'][0]) self.widget = [ self.label, self.line_style, self.line_width, self.marker, self.marker_size, self.alpha, v.Row(children=[self.color], justify='center'), ]
def __init__(self, io): # create the widgets algorithm = v.Select(label=cm.p223.algo, items=cp.algo, v_model=cp.algo[0]['value']) kdim = v.TextField(label=cm.lm.kdim, type='number', hint=cm.frag.invalid_window, v_model=None) prescision = v.Select(label=cm.fad.prescision, items=cp.prescision, v_model=cp.prescision[0]['value']) # bind to the io self.output = sw.Alert() \ .bind(algorithm, io, 'algorithm') \ .bind(kdim, io, 'kdim') \ .bind(prescision, io, 'prescision') # create extra js behaviour kdim.on_event('focusout', self._on_focusout) super().__init__(io=io, inputs=[ algorithm, kdim, prescision, ], output=self.output)
def __init__(self, io): # create the widgets connectivity = v.Select(label=cm.acc.connectivity, items=cp.connectivity, v_model=cp.connectivity[0]['value']) res = v.TextField(label=cm.acc.res, type='number', v_model=None, hint=cm.acc.res_hint) thresholds = cw.Thresholds(label=cm.acc.thresholds) options = v.Select(label=cm.acc.options, items=cp.acc_options, v_model=cp.acc_options[0]['value']) # bind to the io self.output = sw.Alert() \ .bind(connectivity, io, 'connectivity') \ .bind(res, io, 'res') \ .bind(thresholds.save, io, 'thresholds') \ .bind(options, io, 'options') # extra js behaviour res.on_event('focusout', self._on_focus_out) super().__init__(io=io, output=self.output, inputs=[connectivity, res, thresholds, options])
def __init__(self, io): # create the widgets connectivity = v.Select(label=cm.acc.connectivity, items=cp.connectivity, v_model=cp.connectivity[0]['value']) res = v.TextField(label=cm.acc.res, type='number', v_model=None, hint=cm.acc.res_hint) windows = cw.Windows(label=cm.frag.windows) options = v.Select(label=cm.acc.options, items=cp.fad_options, v_model=cp.fad_options[0]['value']) prescision = v.Select(label=cm.fad.prescision, items=cp.prescision, v_model=cp.prescision[0]['value']) # bind to the io self.output = sw.Alert() \ .bind(connectivity, io, 'connectivity') \ .bind(res, io, 'res') \ .bind(windows.save, io, 'window_size') \ .bind(options, io, 'options') \ .bind(prescision, io, 'prescision') # extra js behaviour res.on_event('focusout', self._on_focus_out) super().__init__( io=io, inputs=[connectivity, res, windows, options, prescision], output=self.output)
def __init__(self, aoi_model, model, **kwargs): # gather the model self.aoi_model = aoi_model self.model = model self.scale = v.TextField(label=cm.export.scale, v_model=30) # create buttons self.asset_btn = sw.Btn( cm.export.asset_btn, "mdi-download", disabled=True, class_="ma-5" ) self.sepal_btn = sw.Btn( cm.export.sepal_btn, "mdi-download", disabled=True, class_="ma-5" ) # bindings self.model.bind(self.scale, "scale") # note that btn and alert are not a madatory attributes super().__init__( id_="export_widget", title=cm.export.title, inputs=[self.scale], alert=sw.Alert(), btn=v.Layout(row=True, children=[self.asset_btn, self.sepal_btn]), ) # link the btn self.asset_btn.on_event("click", self._on_asset_click) self.sepal_btn.on_event("click", self._on_sepal_click)
def __init__(self, phys_fields, *args, **kwargs): self.phys_fields = phys_fields self.select_field = v.Select(label='Fields', v_model=[], items=['all'] + phys_fields, required=True, multiple=True) self.select_when = v.Select(label='When', v_model=None, items=[t.value for t in SaveType], required=True) self.when_properties = v.TextField(label='when save the fields?', v_model=None, required=True) self.select_field.observe(self.select_fields_rules, 'v_model') self.select_field.observe(self.select_fields_all, 'v_model') self.select_when.observe(self.select_when_rules, 'v_model') self.select_when.observe(self.when_properties_rules, 'v_model') self.when_properties.observe(self.when_properties_rules, 'v_model') self.fields = [ self.select_field, self.select_when, self.when_properties ] super().__init__(v_model='valid', children=[ self.select_field, self.select_when, self.when_properties, ])
def __init__(self, model): # create the widgets connectivity = v.Select( label=cm.acc.connectivity, items=cp.connectivity, v_model=cp.connectivity[0]["value"], ) res = v.TextField( label=cm.acc.res, type="number", v_model=None, hint=cm.acc.res_hint ) thresholds = cw.Thresholds(label=cm.acc.thresholds) options = v.Select( label=cm.acc.options, items=cp.acc_options, v_model=cp.acc_options[0]["value"], ) big_3_pink = v.Switch(label=cm.acc.big3pink, v_model=True) # bind to the ( model.bind(connectivity, "connectivity") .bind(res, "res") .bind(thresholds.save, "thresholds") .bind(options, "options") .bind(big_3_pink, "big_3_pink") ) # extra js behaviour res.on_event("focusout", self._on_focus_out) super().__init__( model=model, inputs=[connectivity, res, thresholds, options, big_3_pink] )
def __init__(self): title = v.CardTitle(children=[cm.quintile.clip.title]) self.link = v.TextField( class_="ma-5", v_model=None, outlined=True, label=cm.quintile.clip.lbl, hint=cm.quintile.clip.hint, persistent_hint=True, readonly=True, append_icon="mdi-clipboard-outline", ) self.done = v.Btn(color="primary", outlined=True, children=[cm.quintile.clip.done]) self.card = v.Card( children=[title, self.link, v.CardActions(children=[self.done])]) super().__init__(value=False, persistent=True, max_width="600px", children=[self.card]) # js links self.done.on_event("click", self._done_click)
def __init__(self, model, aoi_model): # gather the io as class attribute self.aoi_model = aoi_model self.model = model # create widgets self.date_picker_start = sw.DatePicker(label="Start of event") self.date_picker_end = sw.DatePicker(label="End of event") self.username = v.TextField(label="Copernicus Scihub Username", v_model=None) self.password = sw.PasswordField(label="Copernicus Scihub Password") # bind them with the output self.model.bind(self.date_picker_start, "event_start").bind( self.date_picker_end, "event_end").bind(self.username, "username").bind(self.password, "password") # construct the tile super().__init__( id_="process_widget", title="Set input parameters", inputs=[ self.date_picker_start, self.date_picker_end, self.username, self.password ], alert=sw.Alert(), btn=sw.Btn("Process"), ) # link the click to an event self.btn.on_event("click", self._on_click)
def __init__(self, aoi_tile, questionnaire_tile): # gather the io self.layer_model = questionnaire_tile.layer_model self.aoi_model = aoi_tile.view.model self.question_model = questionnaire_tile.question_model # gather the tiles that need to be filled self.aoi_tile = aoi_tile self.questionnaire_tile = questionnaire_tile # add the naming textField self.w_name = v.TextField(label=cm.custom.recipe.name, v_model=None) # link the widget to the model self.question_model.bind(self.w_name, "recipe_name") # create the layer list widget self.layers_recipe = cw.layerRecipe().hide() mkd = sw.Markdown(" \n".join(cm.valid.txt)) # add the recipe loader self.reset_to_recipe = sw.Btn(text=cm.custom.recipe.apply, icon="mdi-download", class_="ml-2") self.file_select = sw.FileInput([".json"], cp.result_dir, cm.custom.recipe.file) ep = v.ExpansionPanels( class_="mt-5", children=[ v.ExpansionPanel(children=[ v.ExpansionPanelHeader(disable_icon_rotate=True, children=[cm.custom.recipe.title]), v.ExpansionPanelContent( children=[self.file_select, self.reset_to_recipe]), ]) ], ) # create the tile super().__init__( id_="compute_widget", inputs=[ep, mkd, self.w_name, self.layers_recipe], title=cm.valid.title, btn=sw.Btn(cm.valid.display, class_="ma-1"), alert=sw.Alert(), ) # decorate the custom recipe btn self.load_recipe = su.loading_button(self.alert, self.reset_to_recipe, debug=True)(self.load_recipe) # js behaviours aoi_tile.view.observe(self._recipe_placeholder, "updated") self.btn.on_event("click", self._validate_data) self.reset_to_recipe.on_event("click", self.load_recipe) self.w_name.on_event("blur", self._normalize_name)
def __init__(self, io): # create the widgets kdim = v.TextField(label=cm.lm.kdim, type='number', v_model=None) # bind to the io self.output = sw.Alert() \ .bind(kdim, io, 'kdim') super().__init__(io=io, inputs=[kdim], output=self.output)
def __init__(self, extentions=['.txt'], folder=os.path.expanduser('~'), label='select file', **kwargs): self.extentions = extentions self.folder = folder self.selected_file = v.TextField(label='file', v_model=self.file) self.file_list = v.List( dense=True, color='grey lighten-4', flat=True, children=[v.ListItemGroup(children=self.get_items(), v_model='')]) self.file_menu = v.Menu(min_width=300, children=[self.file_list], close_on_content_click=False, max_height='300px', v_slots=[{ 'name': 'activator', 'variable': 'x', 'children': v.Btn(v_model=False, v_on='x.on', children=[label]) }]) super().__init__(row=True, class_='pa-5', align_center=True, children=[ v.Flex(xs12=True, children=[self.selected_file]), v.Flex(xs12=True, children=[self.file_menu]) ], **kwargs) link((self.selected_file, 'v_model'), (self, 'file')) def on_file_select(change): new_value = change['new'] if new_value: if os.path.isdir(new_value): self.folder = new_value self.change_folder() elif os.path.isfile(new_value): self.file = new_value self.file_list.children[0].observe(on_file_select, 'v_model')
def __init__(self, m, aoi_io): # to store the final asset self.assetId = None # the map to display the final tile self.m = m #store the aoi_io self.aoi_io = aoi_io # inputs self.grid_name = v.TextField(label="Asset name", v_model=None) self.size_select = v.TextField(label='Select the tile size (km)', v_model=None, type='number') self.batch_size = v.TextField( label='Select number of tiles in a batch', v_model=None, type='number') self.btn = sw.Btn('tile the aoi', icon='mdi-check') self.output = sw.Alert() super().__init__( 'tile_widget', 'Tiling interface', btn=self.btn, inputs=[self.size_select, self.batch_size, self.grid_name], output=self.output) # link the component together self.btn.on_event('click', self.create_grid) self.batch_size.observe(self.write_name, 'v_model') self.size_select.observe(self.display_square, 'v_model') self.size_select.observe(self.write_name, 'v_model')
def __init__(self, table, out_path, *args, **kwargs): """ Dialog to save as .csv file the content of a ClassTable data table Args: table (ClassTable, v.DataTable): Table linked with dialog out_path (str): Folder path to store table content """ self.max_width = 500 self.v_model = False self.out_path = out_path super().__init__(*args, **kwargs) self.table = table self.w_file_name = v.TextField(label="Insert output file name", type="string", v_model="new_table.csv") # Action buttons self.save = v.Btn(children=["Save"]) save = sw.Tooltip(self.save, "Save table") self.cancel = v.Btn(children=["Cancel"]) cancel = sw.Tooltip(self.cancel, "Cancel") info = (sw.Alert().add_msg("The table will be stored in {}".format( str(out_path))).show()) self.children = [ v.Card( class_="pa-4", children=[ v.CardTitle(children=["Save table"]), self.w_file_name, info, save, cancel, ], ) ] # Create events self.save.on_event("click", self._save) self.cancel.on_event("click", self._cancel)
def __init__(self, model): # create the widgets kdim = v.TextField( class_="mb-2", label=cm.lm.kdim, type="number", v_model=None, hint=cm.frag.invalid_window, ) # bind to the io model.bind(kdim, "kdim") # extra js behaviour kdim.on_event("focusout", self._on_focusout) super().__init__(model=model, inputs=[kdim])
def __init__(self, io): # create the widgets kdim = v.TextField( class_="mb-2", label=cm.lm.kdim, type='number', v_model=None, hint=cm.frag.invalid_window, ) # bind to the io self.output = sw.Alert() \ .bind(kdim, io, 'kdim') # extra js behaviour kdim.on_event('focusout', self._on_focusout) super().__init__(io=io, inputs=[kdim], output=self.output)
def __init__(self, table, out_path, *args, **kwargs): """ Dialog to save as .csv file the content of a ClassTable data table Args: table (ClassTable, v.DataTable): Table linked with dialog out_path (str): Folder path to store table content """ self.max_width = 500 self.v_model = False self.out_path = out_path super().__init__(*args, **kwargs) self.table = table self.w_file_name = v.TextField(label='Insert output file name', type='string', v_model='new_table.csv') # Action buttons self.save = v.Btn(children=['Save']) save = sw.Tooltip(self.save, 'Save table') self.cancel = v.Btn(children=['Cancel']) cancel = sw.Tooltip(self.cancel, 'Cancel') info = sw.Alert().add_msg('The table will be stored in {}'.format( str(out_path))).show() self.children = [ v.Card(class_='pa-4', children=[ v.CardTitle(children=['Save table']), self.w_file_name, info, save, cancel ]) ] # Create events self.save.on_event('click', self._save) self.cancel.on_event('click', self._cancel)
def _get_widgets(self): widgets = [] for title, type_ in self.schema.items(): widget = v.TextField(label=title.capitalize(), type=type_, v_model='') widget.observe(partial(self._populate_dict, title=title), 'v_model') if title == 'id': widget.disabled = True if self.default: widget.v_model = self.default[title] else: if title == 'id': widget.v_model = self._get_index() widgets.append(widget) return widgets
def __init__(self): self.label = v.TextField(label='label', v_model='') self.min_value = FloatField(label='minimum value') self.max_value = FloatField(label='maximum value') headers = [{ 'text': 'Name', 'value': 'name' }, { 'text': 'Color', 'value': 'color' }] self.cmap = v.ListItemGroup( v_model=plt.colormaps().index('RdBu'), children=[ v.ListItem(children=[ v.ListItemContent(children=[ v.ListItemTitle(children=[name]), v.ListItemSubtitle(children=[ v.Img(src=f'pylbm_ui/widgets/cmap/{name}.png', height=30, width=400) ]) ]) ]) for name in plt.colormaps() ]) self.widget = [ self.label, self.min_value, self.max_value, v.ExpansionPanels( v_model=None, children=[ v.ExpansionPanel(children=[ v.ExpansionPanelHeader(children=['Colormaps']), v.ExpansionPanelContent(children=[self.cmap]) ]) ]) ]
def __init__(self, model): # create the widgets connectivity = v.Select( label=cm.acc.connectivity, items=cp.connectivity, v_model=cp.connectivity[0]["value"], ) res = v.TextField(label=cm.acc.res, type="number", v_model=None, hint=cm.acc.res_hint) windows = cw.Windows(label=cm.frag.windows) options = v.Select( label=cm.acc.options, items=cp.frag_options, v_model=cp.frag_options[0]["value"], ) prescision = v.Select( label=cm.fad.prescision, items=cp.prescision, v_model=cp.prescision[0]["value"], ) # bind to the io (model.bind(connectivity, "connectivity").bind(res, "res").bind( windows.save, "window_size").bind(options, "options").bind(prescision, "prescision")) # extra js behaviour res.on_event("focusout", self._on_focus_out) super().__init__( model=model, inputs=[connectivity, res, windows, options, prescision])
def __init__(self, model, aoi_model, result_tile, **kwargs): # define the model and the aoi_model as class attribute so that they can be manipulated in its custom methods self.model = model self.aoi_model = aoi_model # as I will display my results in another tile, I need to gather this extra tile in my attributes self.result_tile = result_tile # create all the widgets that you want to use in the tile # create the widgets following ipyvuetify lib requirements (more information in the ipyvuetify and sepal_ui doc) # if you want to use them in custom function you should consider adding them in the class attirbute self.slider = v.Slider(label=cm.default_process.slider, class_="mt-5", thumb_label=True, v_model=0) self.text = v.TextField(label=cm.default_process.textfield, v_model=None) # link the widgets to the model model \ .bind(self.slider, 'slider_value') \ .bind(self.text, 'text_value') # construct the Tile with the widget we have initialized super().__init__( id_= "default_viz_tile", # the id will be used to make the Tile appear and disapear title=cm.default_process. title, # the Title will be displayed on the top of the tile inputs=[self.slider, self.text], btn=sw.Btn(), alert=sw.Alert()) # now that the Tile is created we can link it to a specific function self.btn.on_event('click', self._on_run)
def test_bind(self): class Test_io: def __init__(self): self.out = None test_io = Test_io() widget = v.TextField(v_model=None) alert = sw.Alert() alert2 = sw.Alert() alert3 = sw.Alert() alert4 = sw.Alert() # binding without text res = alert.bind(widget, test_io, 'out') alert2.bind(widget, test_io, 'out', 'new variable : ') alert3.bind(widget, test_io, 'out', verbose=False) alert4.bind(widget, test_io, 'out', secret=True) self.assertEqual(res, alert) # check when value change msg = 'toto' widget.v_model = msg self.assertTrue(alert.viz) self.assertEqual(test_io.out, widget.v_model) self.assertEqual(alert.children[0].children[0], 'The selected variable is: {}'.format(msg)) self.assertEqual(alert2.children[0].children[0], 'new variable : {}'.format(msg)) self.assertFalse(len(alert3.children)) self.assertEqual(alert4.children[0].children[0], 'The selected variable is: {}'.format("*" * len(msg))) return