Help with my first XPCE GUI

Hello Prolog community,

I am struggling with my first XPCE GUI and I was wondering if anyone could help me.
I’m using: SWI-Prolog version 8.4.3.

I want to code an editable matrix, with the first two rows and the first column being help lables and the rest being textboxes that are used like excel-cells.

Here is a quick figure of how it is looking at the moment, and how it is supposed to look like:

My code looks like this:

t1:-new(D,dialog('My first GUI')), 
send(D, append, label(lab_0_0,'Caption')),
send(D, append, label(lab_1_0,'lab_1_0')),
send(D, append, label(lab_1_1,'lab_1_1'), right),

send(D, append, label(lab_1_2,'lab_1_2'), right),
send(D, append, label(lab_1_3,'lab_1_3'), right),
send(D, append, label(lab_1_4,'lab_1_4'), right),
send(D, append, label(lab_1_5,'lab_1_5'), right),
send(D, append, label(lab_2_0,'lab_2_0'), next_row),
send(D, append, label(lab_2_1,'lab_2_1'), right),
send(D, append, label(lab_2_2,'lab_2_2'), right),
send(D, append, label(lab_2_3,'lab_2_3'), right),
send(D, append, label(lab_2_4,'lab_2_4'), right),
send(D, append, label(lab_2_5,'lab_2_5'), right),
send(D, append, label(lab_3_0,'lab_3_0'), below),
send(D, append, text_item('', 'text3_1',
				  message(D?generate_member, execute)),right),
send(D, append, text_item('', 'text3_2',
				  message(D?generate_member, execute)),right),
send(D, append, text_item('', 'text3_3',
				  message(D?generate_member, execute)),right),
send(D, append, text_item('', 'text3_4',
				  message(D?generate_member, execute)),right),
send(D, append, text_item('', 'text3_5',
				  message(D?generate_member, execute)),right),

The behavior I would like to change, in words:

  • The elements placed with the keyword “below” are not inserted in the left-most column 0, but inserted in the right-most column that exists until then. Is it possible to insert “below-left” or “below element xy”?
  • The textboxes each appear with a “:” to their left, even though their string is empty. Is there a way to turn that off?
  • The auto-spacing makes the textboxes really long sometimes, depending on resolution, amount of monitors, etc. This dynamic spacing is good, but is it possible to fix the elements’ size?
  • The selected text box has a red triangle attached, to indicate the cursor. Is there a way to change the style/color of that symbol, to black for instance?

Best regards and many thanks in advance,

Hi Malo !

Unfortunately I cannot answer your question. But I am also VERY interested in making some matrix processing programs with XPCE.
So, I backup your case and make a call to anyone who can answer your question.
Also, If you ever find the solution, please remember me…

@Malo, don’t know why next_row is not working properly. But this code should help you:

:- use_module(library(pce)).

	new(D,dialog('My first GUI')),
	send(D, append, label(lab_cap,'Plain rows')),
	send(D, append, R1, below),
	send(D, append, R2, below),

	send(D, append, label(lab_cap,'Nice rows')),
	send(D, append, NR1, below),
	send(D, append, NR2, below),


row(R,1,Type) :-
	send(R, append, label(lab_1_0,'lab_1_0')),
	send(R, append, label(lab_1_1,'lab_1_1'), right),
	send(R, append, label(lab_1_2,'lab_1_2'), right),
	send(R, append, label(lab_1_3,'lab_1_3'), right),
	send(R, append, label(lab_1_4,'lab_1_4'), right),
	send(R, append, label(lab_1_5,'lab_1_5'), right).

row(R,2,Type) :-
	send(R, append, label(lab_2_0,'lab_2_0')),
	send(R, append, label(lab_2_1,'lab_2_1'), right),
	send(R, append, label(lab_2_2,'lab_2_2'), right),
	send(R, append, label(lab_2_3,'lab_2_3'), right),
	send(R, append, label(lab_2_4,'lab_2_4'), right),
	send(R, append, label(lab_2_5,'lab_2_5'), right).

Also some tips:

  • run ?- manpce at the prompt, it pops up a tool in which you can browse all kinds of properties
    and methods.
    • Most especially use the browsers->class browser to find out methods and properties.
    • you can use the tools->visual hierarchy to browse the currently displayed object hierarchy
    • play with all menu options in the tool
  • Read through Programming in XPCE/Prolog, I had to read through it many times
  • xpce is tricky and perhaps with some bugs, but it is rather powerful combined with prolog.

To get rid of the colon in the label use this:

	new(TI,text_item('', 'text3_2', message(D?generate_member, execute)) ),

If you go through the class browser in the manpce tool, and load all the information for text_item (and click All in the filters) you will notice a show_label method there. That is how you can find out a lot of the information on how to do things.

This paper from Jan was very useful for me too:



I just now saw your reply. I want to thank you very much for your time, the solution you posted looks great! This along with the additional information you provided surely will help me a lot!

Thanks a lot, Sir!
Best regards,