diff options
author | Walter Bender <walter@sugarlabs.org> | 2013-10-14 18:36:07 (GMT) |
---|---|---|
committer | Walter Bender <walter@sugarlabs.org> | 2013-10-14 18:36:07 (GMT) |
commit | a20fe8fd1c789253bd1936aeb5e9d6b12a5b163c (patch) | |
tree | 6c7d17c37324501da43fb4777b6807008aef2ff8 /plugins | |
parent | 143a2d1dbc73058f65d7ff6118e89ad897c3b278 (diff) |
improvements to keyboard input, labels
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/turtle_blocks_extras/turtle_blocks_extras.py | 87 |
1 files changed, 77 insertions, 10 deletions
diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py index c7288c2..3cb4fb9 100644 --- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py +++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py @@ -1002,24 +1002,91 @@ Journal objects')) def _prim_keyboard(self): """ Return last character typed """ - if self.tw.lc.update_values: - self.tw.lc.update_label_value('keyboard', self.tw.lc.keyboard) return self.tw.lc.keyboard def _prim_kbinput(self): """ Query keyboard """ + DICT = { + 'Left': 1, + 'KP_Left': 1, + 'Up': 2, + 'KP_Up': 2, + 'Right': 3, + 'KP_Right': 3, + 'Down': 4, + 'KP_Down': 4, + 'BackSpace': 8, + 'Tab': 9, + 'Return': 13, + 'Escape': 27, + 'space': 32, + ' ': 32, + 'exclam': 33, + 'quotedbl': 34, + 'numbersign': 35, + 'dollar': 36, + 'percent': 37, + 'ampersand': 38, + 'apostrophe': 39, + 'parenleft': 40, + 'parenright': 41, + 'asterisk': 42, + 'plus': 43, + 'comma': 44, + 'minus': 45, + 'period': 46, + 'slash': 47, + 'colon': 58, + 'semicolon': 59, + 'less': 60, + 'equal': 61, + 'greater': 62, + 'question': 63, + 'at': 64, + 'underscore': 95, + 'bracketleft': 91, + 'backslash': 92, + 'bracketright': 93, + 'asciicircum': 94, + 'grave': 96, + 'braceleft': 123, + 'bar': 124, + 'braceright': 125, + 'asciitilde': 126, + 'Delete': 127, + } + REVERSE_DICT = { + 1: _('left'), + 2: _('up'), + 3: _('right'), + 4: _('down'), + 8: _('backspace'), + 9: _('tab'), + # TRANS: enter is the name of the enter (or return) key + 13: _('enter'), + 27: 'esc', + # TRANS: space is the name of the space key + 32: _('space'), + 127: _('delete') + } + if len(self.tw.keypress) == 1: self.tw.lc.keyboard = ord(self.tw.keypress[0]) + elif self.tw.keypress in DICT: + self.tw.lc.keyboard = DICT[self.tw.keypress] else: - try: - self.tw.lc.keyboard = { - 'Escape': 27, 'space': 32, ' ': 32, - 'Return': 13, 'KP_Up': 2, 'KP_Down': 4, 'KP_Left': 1, - 'KP_Right': 3}[self.tw.keypress] - except KeyError: - self.tw.lc.keyboard = 0 + self.tw.lc.keyboard = 0 if self.tw.lc.update_values: - self.tw.lc.update_label_value('keyboard', self.tw.lc.keyboard) + if self.tw.keypress in DICT: + if DICT[self.tw.keypress] in REVERSE_DICT: + self.tw.lc.update_label_value( + 'keyboard', REVERSE_DICT[DICT[self.tw.keypress]]) + else: + self.tw.lc.update_label_value('keyboard', + chr(DICT[self.tw.keypress])) + elif self.tw.lc.keyboard > 0: + self.tw.lc.update_label_value('keyboard', + chr(self.tw.lc.keyboard)) self.tw.keypress = '' def _prim_list(self, blklist): |