make X autodetect working, cleanups, remove unecressary returns, shotdown of the drivers in the managers

This commit is contained in:
chrys
2016-09-17 01:04:03 +02:00
parent 52fbef639c
commit 7d7c021774
12 changed files with 93 additions and 225 deletions

View File

@ -1,25 +0,0 @@
#!/bin/python
class command():
def __init__(self):
pass
def initialize(self, environment):
return environment
def shutdown(self, environment):
return environment
def getDescription(self):
return ''
def run(self, environment):
if not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'keyboard', 'interruptOnKeyPress'):
return environment
if environment['screenData']['newTTY'] != environment['screenData']['oldTTY']:
return environment
# if environment['screenData']['newCursor'] == environment['screenData']['oldCursor'] and\
# environment['screenData']['newDelta'] == environment['screenData']['oldDelta']:
# return environment
if environment['input']['currShortcut'] != '':
return environment
environment['runtime']['outputManager'].interruptOutput(environment)
return environment
def setCallback(self, callback):
pass

View File

@ -10,11 +10,10 @@ class command():
def getDescription(self):
return ''
def run(self, environment):
if environment['screenData']['newTTY'] == environment['screenData']['oldTTY']:
return environment
environment['runtime']['outputManager'].playSoundIcon(environment,'ChangeTTY')
environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'], interrupt=True)
environment['runtime']['outputManager'].presentText(environment, "screen " + str(environment['screenData']['newTTY']),soundIcon='ChangeTTY', interrupt=True)
environment['runtime']['outputManager'].presentText(environment, environment['screenData']['newDelta'], interrupt=False)
return environment
def setCallback(self, callback):

View File

@ -9,6 +9,9 @@ class commandManager():
def __init__(self):
pass
def initialize(self, environment):
environment['runtime']['commandManager'].loadCommands(environment,'commands')
environment['runtime']['commandManager'].loadCommands(environment,'onInput')
environment['runtime']['commandManager'].loadCommands(environment,'onScreenChanged')
return environment
def shutdown(self, environment):
return environment
@ -35,13 +38,11 @@ class commandManager():
return environment
def executeTriggerCommands(self, environment, trigger):
if environment['runtime']['screenManager'].isSuspendingScreen(environment) :
if environment['runtime']['screenManager'].isSuspendingScreen(environment):
return environment
for cmd in sorted(environment['commands'][trigger]):
try:
environ = environment['commands'][trigger][cmd].run(environment)
if environ != None:
environment = environ
environment['commands'][trigger][cmd].run(environment)
except Exception as e:
print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Error while executing trigger:" + trigger + "." + cmd ,debug.debugLevel.ERROR)
@ -53,9 +54,7 @@ class commandManager():
return environment
if self.isCommandDefined(environment):
try:
environ = environment['commands'][section][currCommand].run(environment)
if environ != None:
environment = environ
environment['commands'][section][currCommand].run(environment)
except Exception as e:
print(e)
environment['runtime']['debug'].writeDebugOut(environment,"Error while executing command:" + section + "." + currCommand ,debug.debugLevel.ERROR)
@ -70,13 +69,4 @@ class commandManager():
def setCurrCommandForExec(self, environment, currCommand):
environment['commandInfo']['currCommand'] = currCommand
return environment
def getCommandForShortcut(self, environment, shortcut):
shortcut = shortcut.upper()
if not self.isShortcutDefined(environment, shortcut):
return ''
return environment['bindings'][shortcut]
def isCommandDefined(self, environment, currCommand):
return( currCommand in environment['commands']['commands'])

View File

@ -7,16 +7,21 @@ class inputManager():
def __init__(self):
pass
def initialize(self, environment):
return environment
environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'keyboard', 'driver'), 'inputDriver')
def shutdown(self, environment):
return environment
environment['runtime']['inputManager'].releaseDevices(environment)
if environment['runtime']['inputDriver']:
environment['runtime']['inputDriver'].shutdown(environment)
def proceedInputEvent(self, environment):
timeout = True
event = environment['runtime']['inputDriver'].getInput(environment)
if event:
timeout = False
print(event)
return environment, timeout
#print(event)
return timeout
def grabDevices(self, environment):
environment['runtime']['inputDriver'].grabDevices(environment)
@ -47,4 +52,13 @@ class inputManager():
return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","")
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):
shortcut = shortcut.upper()
if not self.isShortcutDefined(environment, shortcut):
return ''
return environment['bindings'][shortcut]
def isCommandDefined(self, environment, currCommand):
return( currCommand in environment['commands']['commands'])

