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 os
.path
import expanduser
, isdir
21 from gi
.repository
import Gtk
22 from gi
.repository
import Gdk
23 from gi
.repository
import GObject
26 class PreferencesDialog(Gtk
.Dialog
):
27 def __init__(self
, parent
):
29 GObject
.GObject
.__init
__(self
)
30 self
.set_title("Preferences")
32 self
.connect("response", self
.on_response_cb
)
33 self
.connect("delete-event", self
.on_response_cb
)
35 def create_frame(self
, label
, child
):
38 frame
.set_border_width(3)
39 frame
.set_shadow_type(Gtk
.ShadowType
.NONE
)
40 frame
.get_label_widget().set_markup("<b>%s</b>" % label
)
42 child
.set_margin_top(10)
43 child
.set_margin_bottom(10)
49 vbox
= self
.get_content_area()
51 path_vbox
= Gtk
.Box(orientation
=Gtk
.Orientation
.VERTICAL
)
52 self
.path_entry
= Gtk
.Entry()
53 self
.path_entry
.connect("changed", self
.on_path_entry_changed
)
54 path_vbox
.pack_start(self
.path_entry
, False, False, 3)
55 self
.project_path_chooser
= Gtk
.FileChooserButton(
56 title
="Default Project Path",
57 action
=Gtk
.FileChooserAction
.SELECT_FOLDER
59 project_path
= self
.app
.gui_factory
.default_project_path
60 path_vbox
.pack_start(self
.project_path_chooser
, False, False, 3)
63 self
.path_entry
.set_text(project_path
)
65 if isdir(expanduser(project_path
)):
66 self
.project_path_chooser
.set_current_folder(expanduser(project_path
))
68 self
.project_path_chooser
.connect("file-set", self
.on_project_path_selected
)
69 vbox
.pack_start(self
.create_frame("Default Project Path", path_vbox
), True, True, 0)
71 interface_vbox
= Gtk
.Box(orientation
=Gtk
.Orientation
.VERTICAL
)
72 self
.confirm_quit_checkbutton
= Gtk
.CheckButton("Confirm quit")
73 self
.confirm_quit_checkbutton
.set_tooltip_text(
74 "Always ask for confirmation before " "quitting the application"
76 self
.confirm_quit_checkbutton
.set_active(self
.app
.gui_factory
.get_confirm_quit())
77 self
.confirm_quit_checkbutton
.connect("toggled", self
.on_confirm_quit_toggled
)
78 interface_vbox
.pack_start(self
.confirm_quit_checkbutton
, True, True, 3)
80 self
.custom_widgets_checkbutton
= Gtk
.CheckButton("Use custom widgets")
81 self
.custom_widgets_checkbutton
.set_active(self
.app
.gui_factory
.get_use_custom_widgets())
82 self
.custom_widgets_checkbutton
.connect("toggled", self
.on_custom_widget_toggled
)
83 interface_vbox
.pack_start(self
.custom_widgets_checkbutton
, True, True, 3)
85 self
.vumeter_color_checkbutton
= Gtk
.CheckButton("Use custom vumeter color")
86 self
.vumeter_color_checkbutton
.set_active(
87 self
.app
.gui_factory
.get_vumeter_color_scheme() == "solid"
89 self
.vumeter_color_checkbutton
.connect("toggled", self
.on_vumeter_color_change
)
90 interface_vbox
.pack_start(self
.vumeter_color_checkbutton
, True, True, 3)
92 self
.custom_color_box
= hbox
= Gtk
.Box(orientation
=Gtk
.Orientation
.HORIZONTAL
)
93 interface_vbox
.pack_start(hbox
, True, True, 3)
95 hbox
.set_sensitive(self
.vumeter_color_checkbutton
.get_active())
96 hbox
.pack_start(Gtk
.Label("Custom color:"), False, True, 5)
97 self
.vumeter_color_picker
= Gtk
.ColorButton()
98 self
.vumeter_color_picker
.set_color(
99 Gdk
.color_parse(self
.app
.gui_factory
.get_vumeter_color())
101 self
.vumeter_color_picker
.connect("color-set", self
.on_vumeter_color_change
)
102 hbox
.pack_start(self
.vumeter_color_picker
, True, True, 0)
104 vbox
.pack_start(self
.create_frame("Interface", interface_vbox
), True, True, 0)
106 table
= Gtk
.Table(2, 2, False)
107 table
.set_row_spacings(5)
108 table
.set_col_spacings(5)
110 table
.attach(Gtk
.Label(label
="Meter scale"), 0, 1, 0, 1)
111 self
.meter_scale_combo
= self
.create_meter_store_and_combo()
112 table
.attach(self
.meter_scale_combo
, 1, 2, 0, 1)
114 table
.attach(Gtk
.Label(label
="Slider scale"), 0, 1, 1, 2)
115 self
.slider_scale_combo
= self
.create_slider_store_and_combo()
116 table
.attach(self
.slider_scale_combo
, 1, 2, 1, 2)
118 vbox
.pack_start(self
.create_frame("Scales", table
), True, True, 0)
120 table
= Gtk
.Table(1, 2, False)
121 table
.set_row_spacings(5)
122 table
.set_col_spacings(5)
124 table
.attach(Gtk
.Label(label
="Control Behavior"), 0, 1, 0, 1)
125 self
.midi_behavior_combo
= self
.create_midi_behavior_combo()
126 table
.attach(self
.midi_behavior_combo
, 1, 2, 0, 1)
128 vbox
.pack_start(self
.create_frame("MIDI", table
), True, True, 0)
131 self
.add_button(Gtk
.STOCK_CLOSE
, Gtk
.ResponseType
.CLOSE
)
133 def create_meter_store_and_combo(self
):
134 store
= Gtk
.ListStore(GObject
.TYPE_STRING
, GObject
.TYPE_PYOBJECT
)
135 for scale
in self
.app
.meter_scales
:
136 row
= scale
.scale_id
, scale
137 current_iter
= store
.append(row
)
138 if scale
is self
.app
.gui_factory
.get_default_meter_scale():
139 active_iter
= current_iter
140 self
.meter_store
= store
142 meter_scale_combo
= Gtk
.ComboBox
.new_with_model(store
)
143 cell
= Gtk
.CellRendererText()
144 meter_scale_combo
.pack_start(cell
, True)
145 meter_scale_combo
.add_attribute(cell
, "text", 0)
146 meter_scale_combo
.set_active_iter(active_iter
)
147 meter_scale_combo
.connect("changed", self
.on_meter_scale_combo_changed
)
149 return meter_scale_combo
151 def create_slider_store_and_combo(self
):
152 store
= Gtk
.ListStore(GObject
.TYPE_STRING
, GObject
.TYPE_PYOBJECT
)
153 for scale
in self
.app
.slider_scales
:
154 row
= scale
.scale_id
, scale
155 current_iter
= store
.append(row
)
156 if scale
is self
.app
.gui_factory
.get_default_slider_scale():
157 active_iter
= current_iter
158 self
.slider_store
= store
160 slider_scale_combo
= Gtk
.ComboBox
.new_with_model(store
)
161 cell
= Gtk
.CellRendererText()
162 slider_scale_combo
.pack_start(cell
, True)
163 slider_scale_combo
.add_attribute(cell
, "text", 0)
164 slider_scale_combo
.set_active_iter(active_iter
)
165 slider_scale_combo
.connect("changed", self
.on_slider_scale_combo_changed
)
167 return slider_scale_combo
169 def create_midi_behavior_combo(self
):
170 combo
= Gtk
.ComboBoxText()
171 for i
, mode
in enumerate(self
.app
.gui_factory
.midi_behavior_modes
):
172 combo
.append(str(i
), mode
)
173 combo
.set_active(self
.app
.gui_factory
.get_midi_behavior_mode())
174 combo
.connect("changed", self
.on_midi_behavior_combo_changed
)
177 def on_response_cb(self
, dlg
, response_id
, *args
):
178 self
.app
.preferences_dialog
= None
181 def on_path_entry_changed(self
, *args
):
182 path
= self
.path_entry
.get_text().strip()
185 fullpath
= expanduser(path
)
188 self
.project_path_chooser
.set_current_folder(fullpath
)
189 self
.app
.gui_factory
.set_default_project_path(path
)
191 def on_project_path_selected(self
, *args
):
192 path
= self
.project_path_chooser
.get_current_folder()
193 self
.path_entry
.set_text(path
)
194 self
.app
.gui_factory
.set_default_project_path(path
)
196 def on_meter_scale_combo_changed(self
, *args
):
197 active_iter
= self
.meter_scale_combo
.get_active_iter()
198 scale
= self
.meter_store
.get(active_iter
, 1)[0]
199 self
.app
.gui_factory
.set_default_meter_scale(scale
)
201 def on_slider_scale_combo_changed(self
, *args
):
202 active_iter
= self
.slider_scale_combo
.get_active_iter()
203 scale
= self
.slider_store
.get(active_iter
, 1)[0]
204 self
.app
.gui_factory
.set_default_slider_scale(scale
)
206 def on_midi_behavior_combo_changed(self
, *args
):
207 active
= self
.midi_behavior_combo
.get_active()
208 self
.app
.gui_factory
.set_midi_behavior_mode(active
)
210 def on_vumeter_color_change(self
, *args
):
211 color_scheme
= "default"
212 if self
.vumeter_color_checkbutton
.get_active():
213 color_scheme
= "solid"
214 self
.app
.gui_factory
.set_vumeter_color_scheme(color_scheme
)
216 color
= self
.vumeter_color_picker
.get_color().to_string()
217 self
.app
.gui_factory
.set_vumeter_color(color
)
219 self
.custom_color_box
.set_sensitive(self
.vumeter_color_checkbutton
.get_active())
221 def on_confirm_quit_toggled(self
, *args
):
222 self
.app
.gui_factory
.set_confirm_quit(self
.confirm_quit_checkbutton
.get_active())
224 def on_custom_widget_toggled(self
, *args
):
225 self
.app
.gui_factory
.set_use_custom_widgets(self
.custom_widgets_checkbutton
.get_active())