def make_widgets(country_large): tab1 = v.Tab(children=['New'], v_model='default') tab2 = v.Tab(children=['Total'], v_model='default') widgets = namedtuple( 'Widget', ['chk_mov_ave', 'slider_mov_ave', 'sel_country', 'tab1', 'tab2'])( v.Checkbox(v_model='default', label='moving average'), v.Slider(min=2, max=10, class_='px-4', v_model='default', thumb_label=True, ticks=True), v.Select(items=country_large, v_model='default'), tab1, tab2) return widgets
def __init__(self, titles, content, **kwargs): self.background_color = "primary" self.dark = True self.tabs = [ v.Tabs( v_model=self.current, children=[ v.Tab(children=[title], key=key) for key, title in enumerate(titles) ], ) ] self.content = [ v.TabsItems( v_model=self.current, children=[ v.TabItem(children=[content], key=key) for key, content in enumerate(content) ], ) ] self.children = self.tabs + self.content link((self.tabs[0], "v_model"), (self.content[0], "v_model")) super().__init__(**kwargs)
def __init__(self, cases): """ Widget definition for models. Parameters ========== cases: dict the keys of this dictionary are the name of the model, the values of this dictionary are an instance of the model. This widget is composed by a menu where you can choose the dimension and the model. This widget is also composed by a main widget where a description of the model is given. """ self.cases = cases default_category = next(iter(self.cases)) ## ## The menu ## # widget to select the model self.select_category = v.Select( items=list(self.cases.keys()), v_model=default_category, label='Category', ) self.select_model = v.Select( items=[], v_model=None, label='Model' ) self.menu = [self.select_category, self.select_model] ## ## The main ## self.description = HTML() self.tabs = v.Tabs( v_model=None, children=[ v.Tab(children=['Description']), v.TabItem(children=[self.description]), ] ) self.main = [self.tabs] # Add the widget events self.select_category.observe(self.change_category, 'v_model') self.select_model.observe(self.change_model, 'v_model') # update the category to fix the default model self.change_category(None)
def backend_widget(backend: Union[IBMQBackend, FakeBackend]) -> None: """Display backend information as a widget. Args: backend: Display information about this backend. """ cred = backend._credentials last_tab = vue.TabItem(children=[]) card = vue.Card( height=600, outlined=True, children=[ vue.Toolbar(flat=True, color="#002d9c", children=[ vue.ToolbarTitle(children=[ '{} @ ({}/{}/{})'.format( backend.name(), cred.hub, cred.group, cred.project) ], style_="color:white") ]), vue.Tabs(vertical=True, children=[ vue.Tab(children=['Configuration']), vue.Tab(children=['Qubits']), vue.Tab(children=['Non-local Gates']), vue.Tab(children=['Error map']), vue.Tab(children=['Job Summary']), vue.TabItem(children=[config_tab(backend)]), vue.TabItem(children=[qubits_tab(backend)]), vue.TabItem(children=[gates_tab(backend)]), vue.TabItem(children=[ iplot_error_map( backend, figsize=(None, None), as_widget=True) ]), last_tab ]) ]) # Load job data async for a bit better performance thread = threading.Thread(target=_async_job_loader, args=(last_tab, backend)) thread.start() display(card)
def __init__(self, question_model, layer_model, aoi_view): # name the tile title = cm.questionnaire.title id_ = "questionnaire_widget" # build the tiles self.constraint_tile = ConstraintTile(aoi_view, layer_model) self.priority_tile = PriorityTile() self.tiles = [self.constraint_tile, self.priority_tile] # build the content and the stepper header tab_content = [] for i, tile in enumerate(self.tiles): # add the title and content tab_content.append(v.Tab(children=[tile.get_title()])) tab_content.append(v.TabItem(children=[tile])) # build the tabs tabs = tabs = v.Tabs(class_="mt-5", fixed_tabs=True, centered=True, children=tab_content) # create a dialog widget self.dialog = cw.EditDialog(aoi_view, layer_model) # build the tile super().__init__(id_, title, inputs=[self.dialog, tabs]) # save the associated model and set the default value self.question_model = question_model self.layer_model = layer_model self.question_model.constraints = self.constraint_tile.custom_v_model self.question_model.priorities = self.priority_tile.v_model # js behaviours [ btn.on_event("click", self._open_dialog) for btn in self.priority_tile.table.btn_list ] [ c.btn.on_event("click", self._open_dialog) for c in self.constraint_tile.criterias ] self.constraint_tile.observe(self.__on_constraint, "custom_v_model") self.priority_tile.table.observe(self.__on_priority_tile, "v_model") self.dialog.observe(self.constraint_tile._update_constraints, "updated")
def _refresh(self, tab=0): _restore_endpoints_and_sessions(self.db, self.ipython_display, self.spark_controller, self.endpoints) self.create_session = CreateSessionWidget(self.spark_controller, self.ipywidget_factory, self.ipython_display, self.endpoints, self._refresh, self.state, self.db) self.add_endpoint = AddEndpointWidget(self.spark_controller, self.ipywidget_factory, self.ipython_display, self.endpoints, self._refresh, self.state, self.db) session_tab = [ v.Tab(children=['Sessions']), v.TabItem(style_='border: 1px solid lightgrey', children=[self.create_session]) ] endpoint_tab = [ v.Tab(children=['Endpoint']), v.TabItem(style_='border: 1px solid lightgrey', children=[self.add_endpoint]) ] self.tabs = v.Tabs( style_='border: 1px solid lightgrey', v_model=tab, # loads session tab when on children=session_tab + endpoint_tab) self.children = [self.tabs] for child in self.children: child.parent_widget = self
def construct_tabs(tabs_definition, slider_color=None, color=None, background_color=None, grow=True): tab_heads = [ v.TabItem(children=[tab_head]) for tab_head in tabs_definition.values() ] tab_items = [ v.Tab(children=[tab_name]) for tab_name in tabs_definition.keys() ] tabs = v.Tabs( slider_color=slider_color, color=color, background_color=background_color, grow=grow, children=tab_heads + tab_items, ) return tabs
aggfunc_selection_waffle, # p4_wgt_crosstab, plot_type_waffle ]) waffle = widgets.Output(layout=layout_output_wgt) tab_waffle_content = v.Row(children=[ v.Card(style_=layout_card, children=[info.p4_doc_waffle]), v.Col(col=12, sm=12, md=12, children=[ menu_plant_waffle, waffle, ]), ]) tab_3 = v.Tab(children=['Multiple genotypes']) container_main = v.Container( fluid=True, class_='grid-list-md box', children=[ v.Tabs(children=[ v.Tab(children=['Data extraction']), v.Tab(children=['Single genotype']), tab_3, v.Tab(children=['Waffle']), v.TabItem(children=[tab_extraction_content]), v.TabItem(children=[tab_single_genotype_content]), v.TabItem(children=[tab_multiple_genotype_content]), v.TabItem(children=[tab_waffle_content]), ])
genotypes_selection_waffle, date_selection_waffle, variable_selection_waffle, order_selection_waffle, plot_type_waffle ]) waffle = widgets.Output(layout=layout_output_wgt) tab_waffle_content = v.Row(children=[ v.Card(style_=layout_card, children=[info.p5_doc_waffle]), v.Col(col=12, sm=12, md=12, children=[ menu_plant_waffle, waffle, ]), ]) p5 = v.Tabs(children=[ v.Tab(children=['Waffle']), v.TabItem(children=[tab_waffle_content]), ]) container_main = v.Container(fluid=True, class_='grid-list-md box', children=[p5]) # # ---------------------------------------------------------------- # # Link widgets - event # # ---------------------------------------------------------------- genotypes_selection_waffle.on_event('change', on_change_node_waffle_genotype) date_selection_waffle.on_event('change', on_change_node_waffle_date) variable_selection_waffle.on_event('change', on_change_node_waffle_parameter) plot_type_waffle.on_event('change', on_change_node_plot_type)
def __init__(self, test_case, known_cases): """ Widget definition for lattice Boltzmann schemes. Parameters ========== - test_case: the selected test case. - known_cases: dict A dictionary of all known cases the keys are an instance of a test case the values are a list of available lattice Boltzmann schemes for this test case This widget is composed by a menu where you can Choose the lb scheme and modify its default parameters. If you change any of the parameters, you will see a reset button to revover the default parameters of this scheme. This widget is also composed by a main widget where we have 3 tabs - the description of the lb scheme, - the properties of the lb scheme, - the equivalent equations of the lb scheme. """ self.test_case = test_case self.known_cases = known_cases self.default_cases = {c.name: c for c in known_cases[test_case.get_case()]} self.cases = {c.name: copy.copy(c) for c in known_cases[test_case.get_case()]} self.parameters = {} ## ## The menu ## default_case = list(self.cases.keys())[0] self.select_case = v.Select(items=list(self.cases.keys()), v_model=default_case, label='LBM schemes') self.panels = v.ExpansionPanels(v_model=None, children=[ParametersPanel('Show parameters')]) self.reset = v.Btn(children=['reset to default'], class_='d-none') self.menu = [self.select_case, self.panels, self.reset] ## ## The main ## self.description = Markdown() self.properties = v.Layout() self.eq_pde = v.Layout() self.tabs = v.Tabs( v_model=0, children= [ v.Tab(children=['Description']), v.Tab(children=['Properties']), v.Tab(children=['Equivalent equations']), v.TabItem(children=[self.description]), v.TabItem(children=[self.properties]), v.TabItem(children=[self.eq_pde]), ] ) self.main = [self.tabs] # populate the parameters and the description of the selected # lb scheme self.change_case(None) ## ## Widget events ## self.select_case.observe(self.change_case, 'v_model') # Allow to go back to the default parameters self.reset.on_event('click', self.reset_btn) # Check the tab id to activate the computation # of the equivalent equations or the scheme properties # since it can take time. self.tabs.observe(self.change_tab, 'v_model') # If the test case is changed, we need to list the available # lb schemes for this test. self.test_case.select_case.observe(self.change_test_case, 'v_model') # Bind each parameter to change_param # to make the reset button available if needed. self.panels.children[0].bind(self.change_param)
tab_analyze_content = v.Row(children=[ v.Card(style_=layout_card, children=[info.p3_doc_analyses]), v.Col(col=12, sm=12, md=12, children=[ menu_plant_analyze, v.Row(children=[plot_plantscale, pie_plantscale]), ]), ]) container_main = v.Container(fluid=True, class_='grid-list-md box', children=[ v.Tabs(children=[ v.Tab(children=['Export']), v.Tab(children=['Analyses']), v.TabItem(children=[ tab_extraction_content, ]), v.TabItem(children=[tab_analyze_content]), ]) ]) # # ---------------------------------------------------------------- # # Link widgets - event # # ---------------------------------------------------------------- genotypes_selection_extraction.on_event('change', on_change_genotype_p3_t1) genotypes_selection_analyze.on_event('change', on_change_genotype_p3_t2) date_selection_analyze.on_event('change', on_change_date_p3)
def main(): mc = ModelWidget(cases) tc = TestCaseWidget(mc) lb = LBSchemeWidget(tc) stability = StabilityWidget(tc, lb) simulation = SimulationWidget(tc, lb) parametric = ParametricStudyWidget(tc, lb, simulation.discret, simulation.codegen) posttreatment = PostTreatmentWidget() class DebugWidget: def __init__(self): self.menu = [] self.main = [out] tab_widgets = [ mc, tc, lb, stability, simulation, parametric, posttreatment, DebugWidget() ] tab_titles = [ 'Model', 'Test case', 'Scheme', 'Linear stability', 'LBM Simulation', 'Parametric study', 'Post treatment', 'Debug' ] tab = v.Tabs( v_model=0, center_active=True, fixed_tabs=True, slider_size=4, align_with_title=True, show_arrows=True, children=[v.Tab(children=[k]) for k in tab_titles], ) menu = v.List( children=[], nav=True, v_model='drawer', ) content = v.Content(children=[]) def tab_change(change): tab_id = tab.v_model items = [] if tab_id < 6: items.extend(get_information(tab_id, mc, tc, lb)) widget = tab_widgets[tab_id] items.extend([ v.ListItem( children=[ v.ListItemContent(children=[m]) ] ) for m in widget.menu ]) menu.children = items content.children = widget.main if tab_id == 4: simulation.update_simu_cfg_list() if tab_id == 5: parametric.update_param_cfg_list() if tab_id == 6: posttreatment.update(None) tab_change(None) tab.observe(tab_change, 'v_model') mc.select_category.observe(tab_change, 'v_model') mc.select_model.observe(tab_change, 'v_model') tc.select_case.observe(tab_change, 'v_model') lb.select_case.observe(tab_change, 'v_model') navicon = v.AppBarNavIcon() drawer = v.NavigationDrawer( children=[ v.Row( children=[ v.Img( src='img/pylbm_with_text.svg', max_width=250, class_='ma-5' ) ], align='center', justify='center' ), menu ], v_model=True, width=350, clipped=True, app=True ) def show_drawer(widget, event, data): drawer.v_model = not drawer.v_model navicon.on_event("click.stop", show_drawer) return v.App( children=[ v.AppBar( children=[ navicon, tab, ], clipped_left=True, app=True, dark=True, ), drawer, content, ] )
def __init__(self, cases, default_case): """ Widget definition for test cases. Parameters ========== - cases: dict the keys of this dictionary are the name of the test case, the values of this dictionary are an instance of the test case. - default_case: str one of the keys found into the dictionary cases. This widget is composed by a menu where you can choose the test case and modify its default parameters. If you change any of the parameters, you will see a reset button to revover the default parameters of this case. This widget is also composed by a main widget where a description of the test cases is given and a plot of the reference solution if it exists. """ self.default_cases = cases # make a copy to not modify the input instances self.cases = copy.deepcopy(cases) self.parameters = {} ## ## The menu ## # widget to select the test case self.select_case = v.Select(items=list(self.cases.keys()), v_model=default_case, label='Test cases') self.panels = v.ExpansionPanels( v_model=None, children=[ParametersPanel('Show parameters')]) self.reset = v.Btn(children=['reset to default'], class_='d-none') self.menu = [self.select_case, self.panels, self.reset] ## ## The main ## self.description = Markdown() plt.ioff() self.fig = plt.figure(figsize=(12, 6)) self.fig.canvas.header_visible = False tabs_content = [ v.TabItem(children=[self.description]), v.TabItem(children=[self.fig.canvas]) ] self.tabs = v.Tabs(v_model=None, children=[ v.Tab(children=['Description']), v.Tab(children=['Reference results']) ] + tabs_content) self.main = [self.tabs] # Add the widget events self.reset.on_event('click', self.reset_btn) self.select_case.observe(self.change_case, 'v_model') self.panels.children[0].bind(self.change_param) self.change_case(None)
plot2d_most_central = widgets.Output(layout=layout_output_wgt) panel_2d = v.Row(children=[ v.Col(children=[plot2d_single_p]), v.Col(children=[ plot2d_most_central, ]) ]) tab_2d_content = v.Row(children=[ v.Card(style_=layout_card, children=[info.p2_doc_visu2d]), v.Col(col=12, sm=12, md=12, children=[row_param2d, panel_2d]) ]) # Instantiate tab 3d here to link it to an event tab_3d = v.Tab(children=['3d Visualization']) container_main = v.Container(fluid=True, class_='grid-list-md box', children=[ v.Tabs(children=[ v.Tab(children=['2d Visualization']), tab_3d, v.TabItem(children=[tab_2d_content]), v.TabItem(children=[tab_3d_content]), ]) ]) # # ---------------------------------------------------------------- # # Link widgets - event # # ----------------------------------------------------------------
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 backend_widget(backend: Union[IBMBackend, FakeBackend]) -> None: """Display backend information as a widget. Args: backend: Display information about this backend. """ vue.theme.dark = False if isinstance(backend, FakeBackend): cred = backend._credentials instance = to_instance_format(cred.hub, cred.group, cred.project) else: instance = backend._api_client._params.instance last_tab = vue.TabItem(children=[]) livedata = LiveDataVisualization() card = vue.Card( height=600, outlined=True, children=[ vue.Toolbar( flat=True, color="#002d9c", children=[ vue.ToolbarTitle( children=[ "{} @ ({})".format(backend.name(), instance) ], style_="color:white", ) ], ), vue.Tabs( vertical=True, children=[ vue.Tab(children=["Configuration"]), vue.Tab(children=["Qubits"]), vue.Tab(children=["Non-local Gates"]), vue.Tab(children=["Error map"]), vue.Tab(children=["Live Data"]), vue.Tab(children=["Job Summary"]), vue.TabItem(children=[config_tab(backend)]), vue.TabItem(children=[qubits_tab(backend)]), vue.TabItem(children=[gates_tab(backend)]), vue.TabItem(children=[ iplot_error_map( backend, figsize=(None, None), as_widget=True) ]), vue.TabItem(children=[ iplot_error_map( backend, figsize=(None, None), as_widget=True) ]), vue.TabItem(children=[ livedata.create_visualization( backend, figsize=(11, 9), show_title=False) ]), last_tab, ], ), ], ) # Load job data async for a bit better performance thread = threading.Thread(target=_async_job_loader, args=(last_tab, backend)) thread.start() display(card)
files_description = widgets.Output(layout=layout_output_wgt) panel_files_description = v.Container(fluid=False, children=[files_description]) tab_description_content = v.Row(children=[ v.Col(cols=12, sm=3, md=3, children=[files_selection]), v.Col(cols=12, sm=7, md=9, children=[panel_files_description]) ]) container_main = v.Container( fluid=True, class_='grid-list-md box', children=[ v.Tabs(children=[ v.Tab(children=['Import Files']), v.Tab(children=['Files Description']), v.TabItem(children=[tab_MTG_content]), v.TabItem(children=[tab_description_content]) ]) ]) # # ---------------------------------------------------------------- # # Link widgets - event # # ---------------------------------------------------------------- widgets.jslink((slider_n_plant, 'v_model'), (box_n_plant, 'v_model')) files_selection.on_event('change', on_change_get_files) cb_allplants.on_event('change', on_click_allp) genotypes_selection.on_event('change', on_change_genotype)
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, children=tab_children) app = v.App(style_="background: white", children=[ toolbar, v.Container( fluid=True, mt_3=True,
def main(): tc = TestCaseWidget(cases, default_case) lb = LBSchemeWidget(tc, known_cases) stability = StabilityWidget(tc, lb) simulation = SimulationWidget(tc, lb) parametric = ParametricStudyWidget(tc, lb, simulation.discret) posttreatment = PostTreatmentWidget() class DebugWidget: def __init__(self): self.menu = [] self.main = [out] tab_widgets = [ tc, lb, stability, simulation, parametric, posttreatment, DebugWidget() ] tab_titles = [ 'Test case', 'Scheme', 'Linear stability', 'LBM Simulation', 'Parametric study', 'Post treatment', 'Debug' ] tab = v.Tabs( v_model=0, center_active=True, fixed_tabs=True, slider_size=4, align_with_title=True, show_arrows=True, children=[v.Tab(children=[k]) for k in tab_titles], ) menu = v.List( children=[], nav=True, v_model='drawer', ) content = v.Content(children=[]) def tab_change(change): tab_id = tab.v_model widget = tab_widgets[tab_id] menu.children = [ v.ListItem(children=[v.ListItemContent(children=[m])]) for m in widget.menu ] content.children = widget.main if tab_id == 5: posttreatment.update(None) tab_change(None) tab.observe(tab_change, 'v_model') navicon = v.AppBarNavIcon() drawer = v.NavigationDrawer(children=[ v.Row(children=[ v.Img( src= 'https://pylbm.readthedocs.io/en/latest/_static/img/pylbm_with_text.svg', max_width=250, class_='ma-5') ], align='center', justify='center'), menu ], v_model=True, width=350, clipped=True, app=True) def show_drawer(widget, event, data): drawer.v_model = not drawer.v_model navicon.on_event("click.stop", show_drawer) return v.App(children=[ v.AppBar( children=[ navicon, tab, ], clipped_left=True, app=True, dark=True, ), drawer, content, ])