root/trunk/dabo/dUserSettingProvider.py

Revision 3303, 1.8 kB (checked in by paul, 1 year ago)

Reverted the behavior of _ to how we had it originally: you must explicitly
issue 'from dabo.dLocalize import _' instead of having _ in builtins,
which caused several hard-to-fix problems, and potentially others we
hadn't found yet.

You'll get errors until you add back any of those lines to your own apps.

  • Property svn:eol-style set to native
Line 
1 # -*- coding: utf-8 -*-
2 import dabo
3 from dabo.dObject import dObject
4 from dabo.dLocalize import _
5
6
7 class dUserSettingProvider(dObject):
8     """Class that manages saving and restoring user settings, such as form
9     size and position.
10     """
11     def getUserSettingKeys(self, spec):
12         """Return a list of all keys underneath <spec>.
13         
14         For example, if spec is "appWizard.dbDefaults", and there are
15         userSettings entries for:
16             appWizard.dbDefaults.pkm.Host
17             appWizard.dbDefaults.pkm.User
18             appWizard.dbDefaults.egl.Host
19             
20         The return value would be ["pkm", "egl"]
21         """
22         return self.PreferenceManager.getPrefKeys(spec.lower())
23
24
25     def getUserSetting(self, item, default=None):
26         """ Return the value of the user settings table that
27         corresponds to the preference key passed.
28         """
29         prf = self.PreferenceManager
30         parsedItem = item.lower().split(".")
31         while len(parsedItem) > 1:
32             prf = prf.__getattr__(parsedItem.pop(0))
33         key = parsedItem[0]
34         ret = prf.getValue(key)
35         if ret is None:
36             # No such pref key. Return the default
37             ret = default
38         return ret
39        
40
41     def setUserSetting(self, item, val):
42         """Persist a value to the user settings file."""
43         prf = self.PreferenceManager
44         parsedItem = item.lower().split(".")
45         while len(parsedItem) > 1:
46             prf = prf.__getattr__(parsedItem.pop(0))
47         key = parsedItem[0]
48         prf.setValue(key, val)
49    
50    
51     def setUserSettings(self, dct):
52         """Persist a set of setting name: value pairs."""
53         for nm, val in dct.items():
54             self.setUserSetting(nm, val)
55
56
57     def deleteUserSetting(self, item):
58         """Removes the specified item from the settings file."""
59         self.PreferenceManager.deletePref(item.lower(), False)
60
61
62     def deleteAllUserSettings(self, spec):
63         """Given a spec, deletes all keys that match that spec.
64         See the docs for getUserSettingKeys() for an explanation
65         on key matching.
66         """
67         self.PreferenceManager.deletePref(spec.lower(), True)
Note: See TracBrowser for help on using the browser.