Hi there! I’m working on an application that should “do things” with several (40+) usb storage devices (sticks) - backup them, format them, etc.
I created an UI (using Blueprint, GTK4 and Adw) where I have a GtkGridView which displays a cell for each (possible) stick. The cell is predefined as template ListItem inside a BuilderListItemFactory and updates a label and an icon according to the label: bind template.item as <$Stick>.name;.
However it seems that I cannot bind a CSS class to an item attribute?
I can add a styles [“red”] entry in my Blueprint file for elements of the ListItem, but when trying a binding like styles: bind template … (Gtk.Label does not have a property called styles) or styles bind template … (Unexpected tokens) I get errors from the Blueprint compiler.
Is there any way to change the background color of the ListItemWidget corresponding to the “stick status” (connected, copying, formatting, ejected, removed) either by binding a CSS class or by accessing the ListItemWidget from code and adding the CSS class per code (it doesn’t seem that I can access the Widget, only the Item and the Factory)?
I tried making a subclass of ListItem before, but the Blueprint compiler errors for the BuilderListItemFactory with “Only Gtk.ListItem is allowed as type here”.
Which language bindings are you using? Make sure the class is registered as a GType, and also that the class you’re using it in knows about that GType.
Python. I’m not really sure what I changed but it seems to work now.
Is there any event I can register that is triggered, when the stick property is bound on the subclass? Currently I’m connecting the “notify::propertyname” signal but I’m not sure if that’s the best solution.
I’m not really sure what I changed but it seems to work now.
In PyGObject, it’s important that the module with the class loads, an import is enough for that. __gtype_name__ also has to be set. But those are just two guesses, I’m glad it works now
Is there any event I can register that is triggered, when the stick property is bound on the subclass?
notify::propertyname is correct, but PyGObject also allows you to define a setter for your properties, which you might prefer: