Gtk4.jl get selected values from GtkMultiSelection

Does anyone know how to get the user-selected values from a GtkMultiSelection in Gtk4.jl? I am trying the example code found here and shown below. I can’t seem to find any documentation on how to do it.

using Gtk4

model = GtkStringList(string.(names(Gtk4)))
selmodel = GtkSelectionModel(GtkMultiSelection(GListModel(model)))

function setup_cb(f, list_item)  # here `f` is the item factory
    set_child(list_item, GtkLabel(""))
end

function bind_cb(f, list_item)
    text = list_item[].string
    label = get_child(list_item)
    label.label = text
end

factory = GtkSignalListItemFactory(setup_cb, bind_cb)
list = GtkListView(selmodel, factory)

win = GtkWindow("Listview demo", 250, 800)
sw = GtkScrolledWindow()
win[] = sw
sw[] = list

I was able to figure out that the GtkSelectionModel emits a “selection-changed” signal so I can detect when a change is made, but I don’t know how to extract the selected values. I’m trying to do something like this (which is not working):

function ss(w, x, y)
    for child in selmodel.is_selected
        println("$child")
    end
end
signal_connect(ss, selmodel, "selection-changed")

I just registered a new version of Gtk4.jl that supports getting the selection from GtkMultiSelection. This relies on GtkBitset, which previously wasn’t wrapped. There is a new example “listview_multi.jl”. Eventually I will try to come up with a unified interface for getting the selection from GtkSingleSelection and GtkMultiSelection.

3 Likes

Thank you!