Adw.ComboRow - not sure how to create it the way I want it

I’m struggling with a ComboRow. I want it to display three options; two Labels and a Gtk.SpinButton with an adjacent Label. Ideally, if the user chooses the SpinButton I’d like it to only display the Label (the SpinButton in the ComboRow isn’t functional and ugly) but first I need to get the ComboRow to behave better!

It would be easier to show the problem with screenshots but I can’t seem take one when the ComboRow is showing it’s options (could that be Gnome bug?)

I’ve tried lots of ways of doing this and all work but not without problems. Below is the closest I’ve got.

The two Labels and SpinButton (spin_box) are available as an option, a value can be set on the SpinButton and when the SpinButton is chosen it shows as I’d expect in the ComboRow. But if the ComboRow options are presented again the SpinButton isn’t visible as an option. You can still choose it (the Box, I guess) and the chosen value from earlier is still set but no SpinButton.

class BackupObject(GObject.Object):
    __gtype_name__ = 'BackupObject'

    def __init__(self, string=None, spinbutton=None):
        GObject.Object.__init__(self)
        self._string = string
        self._spinbutton = spinbutton

    @GObject.Property(type=str)
    def string(self):
        return self._string

    @GObject.Property(type=object)
    def spinbutton(self):
        return self._spinbutton

def backup_factory_setup(factory, list_item):
    box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6) 
    spin_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)         
    label = Gtk.Label()
    spin_label = Gtk.Label(label=" days")
    box.append(label)
    box.append(spin_box)
    box.append(spin_label)
    list_item.set_child(box)

def backup_factory_bind(factory, list_item):
    box = list_item.get_child()            
    label = box.get_first_child()
    spin_box = label.get_next_sibling()
    spin_label = spin_box.get_next_sibling()
    option = list_item.get_item()

    if option.string:
        label.set_text(option.string)
        label.set_visible(True)
        spin_box.set_visible(False)
        spin_label.set_visible(False)
    else:
        if option.spinbutton.get_parent():
            option.spinbutton.get_parent().remove(option.spinbutton)
        spin_box.append(option.spinbutton)
        spin_box.set_visible(True)
        spin_label.set_visible(True)
        label.set_visible(False)

self.backup_factory.connect("setup", backup_factory_setup)
self.backup_factory.connect("bind", backup_factory_bind) 

self.backup_liststore.append(BackupObject(string="Forever"))
self.backup_liststore.append(BackupObject(string="Never"))
self.backup_liststore.append(BackupObject(spinbutton=Gtk.SpinButton.new_with_range(0, 999, 1)))

If … is commented out the SpinButton remains displayed an an option but doesn’t show on the ComboRow as selected.

if option.spinbutton.get_parent():
    option.spinbutton.get_parent().remove(option.spinbutton)

I also get the error…

Gtk-CRITICAL **: 15:15:50.344: gtk_box_append: assertion 'gtk_widget_get_parent (child) == NULL' failed

Thank you for any help!

No, it works just fine. Are you on X11? Menus blocking global shortcuts are a well known X11 limitation.

I want it to display three options; two Labels and a Gtk.SpinButton with an adjacent Label

That’s unsupported, don’t even try.

But if the ComboRow options are presented again the SpinButton isn’t visible as an option

Because reparenting widgets is tricky and this isn’t how you do it. I’m not even sure if it’s possible from Python tbh.

This is not gonna work, sorry. Combo row is absolutely not the right tool here, and if you really want a spinbutton in a popover, just use a menu instead.

OK, thank you.

No wonder I was struggling!

Yes, I’m using X11. Last time I tried Wayland I couldn’t even see my browser shortcuts. I should give it another go sometime.

Usual workaround is to delay taking the screenshot, then perform the action (e.g. take screenshot after 3 seconds, and open the menu during those 3 seconds).

It is, except we don’t have delay in the shell screenshot tool