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, 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): 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 vuetify_layout_factory(viewer): def on_click(widget, event, data): drawer.v_model = not drawer.v_model sidebar_button = v.AppBarNavIcon() sidebar_button.on_event('click', on_click) options_panel = v.ExpansionPanels( v_model=[0, 1], multiple=True, accordion=True, style_='padding-left: 1px; min-width: 200px', children=[ v.ExpansionPanel(children=[ v.ExpansionPanelHeader(class_='font-weight-bold', children=['Viewer Options']), v.ExpansionPanelContent(children=[viewer.viewer_options]) ]), v.ExpansionPanel(children=[ v.ExpansionPanelHeader(class_='font-weight-bold', children=['Layer Options']), v.ExpansionPanelContent(children=[viewer.layer_options]) ]) ]) drawer = v.NavigationDrawer(v_model=False, absolute=True, right=True, children=[sidebar_button, options_panel], width="min-content") toolbar = v.Toolbar( dense=True, class_='elevation-0', children=[ v.ToolbarItems(children=[ viewer.toolbar_selection_tools, viewer.toolbar_selection_mode, viewer.toolbar_active_subset ]), v.Spacer(), sidebar_button ]) layout = v.Html(tag='div', children=[ toolbar, v.Row(no_gutters=True, children=[ v.Col(cols=12, children=[viewer.figure_widget]), v.Col(cols=12, children=[viewer.output_widget]) ]), drawer ]) return layout
def vuetify_layout_factory(viewer): def on_click(widget, event, data): drawer.v_model = not drawer.v_model sidebar_button = v.AppBarNavIcon() sidebar_button.on_event('click', on_click) options_panel = v.ExpansionPanels( v_model=[0, 1], multiple=True, accordion=True, style_='padding-left: 1px', children=[ v.ExpansionPanel(children=[ v.ExpansionPanelHeader(class_='font-weight-bold', children=['Viewer Options']), v.ExpansionPanelContent(children=[viewer.viewer_options])]), v.ExpansionPanel(children=[ v.ExpansionPanelHeader(class_='font-weight-bold', children=['Layer Options']), v.ExpansionPanelContent(children=[viewer.layer_options])])]) drawer = v.NavigationDrawer(v_model=False, absolute=True, right=True, children=[sidebar_button, options_panel], width="min-content") toolbar_selection_tools = BasicJupyterToolbar(viewer) tool_ids, subtool_ids = get_viewer_tools(viewer.__class__) if subtool_ids: raise ValueError('subtools are not yet supported in Jupyter viewers') for tool_id in tool_ids: mode_cls = viewer_tool.members[tool_id] mode = mode_cls(viewer) toolbar_selection_tools.add_tool(mode) toolbar_active_subset = SubsetSelect(viewer) toolbar_selection_mode = SelectionModeMenu(viewer) toolbar = v.Toolbar(dense=True, class_='elevation-0', children=[v.ToolbarItems(children=[toolbar_selection_tools, toolbar_selection_mode, toolbar_active_subset]), v.Spacer(), sidebar_button]) layout = v.Html(tag='div', children=[ toolbar, v.Row(no_gutters=True, children=[ v.Col(cols=12, children=[viewer.figure_widget]), v.Col(cols=12, children=[viewer.output_widget]) ]), drawer ]) return layout
def create_main_toolbar(self) -> v.Toolbar: return v.Toolbar( flat=True, block=True, children=[ v.Spacer(), self.create_file_upload(), self.create_show_example(), self.create_link_button( target="examples/data/raw/ics/liverpool.ics", text="Example Data", icon="mdi-file", ), self.create_link_button( target="https://github.com/ricky-lim/calh", text="Source", icon="mdi-github-face", ), v.Spacer(), ], )
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)
for key, value in nb.scraps.data_dict.items(): this_item[key] = value items.append(this_item) filelist[stage.name] = items # + {"Collapsed": "false"} # build toolbar toolbar = v.Toolbar( color=title_bar_color, dark=True, children=[ v.ToolbarItems( children=[v.Img(src=logo['jupyter'], style_='height:100%')]), v.ToolbarTitle(children=[dashboard_name], color='green'), v.Spacer(), v.ToolbarItems(children=app_bar_links) ], app=True) # + {"Collapsed": "false"} tab_children = [] for stage in sorted(filelist.keys()): items = filelist[stage] cards = [ v.Flex(ma_2=True, fluid=True, children=[ v.Card(hover=True, align_center=True,
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, spark_controller, ipywidget_factory, ipython_display, endpoints, refresh_method, state, db): super(AddEndpointWidget, self).__init__(spark_controller, ipywidget_factory, ipython_display, True) self.endpoints = endpoints self.refresh_method = refresh_method self.state = state self.delete_pressed = False self.db = db self.auth = GoogleAuth() add_endpoint_button = v.Btn(class_='ma-2', color='primary', children=['Add Endpoint']) add_endpoint_button.on_event('click', self._add_endpoint) cancel_button = v.Btn(class_='ma-2', color='primary', children=['Cancel']) cancel_button.on_event('click', self._on_cancel_click) backicon = v.Icon(children=['mdi-arrow-left']) backicon.on_event('click', self._on_back_click) back_toolbar = v.Toolbar( elevation="0", children=[ v.ToolbarItems(children=[backicon]), v.ToolbarTitle(children=['Create new endpoint']), v.Spacer() ], app=True, # If true, the other widgets float under on scroll ) self.create_endpoint_widget = v.Container( style_=f'width: {WIDGET_WIDTH};', class_='ma-2', children=[ back_toolbar, v.Row(class_='ma-2', children=[ v.Col(children=[self.auth.account_widget]), v.Col(children=[self.auth.project_widget]), v.Col(children=[self.auth.region_widget]) ]), v.Row(class_='ma-2', children=[ v.Col(children=[self.auth.cluster_widget]), v.Col(children=[self.auth.filter_widget]), v.Col(children=[v.Spacer()]), ]), v.Row(class_='ma-2', children=[add_endpoint_button, cancel_button]) ]) endpoint_table_values = self._generate_endpoint_values() new_endpoint = v.Btn(class_='ma-2', color='primary', children=['New Endpoint']) new_endpoint.on_event('click', self._on_new_endpoint_click) no_back_toolbar = v.Toolbar( elevation="0", children=[ v.ToolbarTitle(titleMarginStart='12dp', contentInsetStartWithNavigation="56dp", children=['Endpoints']), v.Spacer() ], app=True, # If true, the other widgets float under on scroll ) toolbar = v.Row(children=[no_back_toolbar, new_endpoint]) delete_icon = v.Icon(children=['mdi-delete']) delete_icon.on_event('click', self._on_delete_icon_pressed) endpoint_table = v.DataTable(style_=f'width: {WIDGET_WIDTH};', no_data_text='No endpoints', hide_default_footer=True, disable_pagination=True, item_key='url', headers=[ { 'text': 'Cluster', 'align': 'start', 'sortable': False, 'value': 'name' }, { 'text': 'Project', 'sortable': False, 'value': 'project' }, { 'text': 'Region', 'sortable': False, 'value': 'region' }, { 'text': 'Account', 'sortable': False, 'value': 'account' }, { 'text': 'Url', 'sortable': False, 'value': 'url' }, { 'text': '', 'sortable': False, 'value': 'actions' }, ], items=endpoint_table_values, dense=False, v_slots=[{ 'name': 'item.actions', 'children': [delete_icon] }, { 'name': 'no-data', 'children': ['No endpoints'] }]) endpoint_table.on_event('click:row', self._remove_row_from_table) self.toolbar_with_table = v.Container( style_=f'width: {WIDGET_WIDTH};', class_='mx-auto', children=[ v.Row(class_='mx-auto', children=[toolbar]), v.Row(class_='mx-auto', children=[endpoint_table]) ]) self.children = [self.create_endpoint_widget, self.toolbar_with_table] for child in self.children: child.parent_widget = self self._update_view()
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): self.select_dim = v.Select(label='Dimension', items=[1, 2], v_model=1) self.previous_dim = 1 headers = [ { 'text': 'Id', 'value': 'id' }, { 'text': 'Iteration', 'value': 'iteration' }, { 'text': 'Time', 'value': 'time' }, { 'text': 'Field', 'value': 'field' }, { 'text': 'Model', 'value': 'model' }, { '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 + 1 } for i, v in enumerate(headers[1:])], v_model=list(range(1, 7)), 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.properties_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) if e['dim'] == 1: self.select_table.properties.append({ 'label': e['field'], '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'] }) elif e['dim'] == 2: h5 = os.path.join(e['directory'], e['file']) h5_data = h5py.File(h5) data = h5_data[e['field']][:] self.select_table.properties.append({ 'label': e['field'], 'min_value': np.nanmin(data), 'max_value': np.nanmax(data), 'cmap': plt.colormaps().index(plot_config['cmap']) }) 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, 'properties') 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 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 self.title = v.TextField(label='Plot title', v_model='') self.xlabel = v.TextField(label='x label', v_model='') self.ylabel = v.TextField(label='y label', v_model='') self.legend = v.Switch(label='Add legend', v_model=False) self.title.observe(self.set_plot_properties, 'v_model') self.xlabel.observe(self.set_plot_properties, 'v_model') self.ylabel.observe(self.set_plot_properties, 'v_model') self.legend.observe(self.set_plot_properties, 'v_model') dialog = v.Dialog() dialog.v_model = False dialog.width = '200' download_zip.on_event('click', create_zip) self.menu = [ self.select_dim, headers_select, self.title, self.xlabel, self.ylabel, self.legend, download_zip, dialog ] 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'), ]