more work on restructure (screenManager, input handling)

This commit is contained in:
chrys 2016-09-04 15:04:23 +02:00
parent 9d63a30597
commit ae71bd4ef7
5 changed files with 23 additions and 13 deletions

View File

@ -35,7 +35,7 @@ class commandManager():
return environment return environment
def executeTriggerCommands(self, environment, trigger): def executeTriggerCommands(self, environment, trigger):
if environment['generalInformation']['suspend']: if environment['runtime']['screenManager'].isSuspendingScreen(environment) :
return environment return environment
for cmd in sorted(environment['commands'][trigger]): for cmd in sorted(environment['commands'][trigger]):
try: try:
@ -43,6 +43,7 @@ class commandManager():
if environ != None: if environ != None:
environment = environ environment = environ
except Exception as e: 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,"Error while 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)
return environment return environment
@ -56,21 +57,27 @@ class commandManager():
if environ != None: if environ != None:
environment = environ environment = environ
except Exception as e: 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,"Error while executing command:" + section + "." + currCommand ,debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR) environment['runtime']['debug'].writeDebugOut(environment,str(e),debug.debugLevel.ERROR)
environment['commandInfo']['currCommand'] = '' environment['commandInfo']['currCommand'] = ''
environment['commandInfo']['lastCommandTime'] = time.time() environment['commandInfo']['lastCommandTime'] = time.time()
return environment return environment
def isShortcutDefined(self, environment): def isShortcutDefined(self, environment, currCommand):
return( environment['input']['currShortcutString'] in environment['bindings']) return( environment['input']['currShortcutString'] in environment['bindings'])
def getCommandForShortcut(self, environment): def setCurrCommandForExec(self, environment, currCommand=''):
if not self.isShortcutDefined(environment): if not self.isShortcutDefined(environment):
return environment return environment
environment['commandInfo']['currCommand'] = environment['bindings'][environment['input']['currShortcutString']] environment['commandInfo']['currCommand'] = currCommand
return environment return environment
def isCommandDefined(self, environment): def getCommandForShortcut(self, environment, currShortcutString):
return( environment['commandInfo']['currCommand'] in environment['commands']['commands']) if not self.isShortcutDefined(environment):
return environment
return environment['bindings'][currShortcutString]
def isCommandDefined(self, environment, currCommand):
return( currCommand in environment['commands']['commands'])

View File

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

View File

@ -13,6 +13,7 @@ class screenManager():
environment['generalInformation']['suspend'] = self.isSuspendingScreen(environment) environment['generalInformation']['suspend'] = self.isSuspendingScreen(environment)
if not environment['generalInformation']['suspend']: if not environment['generalInformation']['suspend']:
environment = environment['runtime']['screenDriver'].update(environment) environment = environment['runtime']['screenDriver'].update(environment)
environment['screenData']['lastScreenUpdate'] = time.time()
return environment return environment
def isSuspendingScreen(self, environment): def isSuspendingScreen(self, environment):

View File

@ -35,7 +35,9 @@ class fenrir():
except Exception as e: except Exception as e:
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']: if not self.environment['input']['keyForeward']:
self.environment = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment) 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: if not timeout:
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput') self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onInput')
self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged') self.environment = self.environment['runtime']['commandManager'].executeTriggerCommands(self.environment, 'onScreenChanged')

View File

@ -2,19 +2,21 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import difflib import difflib
import time
import re
from utils import debug from utils import debug
class screen(): class screen():
def __init__(self): def __init__(self):
self.vcsaDevicePath = '/dev/vcsa' self.vcsaDevicePath = '/dev/vcsa'
def initialize(self, environment): def initialize(self, environment):
return environment return environment
def shutdown(self, environment): def shutdown(self, environment):
return environment return environment
def insert_newlines(self, string, every=64): def insert_newlines(self, string, every=64):
return '\n'.join(string[i:i+every] for i in range(0, len(string), every)) return '\n'.join(string[i:i+every] for i in range(0, len(string), every))
def getCurrScreen(self): def getCurrScreen(self):
currScreen = -1 currScreen = -1
try: try:
@ -63,7 +65,6 @@ class screen():
# analyze content # analyze content
environment['screenData']['newContentText'] = environment['screenData']['newContentBytes'][4:][::2].decode(screenEncoding, "replace").encode('utf-8').decode('utf-8') 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']['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']) environment['screenData']['newContentText'] = self.insert_newlines(environment['screenData']['newContentText'], environment['screenData']['columns'])
if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']: