示例#1
0
def initialize_environment_gui(gui_config=None, runtime_config=None):

    from rafcon.gui.config import global_gui_config
    from rafcon.gui.runtime_config import global_runtime_config
    global GUI_INITIALIZED

    if GUI_INITIALIZED:
        raise DeprecationWarning("Deprecated use of environment initialization. The gui was already initialized.")

    # initialize global gui config
    if isinstance(gui_config, tuple) and exists(join(gui_config[1], gui_config[0])):
        global_gui_config.load(gui_config[1], gui_config[0])
    else:
        global_gui_config.load(path=RAFCON_TEMP_PATH_CONFIGS)
        if isinstance(gui_config, dict):
            for key, value in gui_config.items():
                global_gui_config.set_config_value(key, value)

    # initialize global runtime config
    if isinstance(runtime_config, tuple) and exists(join(runtime_config[1], runtime_config[0])):
        global_runtime_config.load(runtime_config[1], runtime_config[0])
    else:
        global_runtime_config.load(path=RAFCON_TEMP_PATH_CONFIGS)
        if isinstance(runtime_config, dict):
            for key, value in runtime_config.items():
                global_runtime_config.set_config_value(key, value)

    GUI_INITIALIZED = True
示例#2
0
文件: start.py 项目: DLR-RM/RAFCON
def setup_mvc_configuration(core_config_path, gui_config_path, runtime_config_path, design_config):
    """ Loads all configurations from disk

    :param core_config_path: the path to the core configuration file
    :param gui_config_path:  the path to the gui configuration file
    :param runtime_config_path:  the path to the runtime configuration file
    :param design_config:  the path to the design configuration file
    :return:
    """
    setup_configuration(core_config_path)
    # the design config has to be loaded before loading the gui config as it is used by the gui config
    if design_config:
        design_config_path, design_config_file = filesystem.separate_folder_path_and_file_name(design_config)
        global_design_config.load(design_config_file, design_config_path)
        # the constant has to be overwritten here,
        # as the singleton was already loaded that hus the wrong INTERFACE_FONT was chosen
        from rafcon.gui.utils import constants
        constants.INTERFACE_FONT = global_design_config.get_config_value("PRIMARY_FONT")
    else:
        # no design config file specified => check environment variable
        if os.environ.get('RAFCON_CUSTOM_DESIGN'):
            design_config = os.environ.get('RAFCON_CUSTOM_DESIGN')
            design_config_path, design_config_file = filesystem.separate_folder_path_and_file_name(design_config)
            global_design_config.load(design_config_file, design_config_path)
    gui_config_path, gui_config_file = filesystem.separate_folder_path_and_file_name(gui_config_path)
    global_gui_config.load(gui_config_file, gui_config_path)
    runtime_config_path, runtime_config_file = filesystem.separate_folder_path_and_file_name(runtime_config_path)
    global_runtime_config.load(runtime_config_file, runtime_config_path)
