remove environment parameter and pass it via initialisation
This commit is contained in:
@ -12,16 +12,17 @@ class commandManager():
|
||||
def __init__(self):
|
||||
pass
|
||||
def initialize(self, environment):
|
||||
environment['runtime']['commandManager'].loadCommands(environment,'commands')
|
||||
environment['runtime']['commandManager'].loadCommands(environment,'onInput')
|
||||
environment['runtime']['commandManager'].loadCommands(environment,'onScreenChanged')
|
||||
self.env = environment
|
||||
self.env['runtime']['commandManager'].loadCommands('commands')
|
||||
environment['runtime']['commandManager'].loadCommands('onInput')
|
||||
environment['runtime']['commandManager'].loadCommands('onScreenChanged')
|
||||
|
||||
def shutdown(self, environment):
|
||||
environment['runtime']['commandManager'].shutdownCommands(environment,'commands')
|
||||
environment['runtime']['commandManager'].shutdownCommands(environment,'onInput')
|
||||
environment['runtime']['commandManager'].shutdownCommands(environment,'onScreenChanged')
|
||||
def shutdown(self):
|
||||
self.env['runtime']['commandManager'].shutdownCommands('commands')
|
||||
self.env['runtime']['commandManager'].shutdownCommands('onInput')
|
||||
self.env['runtime']['commandManager'].shutdownCommands('onScreenChanged')
|
||||
|
||||
def loadCommands(self, environment, section='commands'):
|
||||
def loadCommands(self, section='commands'):
|
||||
commandFolder = "commands/" + section +"/"
|
||||
commandList = glob.glob(commandFolder+'*')
|
||||
for command in commandList:
|
||||
@ -34,63 +35,63 @@ class commandManager():
|
||||
spec = importlib.util.spec_from_file_location(fileName, command)
|
||||
command_mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(command_mod)
|
||||
environment['commands'][section][fileName.upper()] = command_mod.command()
|
||||
environment['commands'][section][fileName.upper()].initialize(environment)
|
||||
self.env['commands'][section][fileName.upper()] = command_mod.command()
|
||||
self.env['commands'][section][fileName.upper()].initialize(self.env)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"Loading command:" + command ,debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("Loading command:" + command ,debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
continue
|
||||
|
||||
def shutdownCommands(self, environment, section):
|
||||
for command in sorted(environment['commands'][section]):
|
||||
def shutdownCommands(self, section):
|
||||
for command in sorted(self.env['commands'][section]):
|
||||
try:
|
||||
environment['commands'][section][command].shutdown(environment)
|
||||
del environment['commands'][section][command]
|
||||
self.env['commands'][section][command].shutdown()
|
||||
del self.env['commands'][section][command]
|
||||
except Exception as e:
|
||||
print(e)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"Shutdown command:" + section + "." + cmd ,debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("Shutdown command:" + section + "." + command ,debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
continue
|
||||
|
||||
def executeTriggerCommands(self, environment, trigger):
|
||||
if environment['runtime']['screenManager'].isSuspendingScreen(environment):
|
||||
def executeTriggerCommands(self, trigger):
|
||||
if self.env['runtime']['screenManager'].isSuspendingScreen():
|
||||
return
|
||||
for command in sorted(environment['commands'][trigger]):
|
||||
if self.commandExists(environment, command, trigger):
|
||||
for command in sorted(self.env['commands'][trigger]):
|
||||
if self.commandExists(command, trigger):
|
||||
try:
|
||||
environment['commands'][trigger][command].run(environment)
|
||||
self.env['commands'][trigger][command].run()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"Executing trigger:" + trigger + "." + cmd ,debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("Executing trigger:" + trigger + "." + cmd ,debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
|
||||
def executeCommand(self, environment, command, section = 'commands'):
|
||||
if environment['runtime']['screenManager'].isSuspendingScreen(environment) :
|
||||
def executeCommand(self, command, section = 'commands'):
|
||||
if self.env['runtime']['screenManager'].isSuspendingScreen():
|
||||
return
|
||||
if self.commandExists(environment, command, section):
|
||||
if self.commandExists(command, section):
|
||||
try:
|
||||
if environment['generalInformation']['tutorialMode']:
|
||||
description = environment['commands'][section][command].getDescription(environment)
|
||||
environment['runtime']['outputManager'].presentText(environment, description, interrupt=True)
|
||||
if self.env['generalInformation']['tutorialMode']:
|
||||
description = self.env['commands'][section][command].getDescription()
|
||||
self.env['runtime']['outputManager'].presentText(description, interrupt=True)
|
||||
else:
|
||||
environment['commands'][section][command].run(environment)
|
||||
self.env['commands'][section][command].run()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"Executing command:" + section + "." + command ,debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.clearCommandQueued(environment)
|
||||
environment['commandInfo']['lastCommandExecutionTime'] = time.time()
|
||||
self.env['runtime']['debug'].writeDebugOut("Executing command:" + section + "." + command ,debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
self.clearCommandQueued()
|
||||
self.env['commandInfo']['lastCommandExecutionTime'] = time.time()
|
||||
|
||||
def isCommandQueued(self, environment):
|
||||
return environment['commandInfo']['currCommand'] != ''
|
||||
def isCommandQueued(self):
|
||||
return self.env['commandInfo']['currCommand'] != ''
|
||||
|
||||
def clearCommandQueued(self, environment):
|
||||
environment['commandInfo']['currCommand'] = ''
|
||||
def clearCommandQueued(self):
|
||||
self.env['commandInfo']['currCommand'] = ''
|
||||
|
||||
def queueCommand(self, environment, command):
|
||||
environment['commandInfo']['currCommand'] = command
|
||||
def queueCommand(self, command):
|
||||
self.env['commandInfo']['currCommand'] = command
|
||||
|
||||
def commandExists(self, environment, command, section = 'commands'):
|
||||
return( command.upper() in environment['commands'][section])
|
||||
def commandExists(self, command, section = 'commands'):
|
||||
return( command.upper() in self.env['commands'][section])
|
||||
|
@ -19,10 +19,13 @@ class debug():
|
||||
self._fileName = fileName
|
||||
self._file = None
|
||||
self._fileOpened = False
|
||||
|
||||
def initialize(self, environment):
|
||||
self.env = environment
|
||||
def shutdown(self):
|
||||
self.closeDebugFile()
|
||||
def __del__(self):
|
||||
try:
|
||||
self.closeDebugFile()
|
||||
self.shutdown()
|
||||
except:
|
||||
pass
|
||||
|
||||
@ -34,8 +37,8 @@ class debug():
|
||||
self._file = open(self._fileName,'a')
|
||||
self._fileOpened = True
|
||||
|
||||
def writeDebugOut(self, environment, text, level = debugLevel.DEACTIVE):
|
||||
if environment['runtime']['settingsManager'].getSettingAsInt(environment, 'general','debugLevel') < int(level):
|
||||
def writeDebugOut(self, text, level = debugLevel.DEACTIVE):
|
||||
if self.env['runtime']['settingsManager'].getSettingAsInt('general','debugLevel') < int(level):
|
||||
if self._fileOpened:
|
||||
self.closeDebugFile()
|
||||
return
|
||||
|
@ -12,61 +12,60 @@ class inputManager():
|
||||
def __init__(self):
|
||||
pass
|
||||
def initialize(self, environment):
|
||||
environment['runtime']['settingsManager'].loadDriver(environment,\
|
||||
environment['runtime']['settingsManager'].getSetting(environment,'keyboard', 'driver'), 'inputDriver')
|
||||
self.env = environment
|
||||
self.env['runtime']['settingsManager'].loadDriver(\
|
||||
self.env['runtime']['settingsManager'].getSetting('keyboard', 'driver'), 'inputDriver')
|
||||
# init LEDs with current state
|
||||
environment['input']['newNumLock'] = environment['runtime']['inputDriver'].getNumlock(environment)
|
||||
environment['input']['oldNumLock'] = environment['input']['newNumLock']
|
||||
environment['input']['newCapsLock'] = environment['runtime']['inputDriver'].getCapslock(environment)
|
||||
environment['input']['oldCapsLock'] = environment['input']['newCapsLock']
|
||||
environment['input']['newScrollLock'] = environment['runtime']['inputDriver'].getScrollLock(environment)
|
||||
environment['input']['oldScrollLock'] = environment['input']['newScrollLock']
|
||||
self.grabDevices(environment)
|
||||
self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getNumlock()
|
||||
self.env['input']['oldNumLock'] = self.env['input']['newNumLock']
|
||||
self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getCapslock()
|
||||
self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock']
|
||||
self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getScrollLock()
|
||||
self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock']
|
||||
self.grabDevices()
|
||||
|
||||
def shutdown(self, environment):
|
||||
environment['runtime']['inputManager'].releaseDevices(environment)
|
||||
if environment['runtime']['inputDriver']:
|
||||
environment['runtime']['inputDriver'].shutdown(environment)
|
||||
del environment['runtime']['inputDriver']
|
||||
def shutdown(self):
|
||||
self.env['runtime']['inputManager'].releaseDevices()
|
||||
self.env['runtime']['settingsManager'].shutdownDriver('inputDriver')
|
||||
|
||||
def getInputEvent(self, environment):
|
||||
def getInputEvent(self):
|
||||
eventReceived = False
|
||||
mEvent = environment['runtime']['inputDriver'].getInputEvent(environment)
|
||||
mEvent = self.env['runtime']['inputDriver'].getInputEvent()
|
||||
if mEvent:
|
||||
mEvent['EventName'] = self.convertEventName(environment, mEvent['EventName'])
|
||||
mEvent['EventName'] = self.convertEventName(mEvent['EventName'])
|
||||
if mEvent['EventValue'] == 0:
|
||||
return False
|
||||
eventReceived = True
|
||||
if mEvent['EventState'] == 0:
|
||||
if mEvent['EventName'] in environment['input']['currInput']:
|
||||
environment['input']['currInput'].remove(mEvent['EventName'])
|
||||
environment['input']['currInput'] = sorted(environment['input']['currInput'])
|
||||
if mEvent['EventName'] in self.env['input']['currInput']:
|
||||
self.env['input']['currInput'].remove(mEvent['EventName'])
|
||||
self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
|
||||
elif mEvent['EventState'] == 1:
|
||||
if not mEvent['EventName'] in environment['input']['currInput']:
|
||||
environment['input']['currInput'].append(mEvent['EventName'])
|
||||
environment['input']['currInput'] = sorted(environment['input']['currInput'])
|
||||
if not mEvent['EventName'] in self.env['input']['currInput']:
|
||||
self.env['input']['currInput'].append(mEvent['EventName'])
|
||||
self.env['input']['currInput'] = sorted(self.env['input']['currInput'])
|
||||
elif mEvent['EventState'] == 2:
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
environment['input']['oldNumLock'] = environment['input']['newNumLock']
|
||||
environment['input']['newNumLock'] = environment['runtime']['inputDriver'].getNumlock(environment)
|
||||
environment['input']['oldCapsLock'] = environment['input']['newCapsLock']
|
||||
environment['input']['newCapsLock'] = environment['runtime']['inputDriver'].getCapslock(environment)
|
||||
environment['input']['oldScrollLock'] = environment['input']['newScrollLock']
|
||||
environment['input']['newScrollLock'] = environment['runtime']['inputDriver'].getScrollLock(environment)
|
||||
environment['input']['lastInputTime'] = time.time()
|
||||
environment['input']['shortcutRepeat'] = 1
|
||||
self.env['input']['oldNumLock'] = self.env['input']['newNumLock']
|
||||
self.env['input']['newNumLock'] = self.env['runtime']['inputDriver'].getNumlock()
|
||||
self.env['input']['oldCapsLock'] = self.env['input']['newCapsLock']
|
||||
self.env['input']['newCapsLock'] = self.env['runtime']['inputDriver'].getCapslock()
|
||||
self.env['input']['oldScrollLock'] = self.env['input']['newScrollLock']
|
||||
self.env['input']['newScrollLock'] = self.env['runtime']['inputDriver'].getScrollLock()
|
||||
self.env['input']['lastInputTime'] = time.time()
|
||||
self.env['input']['shortcutRepeat'] = 1
|
||||
return eventReceived
|
||||
|
||||
def grabDevices(self, environment):
|
||||
if environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'grabDevices'):
|
||||
environment['runtime']['inputDriver'].grabDevices(environment)
|
||||
def grabDevices(self):
|
||||
if self.env['runtime']['settingsManager'].getSettingAsBool('keyboard', 'grabDevices'):
|
||||
self.env['runtime']['inputDriver'].grabDevices()
|
||||
|
||||
def releaseDevices(self, environment):
|
||||
environment['runtime']['inputDriver'].releaseDevices(environment)
|
||||
def releaseDevices(self):
|
||||
self.env['runtime']['inputDriver'].releaseDevices()
|
||||
|
||||
def convertEventName(self, environment, eventName):
|
||||
def convertEventName(self, eventName):
|
||||
if not eventName:
|
||||
return ''
|
||||
if eventName == 'KEY_LEFTCTRL':
|
||||
@ -81,58 +80,59 @@ class inputManager():
|
||||
eventName = 'KEY_ALT'
|
||||
elif eventName == 'KEY_RIGHTALT':
|
||||
eventName = 'KEY_ALT'
|
||||
if self.isFenrirKey(environment, eventName):
|
||||
if self.isFenrirKey(eventName):
|
||||
eventName = 'KEY_FENRIR'
|
||||
return eventName
|
||||
|
||||
def isConsumeInput(self, environment):
|
||||
return environment['runtime']['commandManager'].isCommandQueued(environment) and \
|
||||
not environment['input']['keyForeward']
|
||||
def isConsumeInput(self):
|
||||
return self.env['runtime']['commandManager'].isCommandQueued() and \
|
||||
not self.env['input']['keyForeward']
|
||||
#and
|
||||
# not (environment['input']['keyForeward'] or \
|
||||
# environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'grabDevices'))
|
||||
# not (self.env['input']['keyForeward'] or \
|
||||
# self.env['runtime']['settingsManager'].getSettingAsBool(, 'keyboard', 'grabDevices'))
|
||||
|
||||
def clearEventBuffer(self, environment):
|
||||
environment['runtime']['inputDriver'].clearEventBuffer(environment)
|
||||
def clearEventBuffer(self):
|
||||
self.env['runtime']['inputDriver'].clearEventBuffer()
|
||||
|
||||
def writeEventBuffer(self, environment):
|
||||
def writeEventBuffer(self):
|
||||
try:
|
||||
environment['runtime']['inputDriver'].writeEventBuffer(environment)
|
||||
self.env['runtime']['inputDriver'].writeEventBuffer()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"Error while writeUInput",debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment, str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("Error while writeUInput",debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
|
||||
def isFenrirKeyPressed(self, environment):
|
||||
return 'KEY_FENRIR' in environment['input']['currInput']
|
||||
def isFenrirKeyPressed(self):
|
||||
return 'KEY_FENRIR' in self.env['input']['currInput']
|
||||
|
||||
def noKeyPressed(self, environment):
|
||||
return environment['input']['currInput'] == []
|
||||
def getPrevDeepestInput(self, environment):
|
||||
def noKeyPressed(self):
|
||||
return self.env['input']['currInput'] == []
|
||||
|
||||
def getPrevDeepestInput(self):
|
||||
shortcut = []
|
||||
shortcut.append(environment['input']['shortcutRepeat'])
|
||||
shortcut.append(sorted(environment['input']['prevDeepestInput']))
|
||||
shortcut.append(self.env['input']['shortcutRepeat'])
|
||||
shortcut.append(sorted(self.env['input']['prevDeepestInput']))
|
||||
|
||||
def getPrevShortcut(self, environment):
|
||||
def getPrevShortcut(self):
|
||||
shortcut = []
|
||||
shortcut.append(environment['input']['shortcutRepeat'])
|
||||
shortcut.append(sorted(environment['input']['prevInput']))
|
||||
shortcut.append(self.env['input']['shortcutRepeat'])
|
||||
shortcut.append(sorted(self.env['input']['prevInput']))
|
||||
return str(shortcut)
|
||||
|
||||
def getCurrShortcut(self, environment):
|
||||
def getCurrShortcut(self):
|
||||
shortcut = []
|
||||
shortcut.append(environment['input']['shortcutRepeat'])
|
||||
shortcut.append(sorted(environment['input']['currInput']))
|
||||
shortcut.append(self.env['input']['shortcutRepeat'])
|
||||
shortcut.append(sorted(self.env['input']['currInput']))
|
||||
return str(shortcut)
|
||||
|
||||
def isFenrirKey(self,environment, eventName):
|
||||
return eventName in environment['input']['fenrirKey']
|
||||
def isFenrirKey(self, eventName):
|
||||
return eventName in self.env['input']['fenrirKey']
|
||||
|
||||
def getCommandForShortcut(self, environment, shortcut):
|
||||
def getCommandForShortcut(self, shortcut):
|
||||
shortcut = shortcut.upper()
|
||||
if not self.shortcutExists(environment, shortcut):
|
||||
if not self.shortcutExists(shortcut):
|
||||
return ''
|
||||
return environment['bindings'][shortcut].upper()
|
||||
return self.env['bindings'][shortcut].upper()
|
||||
|
||||
def shortcutExists(self, environment, shortcut):
|
||||
return( str(shortcut).upper() in environment['bindings'])
|
||||
def shortcutExists(self, shortcut):
|
||||
return( str(shortcut).upper() in self.env['bindings'])
|
||||
|
@ -10,104 +10,102 @@ class outputManager():
|
||||
def __init__(self):
|
||||
pass
|
||||
def initialize(self, environment):
|
||||
environment['runtime']['settingsManager'].loadDriver(environment,\
|
||||
environment['runtime']['settingsManager'].getSetting(environment,'speech', 'driver'), 'speechDriver')
|
||||
environment['runtime']['settingsManager'].loadDriver(environment,\
|
||||
environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver'), 'soundDriver')
|
||||
self.env = environment
|
||||
self.env['runtime']['settingsManager'].loadDriver(\
|
||||
self.env['runtime']['settingsManager'].getSetting('speech', 'driver'), 'speechDriver')
|
||||
self.env['runtime']['settingsManager'].loadDriver(\
|
||||
self.env['runtime']['settingsManager'].getSetting('sound', 'driver'), 'soundDriver')
|
||||
|
||||
def shutdown(self, environment):
|
||||
if environment['runtime']['soundDriver']:
|
||||
environment['runtime']['soundDriver'].shutdown(environment)
|
||||
del environment['runtime']['soundDriver']
|
||||
if environment['runtime']['speechDriver']:
|
||||
environment['runtime']['speechDriver'].shutdown(environment)
|
||||
del environment['runtime']['speechDriver']
|
||||
def shutdown(self):
|
||||
self.env['runtime']['settingsManager'].shutdownDriver('soundDriver')
|
||||
self.env['runtime']['settingsManager'].shutdownDriver('speechDriver')
|
||||
|
||||
def presentText(self, environment, text, interrupt=True, soundIcon = ''):
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"presentText:\nsoundIcon:'"+soundIcon+"'\nText:\n" + text ,debug.debugLevel.INFO)
|
||||
if self.playSoundIcon(environment, soundIcon, interrupt):
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"soundIcon found" ,debug.debugLevel.INFO)
|
||||
def presentText(self, text, interrupt=True, soundIcon = ''):
|
||||
self.env['runtime']['debug'].writeDebugOut("presentText:\nsoundIcon:'"+soundIcon+"'\nText:\n" + text ,debug.debugLevel.INFO)
|
||||
if self.playSoundIcon(soundIcon, interrupt):
|
||||
self.env['runtime']['debug'].writeDebugOut("soundIcon found" ,debug.debugLevel.INFO)
|
||||
return
|
||||
self.speakText(environment, text, interrupt)
|
||||
self.brailleText(environment, text, interrupt)
|
||||
self.speakText(text, interrupt)
|
||||
self.brailleText(text, interrupt)
|
||||
|
||||
def speakText(self, environment, text, interrupt=True):
|
||||
if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'speech', 'enabled'):
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"Speech disabled in outputManager.speakText",debug.debugLevel.INFO)
|
||||
def speakText(self, text, interrupt=True):
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('speech', 'enabled'):
|
||||
self.env['runtime']['debug'].writeDebugOut("Speech disabled in outputManager.speakText",debug.debugLevel.INFO)
|
||||
return
|
||||
if environment['runtime']['speechDriver'] == None:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"No speechDriver in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
if self.env['runtime']['speechDriver'] == None:
|
||||
self.env['runtime']['debug'].writeDebugOut("No speechDriver in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
return
|
||||
if interrupt:
|
||||
self.interruptOutput(environment)
|
||||
self.interruptOutput()
|
||||
try:
|
||||
environment['runtime']['speechDriver'].setLanguage(environment['runtime']['settingsManager'].getSetting(environment, 'speech', 'language'))
|
||||
self.env['runtime']['speechDriver'].setLanguage(self.env['runtime']['settingsManager'].getSetting('speech', 'language'))
|
||||
except Exception as e:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"setting speech language in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("setting speech language in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
|
||||
try:
|
||||
environment['runtime']['speechDriver'].setVoice(environment['runtime']['settingsManager'].getSetting(environment, 'speech', 'voice'))
|
||||
self.env['runtime']['speechDriver'].setVoice(self.env['runtime']['settingsManager'].getSetting('speech', 'voice'))
|
||||
except Exception as e:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"Error while setting speech voice in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("Error while setting speech voice in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
|
||||
try:
|
||||
environment['runtime']['speechDriver'].setPitch(environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'speech', 'pitch'))
|
||||
self.env['runtime']['speechDriver'].setPitch(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'pitch'))
|
||||
except Exception as e:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"setting speech pitch in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("setting speech pitch in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
|
||||
try:
|
||||
environment['runtime']['speechDriver'].setRate(environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'speech', 'rate'))
|
||||
self.env['runtime']['speechDriver'].setRate(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'rate'))
|
||||
except Exception as e:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"setting speech rate in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("setting speech rate in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
|
||||
try:
|
||||
environment['runtime']['speechDriver'].setModule(environment['runtime']['settingsManager'].getSetting(environment, 'speech', 'module'))
|
||||
self.env['runtime']['speechDriver'].setModule(self.env['runtime']['settingsManager'].getSetting('speech', 'module'))
|
||||
except Exception as e:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"setting speech module in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("setting speech module in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
|
||||
try:
|
||||
environment['runtime']['speechDriver'].setVolume(environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'speech', 'volume'))
|
||||
self.env['runtime']['speechDriver'].setVolume(self.env['runtime']['settingsManager'].getSettingAsFloat('speech', 'volume'))
|
||||
except Exception as e:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"setting speech volume in outputManager.speakText ",debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("setting speech volume in outputManager.speakText ",debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
|
||||
try:
|
||||
environment['runtime']['speechDriver'].speak(text)
|
||||
self.env['runtime']['speechDriver'].speak(text)
|
||||
except Exception as e:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"\"speak\" in outputManager.speakText ",debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("\"speak\" in outputManager.speakText ",debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
|
||||
def brailleText(self, environment, text, interrupt=True):
|
||||
if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'braille', 'enabled'):
|
||||
def brailleText(self, text, interrupt=True):
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('braille', 'enabled'):
|
||||
return
|
||||
if environment['runtime']['brailleDriver'] == None:
|
||||
if self.env['runtime']['brailleDriver'] == None:
|
||||
return
|
||||
print('braille:'+text)
|
||||
def interruptOutput(self, environment):
|
||||
environment['runtime']['speechDriver'].cancel()
|
||||
environment['runtime']['soundDriver'].cancel()
|
||||
|
||||
def playSoundIcon(self, environment, soundIcon = '', interrupt=True):
|
||||
def interruptOutput(self):
|
||||
self.env['runtime']['speechDriver'].cancel()
|
||||
self.env['runtime']['soundDriver'].cancel()
|
||||
|
||||
def playSoundIcon(self, soundIcon = '', interrupt=True):
|
||||
if soundIcon == '':
|
||||
return False
|
||||
soundIcon = soundIcon.upper()
|
||||
if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'sound', 'enabled'):
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"Sound disabled in outputManager.speakText",debug.debugLevel.INFO)
|
||||
if not self.env['runtime']['settingsManager'].getSettingAsBool('sound', 'enabled'):
|
||||
self.env['runtime']['debug'].writeDebugOut("Sound disabled in outputManager.speakText",debug.debugLevel.INFO)
|
||||
return False
|
||||
|
||||
if environment['runtime']['soundDriver'] == None:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"No speechDriver in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
if self.env['runtime']['soundDriver'] == None:
|
||||
self.env['runtime']['debug'].writeDebugOut("No speechDriver in outputManager.speakText",debug.debugLevel.ERROR)
|
||||
return False
|
||||
try:
|
||||
environment['runtime']['soundDriver'].setVolume(environment['runtime']['settingsManager'].getSettingAsFloat(environment, 'sound', 'volume'))
|
||||
environment['runtime']['soundDriver'].playSoundFile(environment['soundIcons'][soundIcon], interrupt)
|
||||
self.env['runtime']['soundDriver'].setVolume(self.env['runtime']['settingsManager'].getSettingAsFloat('sound', 'volume'))
|
||||
self.env['runtime']['soundDriver'].playSoundFile(self.env['soundIcons'][soundIcon], interrupt)
|
||||
return True
|
||||
except Exception as e:
|
||||
environment['runtime']['debug'].writeDebugOut(environment,"\"playSoundIcon\" in outputManager.speakText ",debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut("\"playSoundIcon\" in outputManager.speakText ",debug.debugLevel.ERROR)
|
||||
self.env['runtime']['debug'].writeDebugOut(str(e),debug.debugLevel.ERROR)
|
||||
return False
|
||||
|
@ -12,23 +12,22 @@ class screenManager():
|
||||
self.autoIgnoreScreens = []
|
||||
|
||||
def initialize(self, environment):
|
||||
environment['runtime']['settingsManager'].loadDriver(environment,\
|
||||
environment['runtime']['settingsManager'].getSetting(environment,'screen', 'driver'), 'screenDriver')
|
||||
if environment['runtime']['settingsManager'].getSettingAsBool(environment,'screen', 'autodetectSuspendingScreen'):
|
||||
self.autoIgnoreScreens = environment['runtime']['screenDriver'].getIgnoreScreens()
|
||||
self.env = environment
|
||||
self.env['runtime']['settingsManager'].loadDriver(\
|
||||
self.env['runtime']['settingsManager'].getSetting('screen', 'driver'), 'screenDriver')
|
||||
if self.env['runtime']['settingsManager'].getSettingAsBool('screen', 'autodetectSuspendingScreen'):
|
||||
self.autoIgnoreScreens = self.env['runtime']['screenDriver'].getIgnoreScreens()
|
||||
|
||||
def shutdown(self, environment):
|
||||
if environment['runtime']['screenDriver']:
|
||||
environment['runtime']['screenDriver'].shutdown(environment)
|
||||
del environment['runtime']['screenDriver']
|
||||
def shutdown(self):
|
||||
self.env['runtime']['settingsManager'].shutdownDriver('screenDriver')
|
||||
|
||||
def update(self, environment):
|
||||
if not self.isSuspendingScreen(environment):
|
||||
environment['runtime']['screenDriver'].update(environment)
|
||||
environment['screenData']['lastScreenUpdate'] = time.time()
|
||||
def update(self):
|
||||
if not self.isSuspendingScreen():
|
||||
self.env['runtime']['screenDriver'].update()
|
||||
self.env['screenData']['lastScreenUpdate'] = time.time()
|
||||
|
||||
def isSuspendingScreen(self, environment):
|
||||
currScreen = environment['runtime']['screenDriver'].getCurrScreen()
|
||||
def isSuspendingScreen(self):
|
||||
currScreen = self.env['runtime']['screenDriver'].getCurrScreen()
|
||||
return ((currScreen in \
|
||||
environment['runtime']['settingsManager'].getSetting(environment,'screen', 'suspendingScreen').split(',')) or
|
||||
self.env['runtime']['settingsManager'].getSetting('screen', 'suspendingScreen').split(',')) or
|
||||
(currScreen in self.autoIgnoreScreens))
|
||||
|
@ -19,10 +19,10 @@ class settingsManager():
|
||||
def __init__(self):
|
||||
self.settings = settings
|
||||
def initialize(self, environment):
|
||||
self.env = environment
|
||||
def shutdown(self):
|
||||
pass
|
||||
def shutdown(self, environment):
|
||||
pass
|
||||
def loadShortcuts(self, environment, kbConfigPath='../../config/keyboard/desktop.conf'):
|
||||
def loadShortcuts(self, kbConfigPath='../../config/keyboard/desktop.conf'):
|
||||
kbConfig = open(kbConfigPath,"r")
|
||||
while(True):
|
||||
line = kbConfig.readline()
|
||||
@ -50,10 +50,10 @@ class settingsManager():
|
||||
shortcut.append(shortcutRepeat)
|
||||
shortcut.append(sorted(shortcutKeys))
|
||||
print(str(shortcut), commandName)
|
||||
environment['bindings'][str(shortcut)] = commandName
|
||||
self.env['bindings'][str(shortcut)] = commandName
|
||||
kbConfig.close()
|
||||
|
||||
def loadSoundIcons(self, environment, soundIconPath):
|
||||
def loadSoundIcons(self, soundIconPath):
|
||||
siConfig = open(soundIconPath + '/soundicons.conf',"r")
|
||||
while(True):
|
||||
line = siConfig.readline()
|
||||
@ -76,67 +76,73 @@ class settingsManager():
|
||||
soundIconPath += '/'
|
||||
if os.path.exists(soundIconPath + Values[1]):
|
||||
soundIconFile = soundIconPath + Values[1]
|
||||
environment['soundIcons'][soundIcon] = soundIconFile
|
||||
self.env['soundIcons'][soundIcon] = soundIconFile
|
||||
siConfig.close()
|
||||
|
||||
def loadSettings(self, environment, settingConfigPath):
|
||||
def loadSettings(self, settingConfigPath):
|
||||
if not os.path.exists(settingConfigPath):
|
||||
return False
|
||||
environment['settings'] = ConfigParser()
|
||||
environment['settings'].read(settingConfigPath)
|
||||
self.env['settings'] = ConfigParser()
|
||||
self.env['settings'].read(settingConfigPath)
|
||||
return True
|
||||
|
||||
def setSetting(self, environment, section, setting, value):
|
||||
environment['settings'].set(section, setting, value)
|
||||
def setSetting(self, section, setting, value):
|
||||
self.env['settings'].set(section, setting, value)
|
||||
|
||||
def getSetting(self, environment, section, setting):
|
||||
def getSetting(self, section, setting):
|
||||
value = ''
|
||||
try:
|
||||
value = environment['settings'].get(section, setting)
|
||||
value = self.env['settings'].get(section, setting)
|
||||
except:
|
||||
value = str(self.settings[section][setting])
|
||||
return value
|
||||
|
||||
def getSettingAsInt(self, environment, section, setting):
|
||||
def getSettingAsInt(self, section, setting):
|
||||
value = 0
|
||||
try:
|
||||
value = environment['settings'].getint(section, setting)
|
||||
value = self.env['settings'].getint(section, setting)
|
||||
except:
|
||||
value = self.settings[section][setting]
|
||||
return value
|
||||
|
||||
def getSettingAsFloat(self, environment, section, setting):
|
||||
def getSettingAsFloat(self, section, setting):
|
||||
value = 0.0
|
||||
try:
|
||||
value = environment['settings'].getfloat(section, setting)
|
||||
value = self.env['settings'].getfloat(section, setting)
|
||||
except:
|
||||
value = self.settings[section][setting]
|
||||
return value
|
||||
|
||||
def getSettingAsBool(self, environment, section, setting):
|
||||
def getSettingAsBool(self, section, setting):
|
||||
value = False
|
||||
try:
|
||||
value = environment['settings'].getboolean(section, setting)
|
||||
value = self.env['settings'].getboolean(section, setting)
|
||||
except:
|
||||
value = self.settings[section][setting]
|
||||
return value
|
||||
|
||||
def loadDriver(self, environment, driverName, driverType):
|
||||
if environment['runtime'][driverType] != None:
|
||||
def loadDriver(self, driverName, driverType):
|
||||
if self.env['runtime'][driverType] != None:
|
||||
print('shutdown %s',driverType)
|
||||
environment['runtime'][driverType].shutdown(environment)
|
||||
self.env['runtime'][driverType].shutdown(self.env)
|
||||
spec = importlib.util.spec_from_file_location(driverName, driverType + '/' + driverName + '.py')
|
||||
driver_mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(driver_mod)
|
||||
environment['runtime'][driverType] = driver_mod.driver()
|
||||
environment['runtime'][driverType].initialize(environment)
|
||||
self.env['runtime'][driverType] = driver_mod.driver()
|
||||
self.env['runtime'][driverType].initialize(self.env)
|
||||
|
||||
def setFenrirKeys(self, environment, keys):
|
||||
def shutdownDriver(self, driverType):
|
||||
if self.env['runtime'][driverType] == None:
|
||||
return
|
||||
self.env['runtime'][driverType].shutdown()
|
||||
del self.env['runtime'][driverType]
|
||||
|
||||
def setFenrirKeys(self, keys):
|
||||
keys = keys.upper()
|
||||
keyList = keys.split(',')
|
||||
for key in keyList:
|
||||
if not key in environment['input']['fenrirKey']:
|
||||
environment['input']['fenrirKey'].append(key)
|
||||
if not key in self.env['input']['fenrirKey']:
|
||||
self.env['input']['fenrirKey'].append(key)
|
||||
|
||||
def keyIDasString(self, key):
|
||||
try:
|
||||
@ -147,34 +153,37 @@ class settingsManager():
|
||||
|
||||
def initFenrirConfig(self, environment = environment.environment, settingsRoot = '/etc/fenrir/', settingsFile='settings.conf'):
|
||||
environment['runtime']['debug'] = debug.debug()
|
||||
environment['runtime']['debug'].initialize(environment)
|
||||
if not os.path.exists(settingsRoot):
|
||||
if os.path.exists('../../config/'):
|
||||
settingsRoot = '../../config/'
|
||||
else:
|
||||
return None
|
||||
|
||||
environment['runtime']['settingsManager'] = self
|
||||
validConfig = environment['runtime']['settingsManager'].loadSettings(environment, settingsRoot + '/settings/' + settingsFile)
|
||||
environment['runtime']['settingsManager'] = self
|
||||
environment['runtime']['settingsManager'].initialize(environment)
|
||||
|
||||
validConfig = environment['runtime']['settingsManager'].loadSettings(settingsRoot + '/settings/' + settingsFile)
|
||||
if not validConfig:
|
||||
return None
|
||||
self.setFenrirKeys(environment, self.getSetting(environment, 'general','fenrirKeys'))
|
||||
if not os.path.exists(self.getSetting(environment, 'keyboard','keyboardLayout')):
|
||||
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout')):
|
||||
self.setSetting(environment, 'keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout'))
|
||||
environment['runtime']['settingsManager'].loadShortcuts(environment, self.getSetting('keyboard','keyboardLayout'))
|
||||
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout') + '.conf'):
|
||||
self.setSetting(environment, 'keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout') + '.conf')
|
||||
environment['runtime']['settingsManager'].loadShortcuts(environment, self.getSetting(environment, 'keyboard','keyboardLayout'))
|
||||
self.setFenrirKeys(self.getSetting('general','fenrirKeys'))
|
||||
if not os.path.exists(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(environment, self.getSetting(environment, 'keyboard','keyboardLayout'))
|
||||
environment['runtime']['settingsManager'].loadShortcuts(self.getSetting('keyboard','keyboardLayout'))
|
||||
|
||||
if not os.path.exists(self.getSetting(environment, 'sound','theme') + '/soundicons.conf'):
|
||||
if os.path.exists(settingsRoot + 'sound/'+ self.getSetting(environment, 'sound','theme')):
|
||||
self.setSetting(environment, 'sound', 'theme', settingsRoot + 'sound/'+ self.getSetting(environment, 'sound','theme'))
|
||||
if os.path.exists(settingsRoot + 'sound/'+ self.getSetting(environment, 'sound','theme') + '/soundicons.conf'):
|
||||
environment['runtime']['settingsManager'].loadSoundIcons(environment, self.getSetting(environment, 'sound','theme'))
|
||||
if not os.path.exists(self.getSetting('sound','theme') + '/soundicons.conf'):
|
||||
if os.path.exists(settingsRoot + 'sound/'+ self.getSetting('sound','theme')):
|
||||
self.setSetting('sound', 'theme', settingsRoot + 'sound/'+ self.getSetting('sound','theme'))
|
||||
if os.path.exists(settingsRoot + 'sound/'+ self.getSetting('sound','theme') + '/soundicons.conf'):
|
||||
environment['runtime']['settingsManager'].loadSoundIcons(self.getSetting('sound','theme'))
|
||||
else:
|
||||
environment['runtime']['settingsManager'].loadSoundIcons(environment, self.getSetting(environment, 'sound','theme'))
|
||||
environment['runtime']['settingsManager'].loadSoundIcons(self.getSetting('sound','theme'))
|
||||
|
||||
environment['runtime']['inputManager'] = inputManager.inputManager()
|
||||
environment['runtime']['inputManager'].initialize(environment)
|
||||
@ -182,15 +191,15 @@ class settingsManager():
|
||||
environment['runtime']['outputManager'].initialize(environment)
|
||||
environment['runtime']['commandManager'] = commandManager.commandManager()
|
||||
environment['runtime']['commandManager'].initialize(environment)
|
||||
|
||||
|
||||
if environment['runtime']['screenManager'] == None:
|
||||
environment['runtime']['screenManager'] = screenManager.screenManager()
|
||||
environment['runtime']['screenManager'].initialize(environment)
|
||||
|
||||
environment['runtime']['debug'].writeDebugOut(environment,'\/-------environment-------\/',debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(environment),debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,'\/-------settings.conf-------\/',debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(environment,str(environment['settings']._sections
|
||||
environment['runtime']['debug'].writeDebugOut('\/-------environment-------\/',debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(str(environment),debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut('\/-------settings.conf-------\/',debug.debugLevel.ERROR)
|
||||
environment['runtime']['debug'].writeDebugOut(str(environment['settings']._sections
|
||||
),debug.debugLevel.ERROR)
|
||||
return environment
|
||||
|
||||
|
Reference in New Issue
Block a user