Refactor keyutils._parse_keystring
This commit is contained in:
parent
c9c0bc0bbd
commit
910bbc8521
@ -151,7 +151,7 @@ def _parse_keystring(keystr):
|
|||||||
for c in keystr:
|
for c in keystr:
|
||||||
if c == '>':
|
if c == '>':
|
||||||
if special:
|
if special:
|
||||||
yield _normalize_keystr(key)
|
yield _parse_special_key(key)
|
||||||
key = ''
|
key = ''
|
||||||
special = False
|
special = False
|
||||||
else:
|
else:
|
||||||
@ -162,14 +162,14 @@ def _parse_keystring(keystr):
|
|||||||
elif special:
|
elif special:
|
||||||
key += c
|
key += c
|
||||||
else:
|
else:
|
||||||
yield 'Shift+' + c if c.isupper() else c
|
yield _parse_single_key(c)
|
||||||
if special:
|
if special:
|
||||||
yield '<'
|
yield '<'
|
||||||
for c in key:
|
for c in key:
|
||||||
yield 'Shift+' + c if c.isupper() else c
|
yield _parse_single_key(c)
|
||||||
|
|
||||||
|
|
||||||
def _normalize_keystr(keystr):
|
def _parse_special_key(keystr):
|
||||||
"""Normalize a keystring like Ctrl-Q to a keystring like Ctrl+Q.
|
"""Normalize a keystring like Ctrl-Q to a keystring like Ctrl+Q.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -187,11 +187,17 @@ def _normalize_keystr(keystr):
|
|||||||
)
|
)
|
||||||
for (orig, repl) in replacements:
|
for (orig, repl) in replacements:
|
||||||
keystr = keystr.replace(orig, repl)
|
keystr = keystr.replace(orig, repl)
|
||||||
|
|
||||||
for mod in ['ctrl', 'meta', 'alt', 'shift']:
|
for mod in ['ctrl', 'meta', 'alt', 'shift']:
|
||||||
keystr = keystr.replace(mod + '-', mod + '+')
|
keystr = keystr.replace(mod + '-', mod + '+')
|
||||||
return keystr
|
return keystr
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_single_key(keystr):
|
||||||
|
"""Get a keystring for QKeySequence for a single key."""
|
||||||
|
return 'Shift+' + keystr if keystr.isupper() else keystr
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class KeyInfo:
|
class KeyInfo:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user