make byte shortcuts load from file

This commit is contained in:
chrys 2018-03-26 00:32:25 +02:00
parent 6f287f90a1
commit ed2bb0f223
3 changed files with 62 additions and 23 deletions

View File

@ -88,6 +88,7 @@ Driver (screen, input):
[W]set flag that it is used in emulation [W]set flag that it is used in emulation
[W] handle byte shortcuts [W] handle byte shortcuts
[W] detect shortcuts [W] detect shortcuts
[] Load escape sequence shortcuts
[] write/ consume them (controll it at all) [] write/ consume them (controll it at all)
[W] create keyboard layout [W] create keyboard layout
[X] controll modes (vim like mode to not collide with application shortcuts) [X] controll modes (vim like mode to not collide with application shortcuts)

View File

@ -100,7 +100,7 @@ class fenrirManager():
self.detectByteCommand(event['Data']) self.detectByteCommand(event['Data'])
def handleControlMode(self, escapeSequence): def handleControlMode(self, escapeSequence):
convertedEscapeSequence = self.unifyEscapeSeq(escapeSequence) convertedEscapeSequence = self.environment['runtime']['byteManager'].unifyEscapeSeq(escapeSequence)
if self.switchCtrlModeOnce > 0: if self.switchCtrlModeOnce > 0:
self.switchCtrlModeOnce -= 1 self.switchCtrlModeOnce -= 1
if convertedEscapeSequence == b'^[R': if convertedEscapeSequence == b'^[R':
@ -162,15 +162,12 @@ class fenrirManager():
def handleHeartBeat(self, event): def handleHeartBeat(self, event):
self.environment['runtime']['commandManager'].executeDefaultTrigger('onHeartBeat',force=True) self.environment['runtime']['commandManager'].executeDefaultTrigger('onHeartBeat',force=True)
#self.environment['runtime']['outputManager'].brailleText(flush=False) #self.environment['runtime']['outputManager'].brailleText(flush=False)
def unifyEscapeSeq(self, escapeSequence):
convertedEscapeSequence = escapeSequence
if convertedEscapeSequence[0] == 27:
convertedEscapeSequence = b'^[' + convertedEscapeSequence[1:]
return convertedEscapeSequence
def detectByteCommand(self, escapeSequence): def detectByteCommand(self, escapeSequence):
convertedEscapeSequence = self.unifyEscapeSeq(escapeSequence) convertedEscapeSequence = self.environment['runtime']['byteManager'].unifyEscapeSeq(escapeSequence)
command = '' command = ''
try: try:
'''
commands = { commands = {
b'^[h':'toggle_tutorial_mode', b'^[h':'toggle_tutorial_mode',
b'^[/': 'shut_up', b'^[/': 'shut_up',
@ -207,7 +204,9 @@ class fenrirManager():
b'^[X': 'remove_marks', b'^[X': 'remove_marks',
b'^[x': 'set_mark', b'^[x': 'set_mark',
} }
command = commands[convertedEscapeSequence].upper() '''
command = self.environment['runtime']['inputManager'].getCommandForShortcut(convertedEscapeSequence)
print(convertedEscapeSequence,command)
self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, command) self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, command)
except: except:
pass pass

View File

