Simplify handling of modifier-only keys
Now that we don't rely on str(KeyInfo) being empty anywhere, there's no reason to return an empty string for only-modifier keypresses anymore. While those keys can't be bound (QKeySequence('Shift') == Qt.Key_unknown) there's also no reason to explicitly ignore them.
This commit is contained in:
parent
693178c8ee
commit
7cb781cc92
@ -128,10 +128,6 @@ class BaseKeyParser(QObject):
|
||||
txt = str(keyutils.KeyInfo.from_event(e))
|
||||
self._debug_log("Got key: 0x{:x} / text: '{}'".format(key, txt))
|
||||
|
||||
if keyutils.is_modifier_key(key):
|
||||
self._debug_log("Ignoring, only modifier")
|
||||
return QKeySequence.NoMatch
|
||||
|
||||
if (txt.isdigit() and self._supports_count and not
|
||||
(not self._count and txt == '0')):
|
||||
assert len(txt) == 1, txt
|
||||
|
@ -200,15 +200,14 @@ class KeyInfo:
|
||||
"""Convert this KeyInfo to a meaningful name.
|
||||
|
||||
Return:
|
||||
A name of the key (combination) as a string or
|
||||
an empty string if only modifiers are pressed.
|
||||
A name of the key (combination) as a string.
|
||||
"""
|
||||
if is_modifier_key(self.key):
|
||||
return ''
|
||||
|
||||
key_string = _key_to_string(self.key)
|
||||
|
||||
if is_printable(self.key):
|
||||
if is_modifier_key(self.key):
|
||||
# Don't return e.g. <Shift+Shift>
|
||||
return '<{}>'.format(key_string)
|
||||
elif is_printable(self.key):
|
||||
# "normal" binding
|
||||
# FIXME Add a test to make sure Tab doesn't become TAB
|
||||
assert len(key_string) == 1 or self.key == Qt.Key_Space, key_string
|
||||
|
@ -113,13 +113,13 @@ class TestKeyEventToString:
|
||||
"""Test keyeevent when only control is pressed."""
|
||||
evt = fake_keyevent_factory(key=Qt.Key_Control,
|
||||
modifiers=Qt.ControlModifier)
|
||||
assert not str(keyutils.KeyInfo.from_event(evt))
|
||||
assert str(keyutils.KeyInfo.from_event(evt)) == '<Control>'
|
||||
|
||||
def test_only_hyper_l(self, fake_keyevent_factory):
|
||||
"""Test keyeevent when only Hyper_L is pressed."""
|
||||
evt = fake_keyevent_factory(key=Qt.Key_Hyper_L,
|
||||
modifiers=Qt.MetaModifier)
|
||||
assert not str(keyutils.KeyInfo.from_event(evt))
|
||||
assert str(keyutils.KeyInfo.from_event(evt)) == '<Hyper L>'
|
||||
|
||||
def test_only_key(self, fake_keyevent_factory):
|
||||
"""Test with a simple key pressed."""
|
||||
|
Loading…
Reference in New Issue
Block a user