View File

@ -5,10 +5,19 @@ class outputManager():
def __init__(self):
pass
def initialize(self, environment):
return environment
environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'speech', 'driver'), 'speechDriver')
environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver'), 'soundDriver')
def shutdown(self, environment):
return environment
if environment['runtime']['soundDriver']:
environment['runtime']['soundDriver'].shutdown(environment)
if environment['runtime']['speechDriver']:
environment['runtime']['speechDriver'].shutdown(environment)
def presentText(self, environment, text, interrupt=True, soundIcon = ''):
print(soundIcon,text)
environment['runtime']['debug'].writeDebugOut(environment,"presentText:\nsoundIcon:'"+soundIcon+"'\nText:\n" + text ,debug.debugLevel.INFO)
if self.playSoundIcon(environment, soundIcon, interrupt):
environment['runtime']['debug'].writeDebugOut(environment,"soundIcon found" ,debug.debugLevel.INFO)

View File

@ -7,14 +7,19 @@ class screenManager():
self.autoIgnoreScreens = []
def initialize(self, environment):
environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'screen', 'driver'), 'screenDriver')
if environment['runtime']['settingsManager'].getSettingAsBool(environment,'screen', 'autodetectSuspendingScreen'):
self.autoIgnoreScreens = environment['runtime']['screenDriver'].getIgnoreScreens()
return environment
def shutdown(self, environment):
if environment['runtime']['screenDriver']:
environment['runtime']['screenDriver'].shutdown(environment)
return environment
def update(self, environment):
print(self.isSuspendingScreen(environment))
if not self.isSuspendingScreen(environment):
environment = environment['runtime']['screenDriver'].update(environment)
environment['screenData']['lastScreenUpdate'] = time.time()

View File

