Add keyutils.is_printable()
This commit is contained in:
parent
b4d232badd
commit
1cd86d79d9
@ -30,6 +30,10 @@ from PyQt5.QtGui import QKeySequence, QKeyEvent
|
|||||||
from qutebrowser.utils import utils
|
from qutebrowser.utils import utils
|
||||||
|
|
||||||
|
|
||||||
|
def is_printable(key):
|
||||||
|
return key <= 0xff
|
||||||
|
|
||||||
|
|
||||||
def _key_to_string(key):
|
def _key_to_string(key):
|
||||||
"""Convert a Qt::Key member to a meaningful name.
|
"""Convert a Qt::Key member to a meaningful name.
|
||||||
|
|
||||||
@ -227,7 +231,7 @@ class KeyInfo:
|
|||||||
|
|
||||||
key_string = _key_to_string(self.key)
|
key_string = _key_to_string(self.key)
|
||||||
|
|
||||||
if len(key_string) == 1:
|
if is_printable(self.key) and self.key != Qt.Key_Space:
|
||||||
category = unicodedata.category(key_string)
|
category = unicodedata.category(key_string)
|
||||||
is_special_char = (category == 'Cc')
|
is_special_char = (category == 'Cc')
|
||||||
else:
|
else:
|
||||||
@ -254,8 +258,7 @@ class KeyInfo:
|
|||||||
"""Get the text which would be displayed when pressing this key."""
|
"""Get the text which would be displayed when pressing this key."""
|
||||||
if self.key == Qt.Key_Space:
|
if self.key == Qt.Key_Space:
|
||||||
return ' '
|
return ' '
|
||||||
elif self.key > 0xff:
|
elif not is_printable(self.key):
|
||||||
# Unprintable keys
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
text = QKeySequence(self.key).toString()
|
text = QKeySequence(self.key).toString()
|
||||||
@ -386,7 +389,7 @@ class KeySequence:
|
|||||||
modifiers = ev.modifiers()
|
modifiers = ev.modifiers()
|
||||||
|
|
||||||
if (modifiers == Qt.ShiftModifier and
|
if (modifiers == Qt.ShiftModifier and
|
||||||
len(ev.text()) == 1 and
|
is_printable(ev.key()) and
|
||||||
unicodedata.category(ev.text()) != 'Lu'):
|
unicodedata.category(ev.text()) != 'Lu'):
|
||||||
modifiers = Qt.KeyboardModifiers()
|
modifiers = Qt.KeyboardModifiers()
|
||||||
|
|
||||||
|
@ -280,13 +280,12 @@ class RegisterKeyParser(keyparser.CommandKeyParser):
|
|||||||
if match:
|
if match:
|
||||||
return match
|
return match
|
||||||
|
|
||||||
key = e.text()
|
if not keyutils.is_printable(e.key()):
|
||||||
|
|
||||||
if key == '' or not str(keyutils.KeyInfo.from_event(e)):
|
|
||||||
# this is not a proper register key, let it pass and keep going
|
# this is not a proper register key, let it pass and keep going
|
||||||
# FIXME can we simplify this when we refactor keyutils.py?
|
|
||||||
return QKeySequence.NoMatch
|
return QKeySequence.NoMatch
|
||||||
|
|
||||||
|
key = e.text()
|
||||||
|
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=self._win_id)
|
window=self._win_id)
|
||||||
macro_recorder = objreg.get('macro-recorder')
|
macro_recorder = objreg.get('macro-recorder')
|
||||||
|
Loading…
Reference in New Issue
Block a user