@ -23,6 +23,7 @@ from fenrirscreenreader.core import applicationManager
from fenrirscreenreader.core import helpManager from fenrirscreenreader.core import helpManager
from fenrirscreenreader.core import headLineManager from fenrirscreenreader.core import headLineManager
from fenrirscreenreader.core import tableManager from fenrirscreenreader.core import tableManager
from fenrirscreenreader.core import byteManager
from fenrirscreenreader.core import environment from fenrirscreenreader.core import environment
from fenrirscreenreader.core import inputData from fenrirscreenreader.core import inputData
from fenrirscreenreader.core.settingsData import settingsData from fenrirscreenreader.core.settingsData import settingsData
@ -33,6 +34,7 @@ class settingsManager():
def __init__(self): def __init__(self):
self.settings = settingsData self.settings = settingsData
self.settingArgDict = {} self.settingArgDict = {}
self.shortcutType = 'KEY'
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
def shutdown(self): def shutdown(self):
@ -81,6 +83,25 @@ class settingsManager():
kbConfig.close() kbConfig.close()
# fix bindings # fix bindings
self.env['bindings'][str([1, ['KEY_F1', 'KEY_FENRIR']])] = 'TOGGLE_TUTORIAL_MODE' self.env['bindings'][str([1, ['KEY_F1', 'KEY_FENRIR']])] = 'TOGGLE_TUTORIAL_MODE'
def loadByteShortcuts(self, kbConfigPath=fenrirPath + '/../../config/keyboard/pty.conf'):
kbConfig = open(kbConfigPath,"r")
while(True):
line = kbConfig.readline()
if not line:
break
line = line.replace('\n','')
if line.replace(" ","") == '':
continue
if line.replace(" ","").startswith("#"):
continue
if line.count("=") != 1:
continue
Values = line.split('=')
shortcut = bytes(Values[0],'UTF-8')
commandName = Values[1].upper()
self.env['bindings'][shortcut] = commandName
self.env['runtime']['debug'].writeDebugOut("Byte Shortcut: "+ str(shortcut) + ' command:' +commandName ,debug.debugLevel.INFO, onAnyLevel=True)
kbConfig.close()
def loadSoundIcons(self, soundIconPath): def loadSoundIcons(self, soundIconPath):
siConfig = open(soundIconPath + '/soundicons.conf',"r") siConfig = open(soundIconPath + '/soundicons.conf',"r")
@ -285,7 +306,6 @@ class settingsManager():
validConfig = environment['runtime']['settingsManager'].loadSettings(settingsFile) validConfig = environment['runtime']['settingsManager'].loadSettings(settingsFile)
if not validConfig: if not validConfig:
return None return None
if cliArgs.options != '': if cliArgs.options != '':
self.parseSettingArgs(cliArgs.options) self.parseSettingArgs(cliArgs.options)
if cliArgs.debug: if cliArgs.debug:
@ -296,6 +316,10 @@ class settingsManager():
if cliArgs.emulation: if cliArgs.emulation:
self.setOptionArgDict('screen', 'driver', 'ptyDriver') self.setOptionArgDict('screen', 'driver', 'ptyDriver')
self.setOptionArgDict('keyboard', 'driver', 'ptyDriver') self.setOptionArgDict('keyboard', 'driver', 'ptyDriver')
# TODO needs cleanup use dict
#self.setOptionArgDict('keyboard', 'keyboardLayout', 'pty')
self.setSetting('keyboard', 'keyboardLayout', 'pty')
self.shortcutType = 'BYTE'
self.setOptionArgDict('general', 'debugFile', '/tmp/fenrir-pty.log') self.setOptionArgDict('general', 'debugFile', '/tmp/fenrir-pty.log')
self.setFenrirKeys(self.getSetting('general','fenrirKeys')) self.setFenrirKeys(self.getSetting('general','fenrirKeys'))
self.setScriptKeys(self.getSetting('general','scriptKeys')) self.setScriptKeys(self.getSetting('general','scriptKeys'))
@ -303,15 +327,26 @@ class settingsManager():
environment['runtime']['debug'] = debugManager.debugManager(self.env['runtime']['settingsManager'].getSetting('general','debugFile')) environment['runtime']['debug'] = debugManager.debugManager(self.env['runtime']['settingsManager'].getSetting('general','debugFile'))
environment['runtime']['debug'].initialize(environment) environment['runtime']['debug'].initialize(environment)
if not os.path.exists(self.getSetting('keyboard','keyboardLayout')): if self.shortcutType == 'KEY':
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout')): if not os.path.exists(self.getSetting('keyboard','keyboardLayout')):
self.setSetting('keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout')) if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout')):
self.setSetting('keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout'))
environment['runtime']['settingsManager'].loadShortcuts(self.getSetting('keyboard','keyboardLayout'))
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout') + '.conf'):
self.setSetting('keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout') + '.conf')
environment['runtime']['settingsManager'].loadShortcuts(self.getSetting('keyboard','keyboardLayout'))
else:
environment['runtime']['settingsManager'].loadShortcuts(self.getSetting('keyboard','keyboardLayout')) environment['runtime']['settingsManager'].loadShortcuts(self.getSetting('keyboard','keyboardLayout'))
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout') + '.conf'): elif self.shortcutType == 'BYTE':
self.setSetting('keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout') + '.conf') if not os.path.exists(self.getSetting('keyboard','keyboardLayout')):
environment['runtime']['settingsManager'].loadShortcuts(self.getSetting('keyboard','keyboardLayout')) if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout')):
else: self.setSetting('keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout'))
environment['runtime']['settingsManager'].loadShortcuts(self.getSetting('keyboard','keyboardLayout')) environment['runtime']['settingsManager'].loadByteShortcuts(self.getSetting('keyboard','keyboardLayout'))
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout') + '.conf'):
self.setSetting('keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting('keyboard','keyboardLayout') + '.conf')
environment['runtime']['settingsManager'].loadByteShortcuts(self.getSetting('keyboard','keyboardLayout'))
else:
environment['runtime']['settingsManager'].loadByteShortcuts(self.getSetting('keyboard','keyboardLayout'))
if not os.path.exists(self.getSetting('sound','theme') + '/soundicons.conf'): if not os.path.exists(self.getSetting('sound','theme') + '/soundicons.conf'):
if os.path.exists(soundRoot + self.getSetting('sound','theme')): if os.path.exists(soundRoot + self.getSetting('sound','theme')):
@ -331,8 +366,10 @@ class settingsManager():
else: else:
environment['runtime']['settingsManager'].loadDicts(self.getSetting('general','punctuationProfile')) environment['runtime']['settingsManager'].loadDicts(self.getSetting('general','punctuationProfile'))
if fenrirManager: if fenrirManager:
environment['runtime']['fenrirManager'] = fenrirManager environment['runtime']['fenrirManager'] = fenrirManager
environment['runtime']['memoryManager'] = memoryManager.memoryManager() environment['runtime']['memoryManager'] = memoryManager.memoryManager()
environment['runtime']['memoryManager'].initialize(environment) environment['runtime']['memoryManager'].initialize(environment)
environment['runtime']['eventManager'] = eventManager.eventManager() environment['runtime']['eventManager'] = eventManager.eventManager()
@ -343,6 +380,8 @@ class settingsManager():
environment['runtime']['commandManager'].initialize(environment) environment['runtime']['commandManager'].initialize(environment)
environment['runtime']['inputManager'] = inputManager.inputManager() environment['runtime']['inputManager'] = inputManager.inputManager()
environment['runtime']['inputManager'].initialize(environment) environment['runtime']['inputManager'].initialize(environment)
environment['runtime']['byteManager'] = byteManager.byteManager()
environment['runtime']['byteManager'].initialize(environment)
environment['runtime']['outputManager'] = outputManager.outputManager() environment['runtime']['outputManager'] = outputManager.outputManager()
environment['runtime']['outputManager'].initialize(environment) environment['runtime']['outputManager'].initialize(environment)
environment['runtime']['punctuationManager'] = punctuationManager.punctuationManager() environment['runtime']['punctuationManager'] = punctuationManager.punctuationManager()