Allow bindings to be modified
This commit is contained in:
parent
52c7376402
commit
341481cd99
@ -116,7 +116,7 @@ class CommandKeyParser(KeyParser):
|
|||||||
keystr = self._normalize_keystr(key.strip('@'))
|
keystr = self._normalize_keystr(key.strip('@'))
|
||||||
logging.debug('registered mod key: {} -> {}'.format(keystr,
|
logging.debug('registered mod key: {} -> {}'.format(keystr,
|
||||||
cmd))
|
cmd))
|
||||||
self._modifier_bindings[keystr] = cmd
|
self.modifier_bindings[keystr] = cmd
|
||||||
else:
|
else:
|
||||||
logging.debug('registered key: {} -> {}'.format(key, cmd))
|
logging.debug('registered key: {} -> {}'.format(key, cmd))
|
||||||
self._bindings[key] = cmd
|
self.bindings[key] = cmd
|
||||||
|
@ -40,8 +40,8 @@ class KeyParser(QObject):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
_keystring: The currently entered key sequence
|
_keystring: The currently entered key sequence
|
||||||
_bindings: Bound keybindings
|
bindings: Bound keybindings
|
||||||
_modifier_bindings: Bound modifier bindings.
|
modifier_bindings: Bound modifier bindings.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
keystring_updated: Emitted when the keystring is updated.
|
keystring_updated: Emitted when the keystring is updated.
|
||||||
@ -56,11 +56,12 @@ class KeyParser(QObject):
|
|||||||
|
|
||||||
supports_count = False
|
supports_count = False
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None, bindings=None, modifier_bindings=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._keystring = ''
|
self._keystring = ''
|
||||||
self._bindings = {}
|
self.bindings = {} if bindings is None else bindings
|
||||||
self._modifier_bindings = {}
|
self.modifier_bindings = ({} if modifier_bindings is None
|
||||||
|
else modifier_bindings)
|
||||||
|
|
||||||
def _handle_modifier_key(self, e):
|
def _handle_modifier_key(self, e):
|
||||||
"""Handle a new keypress with modifiers.
|
"""Handle a new keypress with modifiers.
|
||||||
@ -92,7 +93,7 @@ class KeyParser(QObject):
|
|||||||
modstr += s + '+'
|
modstr += s + '+'
|
||||||
keystr = QKeySequence(e.key()).toString()
|
keystr = QKeySequence(e.key()).toString()
|
||||||
try:
|
try:
|
||||||
cmdstr = self._modifier_bindings[modstr + keystr]
|
cmdstr = self.modifier_bindings[modstr + keystr]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logging.debug('No binding found for {}.'.format(modstr + keystr))
|
logging.debug('No binding found for {}.'.format(modstr + keystr))
|
||||||
return True
|
return True
|
||||||
@ -166,11 +167,11 @@ class KeyParser(QObject):
|
|||||||
part was found in.
|
part was found in.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
cmdstr_hay = self._bindings[cmdstr_needle]
|
cmdstr_hay = self.bindings[cmdstr_needle]
|
||||||
return (self.MATCH_DEFINITIVE, cmdstr_hay)
|
return (self.MATCH_DEFINITIVE, cmdstr_hay)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# No definitive match, check if there's a chance of a partial match
|
# No definitive match, check if there's a chance of a partial match
|
||||||
for hay in self._bindings:
|
for hay in self.bindings:
|
||||||
try:
|
try:
|
||||||
if cmdstr_needle[-1] == hay[len(cmdstr_needle) - 1]:
|
if cmdstr_needle[-1] == hay[len(cmdstr_needle) - 1]:
|
||||||
return (self.MATCH_PARTIAL, None)
|
return (self.MATCH_PARTIAL, None)
|
||||||
|
Loading…
Reference in New Issue
Block a user