Ejemplo n.º 1
0
def load_session():
    '''
	load a previously saved session
	'''

    if curdoc().select_one({"name": "session_input"}).value == "":
        curdoc().select_one({
            "name": "status_div"
        }).text = 'You need to select a previous session first'
        return

    select_session = curdoc().select_one({"name": "session_input"}).value
    json_string = np.load(os.path.join(save_path, select_session)).item()

    new_doc = Document.from_json_string(json_string)
    new_grid_models = collect_models(new_doc.roots[0])

    for elem in new_grid_models:
        try:
            elem.document = curdoc()
        except AttributeError:
            elem._document = curdoc()

    new_children = new_doc.roots[0].children

    del grid.children

    grid.children = new_children

    # re-attribute the python callbacks to the widgets
    curdoc().select_one({"name": "do_stuff_button"}).on_click(do_stuff)
    curdoc().select_one({"name": "save_button"}).on_click(save_session)
    curdoc().select_one({"name": "clear_button"}).on_click(clear_fig)
    curdoc().select_one({"name": "load_button"}).on_click(load_session)

    # do custom stuff for the update
    curdoc().select_one({
        "name": "session_input"
    }).options = [''] + os.listdir(save_path)
    curdoc().select_one({"name": "session_input"}).value = select_session
Ejemplo n.º 2
0
def test_structure(pd):
    f = figure(width=400, height=400)
    f.line(x=[1, 2, 3], y=[1, 2, 3])
    K = generate_structure_plot(f)
    assert 43 == len(collect_models(K))