Create plot frames in current eventspace; fix plot snip resize override

As suggested by Robby and Eli here:

  http://lists.racket-lang.org/users/archive/2013-March/056771.html

both `plot-frame' and `plot' (when `plot-new-window?' is #t) now create
frames in the caller's eventspace. Doing so fixes the problem talked
about in that thread, and seems like good behavior overall.

Plots created a separate eventspace because of the issue raised here:

  http://lists.racket-lang.org/users/archive/2012-April/051485.html

in which a user was flummoxed by the fact that framed plots don't draw
during read loops in which events can't be processed, and the suggested
solution wasn't easy or obvious. Users may get Plot's old behavior by

  (parameterize ([current-eventspace  (make-eventspace)])
    (plot ...))

which, though still not obvious, is at least easy.

Related to PR 13535: from the user's feedback, plots having their own
eventspaces may cause framed plots to render at the wrong size
initially, and may partly cause them to not redraw when their frame
is resized. Hopefully the eventspace change fixes one or both
problems.

If not, maybe this will: 2d-plot-snip% and 3d-plot-snip%, which
descend from image-snip%, now properly call the superclass method
within their `resize' overrides, so their editors will be notified
of the change and hopefully redraw them.
This commit is contained in:
Neil Toronto 2014-04-05 16:04:47 -06:00
parent f939725950
commit 32374df556
5 changed files with 7 additions and 12 deletions

View File

@ -20,8 +20,7 @@
(define (make-snip w h) snip)
(define frame
(parameterize ([current-eventspace (make-eventspace)])
(new snip-frame% [label label] [width (+ 20 width)] [height (+ 20 height)])))
(new snip-frame% [label label] [width (+ 20 width)] [height (+ 20 height)]))
(new snip-canvas%
[parent frame]
@ -30,7 +29,3 @@
[horizontal-inset 5] [vertical-inset 5])
frame)
(define (with-new-eventspace thnk)
(parameterize ([current-eventspace (make-eventspace)])
(thnk)))

View File

@ -17,7 +17,7 @@
;; Require lazily, in case someone wants to just (require plot) in a headless setup
(lazy-require ["snip2d.rkt" (make-2d-plot-snip)]
["gui.rkt" (make-snip-frame with-new-eventspace)])
["gui.rkt" (make-snip-frame)])
(provide plot-snip plot-frame plot)
@ -128,7 +128,7 @@
(when out-file
(call plot-file out-file out-kind))
(cond [(plot-new-window?) (define frame (with-new-eventspace (λ () (call plot-frame))))
(cond [(plot-new-window?) (define frame (call plot-frame))
(send frame show #t)
(void)]
[else (call plot-snip)])))

View File

@ -17,7 +17,7 @@
;; Require lazily, in case someone wants to just (require plot) in a headless setup
(lazy-require ["snip3d.rkt" (make-3d-plot-snip)]
["gui.rkt" (make-snip-frame with-new-eventspace)])
["gui.rkt" (make-snip-frame)])
(provide plot3d-snip plot3d-frame plot3d)
@ -160,7 +160,7 @@
(when out-file
(call plot3d-file out-file out-kind))
(cond [(plot-new-window?) (define frame (with-new-eventspace (λ () (call plot3d-frame))))
(cond [(plot-new-window?) (define frame (call plot3d-frame))
(send frame show #t)
(void)]
[else (call plot3d-snip)])))

View File

@ -205,7 +205,7 @@
(when (not (update-thread-running?))
(start-update-thread #t))
(set-update #t))
#f)
(super resize w h))
))
(define (make-2d-plot-snip

View File

@ -131,7 +131,7 @@
(when (not (update-thread-running?))
(start-update-thread #t))
(set-update #t))
#f)
(super resize w h))
))
(define (make-3d-plot-snip