I don't have an explanation (I just guessed exit was being called
somewhere), but the exit handler did have an effect. The example program
quit with "Interactions disabled" in DrRacket, whereas this program does
not (and does display "Called exit"):

#lang racket

(require browser)

(define really-hyper-frame%
  (class hyper-frame%

    (super-new)

    (define (on-close)
      (displayln "Closing!")
      ;; But, how do I prevent the evaluation thread
      ;; from terminating? For example, if I want to launch
      ;; a browser frame from interactions in a GUI application?
      )
    (augment on-close)
    ))

(exit-handler
 (λ (x) (displayln "Called exit")))

;; I'm aware the example is from the module level, but the same issue
applies if
;; I create the frame as a result of, say, a button% click.
(new really-hyper-frame%
     [label "The Frame"]
     [start-url "https://racket-lang.org/";])


Also, closing the frame in this tiny example:

#lang racket/gui

(exit-handler
 (λ (x) (displayln "Called exit")))

(send (new frame%
           [label "hypo-frame"])
      show
      #t)

neither disables interactions not displays "Called exit".

-Philip

On Tue, Apr 18, 2017 at 7:11 AM, Matthew Flatt <mfl...@cs.utah.edu> wrote:

> I don't think setting the exit handler will have an effect. The example
> application quits because an implicit `yield` finishes when the window
> is closed, and then the GUI handler thread has nothing else to do, so
> it exits.
>
> You could add an explicit `yield`, to allow events to be handled, and
> then do more after that `yield` returns:
>
>  (require racket/gui/base)
>  (yield (current-eventspace))
>
>  (printf "do more here...\n")
>
> Or you could make `yield` wait on a semaphore that is never posted, so
> that the application doesn't quit until `exit` is called.
>
> At Mon, 17 Apr 2017 23:53:49 -0500, Philip McGrath wrote:
> > It's a little ugly, but you can change the exit handler:
> > (exit-handler
> >  (λ (x) (displayln "Called exit")))
> >
> > -Philip
> >
> > On Mon, Apr 17, 2017 at 8:57 PM, Matt Jadud <jad...@gmail.com> wrote:
> >
> > > Hi all,
> > >
> > > I would like to spawn a browser frame, but I'd like it if the frame did
> > > not terminate the thread when I close it. I'm having a hard time
> figuring
> > > out what I should override/augment or catch so that I can spawn the
> frame
> > > from within a GUI application, let the user close the frame, and not
> have
> > > the whole application terminate.
> > >
> > > Cheers,
> > > Matt
> > >
> > > #lang racket
> > >
> > > (require browser)
> > >
> > > (define really-hyper-frame%
> > >   (class hyper-frame%
> > >
> > >     (super-new)
> > >
> > >     (define (on-close)
> > >       (printf "Closing!")
> > >       ;; But, how do I prevent the evaluation thread
> > >       ;; from terminating? For example, if I want to launch
> > >       ;; a browser frame from interactions in a GUI application?
> > >       )
> > >     (augment on-close)
> > >     ))
> > >
> > > ;; I'm aware the example is from the module level, but the same issue
> > > applies if
> > > ;; I create the frame as a result of, say, a button% click.
> > > (new really-hyper-frame%
> > >      [label "The Frame"]
> > >      [start-url "https://racket-lang.org/";])
> > >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Racket Users" group.
> > > To unsubscribe from this group and stop receiving emails from it, send
> an
> > > email to racket-users+unsubscr...@googlegroups.com.
> > > For more options, visit https://groups.google.com/d/optout.
> > >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to