diff --git a/src/fenrir-package/commands/commands/curr_line.py b/src/fenrir-package/commands/commands/curr_line.py index b186105b..9382c291 100644 --- a/src/fenrir-package/commands/commands/curr_line.py +++ b/src/fenrir-package/commands/commands/curr_line.py @@ -4,15 +4,14 @@ class command(): def __init__(self): pass def run(self, environment): - environment['runtime']['speechDriver'].cancel() environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] if environment['screenData']['newCursorReview']['y'] == -1: environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() if environment['screenData']['newContentText'].replace(" ","") == '': - environment['runtime']['speechDriver'].speak("empty line") + environment['runtime']['outputManager'].speakText(environment, "empty line") else: - environment['runtime']['speechDriver'].speak(environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursorReview']['y']]) + environment['runtime']['outputManager'].speakText(environment, environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursorReview']['y']]) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/commands/exit_review.py b/src/fenrir-package/commands/commands/exit_review.py index 91115c75..35a17b91 100644 --- a/src/fenrir-package/commands/commands/exit_review.py +++ b/src/fenrir-package/commands/commands/exit_review.py @@ -4,10 +4,9 @@ class command(): def __init__(self): pass def run(self, environment): - environment['runtime']['speechDriver'].cancel() environment['screenData']['oldCursorReview'] = {'x':-1,'y':-1} environment['screenData']['newCursorReview'] = {'x':-1,'y':-1} - environment['runtime']['speechDriver'].speak("leve review mode") + environment['runtime']['outputManager'].speakText(environment, "leve review mode") return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/commands/next_line.py b/src/fenrir-package/commands/commands/next_line.py index 163ca994..c618c0f6 100644 --- a/src/fenrir-package/commands/commands/next_line.py +++ b/src/fenrir-package/commands/commands/next_line.py @@ -4,7 +4,6 @@ class command(): def __init__(self): pass def run(self, environment): - environment['runtime']['speechDriver'].cancel() environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] if environment['screenData']['newCursorReview']['y'] == -1: environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() @@ -12,9 +11,9 @@ class command(): environment['screenData']['newCursorReview']['y'] = environment['screenData']['newCursorReview']['y'] + 1 if environment['screenData']['newContentText'].replace(" ","") == '': - environment['runtime']['speechDriver'].speak("empty line") + environment['runtime']['outputManager'].speakText(environment, "empty line") else: - environment['runtime']['speechDriver'].speak(environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursorReview']['y']]) + environment['runtime']['outputManager'].speakText(environment, environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursorReview']['y']]) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/commands/prev_line.py b/src/fenrir-package/commands/commands/prev_line.py index 94425d80..e8ce6fe5 100644 --- a/src/fenrir-package/commands/commands/prev_line.py +++ b/src/fenrir-package/commands/commands/prev_line.py @@ -4,7 +4,6 @@ class command(): def __init__(self): pass def run(self, environment): - environment['runtime']['speechDriver'].cancel() environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview'] if environment['screenData']['newCursorReview']['y'] == -1: environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy() @@ -12,9 +11,9 @@ class command(): environment['screenData']['newCursorReview']['y'] = environment['screenData']['newCursorReview']['y'] - 1 if environment['screenData']['newContentText'].replace(" ","") == '': - environment['runtime']['speechDriver'].speak("empty line") + environment['runtime']['outputManager'].speakText(environment, "empty line") else: - environment['runtime']['speechDriver'].speak(environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursorReview']['y']]) + environment['runtime']['outputManager'].speakText(environment, environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursorReview']['y']]) return environment def setCallback(self, callback): diff --git a/src/fenrir-package/commands/commands/shut_up.py b/src/fenrir-package/commands/commands/shut_up.py index 4416e19b..680e4d83 100644 --- a/src/fenrir-package/commands/commands/shut_up.py +++ b/src/fenrir-package/commands/commands/shut_up.py @@ -4,7 +4,7 @@ class command(): def __init__(self): pass def run(self, environment): - environment['runtime']['speechDriver'].cancel() + environment['runtime']['outputManager'].interruptOutput(environment) def setCallback(self, callback): pass def shutdown(self): diff --git a/src/fenrir-package/commands/onInput/10000-shut_up.py b/src/fenrir-package/commands/onInput/10000-shut_up.py index a6dc5767..6444e454 100644 --- a/src/fenrir-package/commands/onInput/10000-shut_up.py +++ b/src/fenrir-package/commands/onInput/10000-shut_up.py @@ -5,7 +5,7 @@ class command(): pass def run(self, environment): if environment['screenData']['newDelta'] != environment['screenData']['oldDelta']: - environment['runtime']['speechDriver'].cancel() + environment['runtime']['outputManager'].interruptOutput(environment) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/onInput/70000-speak_incomming.py b/src/fenrir-package/commands/onInput/70000-speak_incomming.py index 365e4adf..5259addd 100644 --- a/src/fenrir-package/commands/onInput/70000-speak_incomming.py +++ b/src/fenrir-package/commands/onInput/70000-speak_incomming.py @@ -6,7 +6,7 @@ class command(): def run(self, environment): if environment['screenData']['newDelta'] != environment['screenData']['oldDelta'] or \ environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: - environment['runtime']['speechDriver'].speak(environment['screenData']['newDelta']) + environment['runtime']['outputManager'].speakText(environment, environment['screenData']['newDelta'], Interrupt=False) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/core/commandManager.py b/src/fenrir-package/core/commandManager.py index 22f81804..565845e9 100644 --- a/src/fenrir-package/core/commandManager.py +++ b/src/fenrir-package/core/commandManager.py @@ -31,6 +31,7 @@ class commandManager(): return environment def executeCommand(self, environment, currCommand, section = 'commands'): + environment = environment['commands'][section][currCommand].run(environment) if self.isCommandDefined(environment): try: environ = environment['commands'][section][currCommand].run(environment) diff --git a/src/fenrir-package/core/inputManager.py b/src/fenrir-package/core/inputManager.py index e66ec0eb..181afd84 100644 --- a/src/fenrir-package/core/inputManager.py +++ b/src/fenrir-package/core/inputManager.py @@ -13,6 +13,7 @@ class inputManager(): def getKeyPressed(self, environment): try: r, w, x = select(self.devices, [], []) + environment['runtime']['globalLock'].acquire(True) currShortcut = environment['input']['currShortcut'] if r != []: for fd in r: diff --git a/src/fenrir-package/core/outputManager.py b/src/fenrir-package/core/outputManager.py index cb35bb57..52e4fc2f 100644 --- a/src/fenrir-package/core/outputManager.py +++ b/src/fenrir-package/core/outputManager.py @@ -3,13 +3,25 @@ class outputManager(): def __init__(self): pass - def presentText(self, environment, Text): - pass - def speakText(self, environment, Text): - pass + def presentText(self, environment, Text, Interrupt=True): + self.speakText(environment, Text, Interrupt) + self.brailleText(environment, Text) + + def speakText(self, environment, Text, Interrupt=True): + if environment['runtime']['speechDriver'] == None: + return + if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'speech', 'enabled'): + return + if Interrupt: + self.interruptOutput(environment) + environment['runtime']['speechDriver'].speak(Text) + def brailleText(self, environment, Text): - pass - def interruptOutput(self, environment, Text): - pass + if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'braile', 'enabled'): + return + print('braille') + def interruptOutput(self, environment): + environment['runtime']['speechDriver'].cancel() + def playSoundIcon(self, environment, Text): pass diff --git a/src/fenrir-package/core/runtime.py b/src/fenrir-package/core/runtime.py index ad193931..6f000af6 100644 --- a/src/fenrir-package/core/runtime.py +++ b/src/fenrir-package/core/runtime.py @@ -1,4 +1,5 @@ #!/bin/python +from _thread import allocate_lock runtime = { 'speechDriver': None, @@ -7,4 +8,5 @@ runtime = { 'inputManager': None, 'commandManager': None, 'debug':None, +'globalLock': allocate_lock(), } diff --git a/src/fenrir-package/core/settingsManager.py b/src/fenrir-package/core/settingsManager.py index 32bd3fe0..295969e8 100644 --- a/src/fenrir-package/core/settingsManager.py +++ b/src/fenrir-package/core/settingsManager.py @@ -3,6 +3,7 @@ import evdev import importlib.util from configparser import ConfigParser from core import inputManager +from core import outputManager from core import commandManager from core import environment from core.settings import settings @@ -80,10 +81,10 @@ class settingsManager(): return value def getSettingAsInt(self, environment, section, setting): - return int(getSetting(self, environment, section, setting)) + return int(self.getSetting( environment, section, setting)) def getSettingAsBool(self, environment, section, setting): - return bool(getSetting(self, environment, section, setting)) + return bool(self.getSetting(environment, section, setting)) def loadSpeechDriver(self, environment, driverName): if environment['runtime']['speechDriver'] != None: @@ -108,7 +109,8 @@ class settingsManager(): driver_mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(driver_mod) environment['runtime']['screenDriver'] = driver_mod.screen() - return environment + return environment + def initFenrirConfig(self): return self.reInitFenrirConfig(environment.environment) @@ -116,6 +118,7 @@ class settingsManager(): environment['runtime']['settingsManager'] = self environment['runtime']['inputManager'] = inputManager.inputManager() + environment['runtime']['outputManager'] = outputManager.outputManager() environment = environment['runtime']['settingsManager'].loadShortcuts(environment) environment = environment['runtime']['settingsManager'].loadSettings(environment) diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index 0b66f209..8ce0dc61 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -16,13 +16,13 @@ from core import settingsManager class fenrir(): def __init__(self): self.threadHandleInput = None + self.environment = settingsManager.settingsManager().initFenrirConfig() signal.signal(signal.SIGINT, self.captureSignal) def proceed(self): self.threadHandleInput = Thread(target=self.handleInput, args=()) self.threadHandleInput.start() - self.updateScreen() while(self.environment['generalInformation']['running']): self.updateScreen() self.shutdown() @@ -35,15 +35,18 @@ class fenrir(): self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput') if self.environment['input']['currShortcutString'] != '': self.handleCommands() + self.environment['runtime']['globalLock'].release() def updateScreen(self): + self.environment['runtime']['globalLock'].acquire(True) self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment) self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged') + self.environment['runtime']['globalLock'].release() time.sleep(0.5) def handleCommands(self): if (self.environment['commandInfo']['currCommand'] != '') and \ - (time.time() - self.environment['commandInfo']['lastCommandTime'] >= 0.04): + (time.time() - self.environment['commandInfo']['lastCommandTime'] >= 0.05): self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands') def shutdown(self):