[racket] Screenshot in OS X

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Dec 12 09:16:49 EST 2012

At Sat, 8 Dec 2012 14:29:50 +0100, Jens Axel Søgaard wrote:
> I have extended the screenshot code. Now it is possible to
> capture both the entire display and a single window.
> As an example I have recreated the images in the
> widget gallery (in the gui docs). I notice that combo-field%
> and editor-canvas behave differently on OS X and GTK(?).
> On OS X the example text is missing. See the attached
> screenshot.
> 
> Any ideas why?

Neat program.

A combo-field% is actually a canvas% with a drop-down decoration, so
it's the same issue in both cases: the control needs to run a callback
to set up the content of the canvas. The `refresh' calls don't help,
because those just queue a refresh request, and you want to wait until
the refresh is actually performed.

You were sortof on the right track with the commented-out `(sleep 1)',
but it would have to be `(sleep/yield 1)'. That will work most of the
time, but there's no guarantee that 1 second is long enough, of course.

There's a `refresh-now' method of `canvas%', but I think that method is
not directly accessible for controls. A more general approach is to
wait until a low-priority callback gets a chance to run, which means
that windows updates (which have a higher priority) will have
completed:

  (make showcase-panel)
  (send frame show #t)
  (let ([s (make-semaphore)])
    (queue-callback (lambda () (semaphore-post s)) #f)
    (yield s))
  (begin0
    (capture-window-with-name name)
    (send frame show #f))



Posted on the users mailing list.