view 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
line wrap: on
line source


from Preference import Preference
import util

START_MAXIMIZED = "START_MAXIMIZED"

class Preferences(object):
    def __init__(self, session):
        self.session = session
        self.cache = {}
        
    def _cachedPreference(self, key, defaultValue=None):
        if self.cache.has_key(key):
            return self.cache[key]
        else:
            pref = Preference.forKey(key, self.session)
            if pref is None:
                pref = Preference(key, defaultValue)
                self.session.add(pref)
            self.cache[key] = pref
            return pref
        
    def startMaximized(self):
        pref = self._cachedPreference(START_MAXIMIZED, False)
        return util.str2bool(pref.value)

    def setStartMaximized(self, flag):
        """ Convert flag to boolean so that a defined value is stored in the DB """
        boolValue = False
        if flag:
            boolValue = True
        pref = self._cachedPreference(START_MAXIMIZED)
        pref.value = boolValue