fix bugs
This commit is contained in:
parent
e5dad5f4c2
commit
9b5b634fcf
@ -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
|
|
@ -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
|
|
@ -6,8 +6,9 @@ import os
|
|||||||
class commandManager():
|
class commandManager():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
def loadCommands(self, environment):
|
|
||||||
commandFolder = "commands/"
|
def loadCommands(self, environment, section='commands'):
|
||||||
|
commandFolder = "commands/" + section +"/"
|
||||||
commandList = glob.glob(commandFolder+'*')
|
commandList = glob.glob(commandFolder+'*')
|
||||||
for currCommand in commandList:
|
for currCommand in commandList:
|
||||||
try:
|
try:
|
||||||
@ -15,24 +16,22 @@ class commandManager():
|
|||||||
fileName = fileName.split('/')[-1]
|
fileName = fileName.split('/')[-1]
|
||||||
if fileName in ['__init__','__pycache__']:
|
if fileName in ['__init__','__pycache__']:
|
||||||
continue
|
continue
|
||||||
print(fileName)
|
if fileExtension.lower() == '.py':
|
||||||
if fileExtension.lower() == 'py':
|
|
||||||
spec = importlib.util.spec_from_file_location(fileName, currCommand)
|
spec = importlib.util.spec_from_file_location(fileName, currCommand)
|
||||||
command_mod = importlib.util.module_from_spec(spec)
|
command_mod = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(command_mod)
|
spec.loader.exec_module(command_mod)
|
||||||
environment['commands']['fileName'] = command_mod()
|
environment['commands'][section][fileName] = command_mod.command()
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
return environment
|
return environment
|
||||||
|
|
||||||
def executeCommand(self, environment):
|
def executeCommand(self, environment, currCommand, section = 'commands'):
|
||||||
print(environment['commandInfo']['currCommand'])
|
|
||||||
if self.isCommandDefined(environment):
|
if self.isCommandDefined(environment):
|
||||||
try:
|
#try:
|
||||||
environ = environment['commands'][environment['commandInfo']['currCommand']].run(environment)
|
environ = environment['commands'][section][currCommand].run(environment)
|
||||||
if environ != None:
|
if environ != None:
|
||||||
environment = environ
|
environment = environ
|
||||||
except:
|
#except:
|
||||||
pass
|
pass
|
||||||
environment['commandInfo']['currCommand'] = ''
|
environment['commandInfo']['currCommand'] = ''
|
||||||
return environment
|
return environment
|
||||||
@ -49,7 +48,7 @@ class commandManager():
|
|||||||
return environment
|
return environment
|
||||||
|
|
||||||
def isCommandDefined(self, environment):
|
def isCommandDefined(self, environment):
|
||||||
return( environment['commandInfo']['currCommand'] in environment['commands'])
|
return( environment['commandInfo']['currCommand'] in environment['commands']['commands'])
|
||||||
|
|
||||||
def enqueueCommand(self, environment):
|
def enqueueCommand(self, environment):
|
||||||
if not self.isCommandDefined(environment):
|
if not self.isCommandDefined(environment):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/python
|
#!/bin/python
|
||||||
from commands import curr_line
|
#from commands import curr_line
|
||||||
from commands import shut_up
|
#from commands import shut_up
|
||||||
|
|
||||||
commandInfo = {
|
commandInfo = {
|
||||||
'currCommand': '',
|
'currCommand': '',
|
||||||
@ -8,6 +8,12 @@ commandInfo = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
commands = {
|
commands = {
|
||||||
'curr_line': curr_line.command(),
|
'onnInput':{
|
||||||
'shut_up': shut_up.command()
|
},
|
||||||
|
'onScreenChanged':{
|
||||||
|
},
|
||||||
|
'commands':{
|
||||||
|
# 'curr_line': curr_line.command(),
|
||||||
|
# 'shut_up': shut_up.command()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,11 @@ class fenrir():
|
|||||||
self.environment = environment.environment
|
self.environment = environment.environment
|
||||||
self.environment['runtime']['inputManager'] = inputManager.inputManager()
|
self.environment['runtime']['inputManager'] = inputManager.inputManager()
|
||||||
self.environment['runtime']['commandManager'] = commandManager.commandManager()
|
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()
|
self.environment['runtime']['debug'] = debug.debug()
|
||||||
signal.signal(signal.SIGINT, self.captureSignal)
|
signal.signal(signal.SIGINT, self.captureSignal)
|
||||||
|
|
||||||
# the following hard coded, in future we have a config loader
|
# the following hard coded, in future we have a config loader
|
||||||
self.environment['runtime']['speechDriver'] = sd.speech()
|
self.environment['runtime']['speechDriver'] = sd.speech()
|
||||||
self.environment['runtime']['screenDriver'] = lx.screenManager()
|
self.environment['runtime']['screenDriver'] = lx.screenManager()
|
||||||
@ -61,7 +62,7 @@ class fenrir():
|
|||||||
self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment)
|
self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment)
|
||||||
#self.environment['input']['currShortcut'] = {}
|
#self.environment['input']['currShortcut'] = {}
|
||||||
if self.environment['commandInfo']['currCommand'] != '':
|
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)
|
time.sleep(0.5)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
|
@ -46,10 +46,10 @@ class screenManager():
|
|||||||
|
|
||||||
# changes on the screen
|
# changes on the screen
|
||||||
if environment['screenData']['oldContentBytes'] != environment['screenData']['newContentBytes']:
|
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'])
|
diff = difflib.ndiff(environment['screenData']['oldContentText'], environment['screenData']['newContentText'])
|
||||||
environment['screenData']['delta'] = ''.join(x[2:] for x in diff if x.startswith('+ '))
|
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'])
|
environment['runtime']['speechDriver'].speak(environment['screenData']['delta'])
|
||||||
# set new "old" values
|
# set new "old" values
|
||||||
environment['screenData']['oldContentBytes'] = environment['screenData']['newContentBytes']
|
environment['screenData']['oldContentBytes'] = environment['screenData']['newContentBytes']
|
||||||
|
Loading…
Reference in New Issue
Block a user