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
import importlib.util
import glob
import os
import time
import glob, os, time
from utils import debug
class commandManager():
@ -55,7 +53,10 @@ class commandManager():
return environment
if self.commandExists(environment, command, section):
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:
print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Error while executing command:" + section + "." + command ,debug.debugLevel.ERROR)

View File

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

View File

@ -2,13 +2,12 @@
import time
input = {
'currInput': {},
'prevInput': {},
'prevDeepestInput': {},
'currInput': [],
'prevInput': [],
'prevDeepestInput': [],
'currEvent': None,
'firstEvent': None,
'currShortcutString': '',
'consumeKey': False,
'shortcutRepeat': 0,
'fenrirKey': ['82'],
'keyForeward': False,
'lastInputTime':time.time(),
@ -17,3 +16,10 @@ input = {
'oldCapsLock':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)
if event:
timeout = False
environment['input']['firstEvent'] = event
environment['input']['currEvent'] = event
if not
#print(event)
return timeout
def grabDevices(self, environment):
@ -42,23 +46,30 @@ class inputManager():
environment['runtime']['debug'].writeDebugOut(environment, str(e),debug.debugLevel.ERROR)
return environment
def getShortcutString(self, environment):
if environment['input']['currShortcut'] == {}:
return ''
currShortcutStringList = []
for key in environment['input']['currShortcut']:
currShortcutStringList.append("%s-%s" % (environment['input']['currShortcut'][key], key))
currShortcutStringList = sorted(currShortcutStringList)
return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","")
def getPrevDeepestInput(self, environment):
shortcut = []
shortcut.append(environment['input']['shortcutRepeat'])
shortcut.append(sorted(environment['input']['prevDeepestInput']))
def getPrevShortcut(self, environment):
shortcut = []
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):
return str(event.code) in environment['input']['fenrirKey']
def getCommandForShortcut(self, environment, shortcut):
shortcut = shortcut.upper()
if not self.isShortcutDefined(environment, shortcut):
if not self.shortcutExists(environment, shortcut):
return ''
return environment['bindings'][shortcut]
return environment['bindings'][shortcut].upper()
def isCommandDefined(self, environment, currCommand):
return( currCommand in environment['commands']['commands'])
def shortcutExists(self, environment, shortcut):
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)
if not (self.environment['input']['keyForeward'] or timeout):
#currShortcut = self.environment['runtime']['inputManager'].getCurrShortcut(self.environment)
currShortcut = ''
currCommand = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment, currShortcut)
self.environment['runtime']['commandManager'].setCurrCommandForExec(self.environment, currCommand)
shortcut = ''
command = self.environment['runtime']['inputManager'].getCommandForShortcut(self.environment, shortcut)
self.environment['runtime']['commandManager'].queueCommand(self.environment, command)
if not timeout:
self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput')
self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')
if not self.environment['input']['keyForeward']:
if self.environment['commandInfo']['currCommand'] != '':
if self.environment['runtime']['commandManager'].isCommandQueued():
self.handleCommands()
def handleCommands(self):