How to notify prolog when an XPCE window/frame is closed

hello !

i am new to XPCE and could not find the answer to the following problem in docs.
i can create an xpce window and draw things on it, attach mouse event handlers, etc.
however, i would like XPCE to send a message to @prolog when the window is closed either when i send free to it or the user closes it “by hand”.
i suspect it would be along the lines of:
send(@mywindow, recogniser, on_free(message(@prolog, window_closed))).
but of course, “on_free” is not known by XPCE.
in general how can i “capture” XPCE events and notify prolog about it ?
besides the “on_free” event, it would be nice to know when the position/size of the window changes as a result of the user moving the window around on the screen.

(using SWI-Prolog version 7.4.2)

thanks for your help,

xpce is a bit old school, so I don’t know how wise it is to invest a lot of time on it. On the other hand, it is likely to stay part of SWI-Prolog for a long time because most of its tools are written in it.

You can trap the user hitting the close window button using frame->done_message. If you generally want to depend on something being destroyed you must subclass the class your are interested in and redefine the ->unlink method (do not forget to call the method of the super class).

Another option is to create an instance of a subclass of class hyper and redefine its ->unlink_to or ->unlink_from methods to get a trap either side of the hyper is being destroyed.

As said, xpce is old. Most of its terminology is currently no longer practiced and may look awkward now :frowning: But then, you run SWI-Prolog 7.4 while we are at 9.1 :slight_smile:

thanks jan for your timely answer.

i have tried it and works well :
send(WndID, done_message, message(@prolog, on_window_close, WndID)),

i will experiment a bit with sublcassing as well.

what would you suggest instead of XPCE for a graphical interface ?

(still using swi 7.4 because i have a few deployed apps i have to maintain and i’m not always at liberty to install/upgrade software on the client’s machines. on some older machines i have swi 5.4 :slight_smile: )

best regards,

Hello attoparsec. Python has a rather popular library, an interface to tk utilities named tkinter, which has many options for building different kinds of GUIs (I know it because for a short time I played with it). If Prolog can now communicate in a rather direct fashion with Python via Janus, maybe you could find a way to use that library. But I am not an expert and I don’t know if that’s possible in the first place or, being possible, whether it is efficient enough to make sense. :wave:

You cannot have failed to notice that, despite being old fashioned, XPCE seems to attract newcomers in a rather clear and maybe unpredictable way…I’m not saying anything, just stating the facts :slight_smile:

I know :slight_smile: XPCE is not bad and its integration with Prolog is nice. But, it has a lot of problems. It can not deal with threads, its memory management is not sound, it cannot deal with arbitrary scaling (i.e., units are pixels), its terminology is dated and its widget set is dated. On anything but Windows we use X11, which is poorly supported on the Mac and it seems its (long) days of glory are almost over.

That would all be fixable, but it requires substantial effort. If someone wants to pick this up (most issues are rather unrelated), please step forward. Most urgent to make it future proof is probably to find a new low-level binding to support Windows, MacOS and POSIX graphics that provides a scalable abstraction.

I briefly looked into the status of GUIs for Python. So far I’m not really impressed. It all looks pretty low level :frowning: I hope that is just because I failed to find the right tools.