Ejemplo n.º 1
0
    def __init__(self, state_machine, meta=None, load_meta_data=True):
        """Constructor
        """
        MetaModel.__init__(self)  # pass columns as separate parameters

        assert isinstance(state_machine, StateMachine)

        self.state_machine = state_machine
        self.state_machine_id = state_machine.state_machine_id

        root_state = self.state_machine.root_state
        if isinstance(root_state, ContainerState):
            self.root_state = ContainerStateModel(
                root_state, parent=self, load_meta_data=load_meta_data)
        else:
            self.root_state = StateModel(root_state,
                                         parent=self,
                                         load_meta_data=load_meta_data)

        if isinstance(meta, Vividict):
            self.meta = meta
        else:
            self.meta = Vividict()

        # ongoing_complex_actions is updated by ComplexActionObserver -> secure encapsulated observation
        # and made observable by state machine model here
        self.ongoing_complex_actions = {}
        self.complex_action_observer = ComplexActionObserver(self)

        self.meta_signal = Signal()
        self.state_meta_signal = Signal()
        self.action_signal = Signal()
        self.state_action_signal = Signal()
        self.sm_selection_changed_signal = Signal()
        self.destruction_signal = Signal()

        self.temp = Vividict()

        if load_meta_data:
            self.load_meta_data(recursively=False)

        self.selection = Selection(self.sm_selection_changed_signal)

        self.storage_lock = threading.Lock(
        )  # lock can not be substituted by the state machine lock -> maybe because it is a RLock

        self.history = None
        if global_gui_config.get_config_value('HISTORY_ENABLED'):
            from rafcon.gui.models.modification_history import ModificationsHistoryModel
            self.history = ModificationsHistoryModel(self)
        else:
            logger.info("The modification history is disabled")

        self.auto_backup = None
        if global_gui_config.get_config_value('AUTO_BACKUP_ENABLED'):
            from rafcon.gui.models.auto_backup import AutoBackupModel
            self.auto_backup = AutoBackupModel(self)

        self.root_state.register_observer(self)
        self.register_observer(self)
Ejemplo n.º 2
0
    def __init__(self, state, parent=None, meta=None):
        if type(self) == AbstractStateModel:
            raise NotImplementedError

        MetaModel.__init__(self, meta)
        assert isinstance(state, State)
        self.is_start = False

        self.state = state

        self.parent = parent

        self.meta_signal = Signal()
        self.action_signal = Signal()
        self.destruction_signal = Signal()

        self.register_observer(self)

        self.input_data_ports = []
        self.output_data_ports = []
        self.outcomes = []
        self._load_input_data_port_models()
        self._load_output_data_port_models()
        self._load_income_model()
        self._load_outcome_models()
Ejemplo n.º 3
0
    def __init__(self, parent, meta=None):
        MetaModel.__init__(self, meta)

        self.parent = parent
        self.destruction_signal = Signal()

        # this class is an observer of its own properties:
        self.register_observer(self)
Ejemplo n.º 4
0
def test_meta_list_modification():
    testing_utils.dummy_gui(None)
    from rafcon.gui.models.meta import MetaModel
    meta_m = MetaModel()
    meta_data = meta_m.set_meta_data_editor("list", [1, 2, 3])
    assert meta_data["list"] == [1, 2, 3]
    meta_data = meta_m.set_meta_data_editor("list.0", 4)
    assert meta_data["list"] == [4, 2, 3]
Ejemplo n.º 5
0
def test_meta_initialization():
    testing_utils.dummy_gui(None)
    from rafcon.gui.models.meta import MetaModel
    meta_m = MetaModel(meta={"1": 2, "2": 1})
    assert meta_m.meta == {"1": 2, "2": 1}

    meta_m = MetaModel(meta={'gui': {'editor_gaphas': {"1": 2, "2": 1}}})
    meta_data = meta_m.get_meta_data_editor()
    assert meta_data == {"1": 2, "2": 1}
