XPCE, how to get value from multiple_selection?

Hello everyone, I have a problem, if you can help me, I will be very glad.

I’m using: SWI-Prolog version 9.0.4

I need to implement a multi-selection, but I can’t extract the values of this selection.
I managed to implement a single choice, it looks like this:

send(W,append,new(S,menu('Your choice:'))),
send_list(S,append, [Answ_list]),
get(S?selection, selection, Answer),

As for the multi-selection:

:- use_module(library(pce)).

create_multi_select :-
    new(Dialog, dialog('Multi-Selection Example')),
    new(Multiselect, menu),
    send_list(Multiselect, append, ['Option 1', 'Option 2', 'Option 3', 'Option 4']),
    send(Multiselect, multiple_selection, @on),
    send(Dialog, append, Multiselect),
    send(Dialog, append, button('Submit', message(@prolog, show_selected, Multiselect))),
    send(Dialog, open).

show_selected(Multiselect) :-

But all I get is @xxxxxxxxxxxx
How can I read the “contents” of the selected responses?

I guess the @xxx is a chain (xpce list). Use chain_list/2 to convert it to a Prolog list.

1 Like

Thanks, it really works for this example and I can get the selected values in the form of [Option 1, Option3].

But when it comes to my expert system, I use get(S,selection,Selection) to get a list of selected answer options in the form of @xxx, using chain_list(Selections,X) I get: [@xxx, @xxx, @xxx].
In order to extract the value of the selected answer, I tried nth0(0,X,First), chain(First,Contents), but it doesn’t work. Can you help me with this, please?

If you use print/1 rather than write/1 it should print something like @xxx/string, meaning @xxx is an instance of class string. Now use ?- manpce(string). to get docs. Its long ago, but I think get(@xxxx, name, Name) should get a Prolog atom that reflects the string.

There is some old documentation. I forgot where, but Google may find it. Basically xpce should be considered a sleeping library though. It may be revived, but more likely it will eventually die.

I was able to extract the value of a variable from a multi-selection by extracting each item from the list and then get(S,value,Answer).

It’s sad about the fate of the xpce library. But I was able to make a window interface for my expert system, and with your help it became even better.
Thanks for your answers!