From 10ddc98d474a670af1fbf8ddb66f5fd4a09d81c1 Mon Sep 17 00:00:00 2001 From: chrys Date: Sat, 17 Sep 2016 01:59:38 +0200 Subject: [PATCH] implement tutorial mode --- src/fenrir-package/core/commandManager.py | 9 ++--- src/fenrir-package/core/generalInformation.py | 1 + src/fenrir-package/core/input.py | 16 ++++++--- src/fenrir-package/core/inputManager.py | 35 ++++++++++++------- src/fenrir-package/fenrir.py | 8 ++--- 5 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/fenrir-package/core/commandManager.py b/src/fenrir-package/core/commandManager.py index 74fd4624..6cd0b792 100644 --- a/src/fenrir-package/core/commandManager.py +++ b/src/fenrir-package/core/commandManager.py @@ -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) diff --git a/src/fenrir-package/core/generalInformation.py b/src/fenrir-package/core/generalInformation.py index 2cacf530..658d0680 100644 --- a/src/fenrir-package/core/generalInformation.py +++ b/src/fenrir-package/core/generalInformation.py @@ -2,4 +2,5 @@ generalInformation = { 'running': True, +'tutorialMode': False, } diff --git a/src/fenrir-package/core/input.py b/src/fenrir-package/core/input.py index 7b235dc3..fa33fe23 100644 --- a/src/fenrir-package/core/input.py +++ b/src/fenrir-package/core/input.py @@ -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, +} diff --git a/src/fenrir-package/core/inputManager.py b/src/fenrir-package/core/inputManager.py index 9cbc7c66..0ec0de41 100644 --- a/src/fenrir-package/core/inputManager.py +++ b/src/fenrir-package/core/inputManager.py @@ -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']) + diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index 4b1ace9a..9aaa822b 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -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):