add first trigger

This commit is contained in:
chrys 2016-07-12 23:09:11 +02:00
parent 0fb493e391
commit 6f84710b6f
11 changed files with 144 additions and 35 deletions

View File

@ -1 +1,26 @@
[sound]
enabled=False,
driver=sox
theme=default
[speech]
enabled=True
driver=speechd
rate=1
pitch=1
module=
voice=de
[braille]
enabled=False
layout=en
['screen]
driver=linux
[general]
keyboardLayout=desktop
debugLevel=0
punctuationLevel=1

View File

@ -0,0 +1,13 @@
#!/bin/python
class command():
def __init__(self):
pass
def run(self, environment):
environment['runtime']['speechDriver'].cancel()
print('input changed stop')
return environment
def setCallback(self, callback):
pass
def shutdown(self):
pass

View File

@ -0,0 +1,15 @@
#!/bin/python
class command():
def __init__(self):
pass
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'])
print('input changed bla')
return environment
def setCallback(self, callback):
pass
def shutdown(self):
pass

View File

@ -0,0 +1,15 @@
#!/bin/python
class command():
def __init__(self):
pass
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'])
print('screenchanged bla')
return environment
def setCallback(self, callback):
pass
def shutdown(self):
pass

View File

@ -25,7 +25,10 @@ class commandManager():
except:
continue
return environment
def executeTriggerCommands(self, environment, trigger):
for cmd in sorted(environment['commands'][trigger]):
environment = environment['commands'][trigger][cmd].run(environment)
return environment
def executeCommand(self, environment, currCommand, section = 'commands'):
if self.isCommandDefined(environment):
try:

View File

@ -8,12 +8,10 @@ commandInfo = {
}
commands = {
'onnInput':{
'onInput':{
},
'onScreenChanged':{
},
'commands':{
# 'curr_line': curr_line.command(),
# 'shut_up': shut_up.command()
}
}

View File

@ -3,12 +3,13 @@
screenData = {
'columns': 0,
'lines': 0,
'delta': '',
'oldDelta': '',
'oldCursorReview':{'x':0,'y':0},
'oldCursor':{'x':0,'y':0},
'oldContentBytes': b'',
'oldContentText': '',
'oldContentAttrib': b'',
'newDelta': '',
'newCursorReview':{'x':0,'y':0},
'newCursor':{'x':0,'y':0},
'newContentBytes': b'',

View File

@ -2,10 +2,11 @@
from configparser import ConfigParser
from core.settings import settings
import evdev
import importlib.util
class settingsManager():
def __init__(self):
pass
self.settings = settings
def loadShortcuts(self, environment, kbConfigPath='../../config/keyboard/desktop.kb'):
kbConfig = open(kbConfigPath,"r")
@ -66,7 +67,43 @@ class settingsManager():
environment['settings'].read(settingConfigPath)
return environment
def getSetting(self, environment, setting):
value = True # do be implemented
def getSetting(self, environment, section, setting):
value = ''
try:
value = environment['settings'].get(section, setting)
except:
value = self.settings[section][setting]
return value
def getSettingAsInt(self, environment, section, setting):
return int(getSetting(self, environment, section, setting))
def getSettingAsBool(self, environment, section, setting):
return bool(getSetting(self, environment, section, setting))
def loadSpeechDriver(self, environment, driverName):
if environment['runtime']['speechDriver'] != None:
environment['runtime']['speechDriver'].shutdown()
spec = importlib.util.spec_from_file_location(driverName, 'speech/' + driverName + '.py')
driver_mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(driver_mod)
environment['runtime']['speechDriver'] = driver_mod.speech()
return environment
def loadSoundDriver(self, environment, driverName):
if environment['runtime']['soundDriver'] != None:
environment['runtime']['soundDriver'].shutdown()
spec = importlib.util.spec_from_file_location(driverName, 'sound/' + driverName + '.py')
driver_mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(driver_mod)
environment['runtime']['soundDriver'] = driver_mod.sound()
return environment
def loadScreenDriver(self, environment, driverName):
spec = importlib.util.spec_from_file_location(driverName, 'screen/' + driverName + '.py')
driver_mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(driver_mod)
environment['runtime']['screenDriver'] = driver_mod.screen()
return environment

View File

@ -16,10 +16,6 @@ from core import commandManager
from core import settingsManager
from utils import debug
from speech import espeak as es
from speech import speechd as sd
from screen import linux as lx
class fenrir():
def __init__(self):
self.threadUpdateScreen = None
@ -29,16 +25,21 @@ class fenrir():
self.environment['runtime']['inputManager'] = inputManager.inputManager()
self.environment['runtime']['settingsManager'] = settingsManager.settingsManager()
self.environment = self.environment['runtime']['settingsManager'].loadShortcuts(self.environment)
self.environment = self.environment['runtime']['settingsManager'].loadSettings(self.environment)
self.environment['runtime']['commandManager'] = commandManager.commandManager()
self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'commands')
self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'onInput')
self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment,'onScreenChanged')
self.environment['runtime']['debug'] = debug.debug()
signal.signal(signal.SIGINT, self.captureSignal)
# the following hard coded, in future we have a config loader
self.environment['runtime']['speechDriver'] = sd.speech()
self.environment['runtime']['screenDriver'] = lx.screenManager()
self.environment = self.environment['runtime']['settingsManager'].loadSpeechDriver(self.environment,\
self.environment['runtime']['settingsManager'].getSetting(self.environment,'speech', 'driver'))
self.environment = self.environment['runtime']['settingsManager'].loadScreenDriver(self.environment,\
self.environment['runtime']['settingsManager'].getSetting(self.environment,'screen', 'driver'))
self.environment = self.environment['runtime']['settingsManager'].loadSoundDriver(self.environment,\
self.environment['runtime']['settingsManager'].getSetting(self.environment,'sound', 'driver'))
def proceed(self):
#self.threadUpdateScreen = Thread(target=self.updateScreen, args=())
self.threadHandleInput = Thread(target=self.handleInput, args=())
@ -53,16 +54,18 @@ class fenrir():
def handleInput(self):
while(self.environment['generalInformation']['running']):
self.environment = self.environment['runtime']['inputManager'].getKeyPressed(self.environment)
self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment)
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment)
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput')
if self.environment['input']['currShortcutString'] != '':
self.handleCommands()
def updateScreen(self):
self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment)
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')
time.sleep(0.5)
def handleCommands(self):
self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment)
if (self.environment['commandInfo']['currCommand'] != '') and \
(time.time() - self.environment['commandInfo']['lastCommandTime'] >= 0.4):
self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands')

