add lock, initial outputManager
This commit is contained in:
parent
7b8d212af6
commit
d9f8229aa5
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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(),
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user