Browse Source

wxGUI/settings: Append() - add overwrite argument

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@52719 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 12 years ago
parent
commit
b18443dce9
1 changed files with 13 additions and 5 deletions
  1. 13 5
      gui/wxpython/core/settings.py

+ 13 - 5
gui/wxpython/core/settings.py

@@ -1081,7 +1081,7 @@ class Settings:
         except KeyError:
             raise GException("%s '%s:%s:%s'" % (_("Unable to set "), group, key, subkey))
         
-    def Append(self, dict, group, key, subkey, value):
+    def Append(self, dict, group, key, subkey, value, overwrite = True):
         """!Set value of key/subkey
 
         Create group/key/subkey if not exists
@@ -1091,25 +1091,33 @@ class Settings:
         @param key key
         @param subkey subkey (value or list)
         @param value value
+        @param overwrite True to overwrite existing value
         """
+        hasValue = True
         if group not in dict:
             dict[group] = {}
-
+            hasValue = False
+        
         if key not in dict[group]:
             dict[group][key] = {}
-
+            hasValue = False
+        
         if type(subkey) == types.ListType:
             # TODO: len(subkey) > 2
             if subkey[0] not in dict[group][key]:
                 dict[group][key][subkey[0]] = {}
+                hasValue = False
+            
             try:
-                dict[group][key][subkey[0]][subkey[1]] = value
+                if overwrite or (not overwrite and not hasValue):
+                    dict[group][key][subkey[0]][subkey[1]] = value
             except TypeError:
                 print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
                     ' (' + group + ':' + key + ':' + subkey[0] + ':' + subkey[1] + ')'
         else:
             try:
-                dict[group][key][subkey] = value
+                if overwrite or (not overwrite and not hasValue):
+                    dict[group][key][subkey] = value
             except TypeError:
                 print >> sys.stderr, _("Unable to parse settings '%s'") % value + \
                     ' (' + group + ':' + key + ':' + subkey + ')'