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 from gi
.repository
import Gtk
20 from gi
.repository
import Gdk
21 from gi
.repository
import GObject
23 class PreferencesDialog(Gtk
.Dialog
):
24 def __init__(self
, parent
):
26 GObject
.GObject
.__init
__(self
)
29 self
.connect('response', self
.on_response_cb
)
30 self
.connect('delete-event', self
.on_response_cb
)
32 def create_frame(self
, label
, child
):
35 frame
.set_border_width(3)
36 frame
.set_shadow_type(Gtk
.ShadowType
.NONE
)
37 frame
.get_label_widget().set_markup('<b>%s</b>' % label
)
39 alignment
= Gtk
.Alignment
.new(0, 0, 12, 0)
49 interface_vbox
= Gtk
.VBox()
50 self
.custom_widgets_checkbutton
= Gtk
.CheckButton('Use custom widgets')
51 self
.custom_widgets_checkbutton
.set_active(
52 self
.app
.gui_factory
.get_use_custom_widgets())
53 self
.custom_widgets_checkbutton
.connect('toggled',
54 self
.on_custom_widget_toggled
)
55 interface_vbox
.pack_start(self
.custom_widgets_checkbutton
, True, True, 0)
57 self
.vumeter_color_checkbutton
= Gtk
.CheckButton('Use custom vumeter color')
58 self
.vumeter_color_checkbutton
.set_active(
59 self
.app
.gui_factory
.get_vumeter_color_scheme() == 'solid')
60 self
.vumeter_color_checkbutton
.connect('toggled',
61 self
.on_vumeter_color_change
)
62 interface_vbox
.pack_start(self
.vumeter_color_checkbutton
, True, True, 0)
64 interface_vbox
.pack_start(hbox
, True, True, 0)
65 self
.custom_color_box
= hbox
66 self
.custom_color_box
.set_sensitive(
67 self
.vumeter_color_checkbutton
.get_active() == True)
68 hbox
.pack_start(Gtk
.Label('Custom color:'), True, True, 0)
69 self
.vumeter_color_picker
= Gtk
.ColorButton()
70 self
.vumeter_color_picker
.set_color(Gdk
.color_parse(
71 self
.app
.gui_factory
.get_vumeter_color()))
72 self
.vumeter_color_picker
.connect('color-set',
73 self
.on_vumeter_color_change
)
74 hbox
.pack_start(self
.vumeter_color_picker
, True, True, 0)
76 vbox
.pack_start(self
.create_frame('Interface', interface_vbox
), True, True, 0)
78 table
= Gtk
.Table(2, 2, False)
79 table
.set_row_spacings(5)
80 table
.set_col_spacings(5)
82 table
.attach(Gtk
.Label(label
='Meter scale'), 0, 1, 0, 1)
83 self
.meter_scale_combo
= self
.create_meter_store_and_combo()
84 table
.attach(self
.meter_scale_combo
, 1, 2, 0, 1)
86 table
.attach(Gtk
.Label(label
='Slider scale'), 0, 1, 1, 2)
87 self
.slider_scale_combo
= self
.create_slider_store_and_combo()
88 table
.attach(self
.slider_scale_combo
, 1, 2, 1, 2)
90 vbox
.pack_start(self
.create_frame('Scales', table
), True, True, 0)
92 table
= Gtk
.Table(1, 2, False)
93 table
.set_row_spacings(5)
94 table
.set_col_spacings(5)
96 table
.attach(Gtk
.Label(label
='Control Behavior'), 0, 1, 0, 1)
97 self
.midi_behavior_combo
= self
.create_midi_behavior_combo()
98 table
.attach(self
.midi_behavior_combo
, 1, 2, 0, 1)
100 vbox
.pack_start(self
.create_frame('MIDI', table
), True, True, 0)
103 self
.add_button(Gtk
.STOCK_CLOSE
, Gtk
.ResponseType
.CLOSE
)
105 def create_meter_store_and_combo(self
):
106 store
= Gtk
.ListStore(GObject
.TYPE_STRING
, GObject
.TYPE_PYOBJECT
)
107 for scale
in self
.app
.meter_scales
:
108 row
= scale
.scale_id
, scale
109 current_iter
= store
.append(row
)
110 if scale
is self
.app
.gui_factory
.get_default_meter_scale():
111 active_iter
= current_iter
112 self
.meter_store
= store
114 meter_scale_combo
= Gtk
.ComboBox
.new_with_model(store
)
115 cell
= Gtk
.CellRendererText()
116 meter_scale_combo
.pack_start(cell
, True)
117 meter_scale_combo
.add_attribute(cell
, 'text', 0)
118 meter_scale_combo
.set_active_iter(active_iter
)
119 meter_scale_combo
.connect('changed',
120 self
.on_meter_scale_combo_changed
)
122 return meter_scale_combo
124 def create_slider_store_and_combo(self
):
125 store
= Gtk
.ListStore(GObject
.TYPE_STRING
, GObject
.TYPE_PYOBJECT
)
126 for scale
in self
.app
.slider_scales
:
127 row
= scale
.scale_id
, scale
128 current_iter
= store
.append(row
)
129 if scale
is self
.app
.gui_factory
.get_default_slider_scale():
130 active_iter
= current_iter
131 self
.slider_store
= store
133 slider_scale_combo
= Gtk
.ComboBox
.new_with_model(store
)
134 cell
= Gtk
.CellRendererText()
135 slider_scale_combo
.pack_start(cell
, True)
136 slider_scale_combo
.add_attribute(cell
, 'text', 0)
137 slider_scale_combo
.set_active_iter(active_iter
)
138 slider_scale_combo
.connect('changed',
139 self
.on_slider_scale_combo_changed
)
141 return slider_scale_combo
143 def create_midi_behavior_combo(self
):
144 combo
= Gtk
.ComboBoxText()
145 for i
, mode
in enumerate(self
.app
.gui_factory
.midi_behavior_modes
):
146 combo
.append(str(i
), mode
)
147 combo
.set_active(self
.app
.gui_factory
.get_midi_behavior_mode())
148 combo
.connect('changed', self
.on_midi_behavior_combo_changed
)
151 def on_response_cb(self
, dlg
, response_id
, *args
):
152 self
.app
.preferences_dialog
= None
155 def on_meter_scale_combo_changed(self
, *args
):
156 active_iter
= self
.meter_scale_combo
.get_active_iter()
157 scale
= self
.meter_store
.get(active_iter
, 1)[0]
158 self
.app
.gui_factory
.set_default_meter_scale(scale
)
160 def on_slider_scale_combo_changed(self
, *args
):
161 active_iter
= self
.slider_scale_combo
.get_active_iter()
162 scale
= self
.slider_store
.get(active_iter
, 1)[0]
163 self
.app
.gui_factory
.set_default_slider_scale(scale
)
165 def on_midi_behavior_combo_changed(self
, *args
):
166 active
= self
.midi_behavior_combo
.get_active()
167 self
.app
.gui_factory
.set_midi_behavior_mode(active
)
169 def on_vumeter_color_change(self
, *args
):
170 color_scheme
= 'default'
171 if self
.vumeter_color_checkbutton
.get_active():
172 color_scheme
= 'solid'
173 self
.app
.gui_factory
.set_vumeter_color_scheme(color_scheme
)
175 color
= self
.vumeter_color_picker
.get_color().to_string()
176 self
.app
.gui_factory
.set_vumeter_color(color
)
178 self
.custom_color_box
.set_sensitive(
179 self
.vumeter_color_checkbutton
.get_active() == True)
181 def on_custom_widget_toggled(self
, *args
):
182 self
.app
.gui_factory
.set_use_custom_widgets(
183 self
.custom_widgets_checkbutton
.get_active())