Clean-up: Remove all volume controls
[panucci.git] / src / panucci / settings.py
blob79da37ec57fcf80d40c5279b8a084a49ed40fb76
1 #!/usr/bin/python
3 # This file is part of Panucci.
4 # Copyright (c) 2008-2010 The Panucci Audiobook and Podcast Player 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/>.
20 from __future__ import absolute_import
22 import logging
24 import panucci
26 import os.path
28 LAST_FOLDER_DEFAULT = os.path.join(os.path.expanduser('~'), 'MyDocs')
30 if not os.path.exists(LAST_FOLDER_DEFAULT):
31 LAST_FOLDER_DEFAULT = os.path.expanduser('~')
33 DEFAULTS = {
34 'dual_action_button_delay' : 0.5,
35 'enable_dual_action_btn' : True,
36 'last_folder' : LAST_FOLDER_DEFAULT,
37 'max_recent_files' : 10,
38 'progress_locked' : False,
39 'scrolling_labels' : True,
40 'seek_long' : 60,
41 'seek_short' : 10,
44 class Settings(object):
45 def __init__(self):
46 self.__log = logging.getLogger('panucci.settings.Settings')
48 def __getattr__(self, key):
49 if DEFAULTS.has_key(key):
50 # FIXME: Load settings from somewhere
51 return DEFAULTS[key]
52 else:
53 self.__log.warning('Setting "%s" doesn\'t exist.' % key)
54 raise AttributeError
56 def __setattr__(self, key, value):
57 if DEFAULTS.has_key(key):
58 if type(value) == type(DEFAULTS[key]):
59 # Don't set the value if it's the same as it used to be
60 #if getattr(self, key) != value:
61 # FIXME: Save setting somewhere
63 return True
64 else:
65 self.__log.warning(
66 'Type of "%s" (%s) does not match default type (%s)',
67 key, type(value).__name__,
68 type(DEFAULTS[key]).__name__ )
69 else:
70 object.__setattr__( self, key, value )
71 self.__log.warning('Setting "%s" doesn\'t exist.', key)
73 return False
75 def attach_checkbutton(self, button, setting):
76 button.connect(
77 'toggled', lambda w: setattr( self, setting, w.get_active()) )
78 #self.register(
79 # setting + SIGNAL_NAME_SUFFIX, lambda v: button.set_active(v) )
80 button.set_active( getattr(self, setting) )
82 settings = Settings()