Move parsing to class

This commit is contained in:
Florian Bruhin 2017-12-29 01:50:51 +01:00
parent 705767bcfb
commit cc747b00ce
2 changed files with 7 additions and 7 deletions

View File

@ -1655,4 +1655,4 @@ class Key(BaseType):
#if utils.is_special_key(value):
# value = '<{}>'.format(utils.normalize_keystr(value[1:-1]))
#return value
return keyutils.parse_keystring(value)
return keyutils.KeySequence.parse(value)

View File

@ -205,12 +205,6 @@ def _parse_keystring(keystr):
yield 'Shift+' + c if c.isupper() else c
def parse_keystring(keystr):
"""Parse a keystring like <Ctrl-x> or xyz and return a KeyInfo list."""
s = ', '.join(_parse_keystring(keystr))
return KeySequence(s)
def normalize_keystr(keystr):
"""Normalize a keystring like Ctrl-Q to a keystring like Ctrl+Q.
@ -266,3 +260,9 @@ class KeySequence:
def append_event(self, ev):
return self.__class__(*self._sequence, ev.modifiers() | ev.key())
@classmethod
def parse(cls, keystr):
"""Parse a keystring like <Ctrl-x> or xyz and return a KeySequence."""
s = ', '.join(_parse_keystring(keystr))
return cls(s)