After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 768980 - Gtk.StyleContext.get_property doesn't set the red and green components when returning colors
Gtk.StyleContext.get_property doesn't set the red and green components when r...
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: general
3.20.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2016-07-20 06:31 UTC by Robin Thompson
Modified: 2018-01-10 20:54 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Robin Thompson 2016-07-20 06:31:54 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()
Comment 1 Christoph Reiter (lazka) 2016-08-22 19:03:42 UTC
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.
Comment 2 GNOME Infrastructure Team 2018-01-10 20:54:58 UTC
-- 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.