3 # This file is part of jack_mixer
5 # Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26 print "Cannot load Python bindings for GConf, your preferences will not be preserved across jack_mixer invocations"
29 def lookup_scale(scales
, scale_id
):
31 if scale_id
== scale
.scale_id
:
35 class factory(gobject
.GObject
):
36 def __init__(self
, glade_xml
, topwindow
, meter_scales
, slider_scales
):
37 gobject
.GObject
.__init
__(self
)
38 self
.glade_xml
= glade_xml
39 self
.topwindow
= topwindow
40 self
.meter_scales
= meter_scales
41 self
.slider_scales
= slider_scales
44 self
.gconf_client
= gconf
.client_get_default()
46 scale_id
= self
.gconf_client
.get_string("/apps/jack_mixer/default_meter_scale")
47 self
.default_meter_scale
= lookup_scale(meter_scales
, scale_id
)
48 if not self
.default_meter_scale
:
49 self
.default_meter_scale
= meter_scales
[0]
51 scale_id
= self
.gconf_client
.get_string("/apps/jack_mixer/default_slider_scale")
52 self
.default_slider_scale
= lookup_scale(slider_scales
, scale_id
)
53 if not self
.default_slider_scale
:
54 self
.default_slider_scale
= slider_scales
[0]
56 self
.gconf_client
.add_dir("/apps/jack_mixer", gconf
.CLIENT_PRELOAD_NONE
)
57 self
.gconf_client
.notify_add("/apps/jack_mixer/default_meter_scale", self
.on_gconf_default_meter_scale_changed
)
58 self
.gconf_client
.notify_add("/apps/jack_mixer/default_slider_scale", self
.on_gconf_default_slider_scale_changed
)
60 self
.default_meter_scale
= meter_scales
[0]
61 self
.default_slider_scale
= slider_scales
[0]
63 def on_gconf_default_meter_scale_changed(self
, client
, connection_id
, entry
, args
):
64 #print "GConf default_meter_scale changed"
65 scale_id
= entry
.get_value().get_string()
66 scale
= lookup_scale(self
.meter_scales
, scale_id
)
68 self
.default_meter_scale
= scale
69 self
.emit("default-meter-scale-changed", self
.default_meter_scale
)
71 print "Ignoring GConf default_meter_scale setting, because \"%s\" scale is not known" % scale_id
73 def on_gconf_default_slider_scale_changed(self
, client
, connection_id
, entry
, args
):
74 #print "GConf default_slider_scale changed"
75 scale_id
= entry
.get_value().get_string()
76 scale
= lookup_scale(self
.slider_scales
, scale_id
)
78 self
.default_slider_scale
= scale
79 self
.emit("default-slider-scale-changed", self
.default_slider_scale
)
81 print "Ignoring GConf default_slider_scale setting, because \"%s\" scale is not known" % scale_id
83 def run_dialog_add_channel(self
):
84 dialog
= self
.glade_xml
.get_widget("dialog_add_channel")
85 name_entry
= self
.glade_xml
.get_widget("new_channel_name")
86 name_entry
.set_text("")
87 dialog
.set_transient_for(self
.topwindow
)
92 if ret
== gtk
.RESPONSE_OK
:
94 'name': name_entry
.get_text(),
95 'stereo': self
.glade_xml
.get_widget("new_channel_stereo").get_active()
101 def run_dialog_rename_channel(self
, name
):
102 dialog
= self
.glade_xml
.get_widget("dialog_rename_channel")
103 name_entry
= self
.glade_xml
.get_widget("channel_name")
104 name_entry
.set_text(name
)
105 dialog
.set_transient_for(self
.topwindow
)
109 if ret
== gtk
.RESPONSE_OK
:
110 return name_entry
.get_text()
114 def run_dialog_choose_meter_scale(self
):
115 dialog
= self
.glade_xml
.get_widget("dialog_choose_scale")
116 dialog
.set_title("Choose meter scale")
117 dialog
.set_transient_for(self
.topwindow
)
119 available_scales
= self
.glade_xml
.get_widget("available_scales")
120 store
= gtk
.ListStore(gobject
.TYPE_STRING
, gobject
.TYPE_STRING
, gobject
.TYPE_PYOBJECT
)
121 renderer
= gtk
.CellRendererText()
123 column_scale
= gtk
.TreeViewColumn("Scale", renderer
, text
=0)
124 column_description
= gtk
.TreeViewColumn("Description", renderer
, text
=1)
126 available_scales
.append_column(column_scale
)
127 available_scales
.append_column(column_description
)
129 selection
= available_scales
.get_selection()
131 for scale
in self
.meter_scales
:
132 #print "%s: %s" % (scale.scale_id, scale.description)
134 row
= scale
.scale_id
, scale
.description
, scale
135 current_iter
= store
.append(row
)
136 if scale
is self
.default_meter_scale
:
137 selected_iter
= current_iter
138 #print "Selected scale is %s" % scale.scale_id
140 available_scales
.set_model(store
)
141 selection
.select_iter(selected_iter
)
147 if ret
== gtk
.RESPONSE_OK
or ret
== gtk
.RESPONSE_APPLY
:
148 scale
= store
.get(selection
.get_selected()[1], 2)[0]
150 # we are setting gconf, and then notified for change
151 self
.gconf_client
.set_string("/apps/jack_mixer/default_meter_scale", scale
.scale_id
)
153 self
.default_meter_scale
= scale
154 self
.emit("default-meter-scale-changed", self
.default_meter_scale
)
156 if ret
== gtk
.RESPONSE_OK
or ret
== gtk
.RESPONSE_CANCEL
or ret
== gtk
.RESPONSE_DELETE_EVENT
:
161 def run_dialog_choose_slider_scale(self
):
162 dialog
= self
.glade_xml
.get_widget("dialog_choose_scale")
163 dialog
.set_title("Choose slider scale")
164 dialog
.set_transient_for(self
.topwindow
)
166 available_scales
= self
.glade_xml
.get_widget("available_scales")
167 store
= gtk
.ListStore(gobject
.TYPE_STRING
, gobject
.TYPE_STRING
, gobject
.TYPE_PYOBJECT
)
168 renderer
= gtk
.CellRendererText()
170 column_scale
= gtk
.TreeViewColumn("Scale", renderer
, text
=0)
171 column_description
= gtk
.TreeViewColumn("Description", renderer
, text
=1)
173 available_scales
.append_column(column_scale
)
174 available_scales
.append_column(column_description
)
176 selection
= available_scales
.get_selection()
178 for scale
in self
.slider_scales
:
179 #print "%s: %s" % (scale.scale_id, scale.description)
181 row
= scale
.scale_id
, scale
.description
, scale
182 current_iter
= store
.append(row
)
183 if scale
is self
.default_slider_scale
:
184 selected_iter
= current_iter
185 #print "Selected scale is %s" % scale.scale_id
187 available_scales
.set_model(store
)
188 selection
.select_iter(selected_iter
)
194 if ret
== gtk
.RESPONSE_OK
or ret
== gtk
.RESPONSE_APPLY
:
195 scale
= store
.get(selection
.get_selected()[1], 2)[0]
197 # we are setting gconf, and then notified for change
198 self
.gconf_client
.set_string("/apps/jack_mixer/default_slider_scale", scale
.scale_id
)
200 self
.default_slider_scale
= scale
201 self
.emit("default-slider-scale-changed", self
.default_slider_scale
)
203 if ret
== gtk
.RESPONSE_OK
or ret
== gtk
.RESPONSE_CANCEL
or ret
== gtk
.RESPONSE_DELETE_EVENT
:
208 def get_default_meter_scale(self
):
209 return self
.default_meter_scale
211 def get_default_slider_scale(self
):
212 return self
.default_slider_scale
214 gobject
.signal_new("default-meter-scale-changed", factory
, gobject
.SIGNAL_RUN_FIRST | gobject
.SIGNAL_ACTION
, gobject
.TYPE_NONE
, [gobject
.TYPE_PYOBJECT
])
215 gobject
.signal_new("default-slider-scale-changed", factory
, gobject
.SIGNAL_RUN_FIRST | gobject
.SIGNAL_ACTION
, gobject
.TYPE_NONE
, [gobject
.TYPE_PYOBJECT
])