|
32 | 32 | from typing import Tuple, Dict, Union |
33 | 33 | import sys |
34 | 34 | import re |
| 35 | +import logging |
35 | 36 | import warnings |
36 | 37 | try: |
37 | 38 | import gi |
|
47 | 48 | GTK_Color = Tuple[Union[float, int], ...] |
48 | 49 | ColorDict = Dict[str, str] |
49 | 50 |
|
| 51 | +logger = logging.getLogger('gpu-utils') |
| 52 | + |
50 | 53 |
|
51 | 54 | class GuiProps: |
52 | 55 | _colors: ColorDict = {'white': '#FFFFFF', |
@@ -141,15 +144,42 @@ def set_gtk_prop(gui_item, top: int = None, bottom: int = None, right: int = Non |
141 | 144 | gui_item.set_alignment(*align) |
142 | 145 | if bg_color: |
143 | 146 | # FIXME - This is deprecated in latest Gtk, need to use css. |
144 | | - if re.fullmatch(r'^#[0-9a-fA-F]+', bg_color): |
| 147 | + if re.fullmatch(r'^#[0-9a-fA-F]{6}', bg_color): |
145 | 148 | gtk_color = GuiProps.hex_to_rgba(bg_color) |
| 149 | + bg_color_hex = bg_color |
146 | 150 | else: |
147 | 151 | gtk_color = GuiProps.color_name_to_rgba(bg_color) |
148 | | - gui_item.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(*gtk_color)) |
| 152 | + bg_color_hex = GuiProps._colors[bg_color] |
| 153 | + #gui_item.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(*gtk_color)) |
| 154 | + css_label = "label { background-color: %s}" % bg_color_hex |
| 155 | + GuiProps.set_style(css_label, widget=gui_item) |
149 | 156 | if color: |
150 | 157 | # FIXME - This is deprecated in latest Gtk, need to use css. |
151 | | - if re.fullmatch(r'^#[0-9a-fA-F]+', color): |
| 158 | + if re.fullmatch(r'^#[0-9a-fA-F]{6}', color): |
152 | 159 | gtk_color = GuiProps.hex_to_rgba(color) |
| 160 | + color_hex = color |
153 | 161 | else: |
154 | 162 | gtk_color = GuiProps.color_name_to_rgba(color) |
155 | | - gui_item.override_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(*gtk_color)) |
| 163 | + color_hex = GuiProps._colors[color] |
| 164 | + #gui_item.override_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(*gtk_color)) |
| 165 | + css_label = "label { color: %s}" % color_hex |
| 166 | + GuiProps.set_style(css_label, widget=gui_item) |
| 167 | + |
| 168 | + @classmethod |
| 169 | + def set_style(cls, css_str, widget=None): |
| 170 | + #css_entry = "entry { background-color: %s; color: %s; entry::selection {color: %s; background: %s;}}" % ( |
| 171 | + ##cls._colors['green'], cls._colors['black'], cls._colors['black'], cls._colors['yellow']) |
| 172 | + #css_entry = "entry { background: %s; color: %s; }" % (cls._colors['green'], cls._colors['black']) |
| 173 | + #css_label = "label { background-color: %s; color: %s}" % (cls._colors['green'], cls._colors['black']) |
| 174 | + #css_str = css_entry |
| 175 | + screen = Gdk.Screen.get_default() |
| 176 | + logger.info('css %s'% css_str) |
| 177 | + print('css %s', css_str) |
| 178 | + css = css_str.encode('utf-8') |
| 179 | + |
| 180 | + provider = Gtk.CssProvider() |
| 181 | + provider.load_from_data(css) |
| 182 | + #style_context = Gtk.StyleContext() |
| 183 | + style_context = widget.get_style_context() |
| 184 | + style_context.add_provider_for_screen(screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) |
| 185 | + |
0 commit comments