Update channel edit/remove menu order when channels are re-ordered
[jack_mixer.git] / styling.py
blob88f3cb3199218ecc71a5e243f48eff9f192cc0ee
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.monitor:hover,
77 button.mute:hover,
78 button.solo:hover,
79 button.monitor:checked,
80 button.mute:checked,
81 button.solo:checked {
82 color: white;
83 text-shadow: unset;
84 background-image: none;
86 button.monitor:hover {
87 background-color: @monitor_bgcolor_hover;
89 button.monitor:checked {
90 background-color: @monitor_bgcolor_checked;
92 button.mute:hover {
93 background-color: @mute_bgcolor_hover;
95 button.mute:checked {
96 background-color: @mute_bgcolor_checked;
98 button.solo:hover {
99 background-color: @solo_bgcolor_hover;
101 button.solo:checked {
102 background-color: @solo_bgcolor_checked;
106 /* Control groups */
108 .control_group {
109 min-width: 0px;
110 padding: 0px;
113 .control_group .label,
114 .control_group .mute,
115 .control_group .prefader,
116 .control_group .solo {
117 font-size: smaller;
118 padding: 0px .1em;
121 .control_group .mute:hover,
122 .control_group .solo:hover,
123 .control_group .prefader:hover,
124 .control_group .mute:checked,
125 .control_group .solo:checked,
126 .control_group .prefader:checked {
127 color: white;
128 text-shadow: unset;
129 background-image: none;
131 .control_group .mute:hover {
132 background-color: @mute_bgcolor_hover;
134 .control_group .mute:checked {
135 background-color:@mute_bgcolor_checked;
137 .control_group .solo:hover {
138 background-color: @solo_bgcolor_hover;
140 .control_group .solo:checked {
141 background-color: @solo_bgcolor_checked;
143 .control_group .prefader:hover {
144 background-color: @prefader_bgcolor_hover;
146 .control_group .prefader:checked {
147 background-color: @prefader_bgcolor_checked;
151 /* Peak meters */
153 .over_zero {
154 background-color: #cc4c00;
157 .is_nan {
158 background-color: #b20000;
162 COLOR_TMPL_CSS = """\
163 .{} {{
164 background-color: {};
165 color: {};
170 def add_css_provider(css, priority=Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION):
171 css_provider = Gtk.CssProvider()
172 css_provider.load_from_data(css.encode("utf-8"))
173 context = Gtk.StyleContext()
174 screen = Gdk.Screen.get_default()
175 context.add_provider_for_screen(screen, css_provider, priority)
178 def get_text_color(background_color):
179 """Calculate the luminance of the given color (GdkRGBA)
180 and return an appropriate text color."""
181 # luminance coefficients taken from section C-9 from
182 # http://www.faqs.org/faqs/graphics/colorspace-faq/
183 brightess = (
184 background_color.red * 0.212671
185 + background_color.green * 0.715160
186 + background_color.blue * 0.072169
189 if brightess > 0.5:
190 return "black"
191 else:
192 return "white"
195 def load_css_styles():
196 add_css_provider(DEFAULT_CSS)
199 def set_background_color(widget, name, color):
200 color_string = color.to_string()
201 add_css_provider(COLOR_TMPL_CSS.format(name, color_string, get_text_color(color)))
202 widget_context = widget.get_style_context()
203 widget_context.add_class(name)
206 def random_color():
207 return Gdk.RGBA(random(), random(), random(), 1)