Exemple #1
0
def store_session():
    """ Stores reference backup information for all open tabs into runtime config

    The backup of never stored tabs (state machines) and not stored state machine changes will be triggered a last
    time to secure data lose.
    """
    from rafcon.gui.singleton import state_machine_manager_model, global_runtime_config
    from rafcon.gui.models.auto_backup import AutoBackupModel
    from rafcon.gui.models import AbstractStateModel
    from rafcon.gui.singleton import main_window_controller
    # check if there are dirty state machines -> use backup file structure maybe it is already stored
    for sm_m in state_machine_manager_model.state_machines.values():
        if sm_m.auto_backup:
            if sm_m.state_machine.marked_dirty:
                sm_m.auto_backup.perform_temp_storage()
        else:
            # generate a backup
            sm_m.auto_backup = AutoBackupModel(sm_m)

    # collect order of tab state machine ids from state machines editor and find selected state machine page number
    state_machines_editor_ctrl = main_window_controller.get_controller(
        'state_machines_editor_ctrl')
    number_of_pages = state_machines_editor_ctrl.view['notebook'].get_n_pages()
    selected_page_number = None
    list_of_tab_meta = []
    for page_number in range(number_of_pages):
        page = state_machines_editor_ctrl.view['notebook'].get_nth_page(
            page_number)
        sm_id = state_machines_editor_ctrl.get_state_machine_id_for_page(page)
        if sm_id == state_machine_manager_model.selected_state_machine_id:
            selected_page_number = page_number

        # backup state machine selection
        selection_of_sm = []
        for model in state_machine_manager_model.state_machines[
                sm_id].selection.get_all():
            if isinstance(model, AbstractStateModel):
                # TODO extend to full range of selection -> see core_identifier action-module
                selection_of_sm.append(model.state.get_path())

        list_of_tab_meta.append({
            'backup_meta':
            state_machine_manager_model.state_machines[sm_id].auto_backup.meta.
            to_dict(native_strings=True),
            'selection':
            selection_of_sm
        })

    # store final state machine backup meta data to backup session tabs and selection for the next run
    global_runtime_config.set_config_value('open_tabs', list_of_tab_meta)
    global_runtime_config.set_config_value(
        'selected_state_machine_page_number', selected_page_number)
Exemple #2
0
def reset_session():
    """Remove all information from the current session """
    from rafcon.gui.singleton import global_runtime_config
    global_runtime_config.set_config_value('open_tabs', [])
    global_runtime_config.set_config_value(
        'selected_state_machine_page_number', None)