[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: focus problem - what's wrong?



It took me a long time to notice that you're using dialog% instead of
frame%. The difference is that `show' method of dialog% doesn't return
until the dialog is closed.

So the `(send ed1 focus)' doesn't get called until the dialog is
closed, which isn't what you wanted. If you change dialog% to frame%,
this small example should work as you expected.

I'm not sure what you really wanted in the larger program (presuambly
you do want dialog% instead of frame%), so it's difficult for me to
suggest a solution. But it probably has something to do with queueing a
function with `queue-callback'.

Sorry it took so long,
Matthew

> Hi all,
> I'm using DrScheme 103 and I've some problems to control the focus by
> program. From a bigger application I have extracted this short example.
> The buttons are simulating other parts which have to set the focus to
> certain input areas. All works fine with the buttons "focus to second"
> and "focus to third", but if the window is hidden and shown again, it
> will not set the focus.
> What's wrong?
> 
> (make-object
>   (class* dialog% () initvars
>     (private (the-panel void)
>              (ed1 void)
>              (ed2 void))
>     (sequence (super-init "TEST" #f 200 200 200 200 null)
>               (set! the-panel (make-object vertical-panel% this '(border)))
>               (set! ed1 (make-object editor-canvas% the-panel
>                           (make-object text% 1.0 null)
>                           '(no-hscroll no-vscroll) 1))
>               (set! ed2 (make-object editor-canvas% the-panel
>                           (make-object text% 1.0 null)
>                           '(no-hscroll no-vscroll) 1))
>               (make-object button% "test" the-panel
>                 (lambda (x y)
>                   (send this show #f)
>                   (send this show #t)
>                   (send ed1 focus))
>                 null)
>               (make-object button% "focus to third" the-panel
>                 (lambda (x y) (send ed1 focus)) null)
>               (make-object button% "focus to second" the-panel
>                 (lambda (x y) (send ed2 focus)) null)
>               (send this show #t))))
>