Skip to content

Commit c216671

Browse files
committed
failed attemp to use css for colors
1 parent 661bb62 commit c216671

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

GPUmodules/GPUgui.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from typing import Tuple, Dict, Union
3333
import sys
3434
import re
35+
import logging
3536
import warnings
3637
try:
3738
import gi
@@ -47,6 +48,8 @@
4748
GTK_Color = Tuple[Union[float, int], ...]
4849
ColorDict = Dict[str, str]
4950

51+
logger = logging.getLogger('gpu-utils')
52+
5053

5154
class GuiProps:
5255
_colors: ColorDict = {'white': '#FFFFFF',
@@ -141,15 +144,42 @@ def set_gtk_prop(gui_item, top: int = None, bottom: int = None, right: int = Non
141144
gui_item.set_alignment(*align)
142145
if bg_color:
143146
# 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):
145148
gtk_color = GuiProps.hex_to_rgba(bg_color)
149+
bg_color_hex = bg_color
146150
else:
147151
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)
149156
if color:
150157
# 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):
152159
gtk_color = GuiProps.hex_to_rgba(color)
160+
color_hex = color
153161
else:
154162
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+

amdgpu-pac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class PACWindow(Gtk.Window):
7575
"""
7676
def __init__(self, gpu_list, devices):
7777
Gtk.Window.__init__(self, title=__program_name__)
78+
#cur_scr = Gdk.Screen.get_default()
79+
#GPUgui.GuiProps.set_style(cur_scr)
7880
self.set_border_width(0)
7981

8082
icon_file = os.path.join(env.GUT_CONST.icon_path, 'amdgpu-pac.icon.png')

0 commit comments

Comments
 (0)