class DialogController(AbstrController): __layout = v.Dialog( width="unset", v_model=False, children=[ v.Card(children=[ v.CardTitle(class_='headline gray lighten-2', primary_title=True, children=[]), v.CardText(children=[]) ]) ] ) def __init__(self): super().__init__("dialog") def _get_layout(self): return self.__layout def show(self, card_title, card_text): card = self.__layout.children[0] card.children[0].children = [card_title] card.children[1].children = [card_text] self.__layout.v_model = True def hide(self): self.__layout.v_model = False
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, table, **kwargs): self.table = table update = v.Btn(children=['update'], color='success') close = v.Btn(children=['close'], color='error') self.form_1d = FormProperties_1D() self.form_2d = FormProperties_2D() self.form = v.CardText(children=self.form_1d.widget) self.dialog = v.Dialog( width='500', v_model=False, children=[ v.Card(children=[ v.CardTitle(class_='headline gray lighten-2', primary_title=True, children=['Plot properties']), self.form, v.CardActions(children=[v.Spacer(), update, close]) ]), ]) def close_btn(widget, event, data): self.dialog.v_model = False update.on_event('click', self.update_btn) close.on_event('click', close_btn) super().__init__(**kwargs)
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): with out: yes = v.Btn(children=['yes'], class_='ma-2', style_='width: 100px', color='success') no = v.Btn(children=['no'], class_='ma-2', style_='width: 100px', color='error') self.width = '500' self.v_model = False self.text = v.CardTitle(children=[]) self.children = [ v.Card(children=[ self.text, v.CardActions(children=[v.Spacer(), yes, no]) ]), ] self.path = None self.replace = True yes.on_event('click', self.yes_click) no.on_event('click', self.no_click) super().__init__()
def __init__(self, states): """ Create a list of state items and a plus button to add new states. Parameter ========= states: list The list of default states defined by the test case. """ self.states = states self.default_state = self.states[0] super().__init__(self.default_state) self.eval_stab = v.Btn(children=['Check stability'], color='primary') for s in states: self.item_list.children.append(self.create_item(s)) self.item_list.notify_change({'name': 'children', 'type': 'change'}) self.widget = v.Card(children=[ v.CardTitle(children=['List of linear states', v.Spacer(), self.add_button]), v.CardText(children=[self.item_list]), v.CardActions(children=[v.Spacer(), self.eval_stab]) ])
def __init__(self, *args, **kwargs): self._viewer_options = v.CardTitle() self._layer_options = v.CardTitle() super().__init__(*args, components={ 'b-viewer-options': self._viewer_options, 'b-layer-options': self._layer_options }, **kwargs) self.hub.subscribe(self, DataCollectionAddMessage, handler=self._data_added) self.hub.subscribe(self, NewProfile1DMessage, handler=self._profile_added)
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, class_path=Path("~").expanduser() / "downloads", *args, **kwargs): """Stand-alone tile composed by a select widget containing .csv reclassify files found in the class_path, and a ClassTable to edit and/or create a new classification table, Args: class_path (str) (optional): Folder path containing classification tables """ super().__init__(*args, **kwargs) self.title = v.CardTitle( children=["Edit or create new classifications"]) self.class_path = class_path self.w_class_file = v.Select( label="Select a classes file", items=self.get_items(), v_model="", dense=True, ) self.ct = ClassTable( out_path=self.class_path, schema={ "id": "number", "code": "number", "description": "string" }, ).hide() use_btn = sw.Btn("Get table") self.children = [ self.title, v.Flex( class_="ml-2 d-flex", children=[ self.w_class_file, use_btn, ], ), self.ct, ] self.get_classes_files() # Events # Listen Class table save dialog to refresh the classes widget self.ct.save_dialog.observe(self._refresh_files, "reload") # Get the corresponding table use_btn.on_event("click", self.get_class_table)
def vuetify_component(self): assert (self._title is not None) return v.Card( min_width="400px", max_width="500px", children=[ v.CardTitle(children=[self._title]), v.CardText( children=[self._description, self._component_output]) ])
def __init__(self, table, schema, *args, default=None, **kwargs): """ Dialog to modify/create new elements from the ClassTable data table Args: table (ClassTable, v.DataTable): Table linked with dialog schema (dict {'title':'type'}): Schema for table showing headers and type of data default (dict): Dictionary with default valules """ self.table = table self.default = default self.title = "New element" if not self.default else "Modify element" self.schema = schema self.v_model = True self.max_width = 500 self.overlay_opcity = 0.7 # Action buttons self.save = v.Btn(children=['Save']) save_tool = sw.Tooltip(self.save, 'Create new element') self.cancel = v.Btn(children=['Cancel']) cancel_tool = sw.Tooltip(self.cancel, 'Ignore changes') self.modify = v.Btn(children=['Modify']) modify_tool = sw.Tooltip(self.modify, 'Update row') save = [save_tool, cancel_tool] modify = [modify_tool, cancel_tool] actions = v.CardActions(children=save if not default else modify) super().__init__(*args, **kwargs) self.children=[ v.Card( class_='pa-4', children=[ v.CardTitle(children=[self.title])] + \ self._get_widgets() + \ [actions] ) ] # Create events self.save.on_event('click', self._save) self.modify.on_event('click', self._modify) self.cancel.on_event('click', self._cancel)
def __init__(self, class_path=Path('~').expanduser() / 'downloads', *args, **kwargs): """Stand-alone tile composed by a select widget containing .csv reclassify files found in the class_path, and a ClassTable to edit and/or create a new classification table, Args: class_path (str) (optional): Folder path containing classification tables """ super().__init__(*args, **kwargs) self.title = v.CardTitle( children=['Edit or create new classifications']) self.class_path = class_path self.w_class_file = v.Select(label='Select a classes file', items=self.get_items(), v_model='', dense=True) self.ct = ClassTable( out_path=self.class_path, schema={ 'id': 'number', 'code': 'number', 'description': 'string' }, ).hide() use_btn = sw.Btn('Get table') self.children = [ self.title, v.Flex(class_='ml-2 d-flex', children=[ self.w_class_file, use_btn, ]), self.ct ] self.get_classes_files() # Events # Listen Class table save dialog to refresh the classes widget self.ct.save_dialog.observe(self._refresh_files, 'reload') # Get the corresponding table use_btn.on_event('click', self.get_class_table)
def exception_widget(exc): """Create an exception notification widget and raises sys.exit() silently. Parameters: exc (Exception): Input exception. Raises: SilentExit: Exits silently. """ tback = traceback.TracebackException.from_exception(exc).format() trace_list = [string for string in tback if 'File' in string] if any(trace_list): tback = trace_list[-1].split('\n')[0] else: tback = '' exc_type = exc.__class__.__name__ exc_msg = exc.args[0] title = vue.CardTitle(class_='headline body-1 font-weight-medium', primary_title=True, children=[ vue.Icon(children=['warning'], style_='color:#ffffff;' 'margin: 0px 5px'), exc_type ], style_='height:35px;' 'background-color:#AA0114;' 'color:#ffffff;' 'padding: 0px 10px') subtitle = vue.CardSubtitle( children=[exc_msg], class_='text--primary body-1 fontweight-medium', style_="margin: 0px 0px; color:#212121") children = [title, subtitle] if tback: text = vue.CardText(children=[tback], class_='font-weight-medium', style_="margin: -15px 0px") children.append(text) exc_card = vue.Card( children=children, style_='height: auto; min-height: 100px;', ) display(exc_card) raise SilentExit
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, *args, **kwargs): self.form = self.form_class(*args, **kwargs) update_btn = v.Btn(children=['update'], color='success') close_btn = v.Btn(children=['close'], color='error') self.update_dialog = v.Dialog( width='500', v_model=False, children=[ v.Card(children=[ v.CardTitle(class_='headline gray lighten-2', primary_title=True, children=[self.update_text]), v.CardText(children=[self.form]), v.CardActions(children=[v.Spacer(), update_btn, close_btn]) ]), ]) update_btn.on_event('click', self.update_click) close_btn.on_event('click', self.close_click) self.content = v.CardText(children=[f'{self}']) self.btn = v.Btn( children=[v.Icon(children=['mdi-close'])], fab=True, color='error', dark=True, x_small=True, ) super().__init__(children=[ v.ListItemAction(children=[self.btn]), v.ListItemContent(children=[ v.Card( children=[self.content], flat=True, color='transparent', light=True, ), self.update_dialog ]), ], **kwargs)
def __init__(self, table, **kwargs): self.table = table update = v.Btn(children=['update']) close = v.Btn(children=['close']) self.form = [ IntField(label='linewidth', v_model=plot_config['linewidth']), v.Select(label='Line style', items=[{ 'text': v, 'value': k } for k, v in Line2D.lineStyles.items()], v_model=plot_config['linestyle']), v.Select(label='Marker', items=[{ 'text': v, 'value': k } for k, v in Line2D.markers.items()], v_model=plot_config['marker']), IntField(label='Marker size', v_model=plot_config['markersize']), FloatField(label='alpha', v_model=plot_config['alpha']), v.ColorPicker(v_model=plot_config['colors'][0]), ] self.dialog = v.Dialog( width='500', v_model=False, children=[ v.Card(children=[ v.CardTitle(class_='headline gray lighten-2', primary_title=True, children=['Plot properties']), v.CardText(children=self.form), v.CardActions(children=[v.Spacer(), update, close]) ]), ]) def close_btn(widget, event, data): self.dialog.v_model = False update.on_event('click', self.update_btn) close.on_event('click', close_btn) super().__init__(**kwargs)
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_information(tab_id, mc, tc, lb): if tab_id == 0: return [] items = [ v.ListItem(children=[ v.ListItemContent(children=[ f"{mc.select_category.v_model}: " + f"{mc.select_model.v_model}" ], class_='px-4 py-0' ) ], class_='mb-0'), v.ListItem(children=[ v.ListItemContent(children=[ f"Test case: {tc.select_case.v_model}" ], class_='px-4 py-0', ) ], class_='mb-0'), v.ListItem(children=[ v.ListItemContent(children=[ f"Scheme: {lb.select_case.v_model}" ], class_='px-4 py-0', ) ], class_='mb-0'), ] return [ v.Card(children=[ v.CardTitle(children=['Information'], class_='pb-1'), v.List(children=items[0:min(tab_id, 3)], dense=True, class_='pa-0') ]) ]
def create_zip(widget, event, data): from zipfile import ZipFile zipfilename = os.path.join(voila_notebook, 'results.zip') with ZipFile(zipfilename, 'w') as zipObj: for folderName, subfolders, filenames in os.walk(default_path): for filename in filenames: #create complete filepath of file in directory filePath = os.path.join(folderName, filename) # Add file to zip zipObj.write(filePath, filePath.replace(default_path, '')) dialog.children = [ v.Card(children=[ v.CardTitle(children=[ widgets.HTML( f'<a href="./results.zip" download="results.zip">Download the archive</a>' ) ]) ]) ] dialog.v_model = True
def __init__(self): self.feature = None self.w_name = v.TextField(label=cm.map.dialog.label, v_model=None) self.btn = sw.Btn(cm.map.dialog.btn, "mdi-check") card = v.Card( class_="ma-5", children=[ v.CardTitle(children=[cm.map.dialog.title]), v.CardText(children=[self.w_name]), v.CardActions(children=[self.btn]), ], ) # init the dialog super().__init__( persistent=True, value=False, max_width="700px", children=[card] ) # add js behavior self.btn.on_event("click", self._on_click)
def __init__(self, test_case_widget, lb_scheme_widget): """ Widget definition for linear stability of a lattice Boltzmann scheme. Parameters ========== - test_case_widget: widget of the test case (see test_case.py). - lb_scheme_widget: widget of the lattice Boltzmann scheme (see lb_scheme.py). This widget is composed by a menu where you can modify the parameters of the lattice Boltzmann scheme. This widget is also composed by a main widget where the linear stability for the states provided by the test case can be tested to check their stability. A user can add its own states. A second tab allows to plot the stability region of a given state. """ self.test_case_widget = test_case_widget self.lb_scheme_widget = lb_scheme_widget ## ## The menu ## self.menu = [self.lb_scheme_widget.panels] ## ## The main ## # Tab 1 test_case = self.test_case_widget.get_case() self.state_widget = StateWidget(test_case.state()) tab1 = v.TabItem(children=[self.state_widget.widget], class_="ma-6") # Tab 2 self.state_list = v.Select(label='States', items=[], v_model=0) plot_stab = v.Btn(children=['Plot stability region'], color='primary') self.alert = v.Alert(children=['Check the stability for this state...'], dense=True, type='info') self.stab_output, self.markers1, self.markers2 = prepare_stab_plot() self.container = Container(children=[v.Row(children=[v.Col(children=[self.alert])]), v.Row(children=[self.stab_output.canvas], align='center', justify='center')], align_content_center=True,) self.container.hide() tab2 = v.TabItem(children=[ v.Card(children=[ v.CardTitle(children=['Plot the linear stability for a given state']), v.CardText(children=[ v.Row(children=[ v.Col(children=[self.state_list], md=9, sm=12), v.Col(children=[plot_stab], md=3, sm=12), ], align='center', justify='space-around' ), self.container ]), ], class_="ma-6", )] ) # main tabs = v.Tabs(v_model=None, children=[v.Tab(children=['Check stability']), v.Tab(children=['Plot stability region']), tab1, tab2 ]) self.main = [tabs] self.update_states(None) self.change_test_case(None) ## ## Widget events ## self.test_case_widget.select_case.observe(self.change_test_case, 'v_model') self.test_case_widget.select_case.observe(self.hide_plot, 'v_model') self.lb_scheme_widget.select_case.observe(self.hide_plot, 'v_model') self.state_widget.eval_stab.on_event('click', self.stability_states) self.state_widget.item_list.observe(self.update_states, 'children') plot_stab.on_event('click', self.plot_stability)
def dialog_button(label='', icon='mdi-help', _class="icon ma-2", _style="", color="primary", dark=False, dialog_width=600, dialog_title="Dialog Title", dialog_content="Dialog Content", ): """ Creates a button and activates a dialog on click Useful to display application documentation/help Parameters ---------- icon : str (optional, default None) Icon to display on button label : str (optoinal, default None) Text to display on button dialog_width : int (optional, default 600) Width of the dialog in pixels dialog_title : str (optional, default 'Help Title') Dialog title dialog_content : str (optional, default '') Dialog content in markdown format color : str (optional, default 'primary') Color of button dark : bool Use dark style _class : str (optional, default 'icon ma-2') CSS classes of button _style: str CSS style of button """ if icon is None: icon='' if label is None: label='' dialog_button = ipyvuetify.Btn( _class_="icon ma-2", _style='', color=color, depressed=True, dark=dark, children=[label, ipyvuetify.Icon(children=[icon])], ) close_dialog_btn = ipyvuetify.Btn(children=["Close"]) dialog_dialog = ipyvuetify.Dialog( v_model=False, scrollable=True, width=dialog_width, children=[ ipyvuetify.Card(children=[ ipyvuetify.CardTitle(class_="headline pa-4", children=[dialog_title]), ipyvuetify.Divider(), ipyvuetify.CardText( class_="pa-4 text--primary", primary_title=True, children=[dialog_content], ), ipyvuetify.Divider(), close_dialog_btn, ]) ], ) def open_dialog_dialog(widget, event, data): dialog_dialog.v_model = True def close_dialog_dialog(widget, event, data): dialog_dialog.v_model = False display(ipyvuetify.Layout(children=[dialog_dialog])) close_dialog_btn.on_event("click", close_dialog_dialog) dialog_button.on_event("click", open_dialog_dialog) return dialog_button
def __init__(self): # init the downloadable informations self.geometry = None self.names = [] self.datasets = {} # create the useful widgets self.w_scale = v.Slider( class_="mt-5", v_model=30, # align on the landsat images, ticks="always", tick_labels=[ str(i) if i in self.TICKS_TO_SHOW else "" for i in range(10, 301, 10) ], min=10, max=300, thumb_label=True, step=10, ) self.w_prefix = v.TextField( label=cm.export.name, small=True, dense=True, v_model=None, ) self.w_datasets = v.Select( dense=True, small=True, label=cm.export.datasets, v_model=None, items=[*self.datasets], multiple=True, chips=True, ) self.w_method = v.RadioGroup( v_model="gee", row=True, children=[ v.Radio(label=cm.export.radio.sepal, value="sepal"), v.Radio(label=cm.export.radio.gee, value="gee"), ], ) self.alert = sw.Alert() self.btn = sw.Btn(cm.export.apply, small=True) export_data = v.Card(children=[ v.CardTitle( children=[v.Html(tag="h4", children=[cm.export.title])]), v.CardText(children=[ self.w_prefix, self.w_datasets, v.Html(tag="h4", children=[cm.export.scale]), self.w_scale, v.Html(tag="h4", children=[cm.export.radio.label]), self.w_method, self.alert, ]), v.CardActions(children=[self.btn]), ]) # the clickable icon self.w_down = v.Btn( v_on="menu.on", color="primary", icon=True, children=[v.Icon(children=["mdi-cloud-download"])], ) super().__init__( value=False, close_on_content_click=False, nudge_width=200, offset_x=True, children=[export_data], v_slots=[{ "name": "activator", "variable": "menu", "children": self.w_down }], ) # add js behaviour self.btn.on_event("click", self._apply)
def __init__(self, test_case_widget, lb_scheme_widget): self.test_case_widget = test_case_widget self.lb_scheme_widget = lb_scheme_widget test_case = test_case_widget.get_case() lb_param = lb_scheme_widget.parameters tc_param = test_case_widget.parameters dx = default_dx nx = int(test_case.size()[0]/dx) + 1 ny = 1 dt = dx/lb_param['la'].value nt = int(test_case.duration/dt) self.discret = { 'nx': NbPointsField(label='Number of points in x', v_model=nx, disabled=True), 'ny': NbPointsField(label='Number of points in y', v_model=ny, disabled=True, class_='d-none'), 'dx': StrictlyPositiveFloatField(label='Space step', v_model=dx), 'nt': StrictlyPositiveIntField(label='Number of steps', v_model=nt, disable=True), 'dt': StrictlyPositiveFloatField(label='Time step', v_model=dt), } self.la_vue = v.CardText(children=[lb_param['la']]) for value in self.discret.values(): value.observe(self.observer, 'v_model') lb_param['la'].observe(self.observer, 'v_model') tc_param['xmin'].observe(self.observer, 'v_model') tc_param['xmax'].observe(self.observer, 'v_model') if test_case_widget.get_case().dim > 1: tc_param['ymin'].observe(self.observer, 'v_model') tc_param['ymax'].observe(self.observer, 'v_model') test_case_widget.select_case.observe(self.change_test_case, 'v_model') lb_scheme_widget.select_case.observe(self.change_test_case, 'v_model') super().__init__(children=[ v.ExpansionPanelHeader(children=['Discretization']), v.ExpansionPanelContent(children=[ v.Card(children=[ v.CardTitle(children=['In space']), v.CardText(children=[ self.discret['nx'], self.discret['ny'], self.discret['dx'], ]), ], class_="ma-1"), v.Card(children=[ v.CardTitle(children=['In time']), v.CardText(children=[ self.discret['nt'], self.discret['dt'], ]), ], class_="ma-1"), v.Card(children=[ v.CardTitle(children=['Scheme velocity']), self.la_vue, ], class_="ma-1"), ], class_="px-1"), ]),
def __init__(self): self.select_dim = v.Select(label='Dimension', items=[1, 2], v_model=1) self.previous_dim = 1 headers = [ { 'text': 'Iteration', 'value': 'iteration' }, { 'text': 'Time', 'value': 'time' }, { 'text': 'Field', 'value': 'field' }, { 'text': 'Test case', 'value': 'test case' }, { 'text': 'LB scheme', 'value': 'lb scheme' }, { 'text': 'Filename', 'value': 'file' }, { 'text': 'Directory', 'value': 'directory' }, ] headers_select = v.Select(label='Show columns', items=[{ 'text': v['text'], 'value': i } for i, v in enumerate(headers)], v_model=list(range(5)), multiple=True) search = v.TextField( v_model=None, append_icon="mdi-magnify", label="Search", single_line=True, hide_details=True, ) self.table = v.DataTable( v_model=[], headers=[headers[i] for i in headers_select.v_model], items=[], item_key="id", single_select=False, show_select=True, search='', ) self.selected_cache = [[]] * 3 self.select_item_cache = [[]] * 3 self.palette_cache = [[]] * 3 self.select_table = SelectedDataTable( self.table, headers=[headers[i] for i in headers_select.v_model] + [{ 'text': 'Action', 'value': 'action' }], ) self.plot = Plot() def select(change): with out: for e in list(self.table.v_model): self.select_table.items.append(e) self.select_table.palette.append({ 'color': plot_config['colors'][0], 'alpha': plot_config['alpha'], 'linewidth': plot_config['linewidth'], 'linestyle': plot_config['linestyle'], 'marker': plot_config['marker'], 'markersize': plot_config['markersize'] }) self.table.items.remove(e) self.table.v_model = [] self.select_table.notify_change({ 'name': 'items', 'type': 'change' }) self.table.notify_change({'name': 'items', 'type': 'change'}) def search_text(change): self.table.search = search.v_model self.update(None) self.select_table.observe(self.plot_result, 'items') self.select_table.observe(self.plot_result, 'palette') self.select_table.observe(self.plot_result, 'selected') search.observe(search_text, 'v_model') self.table.observe(select, 'v_model') self.select_dim.observe(self.cache, 'v_model') def update_headers(change): with out: self.table.headers = [ headers[i] for i in headers_select.v_model ] self.select_table.headers = [ headers[i] for i in headers_select.v_model ] + [{ 'text': 'Action', 'value': 'action' }] self.select_table.notify_change({ 'name': 'items', 'type': 'change' }) self.table.notify_change({'name': 'items', 'type': 'change'}) headers_select.observe(update_headers, 'v_model') download_zip = v.Btn(children=['Download results']) def create_zip(widget, event, data): from zipfile import ZipFile import webbrowser import tempfile zipdir = tempfile.TemporaryDirectory().name if not os.path.exists(zipdir): os.makedirs(zipdir) zipfilename = os.path.join(zipdir, 'results.zip') with ZipFile(zipfilename, 'w') as zipObj: for folderName, subfolders, filenames in os.walk(default_path): for filename in filenames: #create complete filepath of file in directory filePath = os.path.join(folderName, filename) # Add file to zip zipObj.write(filePath, filePath.replace(default_path, '')) webbrowser.open(f'file://{zipfilename}') download_zip.on_event('click', create_zip) self.menu = [self.select_dim, headers_select, download_zip] self.main = [ v.Card( children=[ v.CardTitle( children=['Available results', v.Spacer(), search]), self.table, ], class_='ma-2', ), v.Card( children=[ v.CardTitle(children=[ 'Selected results', ]), self.select_table, self.select_table.dialog, ], class_='ma-2', ), v.Row(children=[self.plot.fig.canvas], justify='center'), # out ]
def __init__(self, *args, **kwargs): self.class_ = "pa-4" self._metadata = {"mount_id": "reclassify"} super().__init__(*args, **kwargs) # Class parameters self.root_dir = None self.class_path = None self.workspace() # self.alert_dialog = Dialog(transition=False) self.alert_dialog = sw.Alert().hide() title = v.CardTitle(children=[cm.reclassify.title]) description = v.CardText( class_="py-0", children=[sw.Markdown(cm.reclassify.description)]) self.customize_class = CustomizeTile(self.class_path) self.w_class_file = v.Select(label="Select a classes file", v_model="", dense=True) self.get_table_btn = sw.Btn("Get reclassify table", class_="mb-2") self.save_raster_btn = sw.Btn("Reclassify", class_="my-2").hide() self.get_items() self.w_select_raster = sw.FileInput([".tif"], label="Search raster") self.w_reclassify_table = ReclassifyTable().show() tabs_titles = ["Reclassify", "Customize classification"] tab_content = [ v.Card(children=[ title, description, self.w_select_raster, self.w_class_file, self.get_table_btn, self.w_reclassify_table, self.save_raster_btn, self.alert_dialog, ]), self.customize_class, ] self.children = [Tabs(tabs_titles, tab_content)] # Decorate functions self.reclassify_and_save = loading_button( self.save_raster_btn, self.alert_dialog)(self.reclassify_and_save) self.get_reclassify_table = loading_button( self.get_table_btn, self.alert_dialog)(self.get_reclassify_table) # Events self.get_table_btn.on_event("click", self.get_reclassify_table) self.save_raster_btn.on_event("click", self.reclassify_and_save) # Refresh tables self.customize_class.observe(self.get_items, "classes_files")
def __init__(self, *args, **kwargs): with out: self.form = self.item_class.form_class(*args, **kwargs) create_add = v.Btn(children=['add'], color='success') create_close = v.Btn(children=['close'], color='error') create_dialog = v.Dialog( width='500', v_model=False, children=[ v.Card(children=[ v.CardTitle(class_='headline gray lighten-2', primary_title=True, children=[self.new_text]), v.CardText(children=[self.form]), v.CardActions( children=[v.Spacer(), create_add, create_close]) ]), ]) self.item_list = v.List(children=[]) add_button = v.Btn( children=[v.Icon(children=['mdi-plus']), create_dialog], fab=True, color='primary', small=True, dark=True, ) def close_click(widget, event, data): create_dialog.v_model = False def on_change(change): self.item_list.notify_change({ 'name': 'children', 'type': 'change' }) def add_click(widget, event, data): self.form.check_rules() if self.form.v_model: new_item = self.create_item() self.item_list.children.append(new_item) create_dialog.v_model = False def remove_item(widget, event, data): self.item_list.children.remove(new_item) self.item_list.notify_change({ 'name': 'children', 'type': 'change' }) new_item.btn.on_event('click', remove_item) new_item.on_event('click', new_item.update_item) new_item.observe(on_change, 'children') self.item_list.notify_change({ 'name': 'children', 'type': 'change' }) create_close.on_event('click', close_click) create_add.on_event('click', add_click) def on_add_click(widget, event, data): with out: self.form.reset_form() create_dialog.v_model = True add_button.on_event('click', on_add_click) self.add_button = add_button self.widget = v.Card(children=[ v.CardText(children=[self.item_list]), v.CardActions(children=[v.Spacer(), add_button]) ])
def __init__(self): # init the downloadable informations self.geometry = None self.dataset = None self.name = None self.aoi_name = None # create the useful widgets self.w_scale = v.Slider( v_model=30, # align on the landsat images min=10, max=300, thumb_label=True, step=10, ) self.w_method = v.RadioGroup( v_model="gee", row=True, children=[ v.Radio(label=cm.export.radio.sepal, value="sepal"), v.Radio(label=cm.export.radio.gee, value="gee"), ], ) self.alert = sw.Alert() self.btn = sw.Btn(cm.export.apply, small=True) export_data = v.Card(children=[ v.CardTitle( children=[v.Html(tag="h4", children=[cm.export.title])]), v.CardText(children=[ v.Html(tag="h4", children=[cm.export.scale]), self.w_scale, v.Html(tag="h4", children=[cm.export.radio.label]), self.w_method, self.alert, ]), v.CardActions(children=[self.btn]), ]) # the clickable icon self.download_btn = v.Btn( v_on="menu.on", color="primary", icon=True, children=[v.Icon(children=["mdi-cloud-download"])], ) super().__init__( value=False, close_on_content_click=False, nudge_width=200, offset_x=True, children=[export_data], v_slots=[{ "name": "activator", "variable": "menu", "children": self.download_btn }], ) # add js behaviour self.btn.on_event("click", self._apply)
items = filelist[stage] cards = [ v.Flex(ma_2=True, fluid=True, children=[ v.Card(hover=True, align_center=True, fluid=True, min_width='300px', max_width='300px', href=details['link'], target='_blank', children=[ v.CardTitle(children=[ v.Html(tag='div', class_='headline mb-0', children=[details['title']]), v.Spacer(), ]), v.CardText(children=[details['description']]), ]) ]) for i, details in enumerate(items) ] tab_children.append(v.Tab(children=[stage])) tab_children.append( v.TabItem(children=[v.Layout(ma_5=True, wrap=True, children=cards)])) # + {"Collapsed": "false"} tabs = v.Tabs(v_model='tab', color='grey lighten-5', fixed_tabs=True,
def __init__(self, *args, **kwargs): self.class_ = 'pa-4' self._metadata = {'mount_id': 'reclassify'} super().__init__(*args, **kwargs) # Class parameters self.root_dir = None self.class_path = None self.workspace() # self.alert_dialog = Dialog(transition=False) self.alert_dialog = sw.Alert().hide() title = v.CardTitle(children=[cm.reclassify.title]) description = v.CardText( class_='py-0', children=[sw.Markdown(cm.reclassify.description)]) self.customize_class = CustomizeTile(self.class_path) self.w_class_file = v.Select(label='Select a classes file', v_model='', dense=True) self.get_table_btn = sw.Btn('Get reclassify table', class_='mb-2') self.save_raster_btn = sw.Btn('Reclassify', class_='my-2').hide() self.get_items() self.w_select_raster = sw.FileInput(['.tif'], label='Search raster') self.w_reclassify_table = ReclassifyTable().show() tabs_titles = ['Reclassify', 'Customize classification'] tab_content = [ v.Card(children=[ title, description, self.w_select_raster, self.w_class_file, self.get_table_btn, self.w_reclassify_table, self.save_raster_btn, self.alert_dialog, ]), self.customize_class ] self.children = [Tabs(tabs_titles, tab_content)] # Decorate functions self.reclassify_and_save = loading_button( self.save_raster_btn, self.alert_dialog)(self.reclassify_and_save) self.get_reclassify_table = loading_button( self.get_table_btn, self.alert_dialog)(self.get_reclassify_table) # Events self.get_table_btn.on_event('click', self.get_reclassify_table) self.save_raster_btn.on_event('click', self.reclassify_and_save) # Refresh tables self.customize_class.observe(self.get_items, 'classes_files')