[plt-scheme] Pasteboard in pasteboard and the error: here: I am
Hi All,
I am still playing around with pasteboards, snips and
friends, but progress is slow.
Can anyone provide a simple example of a
pasteboard containing another pasteboard?
Preferably where the containing pasteboard
is diplayable (via an editor-snip) in the DrScheme REPL?
Anyways, while playing I came upon this error,
here: I am
which, well, is not too informative.
What does it mean, and why does it occur?
To reproduce the error, run the program below.
#lang scheme/gui
(require mrlib/aligned-pasteboard)
(define current-pasteboard (make-parameter #f))
(define current-editor (make-parameter #f))
(define current-frame (make-parameter #f))
(define current-canvas (make-parameter #f))
;;; COMMON
(define (make-string-snip string)
(make-object string-snip% string))
(define (make-image-snip filename)
(make-object image-snip% filename))
(define (insert-snip editor snip)
(send editor insert snip))
(define (insert-snips editor snips)
(for-each (? (s) (insert-snip editor s)) snips))
(define (realign aligned-pasteboard)
(let ([min-width (send aligned-pasteboard get-aligned-min-width)]
[min-height (send aligned-pasteboard get-aligned-min-height)])
(send aligned-pasteboard realign min-width min-height)))
(define (element->snip e f c)
(cond [(string? e) (make-string-snip e)]
[(column? e) (column->snip e f c)]
;[(row? e) (row->snip e)]
[(image? e) (image->snip e)]
[else (error 'element->snip "Unknown element type")]))
;;; IMAGE
(define (image-writer col port write?)
(display (image->snip col) port))
(define-struct image (filename) #:property prop:custom-write image-writer)
(define (image->snip img)
(make-image-snip (image-filename img)))
;;; COLUMN
(define (column-writer col port write?)
(display (column->snip col #f #f) port))
(define-struct column (elements) #:property prop:custom-write column-writer)
(define (column->snip col frame canvas)
(let* ([pasteboard (new vertical-pasteboard%)]
[editor-snip (new editor-snip% [editor pasteboard]
[min-width 1] [min-height 1])]
[frame (if frame frame
(new frame% [label
"never shown, needed by canvas"]))]
[canvas (if canvas canvas
(new aligned-editor-canvas% [parent frame]
[editor pasteboard]))])
(insert-snips pasteboard
(reverse (map (? (e) (element->snip e frame canvas))
(column-elements col))))
(realign pasteboard)
editor-snip))
#;(define (column->snip col frame canvas)
(let* ([pasteboard (new vertical-pasteboard%)]
[editor-snip (new editor-snip% [editor pasteboard]
[min-width 1] [min-height 1])]
[frame (new frame% [label
"never shown, needed by canvas"])]
[canvas (new aligned-editor-canvas%
[parent frame]
[editor pasteboard])])
;(send editor-snip show-border #f)
(insert-snips pasteboard
(reverse (map (? (e) (element->snip e frame canvas))
(column-elements col))))
(realign pasteboard)
editor-snip))
;;; TEST
;; works
(make-column (list "Foo" "Bar" "Baz"))
;(make-row (list "Foo" "Bar" "Baz"))
;(make-image "face-smile.png")
;(make-column (list "FOO" (make-image "face-smile.png") "BAR"))
; broken
(make-column
(list "a"
(make-column (list "1" "2" "3"))
"b"
(make-column (list "x" "y" "z"))
"c"
(make-column (list "!" "?" "@"))))
#;(make-row (list "Foo"
(make-image "face-smile.png")
(make-column (list "Foo" "Bar" "Baz"))
"Baz"))
;(make-column (list "Foo" (make-row (list "123" "456" "789")) "@@@"))