diff --git a/src/fenrir-package/commands/curr_line.py b/src/fenrir-package/commands/curr_line.py index 009b4f5f..49bc8f7c 100644 --- a/src/fenrir-package/commands/curr_line.py +++ b/src/fenrir-package/commands/curr_line.py @@ -4,7 +4,10 @@ class command(): def __init__(self): pass def run(self, environment): - pass + print('fire') + #print(environment['screenData']['newContentText'])i + print(environment['screenData']['newCursor']['x']) + environment['runtime']['speechDriver'].speak(environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['x']-1]) def setCallback(self, callback): pass def shutdown(self): diff --git a/src/fenrir-package/core/bindings.py b/src/fenrir-package/core/bindings.py index 9ea01c26..fe1e805e 100644 --- a/src/fenrir-package/core/bindings.py +++ b/src/fenrir-package/core/bindings.py @@ -1,4 +1,5 @@ #!/bin/python bindings = { +'2-29,1-42':'curr_line', } diff --git a/src/fenrir-package/core/commandManager.py b/src/fenrir-package/core/commandManager.py index 430bb8dc..55a19051 100644 --- a/src/fenrir-package/core/commandManager.py +++ b/src/fenrir-package/core/commandManager.py @@ -3,3 +3,30 @@ class commandManager(): def __init__(self): pass + def loadCommands(self, environment): + return environment + def executeCommand(self, environment): + print(environment['commandInfo']['currCommand']) + if self.isCommandDefined(environment): + environment['commands'][environment['commandInfo']['currCommand']].run(environment) + environment['commandInfo']['currCommand'] = '' + return environment + + def executeNextCommand(self, environment): + pass + def isShortcutDefined(self, environment): + return( environment['input']['currShortcutString'] in environment['bindings']) + + def getCommandForShortcut(self, environment): + if not self.isShortcutDefined(environment): + return environment + environment['commandInfo']['currCommand'] = environment['bindings'][environment['input']['currShortcutString']] + return environment + + def isCommandDefined(self, environment): + return( environment['commandInfo']['currCommand'] in environment['commands']) + + def enqueueCommand(self, environment): + if not self.isCommandDefined(environment): + return False + return True diff --git a/src/fenrir-package/core/environment.py b/src/fenrir-package/core/environment.py index b51e21df..dc5b653f 100644 --- a/src/fenrir-package/core/environment.py +++ b/src/fenrir-package/core/environment.py @@ -6,6 +6,8 @@ from core import bindings from core import runtime from core import screenData from core import generalInformation +from core import commands +from core import input environment = { 'screenData': screenData.screenData, @@ -13,6 +15,9 @@ environment = { 'generalInformation': generalInformation.generalInformation, 'settings': settings.settings, 'bindings': bindings.bindings, +'commands': commands.commands, +'input': input.input, +'commandInfo': commands.commandInfo, 'soundIcons': soundIcons.soundIcons, 'autospeak': ['speak_delta'] } diff --git a/src/fenrir-package/core/inputManager.py b/src/fenrir-package/core/inputManager.py index 12dbb59d..2a803842 100644 --- a/src/fenrir-package/core/inputManager.py +++ b/src/fenrir-package/core/inputManager.py @@ -10,15 +10,24 @@ class inputManager(): self.devices = {dev.fd: dev for dev in self.devices} for dev in self.devices.values(): print(dev) - def getShortcutCommand(self, environment, shortcuts): - if not shortcuts: - return '' - return '' - def getKeyPressed(self, environment): r, w, x = select(self.devices, [], []) + currShortcut = environment['input']['currShortcut'] for fd in r: for event in self.devices[fd].read(): if event.type == evdev.ecodes.EV_KEY: - print(evdev.categorize(event)) + if event.value != 0: + currShortcut[str(event.code)] = event.value + else: + del(currShortcut[str(event.code)]) + environment['input']['currShortcut'] = currShortcut + environment['input']['currShortcutString'] = self.getShortcutString(environment) return environment + + def getShortcutString(self, environment): + if environment['input']['currShortcut'] == {}: + return '' + currShortcutStringList = [] + for key in sorted(environment['input']['currShortcut'] ): + currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key)) + return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","") diff --git a/src/fenrir-package/core/runtime.py b/src/fenrir-package/core/runtime.py index bc18f195..ad193931 100644 --- a/src/fenrir-package/core/runtime.py +++ b/src/fenrir-package/core/runtime.py @@ -5,5 +5,6 @@ runtime = { 'screenDriver': None, 'soundDriver': None, 'inputManager': None, +'commandManager': None, 'debug':None, } diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index f66237ef..88f3e596 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -11,6 +11,7 @@ if not os.getcwd() in sys.path: from threading import Thread from core import environment from core import inputManager +from core import commandManager from utils import debug from speech import espeak as es @@ -24,6 +25,7 @@ class fenrir(): self.threadHandleCommandQueue = None self.environment = environment.environment self.environment['runtime']['inputManager'] = inputManager.inputManager() + self.environment['runtime']['commandManager'] = commandManager.commandManager() self.environment['runtime']['debug'] = debug.debug() signal.signal(signal.SIGINT, self.captureSignal) @@ -34,10 +36,10 @@ class fenrir(): def proceed(self): self.threadUpdateScreen = Thread(target=self.updateScreen, args=()) self.threadHandleInput = Thread(target=self.handleInput, args=()) - self.threadCommandQueue = Thread(target=self.handleCommandQueue, args=()) + self.threadCommands = Thread(target=self.handleCommands, args=()) self.threadUpdateScreen.start() self.threadHandleInput.start() - self.threadCommandQueue.start() + self.threadCommands.start() while(self.environment['generalInformation']['running']): time.sleep(0.2) self.shutdown() @@ -45,14 +47,21 @@ class fenrir(): def handleInput(self): while(self.environment['generalInformation']['running']): self.environment = self.environment['runtime']['inputManager'].getKeyPressed(self.environment) + if self.environment['input']['currShortcutString'] == '': + self.environment['commandInfo']['currCommand'] = '' def updateScreen(self): while(self.environment['generalInformation']['running']): self.environment = self.environment['runtime']['screenDriver'].analyzeScreen(self.environment) - def handleCommandQueue(self): + def handleCommands(self): while(self.environment['generalInformation']['running']): - self.environment = self.environment # command queue here + self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment) + #self.environment['input']['currShortcut'] = {} + #self.environment['input']['currShortcutString'] = '' + if self.environment['input']['currShortcutString'] != '': + self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment) + time.sleep(0.5) def shutdown(self): self.environment['generalInformation']['running'] = False diff --git a/src/fenrir-package/screen/linux.py b/src/fenrir-package/screen/linux.py index bd3623bf..346a206b 100644 --- a/src/fenrir-package/screen/linux.py +++ b/src/fenrir-package/screen/linux.py @@ -20,7 +20,7 @@ class screenManager(): environment['screenData']['newContentBytes'] = vcsa.read() vcsa.close() except: - return runtime + return environment # get metadata like cursor or screensize environment['screenData']['lines'] = int( environment['screenData']['newContentBytes'][0])