trigger command shotdown

This commit is contained in:
chrys 2016-09-17 21:03:03 +02:00
parent dee137f5c6
commit 0729d2daf2
2 changed files with 23 additions and 9 deletions

View File

@ -4,9 +4,9 @@ class command():
def __init__(self): def __init__(self):
pass pass
def initialize(self, environment): def initialize(self, environment):
return environment pass
def shutdown(self, environment): def shutdown(self, environment):
return environment pass
def getDescription(self, environment): def getDescription(self, environment):
environment['generalInformation']['tutorialMode'] = False environment['generalInformation']['tutorialMode'] = False
return 'You are leving the tutorial mode. Press that shortcut again to enter the tutorial mode again.' return 'You are leving the tutorial mode. Press that shortcut again to enter the tutorial mode again.'
@ -15,6 +15,6 @@ class command():
text = 'you entered the tutorial mode. In that mode the commands are not executed. but you get an description what the shortcut does. to leve the tutorial mode press that shortcut again.' text = 'you entered the tutorial mode. In that mode the commands are not executed. but you get an description what the shortcut does. to leve the tutorial mode press that shortcut again.'
environment['runtime']['outputManager'].presentText(environment, text, interrupt=True) environment['runtime']['outputManager'].presentText(environment, text, interrupt=True)
environment['generalInformation']['tutorialMode'] = True environment['generalInformation']['tutorialMode'] = True
return environment
def setCallback(self, callback): def setCallback(self, callback):
pass pass

View File

@ -12,7 +12,10 @@ class commandManager():
environment['runtime']['commandManager'].loadCommands(environment,'onScreenChanged') environment['runtime']['commandManager'].loadCommands(environment,'onScreenChanged')
def shutdown(self, environment): def shutdown(self, environment):
pass environment['runtime']['commandManager'].shutdownCommands(environment,'commands')
environment['runtime']['commandManager'].shutdownCommands(environment,'onInput')
environment['runtime']['commandManager'].shutdownCommands(environment,'onScreenChanged')
def loadCommands(self, environment, section='commands'): def loadCommands(self, environment, section='commands'):
commandFolder = "commands/" + section +"/" commandFolder = "commands/" + section +"/"
commandList = glob.glob(commandFolder+'*') commandList = glob.glob(commandFolder+'*')
@ -30,25 +33,36 @@ class commandManager():
environment['commands'][section][fileName.upper()].initialize(environment) environment['commands'][section][fileName.upper()].initialize(environment)
except Exception as e: except Exception as e:
print(e) print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Error while loading command:" + command ,debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,"Loading command:" + command ,debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
continue continue
def shutdownCommands(self, environment, section):
for command in sorted(environment['commands'][section]):
try:
environment['commands'][section][command].shutdown(environment)
environment['commands'][section][command] = None
except Exception as e:
print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Shutdown command:" + section + "." + cmd ,debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
continue
def executeTriggerCommands(self, environment, trigger): def executeTriggerCommands(self, environment, trigger):
if environment['runtime']['screenManager'].isSuspendingScreen(environment): if environment['runtime']['screenManager'].isSuspendingScreen(environment):
return environment return
for command in sorted(environment['commands'][trigger]): for command in sorted(environment['commands'][trigger]):
if self.commandExists(environment, command, trigger): if self.commandExists(environment, command, trigger):
try: try:
environment['commands'][trigger][command].run(environment) environment['commands'][trigger][command].run(environment)
except Exception as e: except Exception as e:
print(e) print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Error while executing trigger:" + trigger + "." + cmd ,debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,"Executing trigger:" + trigger + "." + cmd ,debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
def executeCommand(self, environment, command, section = 'commands'): def executeCommand(self, environment, command, section = 'commands'):
if environment['runtime']['screenManager'].isSuspendingScreen(environment) : if environment['runtime']['screenManager'].isSuspendingScreen(environment) :
return environment return
if self.commandExists(environment, command, section): if self.commandExists(environment, command, section):
try: try:
if environment['generalInformation']['tutorialMode']: if environment['generalInformation']['tutorialMode']:
@ -58,7 +72,7 @@ class commandManager():
environment['commands'][section][command].run(environment) environment['commands'][section][command].run(environment)
except Exception as e: except Exception as e:
print(e) print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Error while executing command:" + section + "." + command ,debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,"Executing command:" + section + "." + command ,debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
self.clearCommandQueued(environment) self.clearCommandQueued(environment)
environment['commandInfo']['lastCommandExecutionTime'] = time.time() environment['commandInfo']['lastCommandExecutionTime'] = time.time()