GUIML
This is a DSL for describing GUIs. It is inspired by SXML notation and the HTMLPrag library. "GUIML" is a thin wrapper around Racket’s standard GUI library that allows a window and all its initial contents to be specified in a single expression. Since I’ve used it for all my GUI code since I wrote it, I figured it would be useful. Here is a simple GUI:
(define g (guiml (frame% (@ (label "Foobar") |
(width 640) |
(height 150)) |
(vertical-panel% (@) |
(message% (@ (label "Hello, world!"))) |
(editor-canvas% 'ec (@)) |
(button% (@ (label "Close") |
(style '(border)) |
(callback (lambda ignored-args |
(sendmsg g show #f))))))))) |
"g" is not an object, but an S-expression tree of structures that contain the widgets and their optional symbolic identifier. A special version of the "send" syntax is provided, which abstracts over this extra structure, and sends a message to the topmost widget in the hierarchy. All you have to remember is to type "sendmsg" instead of "send", and the widget hierarchy will have the same OO interface as its topmost widget object:
(sendmsg g show #t)
If you use the optional symbolic identifier, it is possible to address widgets that reside deep down in the hierarchy, using the "get-widget-by-id" function:
(sendmsg (get-widget-by-id g 'ec) set-editor (new text%))