Beispiel #1
0
    def __init__(self,
                 shortcut_type=None,
                 shortcut_key=None,
                 shortcut_press_type=None,
                 modifiers=None):

        if shortcut_type is None:

            shortcut_type = SHORTCUT_TYPE_KEYBOARD_SPECIAL

        if shortcut_key is None:

            shortcut_key = SHORTCUT_KEY_SPECIAL_F7

        if shortcut_press_type is None:

            shortcut_press_type = SHORTCUT_PRESS_TYPE_PRESS

        if modifiers is None:

            modifiers = []

        if shortcut_type == SHORTCUT_TYPE_KEYBOARD_CHARACTER and ClientData.OrdIsAlphaUpper(
                shortcut_key):

            shortcut_key += 32  # convert A to a

        modifiers.sort()

        HydrusSerialisable.SerialisableBase.__init__(self)

        self.shortcut_type = shortcut_type
        self.shortcut_key = shortcut_key
        self.shortcut_press_type = shortcut_press_type
        self.modifiers = modifiers
Beispiel #2
0
    def ToString(self):

        components = []

        if SHORTCUT_MODIFIER_CTRL in self.modifiers:

            components.append('ctrl')

        if SHORTCUT_MODIFIER_ALT in self.modifiers:

            components.append('alt')

        if SHORTCUT_MODIFIER_SHIFT in self.modifiers:

            components.append('shift')

        if SHORTCUT_MODIFIER_GROUP_SWITCH in self.modifiers:

            components.append('Mode_switch')

        if self.shortcut_press_type != SHORTCUT_PRESS_TYPE_PRESS:

            action_name = '{} '.format(
                shortcut_press_type_str_lookup[self.shortcut_press_type])

        else:

            action_name = ''

        if self.shortcut_type == SHORTCUT_TYPE_MOUSE and self.shortcut_key in shortcut_mouse_string_lookup:

            action_name += shortcut_mouse_string_lookup[self.shortcut_key]

        elif self.shortcut_type == SHORTCUT_TYPE_KEYBOARD_SPECIAL and self.shortcut_key in special_key_shortcut_str_lookup:

            action_name += special_key_shortcut_str_lookup[self.shortcut_key]

        elif self.shortcut_type == SHORTCUT_TYPE_KEYBOARD_CHARACTER:

            try:

                if ClientData.OrdIsAlphaUpper(self.shortcut_key):

                    action_name += chr(self.shortcut_key +
                                       32)  # + 32 for converting ascii A -> a

                else:

                    action_name += chr(self.shortcut_key)

            except:

                action_name += 'unknown key: {}'.format(repr(
                    self.shortcut_key))

        else:

            action_name += 'unknown key: {}'.format(repr(self.shortcut_key))

        components.append(action_name)

        s = '+'.join(components)

        if SHORTCUT_MODIFIER_KEYPAD in self.modifiers:

            s += ' (on numpad)'

        return s
