Skip to content

Commit 1d44fa6

Browse files
committed
Fixing keys handling and keys code decoding
Some window managers may catch keys in weird manner. So only Keys.remove() will be called. It will cause exception.
1 parent e2de268 commit 1d44fa6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

nodebox/graphics/context.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from hashlib import md5
2626
from types import FunctionType
2727
from datetime import datetime
28+
from numbers import Number
2829

2930
import geometry
3031

@@ -3454,11 +3455,14 @@ def remove(self, code):
34543455
code = self._decode(code)
34553456
if code in MODIFIERS:
34563457
self.modifiers.remove(code)
3457-
list.remove(self, self._decode(code))
3458+
3459+
if code in self: # some window managers catch keys in weird manner
3460+
list.remove(self, code) # .. so we may be in situation where no key code exists in our list
3461+
34583462
self.code = len(self) > 0 and self[-1] or None
34593463

34603464
def _decode(self, code):
3461-
if not isinstance(code, int):
3465+
if not isinstance(code, Number):
34623466
s = code
34633467
else:
34643468
s = pyglet.window.key.symbol_string(code) # 65288 => "BACKSPACE"

0 commit comments

Comments
 (0)