Inspired by a Diaspora* post about simple gui programming in Red , I played with gui programming in Racket. Just a few tweaks to the example in Racket's Windowing documentation(fn:2) and a button in a frame shows an insult. Gui programming seemed too complex too learn, but the Red example got me over the off-putting idea. For some tasked, gui-programming might be simpler and shorter than generating html pages.
The code and .csv data are below
I want to find a way to do poster-style presentations with Racket. I've been experimenting with slideshow and pict hoping to discover an alternative to Inkscape/sozi and Impress.js with
panorama. I never got to use Inkscape/JessyInk but I think the pict/conditional language(module?) with
ghost and other functions make JessyInk-like presentations possible in a relatively straightforward way. But I want to discover a D.R.Y. approach to using an A4 printout as a focus for discussion. With Inkscape it's interesting to layout an A4-sized paper with text and images (plots). Exporting Inkscape's .svg file to .pdf lets me print a page, and then using sozi lets me focus a screen on different parts of the page. But it's awkward to replace images and edit text in Inkscape. It would be great to have Racket generate the page sand screen presentation from easily editable text files and easily replaceable image files.
But I still can't imagine a manageable way to generate the printed page and sozi presentation with
slideshow. Even just the Impress.js style presentation seems complex with
pict... Maybe reading the Racket documentation for gui programming will give me some ideas....
;; GUI setup prep:
(define frame (new frame% [label "Shakespeare-style Insults"]
;;; get insult ready
(define (str->path str)
(build-path (current-directory-for-user) str))
(define (get-lines str)
(define inp (open-input-file (str->path str)))
(define lines (port->lines inp))
(define (csv-lines->lists lines)
(map (lambda (l) (string-split l ",")) lines))
(define (get-random-list-element lst)
(list-ref lst (random (length lst))))
(define (generate-insult insults)
(string-append "You "
(first (get-random-list-element insult-lists) )
(second (get-random-list-element insult-lists) )
(third (get-random-list-element insult-lists)))
; GUI setup: Make a button in the frame
(new button% [parent frame]
[label "Insult Me!"]
; Callback procedure for a button click:
[callback (lambda (button event)
(send msg set-label ; "Insult Time!"
; Make a static text message in the frame
(define msg (new message% [parent frame]
[label "Click Button for a Shakespearean Insult"]))
; Show the frame by calling its show method
(send frame show #t)
- About this code/post: Diaspora* post
- (fn:1) manuelcaeiro's Diaspora* post
- (fn:2) Racket Documentation: Windowing
#racket #DrRacket #Shakespeare #gui #LearningProgramming