Mercurial > hg > Feedworm
comparison Preferences.py @ 44:be990ac6e478
saving the preference "start maximized" from GUI implemented
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 14 May 2010 15:02:15 +0200 |
parents | 12ed8b5fa08c |
children | 03358c113170 |
comparison
equal
deleted
inserted
replaced
43:12ed8b5fa08c | 44:be990ac6e478 |
---|---|
5 START_MAXIMIZED = "START_MAXIMIZED" | 5 START_MAXIMIZED = "START_MAXIMIZED" |
6 | 6 |
7 class Preferences(object): | 7 class Preferences(object): |
8 def __init__(self, session): | 8 def __init__(self, session): |
9 self.session = session | 9 self.session = session |
10 self.cache = {} | |
11 | |
12 def _cachedPreference(self, key, defaultValue=None): | |
13 if self.cache.has_key(key): | |
14 return self.cache[key] | |
15 else: | |
16 pref = Preference.forKey(key, self.session) | |
17 if pref is None: | |
18 pref = Preference(key, defaultValue) | |
19 self.session.add(pref) | |
20 self.cache[key] = pref | |
21 return pref | |
10 | 22 |
11 def startMaximized(self): | 23 def startMaximized(self): |
12 value = Preference.valueForKey(START_MAXIMIZED, self.session) | 24 pref = self._cachedPreference(START_MAXIMIZED, False) |
13 if value is not None: | 25 return util.str2bool(pref.value) |
14 return util.str2bool(value) | 26 |
15 else: | 27 def setStartMaximized(self, flag): |
16 return False | 28 """ Convert flag to boolean so that a defined value is stored in the DB """ |
29 boolValue = False | |
30 if flag: | |
31 boolValue = True | |
32 pref = self._cachedPreference(START_MAXIMIZED) | |
33 pref.value = boolValue |