]> git.0d.be Git - jack_mixer.git/blob - abspeak.py
Renamed bootstrap to autogen.sh to match what is being done in other projects
[jack_mixer.git] / abspeak.py
1 #!/usr/bin/env python
2 #
3 # This file is part of jack_mixer
4 #
5 # Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
6 #  
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
10 #
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.
15 #
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.
19
20 import gtk
21 import fpconst
22 import pango
23 import gobject
24
25 class widget(gtk.EventBox):
26     def __init__(self):
27         gtk.EventBox.__init__(self)
28         self.label = gtk.Label()
29         attrs = pango.AttrList()
30         font_attr =  pango.AttrFamily("monospace")
31         attrs.insert(font_attr)
32         self.label.set_attributes(attrs)
33         self.add(self.label)
34         self.connect("button-press-event", self.on_mouse)
35         self.peak = fpconst.NegInf
36
37     def on_mouse(self, widget, event):
38         if event.type == gtk.gdk.BUTTON_PRESS:
39             if event.button == 1:
40                 self.emit("reset")
41             elif event.button == 2:
42                 adjust = -self.peak
43                 if abs(adjust) < 30:    # we better don't adjust more than +- 30 dB
44                     self.emit("volume-adjust", adjust)
45
46     def set_peak(self, peak):
47         self.peak = peak
48         if fpconst.isNaN(peak):
49             self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(int(65535 * 0.7), 0, 0))
50             self.label.set_text("NaN")
51         else:
52             text = "%+.1f" % peak
53
54             if peak > 0:
55                 self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(int(65535 * 0.8), int(65535 * 0.3), 0))
56             else:
57                 self.modify_bg(gtk.STATE_NORMAL, self.label.style.bg[gtk.STATE_NORMAL])
58
59             self.label.set_text(text)
60
61 gobject.signal_new("reset", widget, gobject.SIGNAL_RUN_FIRST | gobject.SIGNAL_ACTION, gobject.TYPE_NONE, [])
62 gobject.signal_new("volume-adjust", widget, gobject.SIGNAL_RUN_FIRST | gobject.SIGNAL_ACTION, gobject.TYPE_NONE, [gobject.TYPE_FLOAT])