Пример #1
0
    def __call__(self, event):
        """Executes the callback based on the event's content.

        Creates a Value object from the event and passes the two through the
        execution graph until every entry has run or it is aborted.
        """
        if event.event_type in [
                common.InputType.JoystickAxis, common.InputType.JoystickHat
        ]:
            value = actions.Value(event.value)
        elif event.event_type in [
                common.InputType.JoystickButton, common.InputType.Keyboard,
                common.InputType.VirtualButton
        ]:
            value = actions.Value(event.is_pressed)
        else:
            raise error.GremlinError("Invalid event type")

        # Containers representing a virtual button get their individual
        # value instance, all others share one to propagate changes across
        shared_value = copy.deepcopy(value)

        if event == common.InputType.VirtualButton:
            # TODO: remove this at a future stage
            logging.getLogger("system").error(
                "Virtual button code path being used")
        else:
            self.execution_graph.process_event(event, shared_value)
Пример #2
0
    def _create_activation_condition(self, activation_condition):
        """Creates activation condition objects base on the given data.

        :param activation_condition data about activation condition to be
            used in order to generate executable nodes
        """
        conditions = []
        for condition in activation_condition.conditions:
            if isinstance(condition, base_classes.KeyboardCondition):
                conditions.append(
                    actions.KeyboardCondition(
                        condition.scan_code,
                        condition.is_extended,
                        condition.comparison
                    )
                )
            elif isinstance(condition, base_classes.JoystickCondition):
                conditions.append(
                    actions.JoystickCondition(condition)
                )
            elif isinstance(condition, base_classes.VJoyCondition):
                conditions.append(
                    actions.VJoyCondition(condition)
                )
            elif isinstance(condition, base_classes.InputActionCondition):
                conditions.append(
                    actions.InputActionCondition(condition.comparison)
                )
            else:
                raise error.GremlinError("Invalid condition provided")

        return actions.ActivationCondition(
            conditions,
            activation_condition.rule
        )
Пример #3
0
    def __init__(self, data):
        """Creates a new instance for the given container.

        :param container the container using a virtual button configuration
        """
        self.virtual_button = None

        if isinstance(data, base_classes.VirtualAxisButton):
            self.virtual_button = actions.AxisButton(data.lower_limit,
                                                     data.upper_limit,
                                                     data.direction)
        elif isinstance(data, base_classes.VirtualHatButton):
            self.virtual_button = actions.HatButton(data.directions)
        else:
            raise error.GremlinError("Invalid virtual button data provided")