def test_pass_layout_options(self): #pylint: disable=no-self-use """test whether the extra layout options of the template class are passed down to Layout object""" button1 = widgets.Button() button2 = widgets.Button() button3 = widgets.Button() button4 = widgets.Button() box = widgets.TwoByTwoLayout(top_left=button1, top_right=button2, bottom_left=button3, bottom_right=button4, grid_gap="10px", justify_content="center", align_items="center") assert box.layout.grid_gap == "10px" assert box.layout.justify_content == "center" assert box.layout.align_items == "center" # we still should be able to pass them through layout layout = widgets.Layout(grid_gap="10px", justify_content="center", align_items="center") box = widgets.TwoByTwoLayout(top_left=button1, top_right=button2, bottom_left=button3, bottom_right=button4, layout=layout) assert box.layout.grid_gap == "10px" assert box.layout.justify_content == "center" assert box.layout.align_items == "center" # values passed directly in the constructor should overwrite layout options layout = widgets.Layout(grid_gap="10px", justify_content="center", align_items="center") box = widgets.TwoByTwoLayout(top_left=button1, top_right=button2, bottom_left=button3, bottom_right=button4, layout=layout, grid_gap="30px") assert box.layout.grid_gap == "30px" assert box.layout.justify_content == "center" assert box.layout.align_items == "center"
def __init__(self, min_incidence=150): self.min_incidence = min_incidence self.max_incidence = None self.widget_min_incidence = widgets.IntText( value=min_incidence, description="Minimum:", disabled=False ) self.widget_max_incidence = widgets.IntText( value=2000, description="Maximum:", disabled=False ) self.widget_button = widgets.Button( description="Retracer", disabled=False, button_style="", # 'success', 'info', 'warning', 'danger' or '' tooltip="Retracer la figure avec les nouvelles données d'entrée", icon="sync-alt", # (FontAwesome names without the `fa-` prefix) ) self.widget_date_picker = widgets.DatePicker( description="Date début", value=create_date_object(default_first_day_in_plot), disabled=False, ) self.widget_button.on_click(self.sync) self.layout_inputs = widgets.TwoByTwoLayout( top_left=self.widget_max_incidence, bottom_left=self.widget_min_incidence, top_right=self.widget_date_picker, bottom_right=self.widget_button, )
def test_update_dynamically(self, send_state): #pylint: disable=no-self-use """test whether it's possible to add widget outside __init__""" button1 = widgets.Button() button2 = widgets.Button() button3 = widgets.Button() button4 = widgets.Button() box = widgets.TwoByTwoLayout(top_left=button1, top_right=button3, bottom_left=None, bottom_right=button4) from ipykernel.kernelbase import Kernel state = box.get_state() assert len(state['children']) == 3 assert box.layout.grid_template_areas == ('"top-left top-right"\n' + '"top-left bottom-right"') box.layout.comm.kernel = mock.MagicMock( spec=Kernel) #for mocking purposes send_state.reset_mock() box.bottom_left = button2 state = box.get_state() assert len(state['children']) == 4 assert box.layout.grid_template_areas == ('"top-left top-right"\n' + '"bottom-left bottom-right"') # check whether frontend was informed send_state.assert_called_once_with(key="grid_template_areas") box = widgets.TwoByTwoLayout(top_left=button1, top_right=button3, bottom_left=None, bottom_right=button4) assert box.layout.grid_template_areas == ('"top-left top-right"\n' + '"top-left bottom-right"') box.layout.comm.kernel = mock.MagicMock( spec=Kernel) #for mocking purposes send_state.reset_mock() box.merge = False assert box.layout.grid_template_areas == ('"top-left top-right"\n' + '"bottom-left bottom-right"') send_state.assert_called_once_with(key="grid_template_areas")
def test_keep_layout_options(self): #pylint: disable=no-self-use """test whether layout options are passed down to GridBox""" layout = widgets.Layout(align_items="center") button1 = widgets.Button() button2 = widgets.Button() button3 = widgets.Button() button4 = widgets.Button() box = widgets.TwoByTwoLayout(top_left=button1, top_right=button2, bottom_left=button3, bottom_right=button4, layout=layout) assert box.layout.align_items == 'center'
def __init__(self, loc="France"): self.loc = loc self.widget_yscale = widgets.RadioButtons( options=["log", "linear", "linear daily"], value="linear", description="Type:", disabled=False, ) self.widget_yscale.observe(self.change_yscale) if loc != "France": self.widget_dep = widgets.Dropdown( options=[ (idep + " - " + dep, idep) for idep, dep in DEPARTMENTS.items() ], value=loc, description="Département :", ) self.widget_dep.observe(self.change_dep) top_left = self.widget_dep else: top_left = None self.widget_date_picker = widgets.DatePicker( description="Date début", value=create_date_object(default_first_day_in_plot), disabled=False, ) self.widget_date_picker.observe(self.change_date) self.layout_inputs = widgets.TwoByTwoLayout( top_left=top_left, bottom_left=self.widget_date_picker, top_right=self.widget_yscale, bottom_right=None, ) self.ax = None self.axes_incidence = None self.axes_hospi = None
def __init__(self, min_incidence=min_incidence_default): self.index_friday = 0 self.last_days = False self.min_incidence = min_incidence self.max_incidence = None self.ax = None options = [ "Derniers jours", "Dernière semaine", "Avant dernière semaine", "Avant avant dernière semaine", ] self.widget_date = widgets.Dropdown(options=options, value=options[1], description="Période :") self.widget_date.observe(self.handle_change_date) self.widget_min_incidence = widgets.IntText(value=min_incidence, description="Minimum:", disabled=False) self.widget_max_incidence = widgets.IntText(value=10000, description="Maximum:", disabled=False) self.widget_button = widgets.Button( description="Retracer", disabled=False, button_style="", # 'success', 'info', 'warning', 'danger' or '' tooltip="Retracer la figure avec les nouvelles données d'entrée", icon="sync-alt", # (FontAwesome names without the `fa-` prefix) ) self.widget_button.on_click(self.sync) self.layout_inputs = widgets.TwoByTwoLayout( top_left=self.widget_max_incidence, bottom_left=self.widget_min_incidence, top_right=self.widget_button, )
def get_case_explorer(): return ipw.TwoByTwoLayout( top_left=ipw.VBox( [ em_reset, ipw.HBox( [ ipw.VBox([cw, em_case_select]), ipw.VBox([tw, em_table_select]), ipw.VBox([fw, em_column_select]), ipw.VBox([vw, em_filter_select]), ipw.VBox([pw, em_viz_select]), ] ), em_slice_select, em_table_out, ], layout=ipw.Layout(width="100%", min_height="200px", border="solid"), ), bottom_left=ipw.HBox([em_plots_out1]), layout=ipw.Layout(width="100%"), )
def get_explorer(): return ipw.TwoByTwoLayout( top_left=ipw.VBox( [ reset, ipw.HBox( [ ipw.VBox([cw, case_select]), ipw.VBox([tw, table_select]), ipw.VBox([fw, column_select]), ipw.VBox([vw, filter_select]), ipw.VBox([pw, viz_select]), ] ), slice_select, table_out, ], layout=ipw.Layout(width="100%", min_height="200px", border="solid"), ), bottom_left=ipw.HBox( [ipw.VBox([ipw.HBox([fillna]), histo_out])], layout=ipw.Layout(width="100%") ), )
def test_merge_cells(self): #pylint: disable=no-self-use """test merging cells with missing widgets""" button1 = widgets.Button() button2 = widgets.Button() button3 = widgets.Button() button4 = widgets.Button() box = widgets.TwoByTwoLayout(top_left=button1, top_right=button2, bottom_left=button3, bottom_right=button4) assert box.layout.grid_template_areas == ('"top-left top-right"\n' + '"bottom-left bottom-right"') assert box.top_left.layout.grid_area == 'top-left' assert box.top_right.layout.grid_area == 'top-right' assert box.bottom_left.layout.grid_area == 'bottom-left' assert box.bottom_right.layout.grid_area == 'bottom-right' assert len(box.get_state()['children']) == 4 box = widgets.TwoByTwoLayout(top_left=button1, top_right=button2, bottom_left=None, bottom_right=button4) assert box.layout.grid_template_areas == ('"top-left top-right"\n' + '"top-left bottom-right"') assert box.top_left.layout.grid_area == 'top-left' assert box.top_right.layout.grid_area == 'top-right' assert box.bottom_left is None assert box.bottom_right.layout.grid_area == 'bottom-right' assert len(box.get_state()['children']) == 3 box = widgets.TwoByTwoLayout(top_left=None, top_right=button2, bottom_left=button3, bottom_right=button4) assert box.layout.grid_template_areas == ('"bottom-left top-right"\n' + '"bottom-left bottom-right"') assert box.top_left is None assert box.top_right.layout.grid_area == 'top-right' assert box.bottom_left.layout.grid_area == 'bottom-left' assert box.bottom_right.layout.grid_area == 'bottom-right' assert len(box.get_state()['children']) == 3 box = widgets.TwoByTwoLayout(top_left=None, top_right=button2, bottom_left=None, bottom_right=button4) assert box.layout.grid_template_areas == ( '"top-right top-right"\n' + '"bottom-right bottom-right"') assert box.top_left is None assert box.top_right.layout.grid_area == 'top-right' assert box.bottom_left is None assert box.bottom_right.layout.grid_area == 'bottom-right' assert len(box.get_state()['children']) == 2 box = widgets.TwoByTwoLayout(top_left=button1, top_right=None, bottom_left=button3, bottom_right=button4) assert box.layout.grid_template_areas == ('"top-left bottom-right"\n' + '"bottom-left bottom-right"') assert box.top_left.layout.grid_area == 'top-left' assert box.top_right is None assert box.bottom_left.layout.grid_area == 'bottom-left' assert box.bottom_right.layout.grid_area == 'bottom-right' assert len(box.get_state()['children']) == 3 box = widgets.TwoByTwoLayout(top_left=button1, top_right=None, bottom_left=None, bottom_right=None) assert box.layout.grid_template_areas == ('"top-left top-left"\n' + '"top-left top-left"') assert box.top_left is button1 assert box.top_left.layout.grid_area == 'top-left' assert box.top_right is None assert box.bottom_left is None assert box.bottom_right is None assert len(box.get_state()['children']) == 1 box = widgets.TwoByTwoLayout(top_left=None, top_right=button1, bottom_left=None, bottom_right=None) assert box.layout.grid_template_areas == ('"top-right top-right"\n' + '"top-right top-right"') assert box.top_right is button1 assert box.top_right.layout.grid_area == 'top-right' assert box.top_left is None assert box.bottom_left is None assert box.bottom_right is None assert len(box.get_state()['children']) == 1 box = widgets.TwoByTwoLayout(top_left=None, top_right=None, bottom_left=None, bottom_right=None) assert box.layout.grid_template_areas is None assert box.top_left is None assert box.top_right is None assert box.bottom_left is None assert box.bottom_right is None assert not box.get_state()['children'] box = widgets.TwoByTwoLayout(top_left=None, top_right=button1, bottom_left=None, bottom_right=None, merge=False) assert box.layout.grid_template_areas == ('"top-left top-right"\n' + '"bottom-left bottom-right"') assert box.top_right is button1 assert box.top_right.layout.grid_area == 'top-right' assert box.top_left is None assert box.bottom_left is None assert box.bottom_right is None assert len(box.get_state()['children']) == 1
def table_app(df): def save_filtered_data(_): filtered_df = filter_df(df, order_by=order_by.value, ascending=ascending.value, required=filter_selector.value, search_column=search_column.value, search_term=search_term.value) filtered_df.to_csv(save_fn.value) save_status.value = '\t sucessfully saved {} rows as {}.'.format( len(filtered_df), save_fn.value) def plot_filtered(df, required, search_column, search_term, plot_column): filtered_df = filter_df(df, order_by=order_by.value, required=required, search_column=search_column, search_term=search_term) plot_column_dist(df=filtered_df, column=plot_column) nb_items = widgets.Dropdown(options=[10, 20, 50], description='items per page', layout=Layout(width='20%')) order_by = widgets.Dropdown(options=sorted(df.keys()), description='order by') ascending = widgets.ToggleButton(value=True, description='ascending') sorting = widgets.HBox([order_by, ascending, nb_items], layout=Layout(height='50px')) filter_selector = widgets.SelectMultiple(options=sorted(df.keys())) filter_tip = widgets.VBox([ widgets.HTML('Select multiple by dragging or ctrl + click'), widgets.HTML('Deselect with ctrl + click') ]) filtering = widgets.HBox([filter_selector, filter_tip]) save_button = widgets.Button(description='save') save_fn = widgets.Text('filtered_data.csv') save_button.on_click(save_filtered_data) save_status = widgets.Label() saving = widgets.HBox([save_fn, save_button, save_status]) search_term = widgets.Text('', tooltip='Search') search_column = widgets.Dropdown(options=df.keys()) plot_column = widgets.Dropdown(options=df.keys()) column_dist = interactive_output( plot_filtered, dict(df=fixed(df), search_column=search_column, required=filter_selector, search_term=search_term, plot_column=plot_column)) column_plot_box = widgets.VBox( [widgets.Label('Plot Columns'), plot_column, column_dist]) search_box = widgets.VBox( [widgets.Label('Search Columns'), search_column, search_term]) searching = widgets.TwoByTwoLayout(top_left=search_box, top_right=column_plot_box) widgets.dlink((search_column, 'value'), (plot_column, 'value')) accordion = widgets.Tab(children=[sorting, filtering, searching, saving]) accordion.set_title(0, 'Sorting') accordion.set_title(1, 'Required Values') accordion.set_title(2, 'Searching') accordion.set_title(3, 'Save filtered Data') interactive_table = interactive_output( show_filtered_df, dict(df=fixed(df), order_by=order_by, nb_items=nb_items, required=filter_selector, ascending=ascending, search_column=search_column, search_term=search_term)) display(widgets.VBox([accordion, interactive_table]))