[kupfer] settings: Allow resetting accelerators and global bindings to default
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer] settings: Allow resetting accelerators and global bindings to default
- Date: Mon, 29 Mar 2010 05:04:15 +0000 (UTC)
commit 90baac068e0c6c79b5dadae2049f371c9962b75b
Author: Karol BÄ?dkowski <karol bedkowski gmail com>
Date: Thu Apr 7 22:13:13 2005 +0200
settings: Allow resetting accelerators and global bindings to default
kupfer/core/settings.py | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/core/settings.py b/kupfer/core/settings.py
index 625869a..7474b7e 100644
--- a/kupfer/core/settings.py
+++ b/kupfer/core/settings.py
@@ -41,6 +41,7 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
}
def __init__(self):
gobject.GObject.__init__(self)
+ self._defaults_path = None
self._config = self._read_config()
self._save_timer = scheduler.Timer(True)
@@ -77,6 +78,7 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
except config.ResourceLookupError, exc:
print "Error: no default config file %s found!" % self.defaults_filename
else:
+ self._defaults_path = defaults_path
config_files += (defaults_path, )
if read_config:
@@ -195,6 +197,19 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
self._update_config_save_timer()
return False
+ def get_from_defaults(self, section, option=None):
+ """Load values from default configuration file.
+ If @option is None, return all section items as (key, value) """
+ if self._defaults_path is None:
+ print 'Defaults not found'
+ return
+ parser = ConfigParser.SafeConfigParser()
+ parser.read(self._defaults_path)
+ if option is None:
+ return parser.items(section)
+ else:
+ return parser.get(section, option.lower())
+
def get_plugin_enabled(self, plugin_id):
"""Convenience: if @plugin_id is enabled"""
return self.get_plugin_config(plugin_id, "kupfer_enabled",
@@ -322,6 +337,16 @@ class SettingsController (gobject.GObject, pretty.OutputMixin):
def get_accelerators(self):
return self._config['Keybindings']
+ def reset_keybindings(self):
+ self.set_keybinding(self.get_from_defaults('Kupfer', 'keybinding'))
+ self.set_magic_keybinding(
+ self.get_from_defaults('Kupfer', 'magickeybinding'))
+
+ def reset_accelerators(self):
+ for key, value in self.get_from_defaults('Keybindings'):
+ self._set_config('Keybindings', key, value)
+
+
# Section, Key, Value
gobject.signal_new("value-changed", SettingsController, gobject.SIGNAL_RUN_LAST,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]