Ejemplo n.º 6
0
def test_meta_setter_return_value():
    testing_utils.dummy_gui(None)
    from rafcon.gui.models.meta import MetaModel
    meta_m = MetaModel()
    meta_data = meta_m.set_meta_data_editor("key", "value")
    assert meta_data["key"] == "value"

    meta_data = meta_m.set_meta_data_editor("key2", "value2")
    assert meta_data["key"] == "value"
    assert meta_data["key2"] == "value2"
Ejemplo n.º 7
0
def test_editor_setter_getter_conversion(use_gaphas):
    testing_utils.dummy_gui(None)
    from rafcon.gui.models.meta import MetaModel
    meta_m = MetaModel()
    meta_m.meta["gui"]["editor_opengl" if use_gaphas else "editor_gaphas"][
        "test"] = (1, 2)
    meta_data = meta_m.get_meta_data_editor(for_gaphas=use_gaphas)
    assert meta_data["test"] == (1, 2)

    assert_single_editor_meta_data(meta_m, gaphas=use_gaphas)
    assert meta_m.meta["gui"][
        "editor_gaphas" if use_gaphas else "editor_opengl"]["test"] == (1, 2)
Ejemplo n.º 8
0
def test_editor_setter_getter(use_gaphas):
    testing_utils.dummy_gui(None)
    from rafcon.gui.models.meta import MetaModel
    meta_m = MetaModel()

    meta_data = meta_m.get_meta_data_editor(for_gaphas=use_gaphas)
    assert isinstance(meta_data, dict)
    assert len(meta_data) == 0

    meta_m.set_meta_data_editor("test_key", (1, 2), from_gaphas=use_gaphas)
    meta_data = meta_m.get_meta_data_editor(for_gaphas=use_gaphas)
    assert meta_data["test_key"] == (1, 2)

    meta_m.set_meta_data_editor("key1.key2", (2, 1), from_gaphas=use_gaphas)
    meta_data = meta_m.get_meta_data_editor(for_gaphas=use_gaphas)
    assert meta_data["key1"]["key2"] == (2, 1)

    assert_single_editor_meta_data(meta_m, gaphas=use_gaphas)

    assert meta_m.meta["gui"][
        "editor_gaphas" if use_gaphas else "editor_opengl"]["test_key"] == (1,
                                                                            2)
    assert meta_m.meta["gui"]["editor_gaphas" if use_gaphas else
                              "editor_opengl"]["key1"]["key2"] == (2, 1)
Ejemplo n.º 9
0
def test_invalid_model():
    testing_utils.dummy_gui(None)
    from rafcon.core.states.state import State
    from rafcon.gui.models.selection import Selection
    from rafcon.gui.models.meta import MetaModel

    selection = Selection()
    meta_m = MetaModel()

    with pytest.raises(TypeError):
        selection.add(meta_m)
    with pytest.raises(TypeError):
        selection.set(meta_m)
    with pytest.raises(TypeError):
        selection.focus(meta_m)
    with pytest.raises(TypeError):
        selection.handle_new_selection(meta_m)
    with pytest.raises(TypeError):
        selection.handle_prepared_selection_of_core_class_elements(meta_m, State)
Ejemplo n.º 10
0
def test_meta_data_hash():
    testing_utils.dummy_gui(None)
    from rafcon.gui.models.meta import MetaModel

    meta1_m = MetaModel()
    meta1_m.meta["test"] = 1
    meta1_m.meta["nested"]["dict"] = 2

    meta2_m = MetaModel()
    meta2_m.meta["test"] = 1
    meta2_m.meta["nested"]["dict"] = 2

    meta3_m = MetaModel()
    meta3_m.meta["test"] = 1
    meta3_m.meta["nested"]["dict"] = 3

    assert meta1_m.meta_data_hash().digest() == meta2_m.meta_data_hash(
    ).digest()
    assert meta1_m.meta_data_hash().digest() != meta3_m.meta_data_hash(
    ).digest()