1 # Copyright (C) 2006 Ulrik Sverdrup
3 # dragbox -- Commandline drag-and-drop tool for GNOME
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 from gtk
.glade
import XML
22 from globals import glade_directory
25 class preferences_controller(object):
27 Controller to control the preferences window
28 Loads the window, listens to signals and saves/changes preferences
33 glade_file
= path
.normpath(path
.join(glade_directory
, "preferences.glade"))
34 if not path
.exists(glade_file
):
35 from utils
import guess_destdir
36 from utils
import print_debug
37 while glade_file
[0] == "/":
38 glade_file
= glade_file
[1:]
39 glade_file
= path
.join(guess_destdir(), glade_file
)
40 print_debug(glade_file
)
42 self
.ui
= XML(glade_file
)
44 from utils
import print_error
45 print_error("Failed to load UI file for preferences window!")
46 print_error("File: %s" % glade_file
)
49 self
.win
= self
.ui
.get_widget("prefswindow")
50 self
.check_stick
= self
.ui
.get_widget("check_stick")
51 self
.check_open
= self
.ui
.get_widget("check_open")
52 self
.check_remove
= self
.ui
.get_widget("check_remove")
54 # signals from .glade file
56 "on_check_stick_toggled" : self
.cb_stick_toggled
,
57 "on_check_open_toggled" : self
.cb_open_toggled
,
58 "on_close_clicked" : self
.cb_close_clicked
,
59 "on_check_remove_toggled" : self
.cb_remove_toggled
,
60 "on_prefswindow_delete_event" : self
.cb_delete_event
,
63 self
.ui
.signal_autoconnect(signals
)
65 # Set check boxes to prefs values
66 stick
= preferences
.get_bool("stick", if_none
=True)
67 self
.check_stick
.set_active(stick
)
69 open = preferences
.get_bool("open", if_none
=False)
70 self
.check_open
.set_active(open)
72 remove
= preferences
.get_bool("remove", if_none
=False)
73 self
.check_remove
.set_active(remove
)
76 from gtk
import STOCK_DND_MULTIPLE
, ICON_SIZE_DIALOG
77 pixbuf
= self
.win
.render_icon(STOCK_DND_MULTIPLE
, ICON_SIZE_DIALOG
)
78 self
.win
.set_icon(pixbuf
)
80 # hide window -- only show it if asked for
83 def show_window(self
):
85 Shows the preferences window
89 def close_window(self
):
91 Hides the preferences window
95 def cb_delete_event(self
, *args
):
96 # make sure the window is NOT deleted
100 def cb_close_clicked(self
, widget
):
103 def cb_stick_toggled(self
, widget
):
104 val
= widget
.get_active()
105 preferences
.set_bool("stick", val
)
107 def cb_open_toggled(self
, widget
):
108 val
= widget
.get_active()
109 preferences
.set_bool("open", val
)
111 def cb_remove_toggled(self
, widget
):
112 val
= widget
.get_active()
113 preferences
.set_bool("remove", val
)
115 # Shared instance of the preferences controller
116 shared
= preferences_controller()