예제 #1
0
    events.KEY_7: ecodes.KEY_7,
    events.KEY_8: ecodes.KEY_8,
    events.KEY_9: ecodes.KEY_9,

    events.KEY_LEFTBRACE: ecodes.KEY_LEFTBRACE,
    events.KEY_RIGHTBRACE: ecodes.KEY_RIGHTBRACE,
    events.KEY_DOT: ecodes.KEY_DOT,

    events.KEY_LEFT_SHIFT: ecodes.KEY_LEFTSHIFT,
    events.KEY_ENTER: ecodes.KEY_ENTER,
    events.KEY_SPACE: ecodes.KEY_SPACE,
    events.KEY_BACKSPACE: ecodes.KEY_BACKSPACE,
    events.KEY_CAPS_LOCK: ecodes.KEY_CAPSLOCK
}


class EventToEcodeTranslator(object):
    def translate(self, event):
        global _event_to_ecode_map
        return _event_to_ecode_map[event]


_ecode_to_event_map = invert_dictionary(_event_to_ecode_map)


class EcodeToEventTranslator(object):
    def translate(self, ecode):
        return _ecode_to_event_map[ecode]


class StringToEventsTranslator(object):

    def translate(self, string):
        """
        @return: A list of events, corresponding to the translations of the individual
                 characters of the string.
        """
        string = string.lower()
        events_from_string = []
        for char in string:
            event = _map_string_to_event[char]
            events_from_string.append(event)
        return events_from_string


_map_event_to_string = invert_dictionary(_map_string_to_event)


class EventsToStringTranslator(object):

    def translate_event(self, event):
        if isinstance(event, list):
            event = str(event)
        return _map_event_to_string[event]

    def translate_iterable(self, events_iterable):
        translation = ""
        for event in events_iterable:
            translation += self.translate_event(event)
        return translation