build: run configure automatically after autogen
[jack_mixer.git] / preferences.py
blob088d66570c7b60d7fd70d7d1850d2eba332e87e9
1 # This file is part of jack_mixer
3 # Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
4 # Copyright (C) 2009 Frederic Peters <fpeters@0d.be>
6 # This program 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; version 2 of the License
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 USA.
19 import gtk
20 import gobject
22 try:
23 import gconf
24 except ImportError:
25 gconf = None
27 def lookup_scale(scales, scale_id):
28 for scale in scales:
29 if scale_id == scale.scale_id:
30 return scale
31 return None
33 class PreferencesDialog(gtk.Dialog):
34 def __init__(self, parent):
35 self.app = parent
36 gtk.Dialog.__init__(self, '', self.app.window)
37 self.create_ui()
38 self.connect('response', self.on_response_cb)
39 self.connect('delete-event', self.on_response_cb)
41 def create_frame(self, label, child):
42 frame = gtk.Frame('')
43 frame.set_border_width(3)
44 frame.set_shadow_type(gtk.SHADOW_NONE)
45 frame.get_label_widget().set_markup('<b>%s</b>' % label)
47 alignment = gtk.Alignment()
48 alignment.set_padding(0, 0, 12, 0)
49 frame.add(alignment)
50 alignment.add(child)
52 return frame
54 def create_ui(self):
55 vbox = gtk.VBox()
56 self.vbox.add(vbox)
58 interface_vbox = gtk.VBox()
59 self.custom_widgets_checkbutton = gtk.CheckButton('Use custom widgets')
60 self.custom_widgets_checkbutton.set_active(
61 self.app.gui_factory.get_use_custom_widgets())
62 self.custom_widgets_checkbutton.connect('toggled',
63 self.on_custom_widget_toggled)
64 interface_vbox.pack_start(self.custom_widgets_checkbutton)
66 self.vumeter_color_checkbutton = gtk.CheckButton('Use custom vumeter color')
67 self.vumeter_color_checkbutton.set_active(
68 self.app.gui_factory.get_vumeter_color_scheme() == 'solid')
69 self.vumeter_color_checkbutton.connect('toggled',
70 self.on_vumeter_color_change)
71 interface_vbox.pack_start(self.vumeter_color_checkbutton)
72 hbox = gtk.HBox()
73 interface_vbox.pack_start(hbox)
74 self.custom_color_box = hbox
75 self.custom_color_box.set_sensitive(
76 self.vumeter_color_checkbutton.get_active() == True)
77 hbox.pack_start(gtk.Label('Custom color:'))
78 self.vumeter_color_picker = gtk.ColorButton()
79 self.vumeter_color_picker.set_color(gtk.gdk.color_parse(
80 self.app.gui_factory.get_vumeter_color()))
81 self.vumeter_color_picker.connect('color-set',
82 self.on_vumeter_color_change)
83 hbox.pack_start(self.vumeter_color_picker)
85 self.minimize_to_tray_checkbutton = gtk.CheckButton('Minimize to system tray')
86 self.minimize_to_tray_checkbutton.set_active(
87 self.app.gui_factory.get_minimize_to_tray() )
88 self.minimize_to_tray_checkbutton.connect('toggled', self.on_minimize_to_tray_toggled)
89 interface_vbox.pack_start(self.minimize_to_tray_checkbutton)
91 vbox.pack_start(self.create_frame('Interface', interface_vbox))
93 table = gtk.Table(2, 2, False)
94 table.set_row_spacings(5)
95 table.set_col_spacings(5)
97 table.attach(gtk.Label('Meter scale'), 0, 1, 0, 1)
98 self.meter_scale_combo = self.create_meter_store_and_combo()
99 table.attach(self.meter_scale_combo, 1, 2, 0, 1)
101 table.attach(gtk.Label('Slider scale'), 0, 1, 1, 2)
102 self.slider_scale_combo = self.create_slider_store_and_combo()
103 table.attach(self.slider_scale_combo, 1, 2, 1, 2)
105 vbox.pack_start(self.create_frame('Scales', table))
107 self.vbox.show_all()
109 self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
111 def create_meter_store_and_combo(self):
112 store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
113 for scale in self.app.meter_scales:
114 row = scale.scale_id, scale
115 current_iter = store.append(row)
116 if scale is self.app.gui_factory.get_default_meter_scale():
117 active_iter = current_iter
118 self.meter_store = store
120 meter_scale_combo = gtk.ComboBox(store)
121 cell = gtk.CellRendererText()
122 meter_scale_combo.pack_start(cell, True)
123 meter_scale_combo.add_attribute(cell, 'text', 0)
124 meter_scale_combo.set_active_iter(active_iter)
125 meter_scale_combo.connect('changed',
126 self.on_meter_scale_combo_changed)
128 return meter_scale_combo
130 def create_slider_store_and_combo(self):
131 store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
132 for scale in self.app.slider_scales:
133 row = scale.scale_id, scale
134 current_iter = store.append(row)
135 if scale is self.app.gui_factory.get_default_slider_scale():
136 active_iter = current_iter
137 self.slider_store = store
139 slider_scale_combo = gtk.ComboBox(store)
140 cell = gtk.CellRendererText()
141 slider_scale_combo.pack_start(cell, True)
142 slider_scale_combo.add_attribute(cell, 'text', 0)
143 slider_scale_combo.set_active_iter(active_iter)
144 slider_scale_combo.connect('changed',
145 self.on_slider_scale_combo_changed)
147 return slider_scale_combo
149 def on_response_cb(self, dlg, response_id, *args):
150 self.app.preferences_dialog = None
151 self.destroy()
153 def on_meter_scale_combo_changed(self, *args):
154 active_iter = self.meter_scale_combo.get_active_iter()
155 scale = self.meter_store.get(active_iter, 1)[0]
156 self.app.gui_factory.set_default_meter_scale(scale)
158 def on_slider_scale_combo_changed(self, *args):
159 active_iter = self.slider_scale_combo.get_active_iter()
160 scale = self.slider_store.get(active_iter, 1)[0]
161 self.app.gui_factory.set_default_slider_scale(scale)
163 def on_vumeter_color_change(self, *args):
164 color_scheme = 'default'
165 if self.vumeter_color_checkbutton.get_active():
166 color_scheme = 'solid'
167 self.app.gui_factory.set_vumeter_color_scheme(color_scheme)
169 color = self.vumeter_color_picker.get_color().to_string()
170 self.app.gui_factory.set_vumeter_color(color)
172 self.custom_color_box.set_sensitive(
173 self.vumeter_color_checkbutton.get_active() == True)
175 def on_custom_widget_toggled(self, *args):
176 self.app.gui_factory.set_use_custom_widgets(
177 self.custom_widgets_checkbutton.get_active())
179 def on_minimize_to_tray_toggled(self, *args):
180 self.app.gui_factory.set_minimize_to_tray(
181 self.minimize_to_tray_checkbutton.get_active())