Skip to content

Commit

Permalink
filter out non-unicode codepoints and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mrterry committed Sep 19, 2013
1 parent 989ce39 commit 2359f09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/matplotlib/backends/backend_qt4.py
Expand Up @@ -349,6 +349,15 @@ def _get_key(self, event):
# key, rather than unicode
key = SPECIAL_KEYS[event_key]
except KeyError:
# unicode defines code points up to 0x0010ffff
# QT will use Key_Codes larger than that for keyboard keys that are
# are not unicode characters (like multimedia keys)
# skip these
# if you really want them, you should add them to SPECIAL_KEYS
MAX_UNICODE = 0x10ffff
if event_key > MAX_UNICODE:
return None

key = unichr(event_key)
# qt delivers capitalized letters. fix capitalization
# note that capslock is ignored
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_backend_qt4.py
Expand Up @@ -149,3 +149,11 @@ def test_backspace_mod():
assert_correct_key(QtCore.Qt.Key_Backspace,
ControlModifier,
u'ctrl+backspace')


@cleanup
@knownfailureif(not HAS_QT)
def test_non_unicode_key():
assert_correct_key(QtCore.Qt.Key_Play,
QtCore.Qt.NoModifier,
None)

0 comments on commit 2359f09

Please sign in to comment.