summaryrefslogtreecommitdiff
path: root/portato
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2008-09-02 13:22:29 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2008-09-02 13:22:29 +0200
commit978f7b6d8a6c0851abf31ba71fad68be1d34d566 (patch)
tree6d1f8a821b4dceb99a5662e6e25d1247b0f458a1 /portato
parentfdf6ed51db695b0d73d18c87977c898bd66bf3fa (diff)
downloadportato-978f7b6d8a6c0851abf31ba71fad68be1d34d566.tar.gz
portato-978f7b6d8a6c0851abf31ba71fad68be1d34d566.tar.bz2
portato-978f7b6d8a6c0851abf31ba71fad68be1d34d566.zip
Removed ConfigParser.set_boolean and use normal ConfigParser.set instead
Diffstat (limited to '')
-rw-r--r--portato/config_parser.py49
-rw-r--r--portato/gui/windows/preference.py4
2 files changed, 14 insertions, 39 deletions
diff --git a/portato/config_parser.py b/portato/config_parser.py
index e3f78db..37a32bf 100644
--- a/portato/config_parser.py
+++ b/portato/config_parser.py
@@ -354,7 +354,7 @@ class ConfigParser:
raise ValueError, "\"%s\" is not a boolean. (%s)" % (key, val.value)
- def set (self, key, value = "", section = "MAIN"):
+ def set (self, key, value, section = "MAIN"):
"""
Sets a new value of a given key in a section.
@@ -362,7 +362,7 @@ class ConfigParser:
key : string
the key
- value : string
+ value : string or boolean
the new value
section : string
the section
@@ -371,47 +371,22 @@ class ConfigParser:
- `KeyNotFoundException` : Raised if the specified key could not be found.
- `SectionNotFoundException` : Raised if the specified section could not be found.
+ - `ValueError` : if a boolean value is passed and the old/new value is not a boolean
"""
section = section.upper()
key = key.lower()
- self._access(key, section).value = value
-
- def set_boolean (self, key, value, section = "MAIN"):
- """
- Sets a new boolean value of a given key in a section.
- Therefore it invertes the string representation of the boolean (in lowercase).
-
- :Parameters:
-
- key : string
- the key
- value : boolean
- the new value
- section : string
- the section
-
- :Exceptions:
-
- - `KeyNotFoundException` : Raised if the specified key could not be found.
- - `SectionNotFoundException` : Raised if the specified section could not be found.
- - `ValueError` : if the old/new value is not a boolean
- """
-
- section = section.upper()
- key = key.lower()
-
- if not isinstance(value, bool):
- raise ValueError, "Passed value must be a boolean."
-
- val = self._access(key, section)
- if val.is_bool():
- if value is not val.boolean:
- val.boolean = value
- val.value = self._invert(val.value)
+ if not isinstance(value, bool): # str
+ self._access(key, section).value = value
else:
- raise ValueError, "\"%s\" is not a boolean." % key
+ val = self._access(key, section)
+ if val.is_bool():
+ if value is not val.boolean:
+ val.boolean = value
+ val.value = self._invert(val.value)
+ else:
+ raise ValueError, "\"%s\" is not a boolean." % key
def add_section (self, section, comment = None, with_blankline = True):
"""
diff --git a/portato/gui/windows/preference.py b/portato/gui/windows/preference.py
index 94d7ade..57425a0 100644
--- a/portato/gui/windows/preference.py
+++ b/portato/gui/windows/preference.py
@@ -143,9 +143,9 @@ class PreferenceWindow (AbstractDialog):
for box, val in self.checkboxes.iteritems():
if isinstance(val, tuple):
- self.cfg.set_boolean(val[0], self.tree.get_widget(box).get_active(), section = val[1])
+ self.cfg.set(val[0], self.tree.get_widget(box).get_active(), section = val[1])
else:
- self.cfg.set_boolean(val, self.tree.get_widget(box).get_active())
+ self.cfg.set(val, self.tree.get_widget(box).get_active())
for edit, val in self.edits.iteritems():
if isinstance(val,tuple):