def _make_delay_tab(box_factory, selected_index=0): """ Parameters ---------- box_factory : list of (func, tab_name) Example of box_factory: [(_make_gen_box, 'General'), (_make_repr_box, 'Representation')] """ tab = Tab([Box() for box, _ in box_factory]) [tab.set_title(i, title) for i, (_, title) in enumerate(box_factory)] # trick if not tab.children[selected_index].children: tab.selected_index = 1 def on_update_selected_index(change): index = change['new'] if not tab.children[index].children: # make widget on demand tab.children[index].children = [ box_factory[index][0](), ] tab.observe(on_update_selected_index, names='selected_index') # trigger tab.selected_index = selected_index return tab
def _make_delay_tab(box_factory, selected_index=0): """ Parameters ---------- box_factory : list of (func, tab_name) Example of box_factory: [(_make_gen_box, 'General'), (_make_repr_box, 'Representation')] """ tab = Tab([Box() for box, _ in box_factory]) [tab.set_title(i, title) for i, (_, title) in enumerate(box_factory)] # trick if not tab.children[selected_index].children: tab.selected_index = -1 def on_update_selected_index(change): index = change['new'] if not tab.children[index].children: # make widget on demand tab.children[index].children = [box_factory[index][0](),] tab.observe(on_update_selected_index, names='selected_index') # trigger tab.selected_index = selected_index return tab
def display_html(vals): ''' Convert objects into three AXON forms for output in IPython notebook. :param vals: List of objects or ordered dict. :returns: IPython TabbedView widget. ''' try: from ipywidgets import Tab, HTML except: from IPython.html.widgets import Tab, HTML # Compact form p1 = dumps(vals, crossref=1) # Formatted form without braces p2 = dumps(vals, pretty=1, crossref=1) # Formatted form with braces p3 = dumps(vals, pretty=1, braces=1, crossref=1) wg = Tab( ( HTML("<pre>%s</pre>" % p1), HTML("<pre>%s</pre>" % p2), HTML("<pre>%s</pre>" % p3)) ) wg.set_title(0, "Compact") wg.set_title(1, "Formatted") wg.set_title(2, "Formatted with {}") wg.selected_index = 1 return wg