Updated TODO.
[straw.git] / straw / preferences.py
blob2fab43e73c641fb402b0fc6703da5c53f6bbdbdb
1 """ preferences.py
3 Module setting user preferences.
4 """
5 __copyright__ = """
6 Copyright (c) 2002-2004 Juri Pakaste
7 Copyright (c) 2005-2007 Straw Contributors
8 """
9 __license__ = """ GNU General Public License
11 Straw is free software; you can redistribute it and/or modify it under the
12 terms of the GNU General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
14 version.
16 Straw is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA. """
24 import Config
25 import gtk
26 from gtk.glade import XML
28 import os
29 from os.path import join
31 import straw
33 class Preferences:
34 SEC_PER_MINUTE = 60
36 def __init__(self):
37 config = Config.get_instance()
38 self._glade = XML(join(straw.STRAW_DATA_DIR,'preferences.glade'))
39 self._window = self._glade.get_widget('preferences')
40 self._browser_override = self._glade.get_widget("prefs_browser_setting")
41 self._browser_entry = self._glade.get_widget("prefs_browser_setting_entry")
43 # General
44 config = Config.get_instance()
45 poll_frequency = int(config.poll_frequency/self.SEC_PER_MINUTE)
46 items_stored = int(config.number_of_items_stored)
48 browser_cmd = config.browser_cmd
49 if browser_cmd:
50 self._browser_override.set_active(True)
51 self._browser_entry.set_text (browser_cmd)
52 self._browser_entry.set_sensitive (True)
53 else:
54 self._browser_entry.set_text (_("Using desktop setting"))
56 self._glade.get_widget('poll_frequency_spin').set_value(poll_frequency)
57 self._glade.get_widget('number_of_items_spin').set_value(items_stored)
58 self._glade.get_widget(['item_order_oldest',
59 'item_order_newest'][config.item_order]).set_active(1)
60 self._glade.get_widget('vertical_layout').set_active(config.pane_layout == 'vertical')
62 nameFuncMap = {}
63 for key in dir(self.__class__):
64 if key[:3] == 'on_':
65 nameFuncMap[key] = getattr(self, key)
66 self._glade.signal_autoconnect(nameFuncMap)
68 def show(self, *args):
69 self._window.present()
71 def hide(self, *args):
72 self._window.hide()
74 def on_preferences_delete_event(self, *args):
75 self.hide()
76 return True
78 def on_close_button_clicked(self, button):
79 self.hide()
80 return
82 def on_poll_frequency_spin_value_changed(self, spin):
83 Config.get_instance().poll_frequency = int(spin.get_value() * self.SEC_PER_MINUTE)
85 def on_number_of_items_spin_value_changed(self, spin):
86 Config.get_instance().number_of_items_stored = int(spin.get_value())
88 def on_item_order_newest_toggled(self, radio):
89 config = Config.get_instance()
90 config.item_order = not config.item_order
92 def on_item_order_oldest_toggled(self, radio):
93 pass
95 def on_prefs_browser_setting_toggled(self, button):
96 active = button.get_active()
97 if not active:
98 config = Config.get_instance()
99 config.browser_cmd = ""
100 self._browser_entry.set_sensitive(active)
102 def on_prefs_browser_setting_entry_focus_out_event(self, entry, *args):
103 config = Config.get_instance()
104 config.browser_cmd = entry.get_text()
106 def on_vertical_layout_clicked(self, *args):
107 print 'vert clicked'
108 config = Config.get_instance()
109 config.pane_layout = 'vertical'
111 def on_horizontal_layout_clicked(self, *args):
112 print 'orintal clicked'
113 config = Config.get_instance()
114 config.pane_layout = 'horizontal'
117 _dialog = None
118 def preferences_show():
119 global _dialog
120 if not _dialog:
121 _dialog = Preferences()
122 _dialog.show()