Debian packaging for 0.99.3 on Fremantle
[panucci.git] / src / panucci / settings.py
blobb3aa9bd894994e3e914a21e1fa775f3a09531329
1 # -*- coding: utf-8 -*-
3 # This file is part of Panucci.
4 # Copyright (c) 2008-2011 The Panucci Project
6 # Panucci is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # Panucci is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Panucci. If not, see <http://www.gnu.org/licenses/>.
19 from __future__ import absolute_import
21 import logging
22 import os.path
23 import ConfigParser
25 import panucci
26 from panucci import util
28 if not os.path.exists(panucci.SETTINGS_FILE):
29 import shutil
30 _filepath = util.find_data_file("panucci.conf")
31 shutil.copy(_filepath, panucci.HOME)
33 if not os.path.exists(panucci.THEME_FILE):
34 import shutil
35 _filepath = util.find_data_file("theme.conf")
36 shutil.copy(_filepath, panucci.HOME)
38 class Settings(object):
39 def __init__(self):
40 self.__log = logging.getLogger('panucci.settings.Settings')
41 self.config = ConfigParser.SafeConfigParser()
42 # Parse everything
43 _file = open(util.find_data_file("panucci-all.conf"))
44 self.config.readfp(_file)
45 _file.close()
46 # Parse non editable
47 if os.path.exists(panucci.HOME + '/panucci-noedit.conf'):
48 _file = open(panucci.HOME + "/panucci-noedit.conf")
49 self.config.readfp(_file)
50 _file.close()
51 # Parse editable
52 _file = open(panucci.SETTINGS_FILE)
53 self.config.readfp(_file)
54 _file.close()
55 """
56 def __getattr__(self, key):
57 if DEFAULTS.has_key(key):
58 # FIXME: Load settings from somewhere
59 return DEFAULTS[key]
60 else:
61 self.__log.warning('Setting "%s" doesn\'t exist.' % key)
62 raise AttributeError
64 def __setattr__(self, key, value):
65 if DEFAULTS.has_key(key):
66 if type(value) == type(DEFAULTS[key]):
67 # Don't set the value if it's the same as it used to be
68 #if getattr(self, key) != value:
69 # FIXME: Save setting somewhere
71 return True
72 else:
73 self.__log.warning(
74 'Type of "%s" (%s) does not match default type (%s)',
75 key, type(value).__name__,
76 type(DEFAULTS[key]).__name__ )
77 else:
78 object.__setattr__( self, key, value )
79 self.__log.warning('Setting "%s" doesn\'t exist.', key)
81 return False
83 def attach_checkbutton(self, button, setting):
84 button.connect(
85 'toggled', lambda w: setattr( self, setting, w.get_active()) )
86 #self.register(
87 # setting + SIGNAL_NAME_SUFFIX, lambda v: button.set_active(v) )
88 button.set_active( getattr(self, setting) )
89 """
90 settings = Settings()