@ -48,7 +48,7 @@ class settingsManager():
print(str(shortcut))
environment['bindings'][str(shortcut)] = commandName
kbConfig.close()
return environment
def getCodeForKeyID(self, keyID):
try:
@ -85,10 +85,10 @@ class settingsManager():
def loadSettings(self, environment, settingConfigPath):
if not os.path.exists(settingConfigPath):
return None
return False
environment['settings'] = ConfigParser()
environment['settings'].read(settingConfigPath)
return environment
return True
def setSetting(self, environment, section, setting, value):
environment['settings'].set(section, setting, value)
@ -128,13 +128,13 @@ class settingsManager():
def loadDriver(self, environment, driverName, driverType):
if environment['runtime'][driverType] != None:
environment['runtime'][driverType].shutdown()
print('shutdown %s',driverType)
environment['runtime'][driverType].shutdown(environment)
spec = importlib.util.spec_from_file_location(driverName, driverType + '/' + driverName + '.py')
driver_mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(driver_mod)
environment['runtime'][driverType] = driver_mod.driver()
environment['runtime'][driverType].initialize(environment)
return environment
def setFenrirKeys(self, environment, keys):
keys = keys.upper()
@ -142,7 +142,6 @@ class settingsManager():
for key in keyList:
if not key in environment['input']['fenrirKey']:
environment['input']['fenrirKey'].append(key)
return environment
def keyIDasString(self, key):
try:
@ -160,52 +159,39 @@ class settingsManager():
return None
environment['runtime']['settingsManager'] = self
environment = environment['runtime']['settingsManager'].loadSettings(environment, settingsRoot + '/settings/' + settingsFile)
if environment == None:
validConfig = environment['runtime']['settingsManager'].loadSettings(environment, settingsRoot + '/settings/' + settingsFile)
if not validConfig:
return None
environment = self.setFenrirKeys(environment, self.getSetting(environment, 'general','fenrirKeys'))
self.setFenrirKeys(environment, self.getSetting(environment, 'general','fenrirKeys'))
if not os.path.exists(self.getSetting(environment, 'keyboard','keyboardLayout')):
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout')):
self.setSetting(environment, 'keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout'))
environment = environment['runtime']['settingsManager'].loadShortcuts(environment, self.getSetting('keyboard','keyboardLayout'))
environment['runtime']['settingsManager'].loadShortcuts(environment, self.getSetting('keyboard','keyboardLayout'))
if os.path.exists(settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout') + '.conf'):
self.setSetting(environment, 'keyboard', 'keyboardLayout', settingsRoot + 'keyboard/' + self.getSetting(environment, 'keyboard','keyboardLayout') + '.conf')
environment = environment['runtime']['settingsManager'].loadShortcuts(environment, self.getSetting(environment, 'keyboard','keyboardLayout'))
environment['runtime']['settingsManager'].loadShortcuts(environment, self.getSetting(environment, 'keyboard','keyboardLayout'))
else:
environment = environment['runtime']['settingsManager'].loadShortcuts(environment, self.getSetting(environment, 'keyboard','keyboardLayout'))
environment['runtime']['settingsManager'].loadShortcuts(environment, self.getSetting(environment, 'keyboard','keyboardLayout'))
if not os.path.exists(self.getSetting(environment, 'sound','theme') + '/soundicons.conf'):
if os.path.exists(settingsRoot + 'sound/'+ self.getSetting(environment, 'sound','theme')):
self.setSetting(environment, 'sound', 'theme', settingsRoot + 'sound/'+ self.getSetting(environment, 'sound','theme'))
if os.path.exists(settingsRoot + 'sound/'+ self.getSetting(environment, 'sound','theme') + '/soundicons.conf'):
environment = environment['runtime']['settingsManager'].loadSoundIcons(environment, self.getSetting(environment, 'sound','theme'))
environment['runtime']['settingsManager'].loadSoundIcons(environment, self.getSetting(environment, 'sound','theme'))
else:
environment = environment['runtime']['settingsManager'].loadSoundIcons(environment, self.getSetting(environment, 'sound','theme'))
environment['runtime']['settingsManager'].loadSoundIcons(environment, self.getSetting(environment, 'sound','theme'))
environment['runtime']['inputManager'] = inputManager.inputManager()
environment = environment['runtime']['inputManager'].initialize(environment)
environment['runtime']['inputManager'].initialize(environment)
environment['runtime']['outputManager'] = outputManager.outputManager()
environment = environment['runtime']['outputManager'].initialize(environment)
environment['runtime']['outputManager'].initialize(environment)
environment['runtime']['commandManager'] = commandManager.commandManager()
environment = environment['runtime']['commandManager'].initialize(environment)
environment['runtime']['commandManager'].initialize(environment)
if environment['runtime']['screenManager'] == None:
environment['runtime']['screenManager'] = screenManager.screenManager()
environment = environment['runtime']['screenManager'].initialize(environment)
environment['runtime']['screenManager'].initialize(environment)
environment = environment['runtime']['commandManager'].loadCommands(environment,'commands')
environment = environment['runtime']['commandManager'].loadCommands(environment,'onInput')
environment = environment['runtime']['commandManager'].loadCommands(environment,'onScreenChanged')
environment = environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'speech', 'driver'), 'speechDriver')
environment = environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'screen', 'driver'), 'screenDriver')
environment = environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'sound', 'driver'), 'soundDriver')
environment = environment['runtime']['settingsManager'].loadDriver(environment,\
environment['runtime']['settingsManager'].getSetting(environment,'keyboard', 'driver'), 'inputDriver')
environment['runtime']['debug'].writeDebugOut(environment,'\/-------environment-------\/',debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,str(environment),debug.debugLevel.ERROR)
environment['runtime']['debug'].writeDebugOut(environment,'\/-------settings.conf-------\/',debug.debugLevel.ERROR)

View File

