Handle special keys instead of only modifiers
This commit is contained in:
parent
0e3e588038
commit
8648d88b51
@ -53,8 +53,10 @@ class HintKeyParser(KeyParser):
|
|||||||
fire_hint = pyqtSignal(str)
|
fire_hint = pyqtSignal(str)
|
||||||
abort_hinting = pyqtSignal()
|
abort_hinting = pyqtSignal()
|
||||||
|
|
||||||
def _handle_modifier_key(self, e):
|
def _handle_special_key(self, e):
|
||||||
"""We don't support modifiers here, but we'll handle escape in here.
|
"""Handle the escape key.
|
||||||
|
|
||||||
|
FIXME make this more generic
|
||||||
|
|
||||||
Emit:
|
Emit:
|
||||||
abort_hinting: Emitted if hinting was aborted.
|
abort_hinting: Emitted if hinting was aborted.
|
||||||
|
@ -118,9 +118,9 @@ class CommandKeyParser(KeyParser):
|
|||||||
if key.startswith('@') and key.endswith('@'):
|
if key.startswith('@') and key.endswith('@'):
|
||||||
# normalize keystring
|
# normalize keystring
|
||||||
keystr = self._normalize_keystr(key.strip('@'))
|
keystr = self._normalize_keystr(key.strip('@'))
|
||||||
logging.debug('registered mod key: {} -> {}'.format(keystr,
|
logging.debug('registered special key: {} -> {}'.format(keystr,
|
||||||
cmd))
|
cmd))
|
||||||
self.modifier_bindings[keystr] = cmd
|
self.special_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
|
||||||
|
@ -46,7 +46,7 @@ class KeyParser(QObject):
|
|||||||
_keystring: The currently entered key sequence
|
_keystring: The currently entered key sequence
|
||||||
_timer: QTimer for delayed execution.
|
_timer: QTimer for delayed execution.
|
||||||
bindings: Bound keybindings
|
bindings: Bound keybindings
|
||||||
modifier_bindings: Bound modifier bindings.
|
special_bindings: Bound special bindings (@Foo@).
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
keystring_updated: Emitted when the keystring is updated.
|
keystring_updated: Emitted when the keystring is updated.
|
||||||
@ -62,16 +62,16 @@ class KeyParser(QObject):
|
|||||||
|
|
||||||
supports_count = False
|
supports_count = False
|
||||||
|
|
||||||
def __init__(self, parent=None, bindings=None, modifier_bindings=None):
|
def __init__(self, parent=None, bindings=None, special_bindings=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._timer = None
|
self._timer = None
|
||||||
self._keystring = ''
|
self._keystring = ''
|
||||||
self.bindings = {} if bindings is None else bindings
|
self.bindings = {} if bindings is None else bindings
|
||||||
self.modifier_bindings = ({} if modifier_bindings is None
|
self.special_bindings = ({} if special_bindings is None
|
||||||
else modifier_bindings)
|
else special_bindings)
|
||||||
|
|
||||||
def _handle_modifier_key(self, e):
|
def _handle_special_key(self, e):
|
||||||
"""Handle a new keypress with modifiers.
|
"""Handle a new keypress with special keys (@Foo@).
|
||||||
|
|
||||||
Return True if the keypress has been handled, and False if not.
|
Return True if the keypress has been handled, and False if not.
|
||||||
|
|
||||||
@ -92,18 +92,15 @@ class KeyParser(QObject):
|
|||||||
return False
|
return False
|
||||||
mod = e.modifiers()
|
mod = e.modifiers()
|
||||||
modstr = ''
|
modstr = ''
|
||||||
if not mod & (Qt.ControlModifier | Qt.AltModifier | Qt.MetaModifier):
|
|
||||||
# won't be a shortcut with modifiers
|
|
||||||
return False
|
|
||||||
for (mask, s) in modmask2str.items():
|
for (mask, s) in modmask2str.items():
|
||||||
if mod & mask:
|
if mod & mask:
|
||||||
modstr += s + '+'
|
modstr += s + '+'
|
||||||
keystr = QKeySequence(e.key()).toString()
|
keystr = QKeySequence(e.key()).toString()
|
||||||
try:
|
try:
|
||||||
cmdstr = self.modifier_bindings[modstr + keystr]
|
cmdstr = self.special_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 False
|
||||||
self.execute(cmdstr)
|
self.execute(cmdstr)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -281,7 +278,7 @@ class KeyParser(QObject):
|
|||||||
Emit:
|
Emit:
|
||||||
keystring_updated: If a new keystring should be set.
|
keystring_updated: If a new keystring should be set.
|
||||||
"""
|
"""
|
||||||
handled = self._handle_modifier_key(e)
|
handled = self._handle_special_key(e)
|
||||||
if not handled:
|
if not handled:
|
||||||
self._handle_single_key(e)
|
self._handle_single_key(e)
|
||||||
self.keystring_updated.emit(self._keystring)
|
self.keystring_updated.emit(self._keystring)
|
||||||
|
Loading…
Reference in New Issue
Block a user