Get font color of the current GTK theme
Asked Answered
I

1

4

I need to get the font color of the current theme.

I found this question that explains it how to do it in C with gtk_style_lookup_color, but it seems that the function is deprecated.

Making more researches I found the new function gtk_style_context_lookup_color

But I have problems understanding the docs. Also, when I try to call it by using Gtk.style_context_lookup_color( .. ) I get that it doesn't exists!

Is it because I need to call it with something like GtkStyleContext.style_context_lookup_color(arg1,arg2) ?

Infatuation answered 15/1, 2015 at 11:38 Comment(0)
I
3

I found the answer using gtk.settings.

    settings=Gtk.Settings.get_default()

    colors=settings.get_property("gtk-color-scheme")
    colors=colors.split("\n")

    for color in colors:
        if 'text' in color:
            text_color=color.split(':')[1].strip()
            print text_color
            break

It seems that the "gtk-color-scheme" property stores all the colors of the theme, so if you are searching for any other color you can find it in the same way!

Infatuation answered 16/1, 2015 at 10:24 Comment(2)
Unfortunately, color schemes seem to be deprecated now.Baillieu
It seems you're [developer.gnome.org/gtk3/stable/GtkSettings.html](right). What a shame! As of now, it still seems to work.Kosaka

© 2022 - 2024 — McMap. All rights reserved.