예제 #1
0
def run_gui_thread(gui_config=None, runtime_config=None):
    from gi.repository import GLib
    from gi.repository import Gdk
    from rafcon.core.start import reactor_required
    from rafcon.gui.start import start_gtk, install_reactor
    from rafcon.utils.i18n import setup_l10n
    global gui_ready
    # see https://stackoverflow.com/questions/35700140/pygtk-run-gtk-main-loop-in-a-seperate-thread
    # not needed any more:
    # https://pygobject.readthedocs.io/en/latest/guide/threading.html?highlight=threads_init#threads-faq
    # GLib.threads_init()
    if reactor_required():
        install_reactor()
    setup_l10n()
    from rafcon.gui.controllers.main_window import MainWindowController
    from rafcon.gui.views.main_window import MainWindowView

    initialize_environment_gui(gui_config, runtime_config)
    main_window_view = MainWindowView()
    main_window_view.get_top_widget().set_gravity(Gdk.Gravity.STATIC)
    MainWindowController(rafcon.gui.singleton.state_machine_manager_model, main_window_view)

    print("run_gui thread: ", currentThread(), currentThread().ident, "gui.singleton thread ident:", \
        rafcon.gui.singleton.thread_identifier)

    # Wait for GUI to initialize
    wait_for_gui()
    # Set an event when the gtk loop is running
    GLib.idle_add(gui_ready.set)
    start_gtk()
예제 #2
0
def run_gui_thread(gui_config=None, runtime_config=None):
    import gobject
    import gtk
    from rafcon.core.start import reactor_required
    from rafcon.gui.start import start_gtk, install_reactor
    from rafcon.utils.i18n import setup_l10n
    global gui_ready
    # see https://stackoverflow.com/questions/35700140/pygtk-run-gtk-main-loop-in-a-seperate-thread
    gobject.threads_init()
    if reactor_required():
        install_reactor()
    setup_l10n()
    from rafcon.gui.controllers.main_window import MainWindowController
    from rafcon.gui.views.main_window import MainWindowView

    initialize_environment_gui(gui_config, runtime_config)
    main_window_view = MainWindowView()
    main_window_view.get_top_widget().set_gravity(gtk.gdk.GRAVITY_STATIC)
    MainWindowController(rafcon.gui.singleton.state_machine_manager_model,
                         main_window_view)

    print "run_gui thread: ", currentThread(), currentThread().ident, "gui.singleton thread ident:", \
        rafcon.gui.singleton.thread_identifier

    # Wait for GUI to initialize
    wait_for_gui()
    # Set an event when the gtk loop is running
    gobject.idle_add(gui_ready.set)
    start_gtk()
예제 #3
0
def setup_gui():
    # Create the GUI-View
    main_window_view = MainWindowView()

    # set the gravity of the main window controller to static to ignore window manager decorations and get
    # a correct position of the main window on the screen (else there are offsets for some window managers)
    main_window_view.get_top_widget().set_gravity(gtk.gdk.GRAVITY_STATIC)

    sm_manager_model = gui_singletons.state_machine_manager_model
    main_window_controller = MainWindowController(sm_manager_model,
                                                  main_window_view)
    return main_window_controller
예제 #4
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")