Scraping colors from widgets




Hi,

What's the correct procedure for scraping colors from
widgets? So far I've been relatively successful with:

1) building the widget
2) adding the widget to a toplevel window
3) getting the widget style context
4) getting the colors from such style context

(without (2) I was getting wrong results)

For example (in Python):

widget = Gtk.TextView()
window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
window.add(widget)
stylecontext = widget.get_style_context()
bg = stylecontext.get_background_color(Gtk.StateFlags.NORMAL)

However, this is not working for the High Contrast themes.
If I execute this code in one of those, I get (0.0, 0.0, 0.0, 0.0)
as the background color.

Since the alpha is 0.0, at first I thought this was because those
themes somehow set the GtkTextView bg color as "whatever
is the window color", which makes sense. However, if I replace
GtkTextView by a GtkEntry, the code correctly
returns (1.0, 1.0, 1.0, 1.0) for HighContrast and
(0.0, 0.0, 0.2, 1.0) for HighContrastInverse. I peeked at the
HighContrast css and found no explicitly setting for GtkEntry.

So why is the code working for GtkEntry and not for GtkTextView?

Thanks in advance!




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]