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 764774 - Styling for custom widget based on Gtk.RadioButton doesn't work
Styling for custom widget based on Gtk.RadioButton doesn't work
Status: RESOLVED DUPLICATE of bug 701843
Product: gtk+
Classification: Platform
Component: Widget: Other
3.20.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-04-08 11:51 UTC by Vojtech Trefny
Modified: 2017-10-09 11:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
screenshot (15.59 KB, image/png)
2017-08-29 18:44 UTC, Daniel Boles
Details

Description Vojtech Trefny 2016-04-08 11:51:20 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.
Comment 1 Matthias Clasen 2016-04-09 22:19:33 UTC
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.
Comment 2 Vojtech Trefny 2016-04-11 12:27:06 UTC
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.
Comment 3 Daniel Boles 2017-08-29 18:44:48 UTC
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.
Comment 4 Daniel Boles 2017-08-29 18:51:44 UTC
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.
Comment 5 Daniel Boles 2017-08-29 18:54:59 UTC
(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.
Comment 6 Daniel Boles 2017-10-09 11:41:08 UTC
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 ***