[plt-scheme] Embarrasingly basic GUI question

From: Andrew Reilly (andrew-scheme at areilly.bpc-users.org)
Date: Tue Aug 11 21:58:26 EDT 2009

On Tue, Aug 11, 2009 at 01:31:56AM -0400, Eli Barzilay wrote:
> On Aug 11, Andrew Reilly wrote:
> > Hi Eli,
> > 
> > Thanks for answering so promptly!
> > 
> > On Tue, Aug 11, 2009 at 12:39:10AM -0400, Eli Barzilay wrote:
> > > Looks like what you're missing is a (yield 'wait).
> > 
> > Yes, that looks like the main part of the puzzle.
> > 
> > Now I need to figure out how to attach a callback to (or otherwise
> > notice) the window being closed.  The yield isn't exiting when my
> > window closes because I have a timer active.
> Probably something like
>     (define/augment (on-close)
>       ... kill your timer here ...)

For the benefit of posterity, this augmentation to the frame%
class seems to do what I need:

(define my-frame%
  (class frame%
    (init close)
    (define close-hook close)
    (define/augment (on-close) (close-hook))

Now my main code instantiates a my-frame% instead of a frame% as
the top-level window, and passes (lambda () (send heartbeat
stop)) as the argument to the "close" initializer.  Seems to
work nicely!

Does this look reasonable?  I guess that the lack of this sort
of initialization-time hookability is an indicator to me that I
should really be building my whole GUI through class refinement
and inheritance, rather than procedurally hooking together and
parameterizing existing classes.  I had made it so far with the
latter approach, though...

Thanks again for your help!



Posted on the users mailing list.