View File

@ -7,17 +7,26 @@ import time
import re
#import fenrir.utils.debug
class screenManager():
class screen():
def __init__(self, device='/dev/vcsa'):
self.vcsaDevicePath = device
self.textWrapper = textwrap.TextWrapper()
self.textWrapper.drop_whitespace = False
def analyzeScreen(self, environment):
# set new "old" values
environment['screenData']['oldContentBytes'] = environment['screenData']['newContentBytes']
environment['screenData']['oldContentText'] = environment['screenData']['newContentText']
environment['screenData']['oldContentTextAttrib'] = environment['screenData']['newContentAttrib']
environment['screenData']['oldCursor']['x'] = environment['screenData']['newCursor']['x']
environment['screenData']['oldCursor']['y'] = environment['screenData']['newCursor']['y']
environment['screenData']['oldTTY'] = environment['screenData']['newTTY']
environment['screenData']['oldDelta'] = environment['screenData']['newDelta']
# read screen
currTTY = open('/sys/devices/virtual/tty/tty0/active','r')
environment['screenData']['newTTY'] = currTTY.read()[3:-1]
currTTY.close()
try:
vcsa = open(self.vcsaDevicePath + environment['screenData']['newTTY'] ,'rb',0)
environment['screenData']['newContentBytes'] = vcsa.read()
@ -35,10 +44,7 @@ class screenManager():
# analyze content
environment['screenData']['newContentText'] = str(environment['screenData']['newContentBytes'][4:][::2].decode('WINDOWS-1250'))
#environment['screenData']['newContentText'] = str(environment['screenData']['newContentBytes'][4:][::2].decode('cp1252')).encode('utf-8')[2:]
environment['screenData']['newContentAttrib'] = environment['screenData']['newContentBytes'][5:][::2]
# environment['screenData']['newContentText'] = '\n'.join(textwrap.wrap(environment['screenData']['newContentText'], environment['screenData']['columns']))[:-2]
#environment['screenData']['newContentText'] = re.sub("(.{"+ str(environment['screenData']['columns'])+"})", "\\1\n", str(environment['screenData']['newContentText']), 0, re.DOTALL)
environment['screenData']['newContentText'] = '\n'.join(self.textWrapper.wrap(environment['screenData']['newContentText'], ))[:-2]
if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']:
@ -48,20 +54,13 @@ class screenManager():
environment['screenData']['oldContentText'] = ''
environment['screenData']['oldCursor']['x'] = 0
environment['screenData']['oldCursor']['y'] = 0
environment['runtime']['speechDriver'].cancel()
environment['screenData']['oldDelta'] = ''
environment['screenData']['newDelta'] = ''
# changes on the screen
if (environment['screenData']['oldContentText'] != environment['screenData']['newContentText']) and \
(len(environment['screenData']['newContentText']) > 0):
diff = difflib.ndiff(" ".join(environment['screenData']['oldContentText'].split()), " ".join(environment['screenData']['newContentText'].split()))
environment['screenData']['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ '))
if ((len(environment['screenData']['delta']) == 1)):
environment['runtime']['speechDriver'].cancel()
environment['runtime']['speechDriver'].speak(environment['screenData']['delta'])
# set new "old" values
environment['screenData']['oldContentBytes'] = environment['screenData']['newContentBytes']
environment['screenData']['oldContentText'] = environment['screenData']['newContentText']
environment['screenData']['oldContentTextAttrib'] = environment['screenData']['newContentAttrib']
environment['screenData']['oldCursor']['x'] = environment['screenData']['newCursor']['x']
environment['screenData']['oldCursor']['y'] = environment['screenData']['newCursor']['y']
environment['screenData']['oldTTY'] = environment['screenData']['newTTY']
environment['screenData']['newDelta'] = ''.join(x[2:] for x in diff if x.startswith('+ '))
return environment

View File

@ -7,7 +7,7 @@ class sound():
pass
def playSoundFile(self, Path):
pass
def setCallback(self, callback)
def setCallback(self, callback):
pass
def shutdown(self):
pass