add lock, initial outputManager
This commit is contained in:
parent
7b8d212af6
commit
d9f8229aa5
@ -4,15 +4,14 @@ class command():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
environment['runtime']['speechDriver'].cancel()
|
|
||||||
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
||||||
if environment['screenData']['newCursorReview']['y'] == -1:
|
if environment['screenData']['newCursorReview']['y'] == -1:
|
||||||
environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy()
|
environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy()
|
||||||
|
|
||||||
if environment['screenData']['newContentText'].replace(" ","") == '':
|
if environment['screenData']['newContentText'].replace(" ","") == '':
|
||||||
environment['runtime']['speechDriver'].speak("empty line")
|
environment['runtime']['outputManager'].speakText(environment, "empty line")
|
||||||
else:
|
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
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
|
@ -4,10 +4,9 @@ class command():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
environment['runtime']['speechDriver'].cancel()
|
|
||||||
environment['screenData']['oldCursorReview'] = {'x':-1,'y':-1}
|
environment['screenData']['oldCursorReview'] = {'x':-1,'y':-1}
|
||||||
environment['screenData']['newCursorReview'] = {'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
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
|
@ -4,7 +4,6 @@ class command():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
environment['runtime']['speechDriver'].cancel()
|
|
||||||
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
||||||
if environment['screenData']['newCursorReview']['y'] == -1:
|
if environment['screenData']['newCursorReview']['y'] == -1:
|
||||||
environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy()
|
environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy()
|
||||||
@ -12,9 +11,9 @@ class command():
|
|||||||
environment['screenData']['newCursorReview']['y'] = environment['screenData']['newCursorReview']['y'] + 1
|
environment['screenData']['newCursorReview']['y'] = environment['screenData']['newCursorReview']['y'] + 1
|
||||||
|
|
||||||
if environment['screenData']['newContentText'].replace(" ","") == '':
|
if environment['screenData']['newContentText'].replace(" ","") == '':
|
||||||
environment['runtime']['speechDriver'].speak("empty line")
|
environment['runtime']['outputManager'].speakText(environment, "empty line")
|
||||||
else:
|
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
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
|
@ -4,7 +4,6 @@ class command():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
environment['runtime']['speechDriver'].cancel()
|
|
||||||
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
environment['screenData']['oldCursorReview'] = environment['screenData']['newCursorReview']
|
||||||
if environment['screenData']['newCursorReview']['y'] == -1:
|
if environment['screenData']['newCursorReview']['y'] == -1:
|
||||||
environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy()
|
environment['screenData']['newCursorReview'] = environment['screenData']['newCursor'].copy()
|
||||||
@ -12,9 +11,9 @@ class command():
|
|||||||
environment['screenData']['newCursorReview']['y'] = environment['screenData']['newCursorReview']['y'] - 1
|
environment['screenData']['newCursorReview']['y'] = environment['screenData']['newCursorReview']['y'] - 1
|
||||||
|
|
||||||
if environment['screenData']['newContentText'].replace(" ","") == '':
|
if environment['screenData']['newContentText'].replace(" ","") == '':
|
||||||
environment['runtime']['speechDriver'].speak("empty line")
|
environment['runtime']['outputManager'].speakText(environment, "empty line")
|
||||||
else:
|
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
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
|
@ -4,7 +4,7 @@ class command():
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
environment['runtime']['speechDriver'].cancel()
|
environment['runtime']['outputManager'].interruptOutput(environment)
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
@ -5,7 +5,7 @@ class command():
|
|||||||
pass
|
pass
|
||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
if environment['screenData']['newDelta'] != environment['screenData']['oldDelta']:
|
if environment['screenData']['newDelta'] != environment['screenData']['oldDelta']:
|
||||||
environment['runtime']['speechDriver'].cancel()
|
environment['runtime']['outputManager'].interruptOutput(environment)
|
||||||
return environment
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
|
@ -6,7 +6,7 @@ class command():
|
|||||||
def run(self, environment):
|
def run(self, environment):
|
||||||
if environment['screenData']['newDelta'] != environment['screenData']['oldDelta'] or \
|
if environment['screenData']['newDelta'] != environment['screenData']['oldDelta'] or \
|
||||||
environment['screenData']['newTTY'] != environment['screenData']['oldTTY']:
|
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
|
return environment
|
||||||
def setCallback(self, callback):
|
def setCallback(self, callback):
|
||||||
pass
|
pass
|
||||||
|
@ -31,6 +31,7 @@ class commandManager():
|
|||||||
return environment
|
return environment
|
||||||
|
|
||||||
def executeCommand(self, environment, currCommand, section = 'commands'):
|
def executeCommand(self, environment, currCommand, section = 'commands'):
|
||||||
|
environment = environment['commands'][section][currCommand].run(environment)
|
||||||
if self.isCommandDefined(environment):
|
if self.isCommandDefined(environment):
|
||||||
try:
|
try:
|
||||||
environ = environment['commands'][section][currCommand].run(environment)
|
environ = environment['commands'][section][currCommand].run(environment)
|
||||||
|
@ -13,6 +13,7 @@ class inputManager():
|
|||||||
def getKeyPressed(self, environment):
|
def getKeyPressed(self, environment):
|
||||||
try:
|
try:
|
||||||
r, w, x = select(self.devices, [], [])
|
r, w, x = select(self.devices, [], [])
|
||||||
|
environment['runtime']['globalLock'].acquire(True)
|
||||||
currShortcut = environment['input']['currShortcut']
|
currShortcut = environment['input']['currShortcut']
|
||||||
if r != []:
|
if r != []:
|
||||||
for fd in r:
|
for fd in r:
|
||||||
|
@ -3,13 +3,25 @@
|
|||||||
class outputManager():
|
class outputManager():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def presentText(self, environment, Text):
|
def presentText(self, environment, Text, Interrupt=True):
|
||||||
pass
|
self.speakText(environment, Text, Interrupt)
|
||||||
def speakText(self, environment, Text):
|
self.brailleText(environment, Text)
|
||||||
pass
|
|
||||||
|
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):
|
def brailleText(self, environment, Text):
|
||||||
pass
|
if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'braile', 'enabled'):
|
||||||
def interruptOutput(self, environment, Text):
|
return
|
||||||
pass
|
print('braille')
|
||||||
|
def interruptOutput(self, environment):
|
||||||
|
environment['runtime']['speechDriver'].cancel()
|
||||||
|
|
||||||
def playSoundIcon(self, environment, Text):
|
def playSoundIcon(self, environment, Text):
|
||||||
pass
|
pass
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
|
from _thread import allocate_lock
|
||||||
|
|
||||||
runtime = {
|
runtime = {
|
||||||
'speechDriver': None,
|
'speechDriver': None,
|
||||||
@ -7,4 +8,5 @@ runtime = {
|
|||||||
'inputManager': None,
|
'inputManager': None,
|
||||||
'commandManager': None,
|
'commandManager': None,
|
||||||
'debug':None,
|
'debug':None,
|
||||||
|
'globalLock': allocate_lock(),
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import evdev
|
|||||||
import importlib.util
|
import importlib.util
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
from core import inputManager
|
from core import inputManager
|
||||||
|
from core import outputManager
|
||||||
from core import commandManager
|
from core import commandManager
|
||||||
from core import environment
|
from core import environment
|
||||||
from core.settings import settings
|
from core.settings import settings
|
||||||
@ -80,10 +81,10 @@ class settingsManager():
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
def getSettingAsInt(self, environment, section, setting):
|
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):
|
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):
|
def loadSpeechDriver(self, environment, driverName):
|
||||||
if environment['runtime']['speechDriver'] != None:
|
if environment['runtime']['speechDriver'] != None:
|
||||||
@ -109,6 +110,7 @@ class settingsManager():
|
|||||||
spec.loader.exec_module(driver_mod)
|
spec.loader.exec_module(driver_mod)
|
||||||
environment['runtime']['screenDriver'] = driver_mod.screen()
|
environment['runtime']['screenDriver'] = driver_mod.screen()
|
||||||
return environment
|
return environment
|
||||||
|
|
||||||
def initFenrirConfig(self):
|
def initFenrirConfig(self):
|
||||||
return self.reInitFenrirConfig(environment.environment)
|
return self.reInitFenrirConfig(environment.environment)
|
||||||
|
|
||||||
@ -116,6 +118,7 @@ class settingsManager():
|
|||||||
|
|
||||||
environment['runtime']['settingsManager'] = self
|
environment['runtime']['settingsManager'] = self
|
||||||
environment['runtime']['inputManager'] = inputManager.inputManager()
|
environment['runtime']['inputManager'] = inputManager.inputManager()
|
||||||
|
environment['runtime']['outputManager'] = outputManager.outputManager()
|
||||||
environment = environment['runtime']['settingsManager'].loadShortcuts(environment)
|
environment = environment['runtime']['settingsManager'].loadShortcuts(environment)
|
||||||
environment = environment['runtime']['settingsManager'].loadSettings(environment)
|
environment = environment['runtime']['settingsManager'].loadSettings(environment)
|
||||||
|
|
||||||
|
@ -16,13 +16,13 @@ from core import settingsManager
|
|||||||
class fenrir():
|
class fenrir():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.threadHandleInput = None
|
self.threadHandleInput = None
|
||||||
|
|
||||||
self.environment = settingsManager.settingsManager().initFenrirConfig()
|
self.environment = settingsManager.settingsManager().initFenrirConfig()
|
||||||
signal.signal(signal.SIGINT, self.captureSignal)
|
signal.signal(signal.SIGINT, self.captureSignal)
|
||||||
|
|
||||||
def proceed(self):
|
def proceed(self):
|
||||||
self.threadHandleInput = Thread(target=self.handleInput, args=())
|
self.threadHandleInput = Thread(target=self.handleInput, args=())
|
||||||
self.threadHandleInput.start()
|
self.threadHandleInput.start()
|
||||||
self.updateScreen()
|
|
||||||
while(self.environment['generalInformation']['running']):
|
while(self.environment['generalInformation']['running']):
|
||||||
self.updateScreen()
|
self.updateScreen()
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
@ -35,15 +35,18 @@ class fenrir():
|
|||||||
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput')
|
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput')
|
||||||
if self.environment['input']['currShortcutString'] != '':
|
if self.environment['input']['currShortcutString'] != '':
|
||||||
self.handleCommands()
|
self.handleCommands()
|
||||||
|
self.environment['runtime']['globalLock'].release()
|
||||||
|
|
||||||
def updateScreen(self):
|
def updateScreen(self):
|
||||||
|
self.environment['runtime']['globalLock'].acquire(True)
|
||||||
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment)
|
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment)
|
||||||
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')
|
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')
|
||||||
|
self.environment['runtime']['globalLock'].release()
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
def handleCommands(self):
|
def handleCommands(self):
|
||||||
if (self.environment['commandInfo']['currCommand'] != '') and \
|
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')
|
self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands')
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user