示例#3
0
def run_turtle_demo():
    import rafcon.core
    import rafcon.core.start
    signal.signal(signal.SIGINT, rafcon.core.start.signal_handler)
    global_config.load()
    global_gui_config.load()
    # set the test_libraries path temporarily to the correct value
    library_paths = rafcon.core.config.global_config.get_config_value(
        "LIBRARY_PATHS")
    if os.path.exists(
            str(os.path.sep).join(
                [rafcon.__path__[0], '..', '..', '..', 'share',
                 'libraries'])):  # rm-pkg
        os.environ['RAFCON_LIB_PATH'] = os.path.join(rafcon.__path__[0], '..',
                                                     '..', '..', 'share',
                                                     'libraries')
        library_paths["ros_libraries"] = os.path.join(rafcon.__path__[0], '..',
                                                      '..', '..', 'share',
                                                      'examples', 'libraries',
                                                      'ros_libraries')
        library_paths["turtle_libraries"] = os.path.join(
            rafcon.__path__[0], '..', '..', '..', 'share', 'examples',
            'libraries', 'turtle_libraries')
        example_path = os.path.join(rafcon.__path__[0], os.pardir, '..', '..',
                                    'share', 'examples', "tutorials")
    else:  # git repo
        os.environ['RAFCON_LIB_PATH'] = os.path.join(
            dirname(abspath(__file__)), '..', '..', '..', 'libraries')
        library_paths["ros_libraries"] = os.path.join(
            dirname(abspath(__file__)), '..', '..', 'libraries',
            'ros_libraries')
        library_paths["turtle_libraries"] = os.path.join(
            dirname(abspath(__file__)), '..', '..', 'libraries',
            'turtle_libraries')
        example_path = os.path.join(dirname(abspath(__file__)), '..', '..',
                                    "tutorials")
    rafcon.core.singleton.library_manager.initialize()
    rafcon.core.singleton.state_machine_manager.delete_all_state_machines()
    base_path = os.path.dirname(os.path.abspath(__file__))

    basic_turtle_demo_state = create_turtle_statemachine(
        base_path, example_path)
    state_machine = StateMachine(basic_turtle_demo_state)

    # # load the state machine
    # [state_machine, version, creation_time] = storage.load_statemachine_from_path(
    #     "../../share/examples/tutorials/basic_turtle_demo_sm")

    rafcon.core.singleton.library_manager.initialize()
    main_window_view = MainWindowView()
    rafcon.core.singleton.state_machine_manager.add_state_machine(
        state_machine)
    sm_manager_model = rafcon.gui.singleton.state_machine_manager_model

    main_window_controller = MainWindowController(sm_manager_model,
                                                  main_window_view)

    gtk.main()
    logger.debug("Gtk main loop exited!")
示例#4
0
def setup_mvc_configuration(core_config_path, gui_config_path,
                            runtime_config_path):
    setup_configuration(core_config_path)
    gui_config_path, gui_config_file = filesystem.separate_folder_path_and_file_name(
        gui_config_path)
    global_gui_config.load(gui_config_file, gui_config_path)
    runtime_config_path, runtime_config_file = filesystem.separate_folder_path_and_file_name(
        runtime_config_path)
    global_runtime_config.load(runtime_config_file, runtime_config_path)
示例#5
0
def start_client(interacting_function, queue_dict):
    from rafcon.gui.config import global_gui_config
    import os

    from rafcon.gui.controllers.main_window import MainWindowController
    from rafcon.gui.views.main_window import MainWindowView
    import rafcon.gui.singleton as gui_singletons
    from rafcon.gui.runtime_config import global_runtime_config
    from rafcon.gui.start import signal_handler

    import rafcon
    from rafcon.utils import log
    from rafcon.utils import plugins

    from rafcon.core.config import global_config
    from rafcon.core.storage import storage as global_storage
    from rafcon.core.state_machine import StateMachine
    from rafcon.core.states.hierarchy_state import HierarchyState
    import rafcon.core.singleton as core_singletons
    from rafcon.core.start import setup_environment

    # load all plugins specified in the RAFCON_PLUGIN_PATH
    plugins.load_plugins()
    import testing_utils

    # check if twisted is imported
    if "twisted" in sys.modules.keys():
        from twisted.internet import gtk2reactor
        # needed for glib.idle_add, and signals
        gtk2reactor.install()
        from twisted.internet import reactor
    else:
        print "Twisted not imported! Thus the gkt2reatcor is not installed!"
        exit()

    plugins.run_pre_inits()

    setup_logger()
    logger = log.get_logger("start")
    logger.info("RAFCON launcher")

    setup_environment()

    signal.signal(signal.SIGINT, signal_handler)

    global_config.load(path=os.path.dirname(os.path.abspath(__file__)))
    global_gui_config.load(path=os.path.dirname(os.path.abspath(__file__)))
    global_runtime_config.load(path=os.path.dirname(os.path.abspath(__file__)))

    setup_config = dict()
    setup_config["net_config_path"] = os.path.abspath(path=os.path.join(
        os.path.dirname(os.path.abspath(__file__)), "client"))

    # Initialize library
    core_singletons.library_manager.initialize()

    # Create the GUI
    main_window_view = MainWindowView()

    state_machine = global_storage.load_state_machine_from_path(
        testing_utils.get_test_sm_path(
            os.path.join("unit_test_state_machines",
                         "99_bottles_of_beer_monitoring")))

    sm_id = rafcon.core.singleton.state_machine_manager.add_state_machine(
        state_machine)
    rafcon.core.singleton.state_machine_manager.active_state_machine_id = sm_id

    sm_manager_model = gui_singletons.state_machine_manager_model
    main_window_controller = MainWindowController(sm_manager_model,
                                                  main_window_view)

    plugins.run_post_inits(setup_config)

    import threading
    # this is not recognized by pycharm as the module is loaded in plugins.load_plugins()
    from monitoring.monitoring_manager import global_monitoring_manager
    interacting_thread = threading.Thread(
        target=interacting_function,
        args=[main_window_controller, global_monitoring_manager, queue_dict])
    testing_utils.wait_for_gui()
    interacting_thread.start()

    # check if twisted is imported
    if "twisted" in sys.modules.keys():
        reactor.run()
    else:
        logger.error(
            "Client: Twisted is not in sys.modules or twisted is not working! Exiting program ... !"
        )
        os._exit(0)

    logger.info("Joined root state")

    # If there is a running state-machine, wait for it to be finished before exiting
    sm = core_singletons.state_machine_manager.get_active_state_machine()
    if sm:
        sm.root_state.join()

    logger.info("Exiting ...")

    # this is a ugly process shutdown method but works if gtk or twisted process are still blocking
    os._exit(0)
