[orca/new-settings] Some minor fixes to get things working
- From: Juanje Ojeda Croissier <jojeda src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca/new-settings] Some minor fixes to get things working
- Date: Mon, 25 Oct 2010 04:42:18 +0000 (UTC)
commit 1de9ae9d71cfbc549a19a8c69d4c6b5eed72edba
Author: Juanje Ojeda <jojeda emergya es>
Date: Mon Oct 25 06:41:54 2010 +0200
Some minor fixes to get things working
src/orca/backends/yaml.py | 12 +++---
src/orca/settings_manager.py | 78 ++++++++++++++++++++++++++++++++---------
2 files changed, 67 insertions(+), 23 deletions(-)
---
diff --git a/src/orca/backends/yaml.py b/src/orca/backends/yaml.py
index 0348c6a..9a8f43e 100644
--- a/src/orca/backends/yaml.py
+++ b/src/orca/backends/yaml.py
@@ -26,7 +26,8 @@ __date__ = "$Date$"
__copyright__ = "Copyright (c) 2010 Consorcio Fernando de los Rios."
__license__ = "LGPL"
-from yaml import load, dump
+import yaml
+import os
from xdg.BaseDirectory import xdg_data_home
class Backend():
@@ -45,7 +46,7 @@ class Backend():
'pronunciations': pronunciations,
'keybindings': keybindings}
settingsFile = open(self.settingsFile, 'w')
- dump(prefs, settingsFile)
+ yaml.dump(prefs, settingsFile)
settingsFile.close()
def saveProfileSettings(self, profile, general,
@@ -59,12 +60,12 @@ class Backend():
'pronunciations': pronunciations,
'keybindings': keybindings}
settingsFile = open(self.settingsFile, 'w')
- dump(prefs, settingsFile)
+ yaml.dump(prefs, settingsFile)
settingsFile.close()
def _getSettings(self):
settingsFile = open(self.settingsFile)
- prefs = load(settingsFile)
+ prefs = yaml.load(settingsFile)
self.general = prefs['general']
self.pronunciations = prefs['pronunciations']
self.keybindings = prefs['keybindings']
@@ -82,8 +83,7 @@ class Backend():
return self.keybindings[profile]
def isFirstStart(self):
- from orca.path import exists
- if exists(self.settingsFile):
+ if os.path.exists(self.settingsFile):
return False
else:
return True
diff --git a/src/orca/settings_manager.py b/src/orca/settings_manager.py
index 8ff4db6..574de26 100644
--- a/src/orca/settings_manager.py
+++ b/src/orca/settings_manager.py
@@ -28,6 +28,7 @@ __copyright__ = "Copyright (c) 2010 Consorcio Fernando de los Rios."
__license__ = "LGPL"
from orca import settings
+import os
class SettingsManager():
"""Settings backend manager. This class manages orca user's settings
@@ -64,20 +65,20 @@ class SettingsManager():
self.keybindings = {}
if not self._loadBackend():
- return False
+ return None
self._backend = self.backendModule.Backend()
- self.defaultGeneral = self._getDefaultGeneral()
- self.defaultPronunciations = self._getDefaultPronunciations()
- self.defaultKeybindings = self._getDefaultKeybindings()
- self.defaultGeneralValues = self.getRealValues(self.defaultGeneral)
+ self._setDefaultGeneral()
+ self._setDefaultPronunciations()
+ self._setDefaultKeybindings()
+ self.defaultGeneralValues = self._getRealValues(self.defaultGeneral)
self.general = self.defaultGeneralValues
self.pronunciations = self.defaultPronunciations
self.keybindings = self.defaultKeybindings
- self.setProfile(self.profile)
if self.isFirstStart():
self._createDefaults()
+ self.setProfile(self.profile)
def _loadBackend(self):
"""Load specific backend for manage user settings"""
@@ -97,11 +98,44 @@ class SettingsManager():
"""Let the active backend to create the initial structure
for storing the settings and save the default ones from
orca.settings"""
- self._backend.createGeneral(self.defaultGeneral,
- self.defaultPronunciations,
- self.defaultKeybindings)
+ def _createDir(dirName):
+ if not os.path.isdir(dirName):
+ os.mkdir(dirName)
+
+ # Set up the user's preferences directory (~/.orca by default).
+ #
+ orcaDir = settings.userPrefsDir
+ _createDir(orcaDir)
+
+ # Set up ~/.orca/orca-scripts as a Python package
+ #
+ orcaScriptDir = os.path.join(orcaDir, "orca-scripts")
+ _createDir(orcaScriptDir)
+ initFile = os.path.join(orcaScriptDir, "__init__.py")
+ if not os.path.exists(initFile):
+ os.close(os.open(initFile, os.O_CREAT, 0700))
+
+ # Set up ~/.orca/app-settings as a Python package.
+ #
+ orcaSettingsDir = os.path.join(orcaDir, "app-settings")
+ _createDir(orcaSettingsDir)
+ initFile = os.path.join(orcaSettingsDir, "__init__.py")
+ if not os.path.exists(initFile):
+ os.close(os.open(initFile, os.O_CREAT, 0700))
+
+ self._backend.saveDefaultSettings(self.defaultGeneral,
+ self.defaultPronunciations,
+ self.defaultKeybindings)
- def _getDefaultGeneral(self):
+ def _setDefaultPronunciations(self):
+ """Get the pronunciations by default from orca.settings"""
+ self.defaultPronunciations = {}
+
+ def _setDefaultKeybindings(self):
+ """Get the keybindings by default from orca.settings"""
+ self.defaultKeybindings = {}
+
+ def _setDefaultGeneral(self):
"""Get the general settings by default from orca.settings"""
self.defaultGeneral = {}
for key in settings.userCustomizableSettings:
@@ -115,6 +149,14 @@ class SettingsManager():
general settings dictionary.
prefs is a dictionary with the userCustomizableSettings keys
and values."""
+ need2repr = ['brailleEOLIndicator', 'brailleContractionTable',
+ 'brailleRequiredStateString', 'enabledBrailledTextAttributes',
+ 'enabledSpokenTextAttributes', 'magZoomerBorderColor',
+ 'magCursorColor', 'magCrossHairColor', 'magTargetDisplay',
+ 'magSourceDisplay', 'speechRequiredStateString',
+ 'speechServerFactory', 'presentDateFormat',
+ 'presentTimeFormat']
+
def getValueForKey(prefsDict, key):
value = None
if key in prefsDict:
@@ -136,10 +178,12 @@ class SettingsManager():
prefs[key] = getValueForKey(prefs, key)
return prefs
- def _getGeneral(self):
+ def _getGeneral(self, profile=None):
"""Get from the active backend the general settings for
the current profile"""
- generalSettings = self._backend.getGeneral(self.profile)
+ if profile is None:
+ profile = self.profile
+ generalSettings = self._backend.getGeneral(profile)
self.profileGeneral = generalSettings
def _getPronunciations(self):
@@ -154,7 +198,7 @@ class SettingsManager():
keybindingsSettings = self._backend.getKeybindings(self.profile)
self.profileKeybindings = keybindingsSettings
- def _loadProfileSettings(profile=None):
+ def _loadProfileSettings(self, profile=None):
"""Get from the active backend all the settings for the current
profile and store them in the object's attributes.
A profile can be passed as a parameter. This could be useful for
@@ -165,15 +209,15 @@ class SettingsManager():
self.profilePronunciations = self._getPronunciations(profile)
self.profileKeybindings = self._getKeybindings(profile)
- def _mergeSettings():
+ def _mergeSettings(self):
"""Update the changed values on the profile settings
over the current and active settings"""
- profileGeneral = self.getRealValues(self.profileGeneral)
+ profileGeneral = self._getRealValues(self.profileGeneral)
self.general.update(self.profileGeneral)
self.pronunciations.update(self.profilePronunciation)
self.keybindings.update(self.profileKeybindings)
- def setProfile(profile='default'):
+ def setProfile(self, profile='default'):
"""Set a specific profile as the active one.
Also the settings from that profile will be loading
and updated the current settings with them."""
@@ -242,7 +286,7 @@ class SettingsManager():
def isClassic(self):
"""Is the backend the classic one?
If the current backend is the classic one it will return True"""
- if self.backend is 'classic':
+ if self.backendName is 'classic':
return True
else:
return False
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]