Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get color scheme from GTK

I am developing a desktop app using Python 3 and GTK3.

I need a button to change its background color when hover, which can be done with this:

self.uploadbutton.modify_bg(Gtk.StateType.PRELIGHT, self.color)

Until now, I defined a RGB color that matches my own theme, but as I have to release this code, I would like to change that color to one of the established theme colors.

Searching the web, I found there's a way to do it with GTK2, but since version 3.8 of GTK, the gtk-color-scheme property has been deprecated.

Is there any other way to respect the user theme colors without using this property?

like image 752
CarlosMorente Avatar asked Jun 01 '18 13:06

CarlosMorente


1 Answers

For now I have found two ways. Both of them are not the answer to your question, because as far as I understand in GTK3 every single element can have it's own styling (including color).

The first one is official and says not to mess with themes unless you have tested them and know how exactly your modifications would look. I think it's the best solution since it's not clear at compile-time whether your self.color will make it look ok or totally unreadable.


The second solution is to obtain full CSS and parse it yourself.

    gset = Gtk.Settings.get_default ()
    themename = gset.get_property ("gtk-theme-name")
    prefdark = gset.get_property ("gtk-application-prefer-dark-theme") # it's a boolean
    cprov = Gtk.CssProvider.get_named (themename)
    print (cprov.to_string())

Parsing the theme is outside of this question.

like image 123
Alexander Dmitriev Avatar answered Oct 01 '22 12:10

Alexander Dmitriev