AUTHORS: adjust maintainer back to myself; update email address
[jack_mixer.git] / jack_mixer / styling.py
blob40cbc9ca1bf20a57a5c1c3580308bf4228a6ed5e
1 # This file is part of jack_mixer
3 # Copyright (C) 2006-2009 Nedko Arnaudov <nedko@arnaudov.name>
4 # Copyright (C) 2009-2020 Frederic Peters <fpeters@0d.be> et al.
5 # Copyright (C) 2020-2021 Christopher Arndt <info@chrisarndt>
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.
20 from random import random
22 import gi # noqa: F401
23 from gi.repository import Gtk
24 from gi.repository import Gdk
27 # CSS widget styling
28 DEFAULT_CSS = """\
29 /* Global color definitions */
31 @define-color monitor_bgcolor_hover #C0BFBC;
32 @define-color monitor_bgcolor_checked #9A9996;
33 @define-color mute_bgcolor_hover #FFBC80;
34 @define-color mute_bgcolor_checked #FF7800;
35 @define-color solo_bgcolor_hover #76A28E;
36 @define-color solo_bgcolor_checked #26A269;
37 @define-color prefader_bgcolor_hover #A6C2E4;
38 @define-color prefader_bgcolor_checked #3584E4;
41 /* Channel strips */
43 .top_label {
44 padding: 0px .1em;
45 min-height: 1.5rem;
48 .wide {
49 font-size: medium;
52 .narrow {
53 font-size: smaller;
56 .vbox_fader {
57 border: 1px inset #111;
60 .readout {
61 font-size: 80%;
62 margin: .1em;
63 padding: 0;
64 border: 1px inset #111;
65 color: white;
66 background-color: #333;
67 background-image: none;
71 /* Channel buttons */
73 button {
74 padding: 0px .2em;
76 button.prefader_meter {
77 font-size: smaller;
79 button.monitor:hover,
80 button.mute:hover,
81 button.solo:hover,
82 button.prefader:hover,
83 button.prefader_meter:hover,
84 button.monitor:checked,
85 button.mute:checked,
86 button.solo:checked,
87 button.prefader:checked,
88 button.prefader_meter:checked {
89 color: white;
90 text-shadow: unset;
91 background-image: none;
93 button.monitor:hover {
94 background-color: @monitor_bgcolor_hover;
96 button.monitor:checked {
97 background-color: @monitor_bgcolor_checked;
99 button.mute:hover {
100 background-color: @mute_bgcolor_hover;
102 button.mute:checked {
103 background-color: @mute_bgcolor_checked;
105 button.solo:hover {
106 background-color: @solo_bgcolor_hover;
108 button.solo:checked {
109 background-color: @solo_bgcolor_checked;
111 button.prefader:hover {
112 background-color: @prefader_bgcolor_hover;
114 button.prefader:checked {
115 background-color: @prefader_bgcolor_checked;
117 button.prefader_meter:hover {
118 background-color: @prefader_bgcolor_hover;
120 button.prefader_meter:checked {
121 background-color: @prefader_bgcolor_checked;
125 /* Control groups */
127 .control_group {
128 min-width: 0px;
129 padding: 0px;
132 .control_group .label,
133 .control_group .mute,
134 .control_group .prefader,
135 .control_group .solo {
136 font-size: smaller;
137 padding: 0px .1em;
140 .control_group .mute:hover,
141 .control_group .solo:hover,
142 .control_group .prefader:hover,
143 .control_group .mute:checked,
144 .control_group .solo:checked,
145 .control_group .prefader:checked {
146 color: white;
147 text-shadow: unset;
148 background-image: none;
150 .control_group .mute:hover {
151 background-color: @mute_bgcolor_hover;
153 .control_group .mute:checked {
154 background-color:@mute_bgcolor_checked;
156 .control_group .solo:hover {
157 background-color: @solo_bgcolor_hover;
159 .control_group .solo:checked {
160 background-color: @solo_bgcolor_checked;
162 .control_group .prefader:hover {
163 background-color: @prefader_bgcolor_hover;
165 .control_group .prefader:checked {
166 background-color: @prefader_bgcolor_checked;
170 /* Peak meters */
172 .over_zero {
173 background-color: #cc4c00;
176 .is_nan {
177 background-color: #b20000;
181 COLOR_TMPL_CSS = """\
182 .{} {{
183 background-color: {};
184 color: {};
189 def add_css_provider(css, priority=Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION):
190 css_provider = Gtk.CssProvider()
191 css_provider.load_from_data(css.encode("utf-8"))
192 context = Gtk.StyleContext()
193 screen = Gdk.Screen.get_default()
194 context.add_provider_for_screen(screen, css_provider, priority)
197 def get_text_color(background_color):
198 """Calculate the luminance of the given color (GdkRGBA)
199 and return an appropriate text color."""
200 # luminance coefficients taken from section C-9 from
201 # http://www.faqs.org/faqs/graphics/colorspace-faq/
202 brightess = (
203 background_color.red * 0.212671
204 + background_color.green * 0.715160
205 + background_color.blue * 0.072169
208 if brightess > 0.5:
209 return "black"
210 else:
211 return "white"
214 def load_css_styles():
215 add_css_provider(DEFAULT_CSS)
218 def set_background_color(widget, name, color):
219 color_string = color.to_string()
220 add_css_provider(COLOR_TMPL_CSS.format(name, color_string, get_text_color(color)))
221 widget_context = widget.get_style_context()
222 widget_context.add_class(name)
225 def random_color():
226 return Gdk.RGBA(random(), random(), random(), 1)