From be19a67fcdcd985932d812749c65470397ecad54 Mon Sep 17 00:00:00 2001 From: Chrys Date: Mon, 19 Aug 2019 19:10:27 +0200 Subject: [PATCH] make nice shortcut presentation work --- src/fenrirscreenreader/core/environment.py | 1 + src/fenrirscreenreader/core/helpManager.py | 39 ++++++++++++++++++--- src/fenrirscreenreader/core/inputManager.py | 1 + 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/fenrirscreenreader/core/environment.py b/src/fenrirscreenreader/core/environment.py index 7b864a28..729aaf2f 100644 --- a/src/fenrirscreenreader/core/environment.py +++ b/src/fenrirscreenreader/core/environment.py @@ -26,4 +26,5 @@ environment = { 'output': outputData, 'soundIcons': {}, 'bindings': {}, +'rawBindings': {}, } diff --git a/src/fenrirscreenreader/core/helpManager.py b/src/fenrirscreenreader/core/helpManager.py index b20ac9b8..aa1439e1 100755 --- a/src/fenrirscreenreader/core/helpManager.py +++ b/src/fenrirscreenreader/core/helpManager.py @@ -34,6 +34,40 @@ class helpManager(): pass def isTutorialMode(self): return self.env['general']['tutorialMode'] + def getFormattedShortcutForCommand(self, command): + shortcut = [] + rawShortcut = [] + try: + rawShortcut = list(self.env['bindings'].keys())[list(self.env['bindings'].values()).index(command)] + rawShortcut = self.env['rawBindings'][rawShortcut] + # prefer numbers for multitap + if rawShortcut[0] in range(2, 9): + formattedKey = str(rawShortcut[0]) +' times ' + shortcut.append(formattedKey) + # prefer metha keys + for k in ['KEY_FENRIR', 'KEY_SCRIPT', 'KEY_CTRL', 'KEY_SHIFT', 'KEY_ALT', 'KEY_META']: + if k in rawShortcut[1]: + formattedKey = k + formattedKey = formattedKey.lower() + formattedKey = formattedKey.replace('key_kp', ' keypad ') + formattedKey = formattedKey.replace('key_', ' ') + shortcut.append(formattedKey) + rawShortcut[1].remove(k) + # handle other keys + for k in rawShortcut[1]: + formattedKey = k + formattedKey = formattedKey.lower() + formattedKey = formattedKey.replace('key_kp', ' keypad ') + formattedKey = formattedKey.replace('key_', ' ') + shortcut.append(formattedKey) + except Exception as e: + return '' + shortcut = str(shortcut) + shortcut = shortcut.replace('[','') + shortcut = shortcut.replace(']','') + shortcut = shortcut.replace("'",'') + return shortcut + def getCommandHelpText(self, command, section = 'commands'): commandName = command.lower() commandName = commandName.split('__-__')[0] @@ -45,10 +79,7 @@ class helpManager(): commandDescription = self.env['runtime']['commandManager'].getCommandDescription(command, section = 'commands') if commandDescription == '': commandDescription = 'no Description available' - commandShortcut = self.env['runtime']['commandManager'].getShortcutForCommand(command, formatKeys = True) - commandShortcut = commandShortcut.replace('[','') - commandShortcut = commandShortcut.replace(']','') - commandShortcut = commandShortcut.replace("'",'') + commandShortcut = self.getFormattedShortcutForCommand(command) if commandShortcut == '': commandShortcut = 'unbound' helptext = commandName + ', Shortcut ' + commandShortcut + ', Description ' + commandDescription diff --git a/src/fenrirscreenreader/core/inputManager.py b/src/fenrirscreenreader/core/inputManager.py index 0974ba3d..ee3e522e 100644 --- a/src/fenrirscreenreader/core/inputManager.py +++ b/src/fenrirscreenreader/core/inputManager.py @@ -324,6 +324,7 @@ class inputManager(): continue self.env['runtime']['debug'].writeDebugOut("Shortcut: "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.INFO, onAnyLevel=True) self.env['bindings'][str(shortcut)] = commandName + self.env['rawBindings'][str(shortcut)] = shortcut kbConfig.close() # fix bindings self.env['bindings'][str([1, ['KEY_F1', 'KEY_FENRIR']])] = 'TOGGLE_TUTORIAL_MODE'