From ae71bd4ef720e44873a7599aac921d3932f2ad97 Mon Sep 17 00:00:00 2001 From: chrys Date: Sun, 4 Sep 2016 15:04:23 +0200 Subject: [PATCH] more work on restructure (screenManager, input handling) --- src/fenrir-package/core/commandManager.py | 19 +++++++++++++------ src/fenrir-package/core/generalInformation.py | 1 - src/fenrir-package/core/screenManager.py | 3 ++- src/fenrir-package/fenrir.py | 6 ++++-- src/fenrir-package/screen/linux.py | 7 ++++--- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/fenrir-package/core/commandManager.py b/src/fenrir-package/core/commandManager.py index e1ddc36c..44caf3ea 100644 --- a/src/fenrir-package/core/commandManager.py +++ b/src/fenrir-package/core/commandManager.py @@ -35,7 +35,7 @@ class commandManager(): return environment def executeTriggerCommands(self, environment, trigger): - if environment['generalInformation']['suspend']: + if environment['runtime']['screenManager'].isSuspendingScreen(environment) : return environment for cmd in sorted(environment['commands'][trigger]): try: @@ -43,6 +43,7 @@ class commandManager(): if environ != None: environment = environ except Exception as e: + print(e) environment['runtime']['debug'].writeDebugOut(environment,"Error while executing trigger:" + trigger + "." + cmd ,debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR) return environment @@ -56,21 +57,27 @@ class commandManager(): if environ != None: environment = environ except Exception as e: + print(e) environment['runtime']['debug'].writeDebugOut(environment,"Error while executing command:" + section + "." + currCommand ,debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR) environment['commandInfo']['currCommand'] = '' environment['commandInfo']['lastCommandTime'] = time.time() return environment - def isShortcutDefined(self, environment): + def isShortcutDefined(self, environment, currCommand): return( environment['input']['currShortcutString'] in environment['bindings']) - def getCommandForShortcut(self, environment): + def setCurrCommandForExec(self, environment, currCommand=''): if not self.isShortcutDefined(environment): return environment - environment['commandInfo']['currCommand'] = environment['bindings'][environment['input']['currShortcutString']] + environment['commandInfo']['currCommand'] = currCommand return environment + + def getCommandForShortcut(self, environment, currShortcutString): + if not self.isShortcutDefined(environment): + return environment + return environment['bindings'][currShortcutString] - def isCommandDefined(self, environment): - return( environment['commandInfo']['currCommand'] in environment['commands']['commands']) + def isCommandDefined(self, environment, currCommand): + return( currCommand in environment['commands']['commands']) diff --git a/src/fenrir-package/core/generalInformation.py b/src/fenrir-package/core/generalInformation.py index 4157e652..2cacf530 100644 --- a/src/fenrir-package/core/generalInformation.py +++ b/src/fenrir-package/core/generalInformation.py @@ -2,5 +2,4 @@ generalInformation = { 'running': True, -'suspend': False, } diff --git a/src/fenrir-package/core/screenManager.py b/src/fenrir-package/core/screenManager.py index 6fa48274..3cf1cee8 100644 --- a/src/fenrir-package/core/screenManager.py +++ b/src/fenrir-package/core/screenManager.py @@ -13,8 +13,9 @@ class screenManager(): environment['generalInformation']['suspend'] = self.isSuspendingScreen(environment) if not environment['generalInformation']['suspend']: environment = environment['runtime']['screenDriver'].update(environment) + environment['screenData']['lastScreenUpdate'] = time.time() return environment - + def isSuspendingScreen(self, environment): return environment['runtime']['screenDriver'].getCurrScreen() in \ environment['runtime']['settingsManager'].getSetting(environment,'screen', 'suspendingScreen').split(',') diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index 1216bfea..aa54987f 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -34,8 +34,10 @@ class fenrir(): self.environment = self.environment['runtime']['screenManager'].update(self.environment) except Exception as e: self.environment['runtime']['debug'].writeDebugOut(self.environment, str(e),debug.debugLevel.ERROR) - if not self.environment['input']['keyForeward']: - self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment) + if not self.environment['input']['keyForeward']: + currShortcut = self.environment['runtime']['inputManager'].getCurrShortcut(self.environment) + currCommand = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment) + self.environment = self.environment['runtime']['commandManager'].setCurrCommandForExec(self.environment, currCommand) if not timeout: self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput') self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged') diff --git a/src/fenrir-package/screen/linux.py b/src/fenrir-package/screen/linux.py index 686e8fa2..4000b7ce 100644 --- a/src/fenrir-package/screen/linux.py +++ b/src/fenrir-package/screen/linux.py @@ -2,19 +2,21 @@ # -*- coding: utf-8 -*- import difflib -import time -import re from utils import debug class screen(): def __init__(self): self.vcsaDevicePath = '/dev/vcsa' + def initialize(self, environment): return environment + def shutdown(self, environment): return environment + def insert_newlines(self, string, every=64): return '\n'.join(string[i:i+every] for i in range(0, len(string), every)) + def getCurrScreen(self): currScreen = -1 try: @@ -63,7 +65,6 @@ class screen(): # analyze content environment['screenData']['newContentText'] = environment['screenData']['newContentBytes'][4:][::2].decode(screenEncoding, "replace").encode('utf-8').decode('utf-8') environment['screenData']['newContentAttrib'] = environment['screenData']['newContentBytes'][5:][::2] - #environment['screenData']['newContentText'] = '\n'.join(self.textWrapper.wrap(environment['screenData']['newContentText'], ))[:-2] environment['screenData']['newContentText'] = self.insert_newlines(environment['screenData']['newContentText'], environment['screenData']['columns']) if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: