def test_append_msg(self): start = 'toto' msg = 'tutu' #test from empty alert alert = sw.Alert() res = alert.append_msg(msg) self.assertEqual(res, alert) self.assertEqual(len(alert.children), 1) self.assertEqual(alert.children[0].children[0], msg) #test from non empty alert without divider alert = sw.Alert().add_msg(start) res = alert.append_msg(msg) self.assertEqual(res, alert) self.assertEqual(len(alert.children), 2) self.assertEqual(alert.children[0].children[0], start) self.assertEqual(alert.children[1].children[0], msg) #test from non empty alert with divider alert = sw.Alert().add_msg(start) res = alert.append_msg(msg, section=True) self.assertEqual(res, alert) self.assertEqual(len(alert.children), 3) self.assertEqual(alert.children[0].children[0], start) self.assertIsInstance(alert.children[1], sw.Divider) self.assertEqual(alert.children[2].children[0], msg) # check that the divider is changing color alert.type = 'success' self.assertIn(alert.children[1].type_, 'success')
def test_rmv_last_msg(self): # check with a no msg alert alert = sw.Alert().remove_last_msg() self.assertFalse(alert.viz) self.assertEqual(alert.children[0], '') # check with a 1 msg alert alert = sw.Alert().add_msg('toto').remove_last_msg() self.assertFalse(alert.viz) self.assertEqual(alert.children[0], '') # check with a multiple msg alert alert = sw.Alert() string = 'toto' nb_msg = 5 for i in range(nb_msg): alert.append_msg(f'{string}{i}') alert.remove_last_msg() self.assertTrue(alert.viz) self.assertEqual(len(alert.children), 4) self.assertEqual(alert.children[nb_msg - 2].children[0], f'{string}{nb_msg-2}') return
def test_init(self): alert = sw.Alert() self.assertFalse(alert.viz) self.assertEqual(alert.type, 'info') for type_ in sw.TYPES: alert = sw.Alert(type_) self.assertEqual(alert.type, type_) alert = sw.Alert('random') self.assertEqual(alert.type, 'info') return
def test_check_input(self): alert = sw.Alert() var_test = None res = alert.check_input(var_test) self.assertFalse(res) self.assertTrue(alert.viz) self.assertEqual(alert.children[0].children[0], 'The value has not been initialized') res = alert.check_input(var_test, 'toto') self.assertEqual(alert.children[0].children[0], 'toto') var_test = 1 res = alert.check_input(var_test) self.assertTrue(res) # test lists var_test = [range(2)] res = alert.check_input(var_test) self.assertTrue(res) # test empty list var_test = [] res = alert.check_input(var_test) self.assertFalse(res) return
def __init__(self, aoi_tile, model, result_tile): # gather the model objects self.aoi_model = aoi_tile.view.model self.model = model # add the result_tile map to attributes self.m = result_tile.m self.tile = result_tile # create the widgets mkd = sw.Markdown(cm.process_txt) # create the tile super().__init__( "compute_widget", cm.tile.launch, inputs=[mkd], btn=sw.Btn(cm.launch_btn, class_="mt-5"), alert=sw.Alert(), ) # link the js behaviours self.btn.on_event("click", self._launch_fcdm) aoi_tile.view.observe(self._update_geometry, "updated")
def __init__(self, aoi_model, model, **kwargs): # gather the model self.aoi_model = aoi_model self.model = model # widgets self.visSelect = v.RadioGroup( v_model=pm.layer_select[0]["value"], children=[ v.Radio( # key=e['key'], label=e["label"], value=e["value"], ) for e in pm.layer_select ], ) # add the widgets self.m = sm.SepalMap() # bindings self.model.bind(self.visSelect, "viz") # construct the Tile with the widget we have initialized super().__init__( id_= "visualization_widget", # the id will be used to make the Tile appear and disapear title=ms.visualization. title, # the Title will be displayed on the top of the tile inputs=[self.visSelect, self.m], # self.asset, alert=sw.Alert(), ) self.visSelect.observe(self._on_change, "v_model")
def __init__(self, io, nb_class): # gather the io self.io = io # create the widgets self.file = sw.FileInput(['.tif', '.tiff']) self.classes = [ v.Select(label=cp.convert[nb_class]['label'][i], items=None, v_model=None, chips=True, multiple=True) for i in range(nb_class) ] requirements = sw.Markdown(cm.requirement[nb_class]) # bind it to the io self.output = sw.Alert().bind(self.file, self.io, 'file') for i in range(nb_class): self.output.bind(self.classes[i], self.io, cp.convert[nb_class]['io'][i]) # create the btn btn = sw.Btn("Convert the imag classes") super().__init__(self.io.tile_id, "Select map classes", inputs=[requirements, self.file] + self.classes, output=self.output, btn=btn) # bind js event btn.on_event('click', self._on_click) self.file.observe(self._on_change, 'v_model')
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, **kwargs): self.io = io self.btn = sw.Btn(ms.SELECT_ALERTS, 'mdi-map-marker-check') self.output = sw.Alert() # create the inputs self.set_inputs() inputs = [ self.select_type, self.picker_line, self.local_txt, self.select_date_file, self.select_alerts_file, self.gee_txt, self.asset_date_line, self.asset_alerts_line ] # hide all inputs but select_type self.show_inputs() # misc id_ = "driver_widget" title = "Select your alerts" super().__init__(id_, title, btn=self.btn, output=self.output, inputs=inputs, **kwargs)
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, 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']) edge_width = v.Slider(label=cm.mspa.edge_width, min=1, max=30, v_model=1) transition = v.Switch(label=cm.mspa.transition, false_value=0, true_value=1, v_model=1) int_ext = v.Switch(label=cm.mspa.int_ext, false_value=0, true_value=1, v_model=1) # bind to the io self.output = sw.Alert() \ .bind(connectivity, io, 'connectivity') \ .bind(edge_width, io, 'edge_width') \ .bind(transition, io, 'transition') \ .bind(int_ext, io, 'int_ext') super().__init__( io=io, inputs=[connectivity, edge_width, transition, int_ext], 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, 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, tb_model, m): # gather model self.model = tb_model # get the map self.m = m # create widgets file_select = sw.LoadTableField() # bind it to the model self.alert = sw.Alert() self.model.bind(file_select, 'json_table') # create the tile super().__init__( id_ = 'file_widget', title = cm.table.title, btn = sw.Btn(cm.table.btn), alert = self.alert, inputs = [file_select] ) # js behaviour self.btn.on_event('click', self._load_file)
def __init__(self, aoi_model, model, **kwargs): # gather the model self.aoi_model = aoi_model self.model = model # widgets self.measure = v.Select(label=ms.selection.measure, v_model=None, items=pm.measures) self.annual = v.Switch(class_="ml-5", label=ms.selection.annual, v_model=False) # add the map self.m = sm.SepalMap() # create an output alert self.model.bind(self.measure, "measure").bind(self.annual, "annual") # construct the Tile with the widget we have initialized super().__init__( id_= "visualization_widget", # the id will be used to make the Tile appear and disapear title=ms.visualization. title, # the Title will be displayed on the top of the tile inputs=[self.measure, self.annual, self.m], alert=sw.Alert(), ) self.measure.observe(self._on_change, "v_model") self.annual.observe(self._on_change, "v_model")
def download_tile(obj, w_selection): def bind_change(change, obj, attr): setattr(obj, attr, change['new']) w_overwrite = v.Switch(v_model=obj.overwrite, inset=True, label="Overwrite SEPAL images") w_overwrite.observe(partial(bind_change, obj=obj, attr='overwrite'), 'v_model') w_remove = v.Switch(v_model=obj.rmdrive, inset=True, label="Remove Google Drive Images") w_remove.observe(partial(bind_change, obj=obj, attr='rmdrive'), 'v_model') out = widgets.Output() btn = s.Btn(text="Download", icon='download') # Create an alert element for the process process_alert = s.Alert() on_download(obj, w_selection, btn, out, process_alert) html_header = """ <style> .widget-html span { color:black!important; } div.output_stderr{ color:none; } </style> <p>With this module you can track and download the images processed into your Google Earth Engine account by providing the 'tasks' text file, the results will be stored directly into your SEPAL account.</br> <b>Note that if you check the overwrite and remove options, the result can't be undone.</b> </p> """ download_content = v.Layout( class_="pa-5", row=True, align_center=True, children=[ v.Flex(xs12=True, children=[ v.Sheet(class_="pa-5", children=[ widgets.HTML(html_header), w_selection, w_overwrite, w_remove, btn, process_alert, out, ]) ]) ]) return download_content
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 test_reset(self): alert = sw.Alert().add_msg('toto').reset() self.assertFalse(alert.viz) self.assertEqual(len(alert.children), 1) self.assertEqual(alert.children[0], '') return
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, aoi_model, model, viz_tile, export_tile, **kwargs): # gather the model self.aoi_model = aoi_model self.model = model self.viz_tile = viz_tile self.export_tile = export_tile # widgets w_time_title = v.Html(tag="H3", class_="mt-3", children=[ms.selection.time_range]) self.start_picker = sw.DatePicker(label=ms.selection.start) self.end_picker = sw.DatePicker(label=ms.selection.end) w_time_range = v.Layout(row=True, children=[self.start_picker, self.end_picker]) w_collection_title = v.Html(tag="H3", class_="mt-3", children=[ms.selection.collection]) self.sensors = v.Select( label=ms.selection.sensor, items=pm.sensors, v_model=None, chips=True, multiple=True, ) self.t2 = v.Switch(class_="ml-5", label=ms.selection.t2, v_model=False) self.sr = v.Switch(class_="ml-5", label=ms.selection.sr, v_model=False) self.model.bind(self.start_picker, "start").bind(self.end_picker, "end").bind( self.sensors, "sensors").bind(self.t2, "t2").bind(self.sr, "sr") # construct the Tile with the widget we have initialized super().__init__( id_= "selection_widget", # the id will be used to make the Tile appear and disapear title=ms.selection. title, # the Title will be displayed on the top of the tile inputs=[ w_time_title, w_time_range, w_collection_title, self.sensors, self.t2, self.sr, ], btn=sw.Btn(ms.selection.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 __init__(self, model, aoi_model, viz_tile, export_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 # LINK to the result tile self.viz_tile = viz_tile self.export_tile = export_tile # WIDGETS self.year_beg = v.Select( label=cm.process.slider_b, v_model=None, items=[i for i in range(pm.max_year, pm.min_year - 1, -1)], ) self.year_end = v.Select( label=cm.process.slider_e, v_model=None, items=[i for i in range(pm.max_year, pm.min_year - 1, -1)], ) self.type_tmf = v.RadioGroup( row=True, v_model=pm.layer_select[0]["value"], children=[ v.Radio(key=e["key"], label=e["label"], value=e["value"]) for e in pm.layer_select ], ) # self.type_tmf.observe(self._on_change, 'v_model') # Create the alert alert self.model.bind(self.year_beg, "year_beg").bind( self.year_end, "year_end").bind(self.type_tmf, "type_tmf") # construct the Tile with the widget we have initialized super().__init__( id_= "process_widget", # the id will be used to make the Tile appear and disapear title=cm.process. title, # the Title will be displayed on the top of the tile inputs=[self.year_beg, self.year_end, self.type_tmf], btn=sw.Btn(cm.process.validate, "mdi-check", disabled=False, class_="ma-5"), 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 __init__(self, io): # create the widgets connectivity = v.Select(label=cm.acc.connectivity, items=cp.connectivity, v_model=cp.connectivity[0]) # bind to the io self.output = sw.Alert() \ .bind(connectivity, io, 'connectivity') super().__init__(io=io, inputs=[connectivity], output=self.output)
def close_filter_tile(w_selector): def on_click(widget, event, data, out, obj, alert): # Get the current path process_path = obj.get_current_path() # Clear output if there is something printed before out.clear_output() # Once the button is clicked, disable it btn.disable() # Clear old alert messages alert.clear() @out.capture() def run_process(obj): run_filter( process_path, alert, ) run_process(obj) btn.activate() out = Output() btn = s.Btn(text="Start") # Create an alert element for the process alert = s.Alert() content = v.Layout(xs12=True, row=True, class_="ma-5 d-block", children=[ filter_text, w_selector, btn, alert, out, ]) btn.on_event('click', partial( on_click, obj=w_selector, out=out, alert=alert, )) return content
def __init__(self): self.output = sw.Alert() # add the widgets self.m = sm.SepalMap() # construct the Tile with the widget we have initialized super().__init__( id_="visualization_widget", # the id will be used to make the Tile appear and disapear title=cm.visualization.title, # the Title will be displayed on the top of the tile inputs=[self.m], )
def __init__(self, aoi, results_tile, *args, **kwargs): super().__init__(*args, **kwargs) self.aoi = aoi self.results_tile = results_tile self.alert = sw.Alert() self.btn = sw.Btn(ms.buttons.process.label) self.children = [self.alert, self.btn] self.btn.on_event('click', self.process_start)
def test_update_progress(self): # create an alert alert = sw.Alert() # test a random update alert.update_progress(0.5) self.assertEqual(alert.children[1].children[0].children[2].children[0], ' 50.0%') # show that a value > 1 raise an error with self.assertRaises(Exception): alert.update_progress(1.5)
def __init__(self, io, nb_class): # gather the io self.io = io # create the download layout self.down_test = sw.Btn(cm.bin.default.btn, icon="mdi-cloud-download-outline", small=True, outlined=True, class_="ma-5") tooltip = sw.Tooltip(widget=self.down_test, tooltip=cm.bin.default.tooltip) # create the widgets self.file = sw.FileInput(['.tif', '.tiff']) self.classes = [ v.Select(label=cp.convert[nb_class]['label'][i], items=None, v_model=None, chips=True, small_chips=True, multiple=True, dense=True, deletable_chips=True) for i in range(len(cp.convert[nb_class]['label'])) ] requirements = sw.Markdown(cm.requirement[nb_class]) # bind it to the io self.output = sw.Alert().bind(self.file, self.io, 'file') for i in range(len(cp.convert[nb_class]['label'])): self.output.bind(self.classes[i], self.io, cp.convert[nb_class]['io'][i]) # create the btn btn = sw.Btn(cm.bin.btn) super().__init__( self.io.tile_id, cm.bin.title, inputs=[tooltip, v.Divider(), requirements, self.file] + self.classes, output=self.output, btn=btn) # bind js event btn.on_event('click', self._on_click) self.file.observe(self._on_change, 'v_model') self.down_test.on_event('click', self._on_download)
def __init__(self): # create the widget file_input = sw.FileInput(extentions=['']) txt = sw.Markdown("here I will add a lot of explanations") # create the actual tile super().__init__( 'folder_tile', "Select folder", inputs = [txt, file_input], output = sw.Alert(), btn = sw.Btn("validate this folder") )
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