GNOME Bugzilla – Bug 768980
Gtk.StyleContext.get_property doesn't set the red and green components when returning colors
Last modified: 2018-01-10 20:54:58 UTC
The Gdk.RGBA returned Gtk.StyleContext.get_property always has the red and green components set to 0, whilst the blue and alpha components are returned correctly. This always occurs, regardless on the Gtk theme in use. This bit of python demonstrates the problem: #!/usr/bin/env python3 import gi gi.require_version("Gtk", "3.0") from gi.repository import Gtk, Gdk class Testwin(Gtk.Window): def __init__(self): super().__init__(super().__init__(title="Theme color reader")) self.box = Gtk.VBox() self.label = Gtk.Label ("Test window") self.button = Gtk.Button("Button") self.entry = Gtk.Entry() self.mb = Gtk.MenuBar() self.box.add(self.mb) self.box.add(self.label) self.box.add(self.entry) self.box.add(self.button) self.add(self.box) self.set_size_request(300,100) self.connect("realize", self.realized_event) self.connect("delete-event", self.win_delete_event) self.show_all() def win_delete_event(self, widget, event, data=None): Gtk.main_quit() def get_col(self, widget): context = widget.get_style_context() state = context.get_state() print("state is %s" % state) bgcol = context.get_property("background-color", state) print("background color of %s is %s" % (widget.get_name(), bgcol)) bcol = context.get_property("border-color", state) print("border color of %s is %s" % (widget.get_name(), bgcol,)) def realized_event(self, widget): self.get_col(self.mb) self.get_col(self.label) self.get_col(self.entry) self.get_col(self.button) def main(): tw = Testwin() Gtk.main() if __name__ == "__main__": main()
Thanks, I can reproduce with 3.20 context.get_background_color(state) and context.get_border_color(state) works in case you need a workaround.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/119.