mark.warren
2020-4-7 13:27:31

I have a racket/gui question. Does anyone know how I can safely close a frame% ? The documentation appears to say that the default on-exit handler just hides the window, but I want the frame to actually be closed.


soegaard2
2020-4-7 13:29:05

Does (send _a-top-level-window_ on-close) work?


mark.warren
2020-4-7 13:32:04

I’m not sure but I think the on-exit handler sends on-close, wouldn’t that just be the same thing?


mark.warren
2020-4-7 13:33:09

I don’t think on-close actually does anything unless you augment it.


soegaard2
2020-4-7 13:34:08

The exit handler is called when the application stops. On the other hand the close handler is called when a frame (window) needs to close. For an application with more than one frame, it’s not the same.


soegaard2
2020-4-7 13:34:40

> I don’t think on-close actually does anything unless you augment it. Hmm. So we need a way to provoke such an event.


mark.warren
2020-4-7 13:35:43

I understand, but the documentation is confusing me as it seems to imply that if you click the X to close the window that it is not actually closed but is just hidden. I could just be getting confused.


mark.warren
2020-4-7 13:39:09

#lang racket (require framework racket/gui) (application:current-app-name "Test") (define main-frame% (class frame% (super-new) (define (on-close) (println "Closing")) (augment on-close) )) (define frame (new main-frame% [label "Test"])) (send frame show #t) If I run this code in DrRacket and then click the X on the displayed window it disappears, but if I then type (send frame show #t) in DrRacket, the window is shown again, indicating the program has not stopped but just been hidden.


soegaard2
2020-4-7 13:40:39

I see. Hmm. Maybe the frame is kept until it is garbage collected? But how do we test that?


mark.warren
2020-4-7 13:42:14

I was looking for a close or dispose message you could send the frame, but I haven’t seen one yet. Maybe it works differently if you run it from the command line.


soegaard2
2020-4-7 13:42:47

I can’t find one either.


soegaard2
2020-4-7 13:44:14

I was thinking that perhaps: > (send frame show #f) > (send frame on-close) > (set! frame #f) Might make the garbage collector remove the window.


mark.warren
2020-4-7 13:46:06

Hmm.. Maybe, if I were thinking in a native windows way I would say the event dispatch loop was not terminating. Setting the frame to false might be hazardous but I’ll give it a try.


soegaard2
2020-4-7 13:46:50

Maybe we can test this using “Wills”? (Looking at the example: https://docs.racket-lang.org/reference/willexecutor.html )


mflatt
2020-4-7 13:47:36

@mark.warren There’s no difference between “closed” and “hidden and not referenced, so can be GCed” for a frame% object. But if an application needs to know when the user clicked the close box for a frame%, that’s what on-close is for.


mark.warren
2020-4-7 13:48:56

Ooh, blimey that is going to be some reading. @mflatt So, if I re-run the above example will that GC the original frame?


mflatt
2020-4-7 13:50:24

Yes, at least eventually


mark.warren
2020-4-7 13:51:11

Ah right so I’m concerned about nothing then, thanks.


mark.warren
2020-4-7 13:52:13

@soegaard2 Thanks for the reading matter anyway, looks like I don’t need to worry, but that wills stuff looks interesting.


wanpeebaw
2020-4-8 05:14:52

@wanpeebaw has joined the channel