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

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Feb 19 18:05:09 EST 2014

I can replicate the problem on Mac OS X 10.9.x: When I run with
`racket`, the menu bar does not show up initially. If I bring a
different application's window to the front, then move your frame to
the front again, then the menu bar appears. So, the menu bar is there,
but it's not initially displayed.

If I do the same thing on Mac OS X 10.7.x, the menu bar appears from
the beginning.

If I run with `gracket`, then the menu bar appears from the beginning
on both versions of Mac OS X.

The underlying problem is that Apple doesn't really say how to switch
into GUI mode from a command-line application like `racket`, as opposed
to a ".app"-based executable such as `gracket`. The implementation in
`racket/gui` is based on various sources and some guesswork, and it was
developed mostly on 10.6.x and 10.7.x machines (so it's not too
surprising that things have changed). We can poke at the GUI code more
and come up with something that works better on 10.9.x.

Meanwhile, I recommend starting your program with `gracket` instead of

At Wed, 19 Feb 2014 14:45:04 -0800, Tom Dean wrote:
> 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%
>     (super-new)
>     (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)
> ------------------------------------------------------------------------------
> [application/octet-stream "no-menu-bar.scm"] [~/Desktop & open] [~/Temp & open]
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Posted on the users mailing list.