示例#6
0
def convert(config_path, source_path, target_path=None, gui_config_path=None):
    logger.info("RAFCON launcher")
    rafcon.gui.start.setup_l10n(logger)
    from rafcon.gui.controllers.main_window import MainWindowController
    from rafcon.gui.views.main_window import MainWindowView

    setup_environment()

    gui_config_path = gui_config_path or get_default_config_path()

    setup_config = {}
    setup_config["config_path"] = config_path
    setup_config["gui_config_path"] = gui_config_path
    setup_config["source_path"] = [source_path]
    if not target_path:
        setup_config["target_path"] = [source_path]
    else:
        setup_config["target_path"] = [target_path]

    global_config.load(path=setup_config['config_path'])
    global_gui_config.load(path=setup_config['gui_config_path'])
    global_runtime_config.load(path=setup_config['gui_config_path'])

    # Initialize library
    core_singletons.library_manager.initialize()

    # Create the GUI
    main_window_view = MainWindowView()

    if setup_config['source_path']:
        if len(setup_config['source_path']) > 1:
            logger.error("Only one state machine is supported yet")
            exit(-1)
        for path in setup_config['source_path']:
            try:
                state_machine = gui_helper_state_machine.open_state_machine(
                    path)
            except Exception as e:
                logger.error("Could not load state machine {0}: {1}".format(
                    path, e))
    else:
        logger.error(
            "You need to specify exactly one state machine to be converted!")

    sm_manager_model = gui_singletons.state_machine_manager_model

    main_window_controller = MainWindowController(sm_manager_model,
                                                  main_window_view)

    if not os.getenv("RAFCON_START_MINIMIZED", False):
        main_window = main_window_view.get_top_widget()
        size = global_runtime_config.get_config_value("WINDOW_SIZE", None)
        position = global_runtime_config.get_config_value("WINDOW_POS", None)
        if size:
            main_window.resize(size[0], size[1])
        if position:
            position = (max(0, position[0]), max(0, position[1]))
            screen_width = Gdk.Screen.width()
            screen_height = Gdk.Screen.height()
            if position[0] < screen_width and position[1] < screen_height:
                main_window.move(position[0], position[1])

    wait_for_gui()
    thread = threading.Thread(target=trigger_gui_signals,
                              args=[
                                  sm_manager_model, main_window_controller,
                                  setup_config, state_machine
                              ])
    thread.start()

    Gtk.main()
    logger.debug("Gtk main loop exited!")
    logger.debug("Conversion done")