@ -33,10 +33,10 @@ class fenrir():
self.shutdown()
def handleProcess(self):
self.environment, timeout = self.environment['runtime']['inputManager'].proceedInputEvent(self.environment)
timeout = self.environment['runtime']['inputManager'].proceedInputEvent(self.environment)
timeout = True
try:
self.environment = self.environment['runtime']['screenManager'].update(self.environment)
self.environment['runtime']['screenManager'].update(self.environment)
except Exception as e:
print(e)
self.environment['runtime']['debug'].writeDebugOut(self.environment, str(e),debug.debugLevel.ERROR)
@ -44,17 +44,17 @@ class fenrir():
#currShortcut = self.environment['runtime']['inputManager'].getCurrShortcut(self.environment)
currShortcut = ''
currCommand = self.environment['runtime']['commandManager'].getCommandForShortcut(self.environment, currShortcut)
self.environment = self.environment['runtime']['commandManager'].setCurrCommandForExec(self.environment, currCommand)
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')
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'] != '':
self.handleCommands()
def handleCommands(self):
if (self.environment['commandInfo']['currCommand'] != ''):
self.environment = self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands')
self.environment['runtime']['commandManager'].executeCommand(self.environment, self.environment['commandInfo']['currCommand'], 'commands')
def shutdownRequest(self):
self.environment['generalInformation']['running'] = False
@ -63,24 +63,18 @@ class fenrir():
self.shutdownRequest()
def shutdown(self):
self.environment['runtime']['inputManager'].releaseDevices(self.environment)
if self.environment['runtime']['inputManager']:
self.environment['runtime']['inputManager'].shutdown(self.environment)
self.environment['runtime']['outputManager'].presentText(self.environment, "Quit Fenrir", soundIcon='ScreenReaderOff', interrupt=True)
time.sleep(1.0) # wait a little before splatter it :)
if self.environment['runtime']['screenManager']:
self.environment['runtime']['screenManager'].shutdown(self.environment)
if self.environment['runtime']['commandManager']:
self.environment['runtime']['commandManager'].shutdown(self.environment)
if self.environment['runtime']['inputManager']:
self.environment['runtime']['inputManager'].shutdown(self.environment)
self.environment['runtime']['commandManager'].shutdown(self.environment)
if self.environment['runtime']['outputManager']:
self.environment['runtime']['outputManager'].shutdown(self.environment)
if self.environment['runtime']['screenDriver']:
self.environment['runtime']['screenDriver'].shutdown(self.environment)
if self.environment['runtime']['inputDriver']:
self.environment['runtime']['inputDriver'].shutdown(self.environment)
if self.environment['runtime']['soundDriver']:
self.environment['runtime']['soundDriver'].shutdown(self.environment)
if self.environment['runtime']['speechDriver']:
self.environment['runtime']['speechDriver'].shutdown(self.environment)
self.environment['runtime']['outputManager'].shutdown(self.environment)
if self.environment['runtime']['debug']:
self.environment['runtime']['debug'].closeDebugFile()
time.sleep(0.8) # wait a little before splatter it :)

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import difflib
import subprocess
from utils import debug
class driver():
@ -31,12 +32,13 @@ class driver():
def getIgnoreScreens(self):
xlist = []
try:
x = subprocess.Popen('ps a -o tty,comm | grep -e irssi | grep -v "grep -e irssi"', shell=True, stdout=subprocess.PIPE).stdout.read().decode()[:-1].split('\n')
except:
x = subprocess.Popen('ps a -o tty,comm | grep -e Xorg | grep -v "grep -e Xorg"', shell=True, stdout=subprocess.PIPE).stdout.read().decode()[:-1].split('\n')
except Exception as e:
print(e)
return xlist
for i in x:
if x[:3].upper() == 'TTY':
xlist.append(i[4])
if i[:3].upper() == 'TTY':
xlist.append(i[3])
return xlist
def update(self, environment, trigger='updateScreen'):

View File

@ -17,6 +17,7 @@ class driver():
self.frequenceCommand = '=play -q -v fenrirVolume -n -c1 synth fenrirDuration sine fenrirFrequence'
return environment
def shutdown(self, environment):
self.cancel()
return environment
def playFrequence(self, frequence, duration, adjustVolume):
if interrupt:
@ -34,6 +35,8 @@ class driver():
self.proc = subprocess.Popen(popenSoundFileCommand, shell=True)
self.soundType = 'file'
def cancel(self):
if self.soundType == '':
return
if self.soundType == 'file':
self.proc.kill()
if self.soundType == 'frequence':