Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 3
0
def start_gtk():
    # check if twisted is imported
    if reactor_required():
        from twisted.internet import reactor
        import threading
        is_main_thread = isinstance(threading.current_thread(), threading._MainThread)
        reactor.run(installSignalHandlers=is_main_thread)
    else:
        Gtk.main()
Ejemplo n.º 4
0
def pre_setup_plugins():
    """Loads plugins and calls the pre init hooks

    If twisted has been imported by a plugin, the gtk2reactor is installed
    """
    # load all plugins specified in the RAFCON_PLUGIN_PATH
    plugins.load_plugins()

    # check if twisted is imported and if so, install the required reactor
    if reactor_required():
        install_reactor()

    plugins.run_pre_inits()
Ejemplo n.º 5
0
def stop_gtk():
    # shutdown twisted correctly
    if reactor_required():
        from twisted.internet import reactor
        if reactor.running:
            reactor.callFromThread(reactor.stop)
        # Twisted can be imported without the reactor being used
        # => check if GTK main loop is running
        elif gtk.main_level() > 0:
            glib.idle_add(gtk.main_quit)
    else:
        glib.idle_add(gtk.main_quit)

    # Run the GTK loop until no more events are being generated and thus the GUI is fully destroyed
    wait_for_gui()
Ejemplo n.º 6
0
def start_stop_state_machine(state_machine, start_state_path, quit_flag):
    wait_for_gui()

    state_machine_execution_engine = core_singletons.state_machine_execution_engine
    state_machine_execution_engine.execute_state_machine_from_path(
        state_machine=state_machine,
        start_state_path=start_state_path,
        wait_for_execution_finished=True)
    if reactor_required():
        from twisted.internet import reactor
        reactor.callFromThread(reactor.stop)

    if quit_flag:
        gui_singletons.main_window_controller.get_controller(
            'menu_bar_controller').on_quit_activate(None, None)