def open_library_as_state_machine(self): import rafcon.gui.helpers.state_machine as gui_helper_state_machine (model, row) = self.view.get_selection().get_selected() physical_library_path = model[row][self.ITEM_STORAGE_ID] assert isinstance(physical_library_path, str) logger.debug("Opening library as state-machine from path '{0}'".format(physical_library_path)) state_machine = gui_helper_state_machine.open_state_machine(physical_library_path) global_runtime_config.update_recently_opened_state_machines_with(state_machine) return state_machine
def open_state_machines(paths): import rafcon.gui.helpers.state_machine as gui_helper_state_machine first_sm = None for path in paths: try: sm = gui_helper_state_machine.open_state_machine(path=path, recent_opened_notification=True) if first_sm is None: first_sm = sm except Exception as e: logger.exception(_("Could not load state machine '{}': {}").format(path, e)) return first_sm
def test_add_data_flow_to_nested_states(): import rafcon.gui.helpers.state_machine as gui_helper_state_machine from rafcon.gui.models.container_state import ContainerStateModel from rafcon.gui.mygaphas.utils.gap_helper import add_data_flow_to_state from rafcon.gui.singleton import state_machine_manager state_machine_path = os.path.join(testing_utils.TEST_ASSETS_PATH, 'unit_test_state_machines', 'nested_states_data_flow') state_machine = gui_helper_state_machine.open_state_machine( path=state_machine_path, recent_opened_notification=True) root_state_model = ContainerStateModel(state_machine.root_state) # Add the data flows from the root state to the descendant state from_data_port_model = root_state_model.get_input_data_port_m(0) descendant_state = root_state_model.state while len(descendant_state.states) > 0: descendant_state = next(iter(descendant_state.states.values())) descendant_state = ContainerStateModel(descendant_state) to_data_port_model = descendant_state.get_input_data_port_m(0) test_state = root_state_model.state while len(test_state.states) > 0: if test_state.is_root_state: assert len(test_state.input_data_ports) == 1 assert len(test_state.output_data_ports) == 1 else: assert len(test_state.input_data_ports) == 0 assert len(test_state.output_data_ports) == 0 assert len(test_state.data_flows) == 0 test_state = next(iter(test_state.states.values())) add_data_flow_to_state(from_data_port_model, to_data_port_model) test_state = root_state_model.state while len(test_state.states) > 0: if test_state.is_root_state: assert len(test_state.input_data_ports) == 1 assert len(test_state.output_data_ports) == 1 else: assert len(test_state.input_data_ports) == 1 assert len(test_state.output_data_ports) == 0 assert len(test_state.data_flows) == 1 test_state = next(iter(test_state.states.values())) state_machine_manager.delete_all_state_machines()
def on_open_activate(widget=None, data=None, path=None): return gui_helper_state_machine.open_state_machine( path=path, recent_opened_notification=True)
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")
def on_open_activate(widget, data=None): state_m = gui_singletons.state_machine_manager_model.get_selected_state_machine_model().selection.get_selected_state() path, _, _ = gui_singletons.library_manager.get_os_path_to_library(state_m.state.library_path, state_m.state.library_name) gui_helper_state_machine.open_state_machine(path)