GNOME Bugzilla – Bug 764774
Styling for custom widget based on Gtk.RadioButton doesn't work
Last modified: 2017-10-09 11:41:08 UTC
I have a custom widget based on Gtk.RadioButton and I'm trying to style it using CSS but it doesn't work with Gtk 3.20. Simple reproducer in Python -- https://gist.github.com/vojtechtrefny/bea68aa567828bec5968c2e7738021c9 Same code with Gtk.ToggleButton instead of Gtk.RadioButton works fine.
If you opne the inspector, you'll find that your code doesn't succeed in setting the css name. I don't know the python bindings well enough to say how you have to call gtk_widget_class_set_css_name() to make this work.
Hi, the same code with Gtk.Label/Button/ToggleButton works as expected so I think it probably is the right way to set the css name in Python. I was able to reproduce it also in Vala -- https://gist.github.com/vojtechtrefny/a0e8bb64980cc10d992fe7ec39d19dd9 -- and again same code inheriting from Gtk.ToggleButton instead of Gtk.RadioButton works as expected.
Created attachment 358715 [details] screenshot for clarity: Your call to set_css_name() is ignored; either way, the node gets named __main__+MyButton I think the problem is that by the time you're in the instance init method, it's too late: your widget has already gotten its default name from the class, in the GtkWidget init method, and so it shall remain evermore. You're trying to override the property too late. I can't see any indication that the Python GI supports custom class init code yet... but maybe I've just missed it.
That said... hmm. I would've been able to write off the fact that it works with ToggleButton as a sporadic result of undefined behaviour - if not for the Vala example, which clearly has proper class constructor support and looks like it should work.
(In reply to Daniel Boles from comment #4) > I would've been able to write off the fact that it works with ToggleButton > as a sporadic result of undefined behaviour This might still be true. If I just take your test case and change the parent class to ToggleButton or Button, they also get the same default, unwanted name and therefore no theming.
The problem appears to be that Python doesn't really support executing custom code during class init; I guess yours is running later and therefore has no useful effect. *** This bug has been marked as a duplicate of bug 701843 ***