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,67 +1,24 @@
[sound]
# Turn sound on or off:
enabled=True
# Select the driver used to play sounds, choices are generic and gstreamer.
# Sox is the default.
driver=generic
# Sound themes. This is the pack of sounds used for sound alerts.
# Sound packs may be located at /usr/share/sounds
# For system wide availability, or ~/.local/share/fenrir/sounds
# For the current user.
theme=default
# Sound volume controls how loud the sounds for your chosen soundpack are.
# 0 is quietest, 1.0 is loudest.
volume=1.0
# shell commands for generic sound driver
# the folowing variable are substituded
# fenrirVolume = the current volume setting
# fenrirSoundFile = the soundfile for an soundicon
# fenrirFrequence = the frequence to play
# fenrirDuration = the duration of the frequence
# the following command is used for play a soundfile
genericPlayFileCommand=play -q -v fenrirVolume fenrirSoundFile
#the following command is used for generating a frequence beep
genericFrequencyCommand=play -q -v fenrirVolume -n -c1 synth fenrirDuration sine fenrirFrequence
[speech]
# Turn speech on or off:
enabled=True
# Select speech driver, options are speechd (default) or espeak:
driver=speechd
#driver=espeak
# The rate selects how fast fenrir will speak. Options range from 0, slowest, to 1.0, fastest.
rate=0.45
# Pitch controls the pitch of the voice, select from 0, lowest, to 1.0, highest.
rate=0.75
pitch=0.5
# Volume controls the loudness of the voice, select from 0, quietest, to 1.0, loudest.
volume=1.0
# Module is used for speech-dispatcher, to select the speech module you want to use.
# Consult speech-dispatcher's configuration and help ti find out which modules are available.
# The default is espeak.
module=espeak
# Voice selects the varient you want to use, for example, f5 will use the female voice #5 in espeak,
# or if using the espeak module in speech-dispatcher. To find out which voices are available, consult the documentation provided with your chosen synthesizer.
voice=
# Select the language you want fenrir to use.
language=english-us
# Read new text as it happens?
voice=de
language=de
volume=0.8
autoReadIncomming=True
[braille]
#braille is not implemented yet
enabled=False
layout=en
@ -70,40 +27,32 @@ driver=linux
encoding=cp850
screenUpdateDelay=0.4
suspendingScreen=1,2
autodetectSuspendingScreen=False
autodetectSuspendingScreen=True
[keyboard]
driver=evdev
device=all
# gives fenrir exclusive access to the keyboard and let consume keystrokes. just disable on problems.
grabDevices=True
ignoreShortcuts=False
# the current shortcut layout located in /etc/fenrir/keyboard
keyboardLayout=desktop
# echo chars while typing.
charEcho=False
# echo deleted chars
keyboardLayout=test
charEcho=True
charDeleteEcho=True
# echo word after pressing space
wordEcho=False
# interrupt speech on any keypress
wordEcho=True
interruptOnKeyPress=False
# timeout for double tap in sec
doubleTapDelay=0.2
[general]
debugLevel=0
debugLevel=1
punctuationLevel=1
numberOfClipboards=10
# define the current fenrir key
fenrirKeys=KEY_KP0
timeFormat=%H:%M:%P
dateFormat="%A, %B %d, %Y"
autoSpellCheck=True
spellCheckLanguage=en_US
[promote]
enabled=True
inactiveTimeoutSec=120
list=
list=chrys,test

View File

@ -1,58 +0,0 @@
[sound]
enabled=True
driver=generic
theme=default
volume=1.0
# shell commands for generic sound driver
genericPlayFileCommand=play -q -v fenrirVolume fenrirSoundFile
genericFrequencyCommand=play -q -v fenrirVolume -n -c1 synth fenrirDuration sine fenrirFrequence
[speech]
enabled=True
driver=speechd
rate=0.75
pitch=0.5
module=espeak
voice=de
language=de
volume=0.8
autoReadIncomming=True
[braille]
enabled=False
layout=en
[screen]
driver=linux
encoding=cp850
screenUpdateDelay=0.4
suspendingScreen=1,2
autodetectSuspendingScreen=False
[keyboard]
driver=evdev
device=all
grabDevices=True
ignoreShortcuts=False
keyboardLayout=test
charEcho=True
charDeleteEcho=True
wordEcho=True
interruptOnKeyPress=False
# timeout for double tap in sec
doubleTapDelay=0.2
[general]
debugLevel=1
punctuationLevel=1
numberOfClipboards=10
fenrirKeys=KEY_KP0
timeFormat=%H:%M:%P
dateFormat="%A, %B %d, %Y"
autoSpellCheck=True
spellCheckLanguage=en_US
[promote]
enabled=True
inactiveTimeoutSec=120
list=chrys,test

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)
@ -71,12 +70,3 @@ class commandManager():
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)
@ -48,3 +53,12 @@ class inputManager():
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):
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)
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)
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':