Reputation: 14379
I'm looking for a way, on a PyGObject application, to be notified when there is a theme change.
I need this notification because I'm plotting a graph using matplotlib
and I'm setting as text color for the Graph the standard label color of the current GTK3 theme:
temp_label = Gtk.Label()
scrolled_window.add(temp_label)
text_color = rgba_to_hex(temp_label.get_style_context().get_color(Gtk.StateType.NORMAL))
But, when the user switches theme, I need to fetch the new label color and redraw the graph.
Currently, going from a dark to a light theme, makes the labels unreadable:
Upvotes: 3
Views: 788
Reputation: 14379
The closest thing I found is to connect to gtk-theme-name
:
Gtk.Settings.get_default().connect("notify::gtk-theme-name", self._on_theme_name_changed)
@staticmethod
def _on_theme_name_changed(settings, gparam):
print("Theme name:", settings.get_property("gtk-theme-name"))
Upvotes: 5