Beispiel #3
0
    def _UpdateSerialisableInfo(self, version, old_serialisable_info):

        if version == 1:

            # these are dicts that convert fixed wx enums to new stuff
            wx_to_qt_flat_conversion = {
                32: SHORTCUT_KEY_SPECIAL_SPACE,
                8: SHORTCUT_KEY_SPECIAL_BACKSPACE,
                9: SHORTCUT_KEY_SPECIAL_TAB,
                13: SHORTCUT_KEY_SPECIAL_RETURN,
                310: SHORTCUT_KEY_SPECIAL_PAUSE,
                27: SHORTCUT_KEY_SPECIAL_ESCAPE,
                322: SHORTCUT_KEY_SPECIAL_INSERT,
                127: SHORTCUT_KEY_SPECIAL_DELETE,
                315: SHORTCUT_KEY_SPECIAL_UP,
                317: SHORTCUT_KEY_SPECIAL_DOWN,
                314: SHORTCUT_KEY_SPECIAL_LEFT,
                316: SHORTCUT_KEY_SPECIAL_RIGHT,
                313: SHORTCUT_KEY_SPECIAL_HOME,
                312: SHORTCUT_KEY_SPECIAL_END,
                367: SHORTCUT_KEY_SPECIAL_PAGE_DOWN,
                366: SHORTCUT_KEY_SPECIAL_PAGE_UP,
                340: SHORTCUT_KEY_SPECIAL_F1,
                341: SHORTCUT_KEY_SPECIAL_F2,
                342: SHORTCUT_KEY_SPECIAL_F3,
                343: SHORTCUT_KEY_SPECIAL_F4,
                344: SHORTCUT_KEY_SPECIAL_F5,
                345: SHORTCUT_KEY_SPECIAL_F6,
                346: SHORTCUT_KEY_SPECIAL_F7,
                347: SHORTCUT_KEY_SPECIAL_F8,
                348: SHORTCUT_KEY_SPECIAL_F9,
                349: SHORTCUT_KEY_SPECIAL_F10,
                350: SHORTCUT_KEY_SPECIAL_F11,
                351: SHORTCUT_KEY_SPECIAL_F12
            }

            # regular keys, but numpad, that are tracked in wx by combined unique enum
            wx_to_qt_numpad_ascii_conversion = {
                324: ord('0'),
                325: ord('1'),
                326: ord('2'),
                327: ord('3'),
                328: ord('4'),
                329: ord('5'),
                330: ord('6'),
                331: ord('7'),
                332: ord('8'),
                333: ord('9'),
                388: ord('+'),
                392: ord('/'),
                390: ord('-'),
                387: ord('*'),
                391: ord('.')
            }

            wx_to_qt_numpad_conversion = {
                377: SHORTCUT_KEY_SPECIAL_UP,
                379: SHORTCUT_KEY_SPECIAL_DOWN,
                376: SHORTCUT_KEY_SPECIAL_LEFT,
                378: SHORTCUT_KEY_SPECIAL_RIGHT,
                375: SHORTCUT_KEY_SPECIAL_HOME,
                382: SHORTCUT_KEY_SPECIAL_END,
                381: SHORTCUT_KEY_SPECIAL_PAGE_DOWN,
                380: SHORTCUT_KEY_SPECIAL_PAGE_UP,
                385: SHORTCUT_KEY_SPECIAL_DELETE,
                370: SHORTCUT_KEY_SPECIAL_ENTER
            }

            (shortcut_type, shortcut_key, modifiers) = old_serialisable_info

            if shortcut_type == SHORTCUT_TYPE_KEYBOARD_CHARACTER:

                if shortcut_key in wx_to_qt_flat_conversion:

                    shortcut_type = SHORTCUT_TYPE_KEYBOARD_SPECIAL
                    shortcut_key = wx_to_qt_flat_conversion[shortcut_key]

                elif shortcut_key in wx_to_qt_numpad_ascii_conversion:

                    shortcut_key = wx_to_qt_numpad_ascii_conversion[
                        shortcut_key]

                    modifiers = list(modifiers)

                    modifiers.append(SHORTCUT_MODIFIER_KEYPAD)

                    modifiers.sort()

                elif shortcut_key in wx_to_qt_numpad_conversion:

                    shortcut_type = SHORTCUT_TYPE_KEYBOARD_SPECIAL
                    shortcut_key = wx_to_qt_numpad_conversion[shortcut_key]

                    modifiers = list(modifiers)

                    modifiers.append(SHORTCUT_MODIFIER_KEYPAD)

                    modifiers.sort()

            if shortcut_type == SHORTCUT_TYPE_KEYBOARD_CHARACTER:

                if ClientData.OrdIsAlphaUpper(shortcut_key):

                    shortcut_key += 32  # convert 'A' to 'a'

            new_serialisable_info = (shortcut_type, shortcut_key, modifiers)

            return (2, new_serialisable_info)

        if version == 2:

            (shortcut_type, shortcut_key, modifiers) = old_serialisable_info

            shortcut_press_type = SHORTCUT_PRESS_TYPE_PRESS

            new_serialisable_info = (shortcut_type, shortcut_key,
                                     shortcut_press_type, modifiers)

            return (3, new_serialisable_info)