]> git.0d.be Git - jack_mixer.git/blob - abspeak.py
Merge branch 'master' into mergebranch
[jack_mixer.git] / abspeak.py
1 # This file is part of jack_mixer
2 #
3 # Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
4 #
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
8 #
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.
13 #
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.
17
18 from gi.repository import Gtk
19 from gi.repository import Gdk
20 from gi.repository import Pango
21 from gi.repository import GObject
22 import math
23
24 class AbspeakWidget(Gtk.EventBox):
25     def __init__(self):
26         GObject.GObject.__init__(self)
27         self.label = Gtk.Label()
28         #attrs = Pango.AttrList()
29         #font_attr =  Pango.AttrFamily("monospace")
30         #attrs.insert(font_attr)
31         #self.label.set_attributes(attrs)
32         self.add(self.label)
33         self.connect("button-press-event", self.on_mouse)
34         self.peak = -math.inf
35
36     def on_mouse(self, widget, event):
37         if event.type == Gdk.EventType.BUTTON_PRESS:
38             if event.button == 1:
39                 self.emit("reset")
40             elif event.button == 2:
41                 adjust = -self.peak
42                 if abs(adjust) < 30:    # we better don't adjust more than +- 30 dB
43                     self.emit("volume-adjust", adjust)
44
45     def set_peak(self, peak):
46         self.peak = peak
47         if math.isnan(peak):
48             self.modify_bg(Gtk.StateType.NORMAL, Gdk.Color(int(65535 * 0.7), 0, 0))
49             self.label.set_text("NaN")
50         else:
51             text = "%+.1f" % peak
52
53             if peak > 0:
54                 self.modify_bg(Gtk.StateType.NORMAL, Gdk.Color(int(65535 * 0.8), int(65535 * 0.3), 0))
55             else:
56                 pass
57                 #self.modify_bg(Gtk.StateType.NORMAL, self.label.style.bg[Gtk.StateType.NORMAL])
58
59             self.label.set_text(text)
60
61 GObject.signal_new("reset", AbspeakWidget,
62                    GObject.SignalFlags.RUN_FIRST | GObject.SignalFlags.ACTION, None, [])
63 GObject.signal_new("volume-adjust", AbspeakWidget,
64                    GObject.SignalFlags.RUN_FIRST | GObject.SignalFlags.ACTION, None, [GObject.TYPE_FLOAT])