[racket] gui application needs to perform operation upon closing of a window

30 views
Skip to first unread message

Zelah Hutchinson

unread,
May 22, 2013, 6:55:43 PM5/22/13
to us...@racket-lang.org
From the documentation I gather that I need to augment the on-close method. I do not understand how to do this. Can someone show me a tiny example of how to perform an operation when a window is closed? Thank you.

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Check it out at http://www.inbox.com/marineaquarium



____________________
Racket Users list:
http://lists.racket-lang.org/users

Matthias Felleisen

unread,
May 22, 2013, 7:06:18 PM5/22/13
to Zelah Hutchinson, us...@racket-lang.org

Here we go:

#lang racket/gui

(define my-frame%
(class frame%
(super-new)
(define/augment (on-close)
(displayln "closing now"))))

(define frame
(new my-frame% [label "on closing"][width 300][height 200]))

(send frame show #t)

Stephen Chang

unread,
May 22, 2013, 7:14:43 PM5/22/13
to Matthias Felleisen, Racket Users, Zelah Hutchinson
I was about to reply with the same answer as Matthias, but with
define/override instead of define/augment, but I kept getting an
error. Does it say anywhere in the docs whether a method is declared
using pubment or public? I couldnt find it.

Matthias Felleisen

unread,
May 22, 2013, 7:59:23 PM5/22/13
to Stephen Chang, Racket Users, Zelah Hutchinson

From the docs:

"
method
(send a-top-level-window on-close) → void?

Refine this method with augment.
...

Stephen Chang

unread,
May 22, 2013, 10:06:14 PM5/22/13
to Matthias Felleisen, Racket Users, Zelah Hutchinson
Ah ok I see now. I didn't look hard enough.

I saw the "frame%" so I was clicking around here:
http://docs.racket-lang.org/tools/drracket_unit.html?q=on-close#%28meth._%28%28%28lib._drracket%2Ftool-lib..rkt%29._drracket~3aunit~3aframe~25%29._on-close%29%29

On Wed, May 22, 2013 at 7:59 PM, Matthias Felleisen

Robby Findler

unread,
May 22, 2013, 10:32:00 PM5/22/13
to Stephen Chang, Racket Users, Zelah Hutchinson, Matthias Felleisen
Thanks, I've fixed those docs.

Robby
Reply all
Reply to author
Forward
0 new messages