Exemple #1
0
    def model_changed(self, model, prop_name, info):
        """This method notifies the model lists and the parent state about changes

        The method is called each time, the model is changed. This happens, when the state itself changes or one of
        its children (states, transitions, data flows) changes. Changes of the children cannot be observed directly,
        therefore children notify their parent about their changes by calling this method.
        This method then checks, what has been changed by looking at the model that is passed to it. In the following it
        notifies the list in which the change happened about the change.
        E.g. one child state changes its name. The model of that state observes itself and notifies the parent (
        i.e. this state model) about the change by calling this method with the information about the change. This
        method recognizes that the model is of type StateModel and therefore triggers a notify on the list of state
        models.
        "_notify_method_before" is used as trigger method when the changing function is entered and
        "_notify_method_after" is used when the changing function returns. This changing function in the example
        would be the setter of the property name.
        :param model: The model that was changed
        :param prop_name: The property that was changed
        :param info: Information about the change (e.g. the name of the changing function)
        """
        overview = NotificationOverview(info)
        # if info.method_name == 'change_state_type':  # Handled in method 'change_state_type'
        #     return

        # If this model has been changed (and not one of its child states), then we have to update all child models
        # This must be done before notifying anybody else, because other may relay on the updated models
        if not self.child_model_changed(overview):
            if overview.operation_finished():
                self.update_child_models(model, prop_name, info)
                # if there is and exception set is_about_to_be_destroyed_recursively flag to False again
                if info.method_name in ["remove_state"] and isinstance(
                        info.result, Exception):
                    state_id = info.kwargs[
                        'state_id'] if 'state_id' in info.kwargs else info.args[
                            1]
                    self.states[
                        state_id].is_about_to_be_destroyed_recursively = False
            elif overview.operation_started():
                # while before notification mark all states which get destroyed recursively
                if info.method_name in ["remove_state"] and \
                        info.kwargs.get('destroy', True) and info.kwargs.get('recursive', True):
                    state_id = info.kwargs[
                        'state_id'] if 'state_id' in info.kwargs else info.args[
                            1]
                    self.states[
                        state_id].is_about_to_be_destroyed_recursively = True

        # Finally call the method of the base class, to forward changes in ports and outcomes
        super(ContainerStateModel, self).model_changed(model, prop_name, info)
Exemple #2
0
    def model_changed(self, model, prop_name, info):
        """This method notifies the model lists and the parent state about changes

        The method is called each time, the model is changed. This happens, when the state itself changes or one of
        its children (outcomes, ports) changes. Changes of the children cannot be observed directly,
        therefore children notify their parent about their changes by calling this method.
        This method then checks, what has been changed by looking at the method that caused the change. In the
        following, it notifies the list in which the change happened about the change.
        E.g. one input data port changes its name. The model of the port observes itself and notifies the parent (
        i.e. the state model) about the change by calling this method with the information about the change. This
        method recognizes that the method "modify_input_data_port" caused the change and therefore triggers a notify
        on the list if input data port models.
        "_notify_method_before" is used as trigger method when the changing function is entered and
        "_notify_method_after" is used when the changing function returns. This changing function in the example
        would be "modify_input_data_port".

        :param model: The model that was changed
        :param prop_name: The property that was changed
        :param info: Information about the change (e.g. the name of the changing function)
        """
        overview = NotificationOverview(info)

        # If this model has been changed (and not one of its child states), then we have to update all child models
        # This must be done before notifying anybody else, because other may rely on the updated models
        if overview.operation_finished(
        ) and not self.child_model_changed(overview):
            self.update_models(model, prop_name, info)

        cause, changed_list = self.get_cause_and_affected_model_list(model)

        if not (cause is None or cause is "income_change"
                or changed_list is None):
            if overview.operation_started():
                changed_list._notify_method_before(self.state, cause,
                                                   (self.state, ), info)
            else:
                changed_list._notify_method_after(self.state, cause, None,
                                                  (self.state, ), info)

        # Notifies parent state
        super(StateModel, self).model_changed(model, prop_name, info)