NetworkConstants.py + ConfigOptions.py = Constants.py
[straw.git] / straw / preferences.py
blobf44ceeb2afcdf577f61a0b079619ea5dad8ba193
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 from ConfigOptions import *
25 from gtk.glade import XML
26 from os.path import join
27 import Config
28 import MVP
29 import gtk
30 import os
31 import straw.defs
33 class PreferencesView(MVP.GladeView):
34 def _initialize(self):
35 self._window = self._widget.get_widget('preferences')
36 self._browser_override = self._widget.get_widget("prefs_browser_setting")
37 self._browser_entry = self._widget.get_widget("prefs_browser_setting_entry")
39 # General
40 poll_frequency = int(Config.get(OPTION_POLL_FREQUENCY) / 60)
41 items_stored = int(Config.get(OPTION_ITEMS_STORED))
43 browser_cmd = Config.get(OPTION_BROWSER_CMD)
45 if browser_cmd:
46 self._browser_override.set_active(True)
47 self._browser_entry.set_text(browser_cmd)
48 self._browser_entry.set_sensitive(True)
49 else:
50 self._browser_entry.set_text(_("Using desktop setting"))
52 self._widget.get_widget('poll_frequency_spin').set_value(poll_frequency)
53 self._widget.get_widget('number_of_items_spin').set_value(items_stored)
54 #self._widget.get_widget('vertical_layout').set_active(Config.get(OPTION_PANE_LAYOUT) == 'vertical')
56 def _apply_settings(self):
57 a = self._widget.get_widget('number_of_items_spin').get_value_as_int()
58 Config.set(OPTION_ITEMS_STORED, a)
60 def show(self, *args):
61 self._window.present()
63 def hide(self, *args):
64 self._window.hide()
65 self._window.destroy()
67 def _on_ok_button_clicked(self, button):
68 self._apply_settings()
69 self.hide()
71 def _on_cancel_button_clicked(self, button):
72 self.hide()
74 def _on_apply_button_clicked(self, button):
75 self._apply_settings()
77 def on_preferences_delete_event(self, *args):
78 self.hide()
79 return True
81 def on_close_button_clicked(self, button):
82 self.hide()
84 class PreferencesPresenter(MVP.BasicPresenter):
85 pass
87 def show():
88 gladefile = XML(os.path.join(straw.defs.STRAW_DATA_DIR, "preferences.glade"))
89 dialog = PreferencesPresenter(view = PreferencesView(gladefile))
91 dialog.view.show()