gitignore generated files for jack_mix_box
[jack_mixer.git] / abspeak.py
blobaf76bf2cfbbcc38fde68bdc2e96ffe92e4a93ade
1 # This file is part of jack_mixer
3 # Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
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; version 2 of the License
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 import gtk
19 import fpconst
20 import pango
21 import gobject
23 class AbspeakWidget(gtk.EventBox):
24 def __init__(self):
25 gtk.EventBox.__init__(self)
26 self.label = gtk.Label()
27 attrs = pango.AttrList()
28 font_attr = pango.AttrFamily("monospace")
29 attrs.insert(font_attr)
30 self.label.set_attributes(attrs)
31 self.add(self.label)
32 self.connect("button-press-event", self.on_mouse)
33 self.peak = fpconst.NegInf
35 def on_mouse(self, widget, event):
36 if event.type == gtk.gdk.BUTTON_PRESS:
37 if event.button == 1:
38 self.emit("reset")
39 elif event.button == 2:
40 adjust = -self.peak
41 if abs(adjust) < 30: # we better don't adjust more than +- 30 dB
42 self.emit("volume-adjust", adjust)
44 def set_peak(self, peak):
45 self.peak = peak
46 if fpconst.isNaN(peak):
47 self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(int(65535 * 0.7), 0, 0))
48 self.label.set_text("NaN")
49 else:
50 text = "%+.1f" % peak
52 if peak > 0:
53 self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(int(65535 * 0.8), int(65535 * 0.3), 0))
54 else:
55 self.modify_bg(gtk.STATE_NORMAL, self.label.style.bg[gtk.STATE_NORMAL])
57 self.label.set_text(text)
59 gobject.signal_new("reset", AbspeakWidget,
60 gobject.SIGNAL_RUN_FIRST | gobject.SIGNAL_ACTION, gobject.TYPE_NONE, [])
61 gobject.signal_new("volume-adjust", AbspeakWidget,
62 gobject.SIGNAL_RUN_FIRST | gobject.SIGNAL_ACTION, gobject.TYPE_NONE, [gobject.TYPE_FLOAT])