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
26 from panucci
import util
28 if not os
.path
.exists(panucci
.SETTINGS_FILE
):
30 _filepath
= util
.find_data_file("panucci.conf")
31 shutil
.copy(_filepath
, panucci
.HOME
)
33 if not os
.path
.exists(panucci
.THEME_FILE
):
35 _filepath
= util
.find_data_file("theme.conf")
36 shutil
.copy(_filepath
, panucci
.HOME
)
38 class Settings(object):
40 self
.__log
= logging
.getLogger('panucci.settings.Settings')
41 self
.config
= ConfigParser
.SafeConfigParser()
43 _file
= open(util
.find_data_file("panucci-all.conf"))
44 self
.config
.readfp(_file
)
47 if os
.path
.exists(panucci
.HOME
+ '/panucci-noedit.conf'):
48 _file
= open(panucci
.HOME
+ "/panucci-noedit.conf")
49 self
.config
.readfp(_file
)
52 _file
= open(panucci
.SETTINGS_FILE
)
53 self
.config
.readfp(_file
)
56 def __getattr__(self, key):
57 if DEFAULTS.has_key(key):
58 # FIXME: Load settings from somewhere
61 self.__log.warning('Setting "%s" doesn\'t exist.' % key)
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
74 'Type of "%s" (%s) does not match default type (%s)',
75 key, type(value).__name__,
76 type(DEFAULTS[key]).__name__ )
78 object.__setattr__( self, key, value )
79 self.__log.warning('Setting "%s" doesn\'t exist.', key)
83 def attach_checkbutton(self, button, setting):
85 'toggled', lambda w: setattr( self, setting, w.get_active()) )
87 # setting + SIGNAL_NAME_SUFFIX, lambda v: button.set_active(v) )
88 button.set_active( getattr(self, setting) )