[racket] Two more focus questions

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed May 4 08:37:41 EDT 2011

At Wed, 04 May 2011 12:51:40 +0100, Erich Rast wrote:
> 1.) Is it possible to change the default "gadget order" in a frame%?
> Right now, the first created gets the first focus. I have a text-field
> and a popup menu above a list-box, but would like to have the list-box
> get the default keyboard focus (i.e. when the frame is shown, without
> having to press tab to get there).

There's not currently a way to set the order, but to set the initial
focus, you should be able to call `focus' on a control before showing
the frame.

> 2.) I have a frame% with text% fields in it and would like to bring it
> to the foreground programmatically. However, no combination of show and
> focus I've tried so far seems to actually move the keyboard focus from
> the window that currently has the focus to the frame that is moved to
> the foreground. The frame is moved to the foreground, but text% editors
> remain greyed out and the focus method does not seem to have any effect
> on them.

If I remember correctly, you're usually on a Mac? The `show' method on
frame% should move the focus, too.

Below is the program I tired, where clicking "Switch" switches the
front frame and sets the focus as expected. Does that example fail on
your machine?

----------------------------------------

#lang racket/gui

(define f (new frame% [label "First"]))
(new text-field% [parent f] [label #f])
(new button% [parent f] [label "Switch"]
     [callback (lambda (b e) (send g show #t))])

(define g (new frame% [label "Second"]))
(new text-field% [parent g] [label #f])
(new button% [parent g] [label "Switch"]
     [callback (lambda (b e) (send f show #t))])

(send f show #t)
(send g show #t)



Posted on the users mailing list.