make nice shortcut presentation work

This commit is contained in:
Chrys 2019-08-19 19:10:27 +02:00
parent a5b7694e59
commit be19a67fcd
3 changed files with 37 additions and 4 deletions

View File

@ -26,4 +26,5 @@ environment = {
'output': outputData,
'soundIcons': {},
'bindings': {},
'rawBindings': {},
}

View File

@ -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

View File

@ -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'