[plt-scheme] DrScheme Printing of picts
At Fri, 19 May 2006 17:18:18 +0100, "Paulo J. Matos" wrote:
> By default a pict is printed in the interaction window of DrScheme as
> a real picture and not as a <struct:pict>, however if you have a
> function foo which returns a pict and if you do (write (foo)),
> (display (foo)) or (printf "~a" foo), in all cases you get
> <struct:pict>.
Use `print', or use "~v" with `printf'.
(The idea is that `display' and `write' should have relatively
well-defined and consistent output in any context, but `print' can be
tailored to its environment.)
> How is DrScheme printing the picts? I though that grabbing the
> current-display/print/write-handler would do the job but neither of
> these work.
I think DrScheme does set the print handler, but only uses it when the
output port is its own output port.
> My real need is the following. I want be able to grab the object which
> results in the evaluation and if it is some kind of specific object I
> know it calls foo with it to return a custom pict to be printed as an
> image, else I just release the object to drscheme care.
>
> I tried:
> (let ([old-display-handler (port-display-handler (current-output-port))])
> (port-display-handler (current-output-port)
> (lambda (val port)
> (if (is-a? val myobj<%>)
> (old-display-handler (foo val) port)
> (old-display-handler val port)))))
>
> but this is not working. It's printing the pict resulting of foo as
> <struct:pict>. Any ideas?
If I understand, this sort of strategy should work if you use `print'
and if you set the print handler.
Matthew