def test_invalid_locale_setting(caplog, monkeypatch): create_mo_files() with use_locale("invalid", monkeypatch): i18n.setup_l10n() testing_utils.assert_logger_warnings_and_errors(caplog=caplog, expected_warnings=1)
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()
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()
def test_basic_string_translation(caplog, monkeypatch): # target_locale = "de_DE.UTF-8" # on debian systems the german utf locale is: "de_DE.utf8" target_locale = "de_DE.utf8" if testing_utils.check_if_locale_exists(target_locale): logger.info("Execute locale test as locale was found on system") with use_locale(target_locale, monkeypatch): i18n.setup_l10n(logger) assert _("Remove") == "Entfernen" testing_utils.assert_logger_warnings_and_errors(caplog=caplog) else: logger.info( "Locale test is not executed as locale was NOT found on system")
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 ..."))
import sys import os import datetime # Flag indicating whether the build is run on Read The Docs on_rtd = os.environ.get('READTHEDOCS') == 'True' # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath(os.path.join('..', 'source'))) # Required to make the gettext function _("") globally available from rafcon.utils.i18n import setup_l10n setup_l10n() # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. needs_sphinx = '1.4' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.ifconfig', 'sphinx.ext.autosectionlabel', 'sphinx.ext.extlinks' ] try:
def test_basic_string_translation(caplog, monkeypatch): with use_locale("de_DE.UTF-8", monkeypatch): i18n.setup_l10n() assert _("Remove") == "Entfernen" testing_utils.assert_logger_warnings_and_errors(caplog=caplog)
def start_client(interacting_function, queue_dict): from rafcon.gui.config import global_gui_config import os from rafcon.utils.i18n import setup_l10n setup_l10n() 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() from tests import utils as testing_utils # check if twisted is imported if "twisted" in sys.modules: from twisted.internet import gtk3reactor # needed for GLib.idle_add, and signals gtk3reactor.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) # the active_state_machine_id must be set here, as the state machine can be active (e.g. if the server started the sm already) # although it is not yet started on the client 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, sm_id]) testing_utils.wait_for_gui() interacting_thread.start() # check if twisted is imported if "twisted" in sys.modules: 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)
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()
def run_turtle_demo(): import rafcon.core import rafcon.core.start from rafcon.utils.i18n import setup_l10n signal.signal(signal.SIGINT, rafcon.core.start.signal_handler) setup_l10n() 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") from rafcon.gui.controllers.main_window import MainWindowController from rafcon.gui.views.main_window import MainWindowView 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!")