[plt-scheme] Embarrasingly basic GUI question

From: Eli Barzilay (eli at barzilay.org)
Date: Tue Aug 11 00:39:10 EDT 2009

On Aug 11, Andrew Reilly wrote:
> But I can't find a "main-loop" function or method that I'd assumed
> would be there.  My "GUI" function gets to the (send frame show #t)
> and just falls off the end.  The gui stays there, on the screen, but
> my data model and communications protocol have cleaned themselves up
> and gone home, so when I touch one of the GUI widgets, and the
> callback tries to write to the control port, the port is closed.

Looks like what you're missing is a (yield 'wait).

> Clearly I'm missing some bigger-picture information about how to
> handle exit conditions, window-closes, and so on.  I've looked all
> through the Graphics Toolkit manual, but can't see it.  Can someone
> please point me to a hello-world #lang scheme/gui example that
> includes close/quit functionality?

The main thing to learn is that an "eventspace" is basically wrapping
a single gui thread, and something like (yield 'wait) will wait until
the thread has nothing else to do (no more windows etc).  Based on
this you can see why you need two eventspaces if you want two
independent gui elements, and you can also see why it's bad to have
threads do work in a gui code (you're likely to get race conditions)
and instead a utility thread uses `queue-callback' to register a thunk
that the main thread will use to do the work in the usual
gui-serializable way.

> Also: I'm going to need a File->open... dialog at some stage.
> Should I be using the "PLT GUI Application Framework" instead of the
> "PLT Graphics Toolkit"?

IIRC, the framework's dialogs are not doing anything more than the
basic mred functions (eg, `get-file').

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.