2

I am writing an XPCE-program in which a user can enter a text in a text window which is then processed further by a Prolog program (say, by running a spelling check).

Thus, I would need a text window in which one can enter text freely (including paragraphs, punctuation marks etc.) and then store the text in a Prolog variable for further processing.

This is easy (and works well) using a text_item as follows:

 send(D, append(new(Text,   text_item('Enter Text'))))

However, this only allows to enter a single line, which is unsuitable for longer texts.

The "editor" environment looks well suited to this task; and I can create an editor using

send(D, append(new(Text1,editor),below))

Here, one can enter a text of many lines, including paragraphs etc. But now, how do I access the text entered by the user? It is apparently not stored in the variable Text1. I read about a text_buffer, but I do not know how to link it to the editor.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
M Carl
  • 123
  • 3

1 Answers1

0

adapted from XPCE guide

:- use_module(library(pce)).

multiline_input(Text) :-
        new(D, dialog('Prompting for name')),
        send(D, append, new(TI, editor)),
        send(D, append,
             button(ok, message(D, return,
                                TI?contents))),
        send(D, append,
             button(cancel, message(D, return, @nil))),
        send(D, default_button, ok), % Ok: default button
        get(D, confirm, Answer),     % This blocks!
        send(D, destroy),
        Answer \== @nil,             % canceled
        get(Answer, value, Text).

Just replaced text_item with editor, getting its content, and then getting value out of it.

CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • Thanks, this helps. However, now the text value is handed over once as the value of the variable "Text". Is it also possible to set it up in such a way that one can change the text and, whenever the "OK"-button is pressed, the new version is processed? – M Carl Aug 08 '19 at 15:08
  • Should be enough to get the `contents` from the editor, and then the `value`. Of course, you can do from any event handler where you have the variable bound to the editor instance - here `TI` – CapelliC Aug 08 '19 at 17:07