Beispiel #1
0
def main():

    # check if all env variables are set
    if not os.environ.get("HOME", False):
        logger.error(
            "For starting RAFCON in GUI mode, the HOME environment variable has to be set!"
        )
        return

    register_signal_handlers(signal_handler)

    splash_screen = SplashScreen(contains_image=True, width=530, height=350)
    splash_screen.rotate_image(random_=True)
    splash_screen.set_text(_("Starting RAFCON..."))
    while gtk.events_pending():
        gtk.main_iteration()

    setup_installation()
    setup_l10n()
    setup_l10n_gtk()

    splash_screen.set_text("Setting up logger...")
    setup_gtkmvc_logger()

    splash_screen.set_text("Initializing plugins...")
    pre_setup_plugins()

    splash_screen.set_text("Setting up environment...")
    setup_mvc_environment()

    parser = setup_argument_parser()
    user_input = parser.parse_args()

    splash_screen.set_text("Loading configurations...")
    setup_mvc_configuration(user_input.config_path, user_input.gui_config_path,
                            user_input.gui_config_path)

    # create lock file -> keep behavior for hole instance
    if global_gui_config.get_config_value('AUTO_RECOVERY_LOCK_ENABLED'):
        rafcon.gui.models.auto_backup.generate_rafcon_instance_lock_file()

    # setup the gui before loading the state machine as then the debug console shows the errors that emerged during
    # loading the state state machine
    splash_screen.set_text("Loading GUI...")
    setup_gui()

    wait_for_gui()

    post_setup_plugins(user_input)

    state_machine = None
    if user_input.state_machine_paths:
        state_machine = open_state_machines(user_input.state_machine_paths)

    if user_input.new:
        create_new_state_machine()

    # initiate stored session # TODO think about a controller for this
    if not user_input.new and not user_input.state_machine_paths \
            and rafcon.gui.singleton.global_gui_config.get_config_value("SESSION_RESTORE_ENABLED"):
        glib.idle_add(backup_session.restore_session_from_runtime_config,
                      priority=glib.PRIORITY_LOW)

    if state_machine and (user_input.start_state_machine_flag
                          or state_machine.get_state_by_path(
                              user_input.start_state_path)):
        start_state_machine(state_machine, user_input.start_state_path,
                            user_input.quit_flag)

    splash_screen.destroy()
    try:
        start_gtk()

        logger.info(_("Main window was closed"))

    finally:
        post_gui_destruction()

    if core_singletons.state_machine_execution_engine.status.execution_mode == StateMachineExecutionStatus.STARTED:
        logger.info(_("Waiting for the state machine execution to finish"))
        core_singletons.state_machine_execution_engine.join()
        logger.info(_("State machine execution has finished"))

    logger.info(_("Exiting ..."))
Beispiel #2
0
def main():

    # check if all env variables are set
    if not os.environ.get("HOME", False):
        logger.error("For starting RAFCON in GUI mode, the HOME environment variable has to be set!")
        return

    register_signal_handlers(signal_handler)

    setup_l10n(logger)

    parser = setup_argument_parser()
    user_input = parser.parse_args()

    if user_input.memory_profiling:
        tracemalloc.start()
        memory_profiling_args = {
            'memory_profiling_path': user_input.memory_profiling_path,
            'memory_profiling_interval': user_input.memory_profiling_interval,
            'memory_profiling_print': user_input.memory_profiling_print,
            'stop': False,
        }
        memory_profiling_thread = threading.Thread(target=profiling.memory_profiling, args=(memory_profiling_args,))
        memory_profiling_thread.start()

    setup_mvc_environment()
    setup_mvc_configuration(user_input.config_path, user_input.gui_config_path,
                            user_input.gui_config_path, user_input.design_config_path)

    splash_screen = create_splash_screen()
    while Gtk.events_pending():
        Gtk.main_iteration()

    splash_screen.set_text("Install missing resources ...")
    setup_installation()

    splash_screen.set_text("Setting up logger...")
    setup_gtkmvc3_logger()

    splash_screen.set_text("Initializing plugins...")
    pre_setup_plugins()

    splash_screen.set_text("Setting up environment...")

    # create lock file -> keep behavior for hole instance
    if global_gui_config.get_config_value('AUTO_RECOVERY_LOCK_ENABLED'):
        import rafcon.gui.models.auto_backup
        rafcon.gui.models.auto_backup.generate_rafcon_instance_lock_file()

    # setup the gui before loading the state machine as then the debug console shows the errors that emerged during
    # loading the state state machine
    splash_screen.set_text("Loading GUI...")
    setup_gui()
    wait_for_gui()

    post_setup_plugins(user_input)

    state_machine = None
    if user_input.state_machine_paths:
        state_machine = open_state_machines(user_input.state_machine_paths)

    if user_input.new:
        create_new_state_machine()

    # initiate stored session # TODO think about a controller for this
    if not user_input.new and not user_input.state_machine_paths \
            and global_gui_config.get_config_value("SESSION_RESTORE_ENABLED"):
        # do in background in order not to block GUI
        GLib.idle_add(backup_session.restore_session_from_runtime_config, priority=GLib.PRIORITY_LOW)

    if state_machine and (user_input.start_state_machine_flag or state_machine.get_state_by_path(user_input.start_state_path)):
        start_state_machine(state_machine, user_input.start_state_path, user_input.quit_flag)

    splash_screen.destroy()
    try:
        start_gtk()

        logger.info(_("Main window was closed"))

    finally:
        post_gui_destruction()

    if core_singletons.state_machine_execution_engine.status.execution_mode == StateMachineExecutionStatus.STARTED:
        logger.info(_("Waiting for the state machine execution to finish"))
        # overwriting signal handlers here does not work either
        import rafcon
        rafcon.core.start.register_signal_handlers(rafcon.core.start.signal_handler)
        core_singletons.state_machine_execution_engine.join()
        logger.info(_("State machine execution has finished"))
        core_singletons.state_machine_manager.delete_all_state_machines()

    logger.info(_("Exiting ..."))
    logging.shutdown()

    if user_input.memory_profiling:
        memory_profiling_args['stop'] = True
        memory_profiling_thread.join()