def restore_session(path): """ Reload a previously-saved session Parameters ---------- path : str Path to the file to load Returns ------- app : :class:`Application` The loaded application """ from glue.core.state import GlueUnSerializer # In case relative paths are needed in the session file, we do the # loading while setting the current directory to the directory # in which the session file is so that relative paths are interpreted # as relative to the session file. start_dir = os.path.abspath('.') session_dir = os.path.dirname(path) or '.' session_file = os.path.basename(path) try: os.chdir(session_dir) with open(session_file) as infile: state = GlueUnSerializer.load(infile) return state.object('__main__') finally: os.chdir(start_dir)
def restore_session(path): """ Reload a previously-saved session Parameters ---------- path : str Path to the file to load Returns ------- app : :class:`Application` The loaded application """ from glue.core.state import GlueUnSerializer with open(path) as infile: state = GlueUnSerializer.load(infile) return state.object('__main__')
def test_table_widget_010(): from glue.viewers.table.qt.tests.test_data_viewer import check_values_and_color # This loads a session file made with Glue v0.10 that includes a table # viewer. This is to make sure that loading table viewers from old files # will always be backward-compatible. with open(os.path.join(DATA, 'glue_v0.10_table.glu'), 'r') as f: state = GlueUnSerializer.load(f) ga = state.object('__main__') viewer = ga.viewers[0][0] data = {'x': [1, 2, 3], 'y': [4, 5, 6]} colors = ['#e31a1c', '#6d7326', None] check_values_and_color(viewer.model, data, colors) ga.close()