[plt-scheme] Editor Canvas as Output Port

From: Williams, M. Douglas (M.DOUGLAS.WILLIAMS at saic.com)
Date: Sun Apr 29 00:27:27 EDT 2007

The following short piece of code creates an output port to write text onto an editor canvas.  The attached file has a short example.  It works, but I'm not sure it's an adequate implementation for general usage.  For one thing, it only works for text, while, for example, DrScheme lets me write graphic elements (e.g., an image snip) using print (or printf even).  Am I correct in that I need to supply an optional-write-special-proc to handle these?  It's hard to tell from the documentation I've look at so far.

(define (make-editor-canvas-port editor-canvas)
  (let ((text (send editor-canvas get-editor)))
    (if text
        (make-output-port
         'canvas-port
         always-evt
         (lambda (s start end non-block? breakable?)
           (send text insert
                  (bytes->string/latin-1 s #f start end))
           (- end start))
         void)
        #f)))

Is there a similar set of procedures that already exist somewhere I can use?

There seem to be similar things in the Application Framework, but I've only skimmed over them so far.  They seem to be overkill for simple MrEd applications, but that may well be a learning curve issue more than anything.

Thanks,
Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070428/ad78fff7/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.ss
Type: application/octet-stream
Size: 1072 bytes
Desc: test.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20070428/ad78fff7/attachment.obj>

Posted on the users mailing list.