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 from gi
.repository
import Gtk
19 from gi
.repository
import Gdk
20 from gi
.repository
import Pango
21 from gi
.repository
import GObject
26 background-color: #cc4c00;
30 background-color: #b20000;
33 css_provider
= Gtk
.CssProvider()
34 css_provider
.load_from_data(css
)
35 context
= Gtk
.StyleContext()
36 screen
= Gdk
.Screen
.get_default()
37 context
.add_provider_for_screen(screen
, css_provider
, Gtk
.STYLE_PROVIDER_PRIORITY_APPLICATION
)
39 class AbspeakWidget(Gtk
.EventBox
):
41 GObject
.GObject
.__init
__(self
)
42 self
.label
= Gtk
.Label()
43 #attrs = Pango.AttrList()
44 #font_attr = Pango.AttrFamily("monospace")
45 #attrs.insert(font_attr)
46 #self.label.set_attributes(attrs)
48 self
.connect("button-press-event", self
.on_mouse
)
51 def on_mouse(self
, widget
, event
):
52 if event
.type == Gdk
.EventType
.BUTTON_PRESS
:
53 if event
.button
== 1 or event
.button
== 2 or event
.button
== 3:
54 context
= self
.get_style_context()
55 context
.remove_class('over_zero')
56 context
.remove_class('is_nan')
57 if event
.button
== 1 or event
.button
== 3:
59 elif event
.button
== 2:
61 if abs(adjust
) < 30: # we better don't adjust more than +- 30 dB
62 self
.emit("volume-adjust", adjust
)
64 def set_peak(self
, peak
):
67 self
.get_style_context().add_class('is_nan')
68 self
.label
.set_text("NaN")
73 self
.get_style_context().add_class('over_zero')
77 self
.label
.set_text(text
)
79 GObject
.signal_new("reset", AbspeakWidget
,
80 GObject
.SignalFlags
.RUN_FIRST | GObject
.SignalFlags
.ACTION
, None, [])
81 GObject
.signal_new("volume-adjust", AbspeakWidget
,
82 GObject
.SignalFlags
.RUN_FIRST | GObject
.SignalFlags
.ACTION
, None, [GObject
.TYPE_FLOAT
])