How can I generate WXME files from some other external files?

how can I generate WXME files from some other external files?

the decoding wxme chapter appearst to assume you already have a wxme file, I want to GENERATE a wxme file that can be edited afterwards in drracket

1 Like

Sorry I don’t have time to work this out myself.

If I was to do it it’d check the DrRacket and gui framework documentation to start, and follow that by reading the respective source code.
I’d also probably use a text or even hex editor to inspect a sample file I made with DrRacket to take a look. Racket source code search in DrRacket and GitHub are also useful.

Sorry I can’t offer more specific help but I hope this gets you on the right path.

Stephen

You can generate WXME files by setting up a text% or pasteboard% with the snips you want and calling save-file. The example below will save a WXME file with some text and an image in the "hello.wxme" file. You can open the resulting file in DrRacket to see that it has the same contents as the opened window.

Note that the snips that can be saved into WXME format need to have read and write methods implemented correctly -- in the example below, the plot is interactive in the window, but if you open the WXME file in DrRacket, you'll get a static image -- this is because the plot snip does not implement a correct save/read operation and relies on the parent image snip for this...

Hope this helps,
Alex.

#lang racket/gui
(require pict pict/snip plot)

(define toplevel (new frame% [label "WXME Demo"] [width 400] [height 300]))
(define canvas (new editor-canvas% [parent toplevel]))
(define text (new text%))

(send canvas set-editor text)

(send text insert "Hello World! ")
(send text insert (new pict-snip% [pict (standard-fish 100 50)]))
(send text insert (plot-snip (function sin -5 5) #:width 300 #:height 200))

(send text save-file "hello.wxme")

(send toplevel show #t)
1 Like