From joao.mariz@mail.ineti.pt Mon May 21 18:44:17 2001
Received: from mail.ineti.pt (ettn.ineti.pt [193.136.150.130])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f4LGiF324803;
	Mon, 21 May 2001 18:44:16 +0200 (MET DST)
Received: from mail.ineti.pt (pc_4.ineti.pt [193.136.150.120]) by mail.ineti.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13)
	id LL9316BB; Mon, 21 May 2001 17:41:18 +0100
Message-ID: <3B0947EB.86B8D151@mail.ineti.pt>
Date: Mon, 21 May 2001 17:52:59 +0100
From: =?iso-8859-1?Q?Jo=E3o?= Mariz <joao.mariz@mail.ineti.pt>
X-Mailer: Mozilla 4.72 [en] (Win98; I)
X-Accept-Language: en
MIME-Version: 1.0
To: Jan Wielemaker <jan@swi.psy.uva.nl>,
   Swi-PROLOG usergroup <prolog@swi.psy.uva.nl>
Subject: Re: [SWIPL] Newbie question for XPCE
References: <200105190930.f4J9U0d28216@gollem.swi.psy.uva.nl>
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Hello Jan and SwiProlog users,

Now I am trying to build city/2 predicate (above); the difference is
that I am
trying to pass two attribute values, one from the choosen city, and the
other
from the button selected (Rules or Search); to other predicates.
I could assert something in meu_prolog/2 predicate (which I would
retract later
on), however I am more interested on passing those values through
attribute
values to the city/2 predicate.

thanks in advance for any help you can provide,

João

city(City, X):-
    new(C, dialog('My Expert System' ) ) ,
    send(C, append, new(Gr1, dialog_group('Choose a City'))),
    send(Gr1, append, new(LB, list_browser)),
    add_cities(LB),
    send(C, append, new(Bts, dialog_group('Options')), right),
    send(Bts, append,
               button('Rules' ,
                      and(message(@prolog, meu_prolog, LB?selection?key,
'Rules'),
                          message(C, destroy) ) ) ) ,
    send(Bts, append,
               button('Search' ,
                       and(message(@prolog, meu_prolog,
LB?selection?key,
'Search'),
                           message(C, destroy) ) ) ,  below ),
    send(Bts, append, button('Cancel', message(C, destroy)), below ) ,
/* How to get City and X values??? */
send(C, open)  .

meu_prolog(City, 'Rules'):-
     nl,nl, write('The City is ' ), write(City), nl,nl,
     write('My Expert System / Good Pratice Rules'), nl, nl, !.

meu_prolog( City, 'Search'):-
     nl,nl, write('The city is ' ), write(City), nl,nl,
     write('My Expert System / Search of Minimal Solution'), nl, nl, !.


add_cities(LB):-
  send_list(LB , append,
   ['Abrantes',
    'Açores',
    'Águeda',
    'Aguiar da Beira',
    'Alandroal', 'Coimbra', 'Lisboa', 'Porto', 'Faro'] ).



Jan Wielemaker wrote:

> > Hello SwiProlog users;
> >
> > I have done some work with SWI PROLOG. Now I am trying to do something
> > with XPCE so that my application becames more pretty.
> > I have developped a simple predicate [called city/0] that selectes text
> > from a list. I write it above:
> >
> > city:-
> >        new(C, dialog('Select a City')),
> >        send(C, append, new(LB, list_browser)),
> >        send(LB, width,  28),
> >             add_cities(LB),
> >        send(C, append,
> >                    new(Bts, dialog_group('Options')), below),
> >        send(Bts, append, button(quit, message(C, destroy))),
> >        send(Bts, append, button(ok, message(@prolog, listar,
> > LB?selection?key, C), right )),
> >        send(C, open) .
> >
> > listar(L, C):-
> >        get(L, name, Text_item),
> >        nl,  nl,  write('The city is '), write(Text_item), nl, nl,
> >        send(C, destroy) .
> >
> > add_cities(LB):-
> >         send(LB, append, new(Ti1, text_item('Abrantes', 'Abrantes'))),
> >         send(LB, append, new(Ti2, text_item('Coimbra', 'Coimbra'))),
> >         send(LB, append, new(Ti3, text_item('Lisboa', 'Lisboa'))),
> >         send(LB, append, new(X1, text_item('Golegã', 'golega'))),
> >         send(LB, append, new(X2, text_item('Salva Terra de Magos',
> > 'salva terra de magos'))),
> >         send(LB, append, new(Xl3, text_item('Chamusca',  'chamusca'))),
> >         send(LB, append, new(X4, text_item('Santarém',  'santarem'))),
> >         send(LB, append, new(S1, text_item('Porto', 'porto'))),
> >         send(LB, append, new(B2, text_item('Faro', 'faro'))),
> >         send(LB, append, new(N3, text_item('Évora',  'evora'))),
> >         send(LB, append, new(C4, text_item('Beja',  'beja'))), ! .
> >
> > However, after querying with city/0 predicate, when I select both, the
> > text from the list_browser and the ok button, I do not get a "yes"
> > answer on my XPCE ?- prompt. Perhaps I did not finnish city/0 predicate.
>
> City/0 simply returns after opening the window.  If you hit the ok button,
> it will print the selection and remove the window in a `call-back'.  The
> Prolog toplevel isn't aware of the call-back and doesn't repeat the prompt
> (this has been improved in 4.0.6 on Unix when using the readline library).
> If you hit return it will show the continuation prompt `|'.
>
> > If I have a city/0 predicate inside another predicate I get the answer
> > "no" at the XPCE '- prompt and I still have my XPCE window open.
> > How can I have a Yes answer? or pursuit with the city/0 predicate until
> > it finnishes?
>
> What you want is a blocking dialog.  There is a section on modal dialogs
> in the User Guide.  For short:
>
> city(City):-
>        new(C, dialog('Select a City')),
>        send(C, append, new(LB, list_browser)),
>        send(LB, width,  28),
>             add_cities(LB),
>        send(C, append,
>                    new(Bts, dialog_group('Options')), below),
>        send(Bts, append, button(quit, message(C, destroy))),
>        send(Bts, append, button(ok, message(C, return,
>                                 LB?selection?key), right )),
>        get(C, confirm, Answer),
>        send(C, destroy),
>         get(Answer, name, City).
>
> Next, a list_browser contains dict_items that are normally created from
> atoms.  So your add_cities can look like:
>
> add_cities(LB) :-
>         send_list(LB, append,
>                   [ 'Abrantes',
>                     'Coimbra',
>                     ....
>                   ]).
>
> And you won't need the get(Answer, name, City) anymore.  A text_item is
> a controller that allows the user to enter a value.  Due to type-conversion
> and automatic generation of printable labels, your code works, but doesn't
> really reflect the purpose.
>
>         Cheers --- Jan
>
>         --- Jan
>
>

