Racket gui: Shakespearean Insults

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 tasks, gui-programming might be simpler and shorter than generating html pages.

Racket Gui: Shakespearean Insults

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 refocus and 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 pict and 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....

code .rkt

#lang racket/gui

;; GUI setup prep:
(define frame (new frame% [label "Shakespeare-style Insults"]
                  (min-width 600)))

;;; 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))
  (close-input-port inp)
  lines)

(define text-file-lines
  (get-lines "Shakespeare-Insult-Columns-3.csv"))

(define (csv-lines->lists lines)
  (map (lambda (l) (string-split l ",")) lines))

(define insult-lists
  (csv-lines->lists text-file-lines))

(define (get-random-list-element lst)
  (list-ref lst (random (length lst))))

(define (generate-insult insults)
  (string-append "You "
		 (string-join
		  (list
		   (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!"
                              (generate-insult insult-lists)
                              
                              ))])

; 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)

data .csv

artless,base-court,apple-john
bawdy,bat-fowling,baggage
beslubbering,beef-witted,barnacle
bootless,beetle-headed,bladder
churlish,boil-brained,boar-pig
cockered,clapper-clawed,bugbear
clouted,clay-brained,bum-bailey
craven,common-kissing,canker-blossom
currish,crook-pated,clack-dish
dankish,dismal-dreaming,clotpole
dissembling,dizzy-eyed,coxcomb
droning,doghearted,codpiece
errant,dread-bolted,death-token
fawning,earth-vexing,dewberry
fobbing,elf-skinned,flap-dragon
froward,fat-kidneyed,flax-wench
frothy,fen-sucked,flirt-gill
gleeking,flap-mouthed,foot-licker
goatish,fly-bitten,fustilarian
gorbellied,folly-fallen,giglet
impertinent,fool-born,gudgeon
infectious,full-gorged,haggard
jarring,guts-griping,harpy
loggerheaded,half-faced,hedge-pig
lumpish,hasty-witted,horn-beast
mammering,hedge-born,hugger-mugger
mangled,hell-hated,joithead
mewling,idle-headed,lewdster
paunchy,ill-breeding,lout
pribbling,ill-nurtured,maggot-pie
puking,knotty-pated,malt-worm
puny,milk-livered,mammet
qualling,motley-minded,measle
rank,onion-eyed,minnow
reeky,plume-plucked,miscreant
roguish,pottle-deep,moldwarp
ruttish,pox-marked,mumble-news
saucy,reeling-ripe,nut-hook
spleeny,rough-hewn,pigeon-egg
spongy,rude-growing,pignut
surly,rump-fed,puttock
tottering,shard-borne,pumpion
unmuzzled,sheep-biting,ratsbane
vain,spur-galled,scut
venomed,swag-bellied,skainsmate
villainous,tardy-gaited,strumpet
warped,tickle-brained,varlot
wayward,toad-spotted,vassal
weedy,unchin-snouted,whey-face
yeasty,weather-bitten,wagtail

footnotes

#racket #DrRacket #Shakespeare #gui #LearningProgramming