Gtk.StyleContext.get_property doesn't set the red and green components when returning colors
Submitted by Robin Thompson
Link to original bug (#768980)
Description
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()