diff --git a/src/fenrir-package/commands/curr_line.py b/src/fenrir-package/commands/curr_line.py deleted file mode 100644 index 17da62a3..00000000 --- a/src/fenrir-package/commands/curr_line.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/python - -class command(): - def __init__(self): - pass - def run(self, environment): - environment['runtime']['speechDriver'].cancel() - if environment['screenData']['newContentText'].replace(" ","") == '': - environment['runtime']['speechDriver'].speak("empty screen") - else: - environment['runtime']['speechDriver'].speak(environment['screenData']['newContentText'].split('\n')[environment['screenData']['newCursor']['y']]) - def setCallback(self, callback): - pass - def shutdown(self): - pass diff --git a/src/fenrir-package/commands/shut_up.py b/src/fenrir-package/commands/shut_up.py deleted file mode 100644 index 4416e19b..00000000 --- a/src/fenrir-package/commands/shut_up.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/python - -class command(): - def __init__(self): - pass - def run(self, environment): - environment['runtime']['speechDriver'].cancel() - def setCallback(self, callback): - pass - def shutdown(self): - pass diff --git a/src/fenrir-package/core/commandManager.py b/src/fenrir-package/core/commandManager.py index 7bf0e642..24f06aab 100644 --- a/src/fenrir-package/core/commandManager.py +++ b/src/fenrir-package/core/commandManager.py @@ -6,8 +6,9 @@ import os class commandManager(): def __init__(self): pass - def loadCommands(self, environment): - commandFolder = "commands/" + + def loadCommands(self, environment, section='commands'): + commandFolder = "commands/" + section +"/" commandList = glob.glob(commandFolder+'*') for currCommand in commandList: try: @@ -15,24 +16,22 @@ class commandManager(): fileName = fileName.split('/')[-1] if fileName in ['__init__','__pycache__']: continue - print(fileName) - if fileExtension.lower() == 'py': + if fileExtension.lower() == '.py': spec = importlib.util.spec_from_file_location(fileName, currCommand) command_mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(command_mod) - environment['commands']['fileName'] = command_mod() + environment['commands'][section][fileName] = command_mod.command() except: continue return environment - def executeCommand(self, environment): - print(environment['commandInfo']['currCommand']) + def executeCommand(self, environment, currCommand, section = 'commands'): if self.isCommandDefined(environment): - try: - environ = environment['commands'][environment['commandInfo']['currCommand']].run(environment) - if environ != None: - environment = environ - except: + #try: + environ = environment['commands'][section][currCommand].run(environment) + if environ != None: + environment = environ + #except: pass environment['commandInfo']['currCommand'] = '' return environment @@ -49,7 +48,7 @@ class commandManager(): return environment def isCommandDefined(self, environment): - return( environment['commandInfo']['currCommand'] in environment['commands']) + return( environment['commandInfo']['currCommand'] in environment['commands']['commands']) def enqueueCommand(self, environment): if not self.isCommandDefined(environment): diff --git a/src/fenrir-package/core/commands.py b/src/fenrir-package/core/commands.py index d3696098..0bddfb5b 100644 --- a/src/fenrir-package/core/commands.py +++ b/src/fenrir-package/core/commands.py @@ -1,6 +1,6 @@ #!/bin/python -from commands import curr_line -from commands import shut_up +#from commands import curr_line +#from commands import shut_up commandInfo = { 'currCommand': '', @@ -8,6 +8,12 @@ commandInfo = { } commands = { -'curr_line': curr_line.command(), -'shut_up': shut_up.command() +'onnInput':{ + }, +'onScreenChanged':{ + }, +'commands':{ +# 'curr_line': curr_line.command(), +# 'shut_up': shut_up.command() + } } diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index 95e6fe27..501316d4 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -27,10 +27,11 @@ class fenrir(): self.environment = environment.environment self.environment['runtime']['inputManager'] = inputManager.inputManager() self.environment['runtime']['commandManager'] = commandManager.commandManager() - self.environment = self.environment['runtime']['commandManager'].loadCommands(self.environment) + 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() @@ -61,7 +62,7 @@ class fenrir(): self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment) #self.environment['input']['currShortcut'] = {} if self.environment['commandInfo']['currCommand'] != '': - self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment) + self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands') time.sleep(0.5) def shutdown(self): diff --git a/src/fenrir-package/screen/linux.py b/src/fenrir-package/screen/linux.py index a9de63c9..1e83d88c 100644 --- a/src/fenrir-package/screen/linux.py +++ b/src/fenrir-package/screen/linux.py @@ -46,10 +46,10 @@ class screenManager(): # changes on the screen if environment['screenData']['oldContentBytes'] != environment['screenData']['newContentBytes']: - if ((len(environment['screenData']['delta']) < 4) or environment['screenData']['oldTTY'] != environment['screenData']['newTTY']): - environment['runtime']['speechDriver'].cancel() diff = difflib.ndiff(environment['screenData']['oldContentText'], environment['screenData']['newContentText']) environment['screenData']['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ ')) + if ((len(environment['screenData']['delta']) < 3)): + environment['runtime']['speechDriver'].cancel() environment['runtime']['speechDriver'].speak(environment['screenData']['delta']) # set new "old" values environment['screenData']['oldContentBytes'] = environment['screenData']['newContentBytes']