implement tutorial mode

This commit is contained in:
chrys 2016-09-17 01:59:38 +02:00
parent cc129cefe1
commit 10ddc98d47
5 changed files with 44 additions and 25 deletions

View File

@ -1,8 +1,6 @@
#!/bin/python #!/bin/python
import importlib.util import importlib.util
import glob import glob, os, time
import os
import time
from utils import debug from utils import debug
class commandManager(): class commandManager():
@ -55,7 +53,10 @@ class commandManager():
return environment return environment
if self.commandExists(environment, command, section): if self.commandExists(environment, command, section):
try: try:
environment['commands'][section][command].run(environment) if environment['generalInformation']['tutorialMode']:
environment['commands'][section][command].getDescription()
else:
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,"Error while executing command:" + section + "." + command ,debug.debugLevel.ERROR)

View File

@ -2,4 +2,5 @@
generalInformation = { generalInformation = {
'running': True, 'running': True,
'tutorialMode': False,
} }

View File

@ -2,13 +2,12 @@
import time import time
input = { input = {
'currInput': {}, 'currInput': [],
'prevInput': {}, 'prevInput': [],
'prevDeepestInput': {}, 'prevDeepestInput': [],
'currEvent': None, 'currEvent': None,
'firstEvent': None, 'firstEvent': None,
'currShortcutString': '', 'shortcutRepeat': 0,
'consumeKey': False,
'fenrirKey': ['82'], 'fenrirKey': ['82'],
'keyForeward': False, 'keyForeward': False,
'lastInputTime':time.time(), 'lastInputTime':time.time(),
@ -17,3 +16,10 @@ input = {
'oldCapsLock':False, 'oldCapsLock':False,
'newCapsLock':False 'newCapsLock':False
} }
inputEvent = {
'EventName': '',
'EventValue': '',
'EventTime': time.time(),
'EventState': 0,
}

View File

@ -20,7 +20,11 @@ class inputManager():
event = environment['runtime']['inputDriver'].getInput(environment) event = environment['runtime']['inputDriver'].getInput(environment)
if event: if event:
timeout = False timeout = False
environment['input']['firstEvent'] = event
environment['input']['currEvent'] = event
if not
#print(event) #print(event)
return timeout return timeout
def grabDevices(self, environment): def grabDevices(self, environment):
@ -42,23 +46,30 @@ class inputManager():
environment['runtime']['debug'].writeDebugOut(environment, str(e),debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment, str(e),debug.debugLevel.ERROR)
return environment return environment
def getShortcutString(self, environment): def getPrevDeepestInput(self, environment):
if environment['input']['currShortcut'] == {}: shortcut = []
return '' shortcut.append(environment['input']['shortcutRepeat'])
currShortcutStringList = [] shortcut.append(sorted(environment['input']['prevDeepestInput']))
for key in environment['input']['currShortcut']:
currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key)) def getPrevShortcut(self, environment):
currShortcutStringList = sorted(currShortcutStringList) shortcut = []
return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","") shortcut.append(environment['input']['shortcutRepeat'])
shortcut.append(sorted(environment['input']['prevInput']))
def getPrevShortcut(self, environment):
shortcut = []
shortcut.append(environment['input']['shortcutRepeat'])
shortcut.append(sorted(environment['input']['prevInput']))
def isFenrirKey(self,environment, event): def isFenrirKey(self,environment, event):
return str(event.code) in environment['input']['fenrirKey'] return str(event.code) in environment['input']['fenrirKey']
def getCommandForShortcut(self, environment, shortcut): def getCommandForShortcut(self, environment, shortcut):
shortcut = shortcut.upper() shortcut = shortcut.upper()
if not self.isShortcutDefined(environment, shortcut): if not self.shortcutExists(environment, shortcut):
return '' return ''
return environment['bindings'][shortcut] return environment['bindings'][shortcut].upper()
def isCommandDefined(self, environment, currCommand): def shortcutExists(self, environment, shortcut):
return( currCommand in environment['commands']['commands']) return( str(shortcut).upper() in environment['bindings'])

View File

@ -42,14 +42,14 @@ class fenrir():
self.environment['runtime']['debug'].writeDebugOut(self.environment, str(e),debug.debugLevel.ERROR) self.environment['runtime']['debug'].writeDebugOut(self.environment, str(e),debug.debugLevel.ERROR)
if not (self.environment['input']['keyForeward'] or timeout): if not (self.environment['input']['keyForeward'] or timeout):
#currShortcut = self.environment['runtime']['inputManager'].getCurrShortcut(self.environment) #currShortcut = self.environment['runtime']['inputManager'].getCurrShortcut(self.environment)
currShortcut = '' shortcut = ''
currCommand = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment, currShortcut) command = self.environment['runtime']['inputManager'].getCommandForShortcut(self.environment, shortcut)
self.environment['runtime']['commandManager'].setCurrCommandForExec(self.environment, currCommand) self.environment['runtime']['commandManager'].queueCommand(self.environment, command)
if not timeout: if not timeout:
self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput') self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput')
self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged') self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')
if not self.environment['input']['keyForeward']: if not self.environment['input']['keyForeward']:
if self.environment['commandInfo']['currCommand'] != '': if self.environment['runtime']['commandManager'].isCommandQueued():
self.handleCommands() self.handleCommands()
def handleCommands(self): def handleCommands(self):