[plt-scheme] How does a GUI application terminate?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Aug 26 17:47:44 EDT 2008

At Tue, 26 Aug 2008 14:29:39 -0700, Woodhouse Gregory wrote:
> I'm trying to get my feet wet with GUI applications, and one thing  
> that's not clear to me is how to ask an application to close. Right  
> now, I have code that looks like this for the "Close" menu item
> (define mi-quit (new menu-item% [label "Quit"]
>                                   [callback
>                                   (lambda (item evt)
>                                     (printf "Invoking ~s  
> menu...~n" (send item get-label))
>                                     (send f show #f))]
>                                   [parent m-file]))
> but then it seems that I ought to signal that event processing should  
> stop.

MrEd essentially adds

 (yield 'sync)

to the end of any program that it runs. As a result, the process waits
until there are no visible top-level windows, no timers running, and no
functions previously queued with `queue-callback' that are still
waiting to be called.

So, `(send f show #f)' is probably all you need, though you might want

  (when (send f can-close?)
    (send f on-close)
    (send f show #f))

> My first thought was something like (send f close), but there  
> is no close method in frame%.

For some reason (probably just history), a `close' method that performs
the above sequence is added by the Framework's `frame:basic-mixin'
instead of being built into `frame%'.


Posted on the users mailing list.