[orca/new-settings] More settings manager's code cleaning
- From: Juanje Ojeda Croissier <jojeda src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca/new-settings] More settings manager's code cleaning
- Date: Mon, 9 Aug 2010 22:53:51 +0000 (UTC)
commit 3b705a8faa47bc4abef44c70b1a23e49b148433f
Author: Juanje Ojeda <jojeda emergya es>
Date: Mon Aug 9 08:57:49 2010 +0200
More settings manager's code cleaning
src/orca/backends/classic.py | 8 ++--
src/orca/backends/gconf_backend.py | 96 ++++++++++++++++++++----------------
2 files changed, 58 insertions(+), 46 deletions(-)
---
diff --git a/src/orca/backends/classic.py b/src/orca/backends/classic.py
index 4540553..88e051e 100644
--- a/src/orca/backends/classic.py
+++ b/src/orca/backends/classic.py
@@ -829,8 +829,8 @@ class OrcaPrefs:
def loadSettings(self):
"""Load settings"""
- UserSettings = __import__("user-settings")
- return UserSettings
+ userSettings = __import__("user-settings")
+ return userSettings
def readPreferences():
"""Returns a dictionary containing the names and values of the
@@ -873,5 +873,5 @@ def writePreferences(prefsDict, keyBindingsTreeModel=None,
def loadSettings():
"""Load settings"""
- UserSettings = __import__("user-settings")
- return UserSettings
+ userSettings = __import__("user-settings")
+ return userSettings
diff --git a/src/orca/backends/gconf_backend.py b/src/orca/backends/gconf_backend.py
index 3d9f1a4..7e42288 100644
--- a/src/orca/backends/gconf_backend.py
+++ b/src/orca/backends/gconf_backend.py
@@ -63,10 +63,13 @@ class OrcaPrefs():
DEFAULTS = gconf_defaults.defaults
- need2repr = ['brailleEOLIndicator', 'brailleContractionTable', 'brailleRequiredStateString',
- 'enabledBrailledTextAttributes', 'enabledSpokenTextAttributes', 'magZoomerBorderColor',
- 'magCursorColor', 'magCrossHairColor', 'magTargetDisplay', 'magSourceDisplay',
- 'speechRequiredStateString', 'speechServerFactory', 'presentDateFormat', 'presentTimeFormat']
+ need2repr = ['brailleEOLIndicator', 'brailleContractionTable',
+ 'brailleRequiredStateString', 'enabledBrailledTextAttributes',
+ 'enabledSpokenTextAttributes', 'magZoomerBorderColor',
+ 'magCursorColor', 'magCrossHairColor', 'magTargetDisplay',
+ 'magSourceDisplay', 'speechRequiredStateString',
+ 'speechServerFactory', 'presentDateFormat',
+ 'presentTimeFormat']
def __init__(self, prefsDict=None, keyBindingsTreeModel=None,
@@ -87,7 +90,8 @@ class OrcaPrefs():
# init gconf
self.__app_key = self.GCONF_BASE_DIR
self._client = gconf.client_get_default()
- self._client.add_dir(self.GCONF_BASE_DIR[:-1], gconf.CLIENT_PRELOAD_RECURSIVE)
+ self._client.add_dir(self.GCONF_BASE_DIR[:-1],
+ gconf.CLIENT_PRELOAD_RECURSIVE)
self._notifications = []
self.options = GConfKeysDict()
@@ -102,51 +106,54 @@ class OrcaPrefs():
self.options = self.prefsDict
- def gconf_load(self, dir = None):
+ def gconf_load(self, path = None):
casts = {gconf.VALUE_BOOL: gconf.Value.get_bool,
- gconf.VALUE_INT: gconf.Value.get_int,
- gconf.VALUE_FLOAT: gconf.Value.get_float,
- gconf.VALUE_STRING: gconf.Value.get_string,
- gconf.VALUE_LIST: gconf.Value.get_list}
+ gconf.VALUE_INT: gconf.Value.get_int,
+ gconf.VALUE_FLOAT: gconf.Value.get_float,
+ gconf.VALUE_STRING: gconf.Value.get_string,
+ gconf.VALUE_LIST: gconf.Value.get_list}
new_settings = False
- if dir:
- self.__app_key = dir
+ if path:
+ self.__app_key = path
for entry in self._client.all_entries(self.__app_key):
-#PORQUE? self.options[entry.key.split(self.__app_key + '/')[1]] = self._client.get(entry.key).to_string()
+ #TODO: Javi ask why. Find out what he means...
+ # optionKey = entry.key.split(self.__app_key + '/')[1]
+ # optionValue = self._client.get(entry.key).to_string()
+ # self.options[optionKey] = optionValue
gval = self._client.get(entry.key)
if gval == None: continue
if gval.type == gconf.VALUE_LIST:
string_list = [item.get_string() for item in gval.get_list()]
- if dir:
+ if path:
dictString = ''
- dictString = self.__format_gconf_dir(dir, entry)
+ dictString = self.__format_gconf_dir(path, entry)
dictString += ' = %s ' % string_list
exec(dictString)
else:
self.options[entry.key.split('/')[-1]] = string_list
else:
- if dir:
+ if path:
dictString = ''
- dictString = self.__format_gconf_dir(dir, entry)
+ dictString = self.__format_gconf_dir(path, entry)
dictString += ' = %s ' % repr(casts[gval.type](gval))
exec(dictString)
else:
self.options[entry.key.split('/')[-1]] = casts[gval.type](gval)
- for dir in self._client.all_dirs(self.__app_key):
- self.gconf_load(dir)
+ for path in self._client.all_dirs(self.__app_key):
+ self.gconf_load(path)
self.__app_key = \
self.__app_key.split(reversed(self.__app_key.split('/')).next())[0][:-1]
if not new_settings:
return True
- def __format_gconf_dir(self, dir, entry):
- formatDir = dir.split('/')
+ def __format_gconf_dir(self, path, entry):
+ formatDir = path.split('/')
for item in range(4):
formatDir.pop(0)
@@ -161,11 +168,11 @@ class OrcaPrefs():
def gconf_save(self, key = None, keyDictionary = None):
casts = {types.BooleanType: gconf.Client.set_bool,
- types.IntType: gconf.Client.set_int,
- types.FloatType: gconf.Client.set_float,
- types.StringType: gconf.Client.set_string,
- types.ListType: gconf.Client.set_list,
- types.TupleType: gconf.Client.set_list}
+ types.IntType: gconf.Client.set_int,
+ types.FloatType: gconf.Client.set_float,
+ types.StringType: gconf.Client.set_string,
+ types.ListType: gconf.Client.set_list,
+ types.TupleType: gconf.Client.set_list}
if key and keyDictionary:
self.__app_key += '/%s' % key
@@ -193,8 +200,8 @@ class OrcaPrefs():
if name in self.need2repr and value != None:
value = self._fix_quotes(value)
if value != None and not isinstance(value, dict):
- casts[type(value)](self._client, self.__app_key + '/' + name,
- value)
+ casts[type(value)](self._client, self.__app_key + '/' + \
+ name, value)
else:
print 'se obvia %s por ser None' % name
@@ -938,14 +945,15 @@ class OrcaPrefs():
self.prefsDict['activeProfile'] = 'default'
if self.prefsDict:
- self._client.set_string('/apps/gnome-orca/activeProfile',self.prefsDict['activeProfile'])
- self.__app_key += '/%s' % self.prefsDict['activeProfile']
-
- for key in settings.userCustomizableSettings:
- if key != 'voices':
- self.prefsDict[key] = self._getValueForKey(self.prefsDict, key)
- if key in self.need2repr:
- self.prefsDict[key] = self._fix_quotes(self.prefsDict[key])
+ self._client.set_string('/apps/gnome-orca/activeProfile',
+ self.prefsDict['activeProfile'])
+ self.__app_key += '/%s' % self.prefsDict['activeProfile']
+
+ for key in settings.userCustomizableSettings:
+ if key != 'voices':
+ self.prefsDict[key] = self._getValueForKey(self.prefsDict, key)
+ if key in self.need2repr:
+ self.prefsDict[key] = self._fix_quotes(self.prefsDict[key])
if self.keyBindingsTreeModel:
self.prefsDict['overridenKeyBindings'] = {}
@@ -1008,7 +1016,8 @@ class OrcaPrefs():
if not self._client.all_entries(self.__app_key):
return False
else:
- self.__app_key += '/%s' % self._client.get_string('/apps/gnome-orca/activeProfile')
+ path = '/apps/gnome-orca/activeProfile'
+ self.__app_key += '/%s' % self._client.get_string(path)
# self.options = self.DEFAULTS
# self.gconf_save()
@@ -1073,9 +1082,9 @@ class OrcaPrefs():
#
import orca.pronunciation_dict
- orca.pronunciation_dict.pronunciation_dict={}
+ orca.pronunciation_dict.pronunciation_dict = {}
for key, value in self.settingsDict['pronunciations'].items():
- orca.pronunciation_dict.setPronunciation(str(key), str(value))
+ orca.pronunciation_dict.setPronunciation(str(key), str(value))
import orca.orca_state
@@ -1141,7 +1150,8 @@ def readPreferences():
# must be in userCustomizableSettings
# profile support
- prefsDict['activeProfile'] = gconf.client_get_default().get_string('/apps/gnome-orca/activeProfile')
+ path = '/apps/gnome-orca/activeProfile'
+ prefsDict['activeProfile'] = gconf.client_get_default().get_string(path)
return prefsDict
@@ -1182,6 +1192,8 @@ def availableProfiles():
"""Returns available profiles"""
client = gconf.client_get_default()
- profiles = client.all_dirs('/apps/gnome-orca')
- profiles = [profiles[profiles.index(profile)].split('/apps/gnome-orca/')[1] for profile in profiles]
+ path = '/apps/gnome-orca'
+ profiles = client.all_dirs(path)
+ profiles = [profiles[profiles.index(profile)].split("%s/" % path)[1] \
+ for profile in profiles]
return profiles
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]