[racket] problems building simple UIs with menu-bar% class instances

From: Tom Dean (tld at google.com)
Date: Wed Feb 19 17:45:04 EST 2014

I recently decided to start using Racket for my scripting and for the most
part I've found the experience fun and productive. GUIs are another matter,
and I'm mainly building the simple UIs I need by copying and modifying
existing code. I am having one vexing problem that's driving me crazy
however.  I want to add a menu-bar% to an application I'm building. After
failing repeatedly to do from the Racket Guide alone, I searched and found
several examples but none of them succeeded in building a frame with a
menu-bar. Assuming they were just buggy, I kept searching.

Finally I came upon a piece of Matthias Feldman's code—see attached—and it
too failed to work as advertised.  I'm using Racket  (v5.92) on a Mac Pro
workstation with OS 10.9.1 and running ./bin/racket in Emacs, but I've also
tried from a shell and on both of my workstation mac and laptop. Matthias
says the code works fine for him. Does this code work for you? I have no
trouble building UIs with editor-canvas%, panel%, button% classes, but
menu-bars's are eluding me so far.

;; Matthias Felleisen Sat, 21 Sep 2013 06:43:24 -0700

(define f (new frame% [label "Notes"] [width 400] [height 600]))
(define my-canvas%
  (class canvas%
    (define/override (on-char . x)
      (displayln x)
      (define dc (send this get-dc))
      (send dc set-scale 1 1)
      (send dc set-text-foreground "blue")
      (send dc draw-text "Use this window for notes" 10 10))))
(define c (new my-canvas% [parent f]))
(define t (new text%))

(define mb (new menu-bar% [parent f]))
(define m-edit (new menu% [label "Edit"] [parent mb]))
(define m-font (new menu% [label "Font"] [parent mb]))
(append-editor-operation-menu-items m-edit #f)
(append-editor-font-menu-items m-font)

(send f show #t)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140219/0c3e57bc/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: no-menu-bar.scm
Type: application/octet-stream
Size: 679 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20140219/0c3e57bc/attachment.obj>

Posted on the users mailing list.