fix bugs
This commit is contained in:
		@@ -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():
 | 
			
		||||
    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):
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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):
 | 
			
		||||
 
 | 
			
		||||
@@ -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']
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user