From d6a6ad55837af79974620fc74633a9bde052ebd7 Mon Sep 17 00:00:00 2001 From: chrys Date: Mon, 25 Jul 2016 19:48:03 +0200 Subject: [PATCH] fix enable/disable commands --- config/settings/settings.cfg | 18 ++++--- config/settings/settings.cfg.chrys | 36 ------------- .../commands/toggle_braille_enable.py | 9 ++-- .../commands/commands/toggle_output_enable.py | 18 +++---- .../commands/commands/toggle_sound_enable.py | 9 ++-- .../commands/commands/toggle_speech_enable.py | 9 ++-- src/fenrir-package/core/inputManager.py | 53 ------------------- src/fenrir-package/core/settingsManager.py | 10 ++-- 8 files changed, 43 insertions(+), 119 deletions(-) delete mode 100644 config/settings/settings.cfg.chrys diff --git a/config/settings/settings.cfg b/config/settings/settings.cfg index d6708f84..4d62ded9 100644 --- a/config/settings/settings.cfg +++ b/config/settings/settings.cfg @@ -1,3 +1,4 @@ + [sound] enabled=False, driver=sox @@ -5,19 +6,23 @@ theme=default [speech] enabled=True -driver=espeak -rate=800 +#driver=espeak +#language=en-us +#voice=en-us +driver=speechd +#rate=800 +rate=50 +volume=100 pitch=50 module=espeak -voice=en-us -language=en-us -volume=200 +voice=de +language=de [braille] enabled=False layout=en -[screen] +['screen] driver=linux [keyboard] @@ -28,3 +33,4 @@ wordEcho=True [general] debugLevel=0 punctuationLevel=1 + diff --git a/config/settings/settings.cfg.chrys b/config/settings/settings.cfg.chrys deleted file mode 100644 index 4d62ded9..00000000 --- a/config/settings/settings.cfg.chrys +++ /dev/null @@ -1,36 +0,0 @@ - -[sound] -enabled=False, -driver=sox -theme=default - -[speech] -enabled=True -#driver=espeak -#language=en-us -#voice=en-us -driver=speechd -#rate=800 -rate=50 -volume=100 -pitch=50 -module=espeak -voice=de -language=de - -[braille] -enabled=False -layout=en - -['screen] -driver=linux - -[keyboard] -keyboardLayout=desktop -charEcho=False -wordEcho=True - -[general] -debugLevel=0 -punctuationLevel=1 - diff --git a/src/fenrir-package/commands/commands/toggle_braille_enable.py b/src/fenrir-package/commands/commands/toggle_braille_enable.py index f834bd0d..a2ea5637 100644 --- a/src/fenrir-package/commands/commands/toggle_braille_enable.py +++ b/src/fenrir-package/commands/commands/toggle_braille_enable.py @@ -4,11 +4,12 @@ class command(): def __init__(self): pass def run(self, environment): - environment['braille']['enabled'] = not environment['braille']['enabled'] - if environment['braille']['enabled']: - environment['runtime']['outputManager'].presentText(environment, "braille enabled") - else: + + if environment['runtime']['settingsManager'].getSettingAsBool(environment, 'braille', 'enabled'): environment['runtime']['outputManager'].presentText(environment, "braille disabled") + else: + environment['runtime']['outputManager'].presentText(environment, "braille enabled") + environment = environment['runtime']['settingsManager'].setSetting(environment, 'braille', 'enabled', str(not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'braille', 'enabled'))) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/commands/toggle_output_enable.py b/src/fenrir-package/commands/commands/toggle_output_enable.py index e79417cf..c5d78a3e 100644 --- a/src/fenrir-package/commands/commands/toggle_output_enable.py +++ b/src/fenrir-package/commands/commands/toggle_output_enable.py @@ -4,18 +4,18 @@ class command(): def __init__(self): pass def run(self, environment): - if environment['speech']['enabled'] or \ - environment['sound']['enabled'] or \ - environment['braille']['enabled']: + if environment['runtime']['settingsManager'].getSettingAsBool(environment, 'speech', 'enabled') or \ + environment['runtime']['settingsManager'].getSettingAsBool(environment, 'sound', 'enabled') or \ + environment['runtime']['settingsManager'].getSettingAsBool(environment, 'braille', 'enabled'): environment['runtime']['outputManager'].presentText(environment, "fenrir muted") - environment['speech']['enabled'] = False - environment['sound']['enabled'] = False - environment['braille']['enabled'] = False + environment = environment['runtime']['settingsManager'].setSetting(environment, 'speech', 'enabled','False') + environment = environment['runtime']['settingsManager'].setSetting(environment, 'sound', 'enabled','False') + environment = environment['runtime']['settingsManager'].setSetting(environment, 'braille', 'enabled','False') else: environment['runtime']['outputManager'].presentText(environment, "fenrir unmuted") - environment['speech']['enabled'] = True - environment['sound']['enabled'] = True - environment['braille']['enabled'] = True + environment = environment['runtime']['settingsManager'].setSetting(environment, 'speech', 'enabled','True') + environment = environment['runtime']['settingsManager'].setSetting(environment, 'sound', 'enabled','True') + environment = environment['runtime']['settingsManager'].setSetting(environment, 'braille', 'enabled','True') return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/commands/toggle_sound_enable.py b/src/fenrir-package/commands/commands/toggle_sound_enable.py index 71f619c2..21e42aaa 100644 --- a/src/fenrir-package/commands/commands/toggle_sound_enable.py +++ b/src/fenrir-package/commands/commands/toggle_sound_enable.py @@ -4,11 +4,12 @@ class command(): def __init__(self): pass def run(self, environment): - environment['sound']['enabled'] = not environment['sound']['enabled'] - if environment['sound']['enabled']: - environment['runtime']['outputManager'].presentText(environment, "sound enabled") - else: + + if environment['runtime']['settingsManager'].getSettingAsBool(environment, 'sound', 'enabled'): environment['runtime']['outputManager'].presentText(environment, "sound disabled") + else: + environment['runtime']['outputManager'].presentText(environment, "sound enabled") + environment = environment['runtime']['settingsManager'].setSetting(environment, 'sound', 'enabled', str(not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'sound', 'enabled'))) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/commands/commands/toggle_speech_enable.py b/src/fenrir-package/commands/commands/toggle_speech_enable.py index 013298a3..d0519a46 100644 --- a/src/fenrir-package/commands/commands/toggle_speech_enable.py +++ b/src/fenrir-package/commands/commands/toggle_speech_enable.py @@ -4,11 +4,12 @@ class command(): def __init__(self): pass def run(self, environment): - environment['speech']['enabled'] = not environment['speech']['enabled'] - if environment['speech']['enabled']: - environment['runtime']['outputManager'].presentText(environment, "speech enabled") - else: + + if environment['runtime']['settingsManager'].getSettingAsBool(environment, 'speech', 'enabled'): environment['runtime']['outputManager'].presentText(environment, "speech disabled") + else: + environment['runtime']['outputManager'].presentText(environment, "speech enabled") + environment = environment['runtime']['settingsManager'].setSetting(environment, 'speech', 'enabled', str(not environment['runtime']['settingsManager'].getSettingAsBool(environment, 'speech', 'enabled'))) return environment def setCallback(self, callback): pass diff --git a/src/fenrir-package/core/inputManager.py b/src/fenrir-package/core/inputManager.py index 6f84ea2b..4eb7e0cd 100644 --- a/src/fenrir-package/core/inputManager.py +++ b/src/fenrir-package/core/inputManager.py @@ -41,56 +41,3 @@ class inputManager(): currShortcutStringList = sorted(currShortcutStringList) return str(currShortcutStringList)[1:-1].replace(" ","").replace("'","") - def loadShortcuts(self, environment, kbConfigPath='../../config/keyboard/desktop.kb'): - kbConfig = open(kbConfigPath,"r") - while(True): - line = kbConfig.readline() - if not line: - break - line = line.replace('\n','') - if line.replace(" ","").startswith("#"): - continue - if line.split('#')[0].count("=") != 1: - continue - sepLine = line.split('#')[0].split('=') - commandString = sepLine[1] - keys = sepLine[0].replace(" ","").split(',') - currShortcut = [] - validKeyString = True - for key in keys: - if len(key) < 3: - validKeyString = False - break - if not key[0] in ['0','1','2']: - validKeyString = False - break - if key[1] != '-': - validKeyString = False - break - if key[2:] != '': - keyInt = self.getCodeForKeyID(key[2:]) - else: - validKeyString = False - break - if keyInt == 0: - validKeyString = False - break - if not validKeyString: - break - else: - currShortcut.append(key[0] + '-' + str(keyInt)) - if validKeyString: - keyString = '' - for k in sorted(currShortcut): - if keyString != '': - keyString += ',' - keyString += k - environment['bindings'][keyString] = commandString - kbConfig.close() - return environment - - def getCodeForKeyID(self, keyID): - try: - return evdev.ecodes.ecodes[keyID.upper()] - except: - return 0 diff --git a/src/fenrir-package/core/settingsManager.py b/src/fenrir-package/core/settingsManager.py index e7464a00..dbc24071 100644 --- a/src/fenrir-package/core/settingsManager.py +++ b/src/fenrir-package/core/settingsManager.py @@ -72,6 +72,10 @@ class settingsManager(): environment['settings'].read(settingConfigPath) return environment + def setSetting(self, environment, section, setting, value): + environment['settings'].set(section, setting, value) + return environment + def getSetting(self, environment, section, setting): value = '' try: @@ -81,7 +85,7 @@ class settingsManager(): return value def getSettingAsInt(self, environment, section, setting): - value = '' + value = 0 try: value = environment['settings'].getint(section, setting) except: @@ -89,14 +93,14 @@ class settingsManager(): return value def getSettingAsFloat(self, environment, section, setting): - value = '' + value = 0.0 try: value = environment['settings'].getfloat(section, setting) except: value = self.settings[section][setting] return value def getSettingAsBool(self, environment, section, setting): - value = '' + value = False try: value = environment['settings'].getboolean(section, setting) except: