Writing User Interfaces in Prolog with XPCE

Hi,

Writing UIs in Prolog is a very simple thing !

First, with SWI-Prolog, there’s a dialog editor based on Drag & Drop, like we have for Java, C# or C++, and it generates a prolog-xpce code that we just have to execute to see the window being shown on our screen.

However, we can manually write code with XPCE predicates.

Just see it in action. Here is a code that shows a 250×100 window with a text label.

?View Code PROLOG
1
2
3
4
5
6
7
8
9
10
11
12
13
:- use_module(library(pce)).
 
my_first_program :-
	% creates the window
	new(D, window('Ma premiere fenetre')),
	% resize the window
	send(D, size, size(250, 100)),
	% creates a textlabel
	new(T, text('Hello World !')),
	% displays the textlabel at the given point
	send(D, display, T, point(80, 40)),
	% show the window
	send(D, open).

Save it as xpce.pl for example.

Then, open a terminal. Launch xpce.

$ xpce
XPCE 6.6.44, October 2007 for i386-linux-gnu and X11R6
Copyright (C) 1993-2007 University of Amsterdam.
XPCE comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
The host-language is SWI-Prolog version 5.6.47

For HELP on prolog, please type help. or apropos(topic).
         on xpce, please type manpce.

?-

Then just use consult :

?View Code PROLOG
1
2
3
4
?- consult('xpce.pl').
% xpce.pl compiled 0.01 sec, 1,280 bytes
 
Yes

and launch your predicate :

?View Code PROLOG
1
?- my_first_program.

You’ll obtain something like the following image.
First program with XPCE in Prolog

Have fun with XPCE !


One Comment

  1. Avgust Says:

    iixkfno@nzdakfu.ru” rel=”nofollow”>1…

    no more…

Leave a Comment