focus shifts to wrong window after using tk_ built in dialogs 
Author Message
 focus shifts to wrong window after using tk_ built in dialogs

Tk 8.3.0 Bug:  Generated by Scriptics' bug entry form at
        http://www.*-*-*.com/
Responses to this post are encouraged.
------

Submitted by:  Vince Darley
OperatingSystem:  Windows NT
OperatingSystemVersion:  4.0sp5
Synopsis:  focus shifts to wrong window after using tk_ built in dialogs

ReproducibleScript:
# focuslostbug.tcl
wm title . "New focus"
toplevel .t
wm title .t "Original focus"
update
button .t.b -text "Press me!" -command focusbug
pack .t.b
focus .t
proc focusbug {} {
    tk_messageBox \
      -icon    question \
      -type    yesno \
      -default no \
      -message "Please press a button!  Notice how focus shifts" \
      -title  "Focus bug"

Quote:
}

ObservedBehavior:
When using tk_messageBox, or similar dialogs (on WinNT at least), the focus is not reset correctly when the dialog is dismissed.  This happens even though the dialog tries to do 'set oldFocus [focus] .... catch {focus $oldFocus}' internally.

The script attached demonstrates this problem.  There are two windows, with the focus on one containing a button.  Pressing the button brings up a simple dialog, but when that dialog is dismissed the focus is now on the window without the button (the root '.' window).

DesiredBehavior:
Focus should remain where it was before.

Patch:
Using 'focus -force' can solve the problem, but I don't think it's a good solution (at least the focus man page suggests not to use -force).

Comments:
    Tk 8.2.3 and 8.3.0 show the bug on WinNT.



Fri, 16 Aug 2002 03:00:00 GMT  
 focus shifts to wrong window after using tk_ built in dialogs
Quote:
> The script attached demonstrates this problem.  There are two windows,

with the focus on one >containing a button.  Pressing the button brings up a
simple dialog, but when that dialog is dismissed >the focus is now on the
window without the button (the root '.' window).

Hi Vince,
I had the same problem until I discovered the -parent option for tk_ built
in dialogs.  In your case if you just add "-parent .t" to your call to
tk_messageBox, that should resolve your problem.
HTH,
Brian


Quote:

> Tk 8.3.0 Bug:  Generated by Scriptics' bug entry form at
> http://www.scriptics.com/support/bugForm.html
> Responses to this post are encouraged.
> ------

> Submitted by:  Vince Darley
> OperatingSystem:  Windows NT
> OperatingSystemVersion:  4.0sp5
> Synopsis:  focus shifts to wrong window after using tk_ built in dialogs

> ReproducibleScript:
> # focuslostbug.tcl
> wm title . "New focus"
> toplevel .t
> wm title .t "Original focus"
> update
> button .t.b -text "Press me!" -command focusbug
> pack .t.b
> focus .t
> proc focusbug {} {
>     tk_messageBox \
>       -icon    question \
>       -type    yesno \
>       -default no \
>       -message "Please press a button!  Notice how focus shifts" \
>       -title  "Focus bug"
> }

> ObservedBehavior:
> When using tk_messageBox, or similar dialogs (on WinNT at least), the

focus is not reset correctly when the dialog is dismissed.  This happens
even though the dialog tries to do 'set oldFocus [focus] .... catch {focus
$oldFocus}' internally.
Quote:

> The script attached demonstrates this problem.  There are two windows,

with the focus on one >containing a button.  Pressing the button brings up a
simple dialog, but when that dialog is dismissed >the focus is now on the
window without the button (the root '.' window).
Quote:

> DesiredBehavior:
> Focus should remain where it was before.

> Patch:
> Using 'focus -force' can solve the problem, but I don't think it's a good

solution (at least the focus man page suggests not to use -force).

- Show quoted text -

Quote:

> Comments:
>     Tk 8.2.3 and 8.3.0 show the bug on WinNT.



Fri, 16 Aug 2002 03:00:00 GMT  
 focus shifts to wrong window after using tk_ built in dialogs


Quote:
> Hi Vince,
> I had the same problem until I discovered the -parent option for tk_
built
> in dialogs.  In your case if you just add "-parent .t" to your call to
> tk_messageBox, that should resolve your problem.

Indeed you're right, for those dialogs which take '-parent'.  But, for
example tk_dialog doesn't, so the following script still shows a bug:

# focuslostbug.tcl
wm title . "New focus"
toplevel .t
wm title .t "Original focus"
update
button .t.b -text "Press me!" -command focusbug
pack .t.b
focus .t
proc focusbug {} {
    tk_dialog .foo "Focus bug" \
      "Please press a button!  Notice how focus shifts" \
      "" 0 "Ok"

Quote:
}



> > Tk 8.3.0 Bug:  Generated by Scriptics' bug entry form at
> > http://www.scriptics.com/support/bugForm.html
> > Responses to this post are encouraged.
> > ------

> > Submitted by:  Vince Darley
> > OperatingSystem:  Windows NT
> > OperatingSystemVersion:  4.0sp5
> > Synopsis:  focus shifts to wrong window after using tk_ built in
dialogs

> > ReproducibleScript:
> > # focuslostbug.tcl
> > wm title . "New focus"
> > toplevel .t
> > wm title .t "Original focus"
> > update
> > button .t.b -text "Press me!" -command focusbug
> > pack .t.b
> > focus .t
> > proc focusbug {} {
> >     tk_messageBox \
> >       -icon    question \
> >       -type    yesno \
> >       -default no \
> >       -message "Please press a button!  Notice how focus shifts" \
> >       -title  "Focus bug"
> > }

> > ObservedBehavior:
> > When using tk_messageBox, or similar dialogs (on WinNT at least),
the
> focus is not reset correctly when the dialog is dismissed.  This
happens
> even though the dialog tries to do 'set oldFocus [focus] .... catch
{focus
> $oldFocus}' internally.

> > The script attached demonstrates this problem.  There are two
windows,
> with the focus on one >containing a button.  Pressing the button
brings up a
> simple dialog, but when that dialog is dismissed >the focus is now on
the
> window without the button (the root '.' window).

> > DesiredBehavior:
> > Focus should remain where it was before.

> > Patch:
> > Using 'focus -force' can solve the problem, but I don't think it's
a good
> solution (at least the focus man page suggests not to use -force).

> > Comments:
> >     Tk 8.2.3 and 8.3.0 show the bug on WinNT.

Sent via Deja.com http://www.deja.com/
Before you buy.


Sat, 17 Aug 2002 03:00:00 GMT  
 focus shifts to wrong window after using tk_ built in dialogs

Quote:



> > Hi Vince,
> > I had the same problem until I discovered the -parent option for tk_
> built
> > in dialogs.  In your case if you just add "-parent .t" to your call to
> > tk_messageBox, that should resolve your problem.

> Indeed you're right, for those dialogs which take '-parent'.  But, for
> example tk_dialog doesn't, so the following script still shows a bug:

> # focuslostbug.tcl
> wm title . "New focus"
> toplevel .t
> wm title .t "Original focus"
> update
> button .t.b -text "Press me!" -command focusbug
> pack .t.b
> focus .t
> proc focusbug {} {
>     tk_dialog .foo "Focus bug" \
>       "Please press a button!  Notice how focus shifts" \
>       "" 0 "Ok"
> }

Change the .foo to .t.foo and you're OK, as tk_dialog (which I
recommend upgrading to tk_messageBox) takes the parent toplevel
as the master.

--
   Jeffrey Hobbs                          The Tcl Guy
   jeffrey.hobbs at scriptics.com         Scriptics Corp.



Sat, 17 Aug 2002 03:00:00 GMT  
 focus shifts to wrong window after using tk_ built in dialogs


Quote:

> Change the .foo to .t.foo and you're OK, as tk_dialog (which I
> recommend upgrading to tk_messageBox) takes the parent toplevel
> as the master.

I see!  So is this supposed to be the correct behaviour?: all dialogs
should be either children of the toplevel which calls them, or you must
specify the appropriate -parent flag (which probably does the same
thing behind the scenes?).

If this is the correct behaviour, can I suggest it is documented
somewhere in the dialog man pages?  (Neither tk_dialog not
tk_messageBox mention any of this -- even the -parent flag simply says
it will make the window the logical parent of the dialog, and the
dialog will be displayed on top of that window -- there is no mention
of 'focus' movement).

Something like:

'When the dialog is cancelled, focus will return to the parent window
of the dialog, hence it is important to specify the dialog's parent
correctly for an intuitive user interface.'

would clear things up a lot...

It still seems to me more logical to revert focus to where it was
before, but at least if the behaviour is documented it's ok...

Thanks for the quick responses to my questions.  Now I just have to fix
my code!

Vince.

Sent via Deja.com http://www.deja.com/
Before you buy.



Sat, 17 Aug 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. convert 2d array to 1d array without using shift registers and build array

2. New wiki page shows how to build Tcl/Tk for Windows using Msys+Mingw

3. Grab and focus for dialogs in Tk 4.0b3

4. Focus with modal dialogs in Windows?

5. Using shift tab binding in x windows

6. Problem with modal dialog when using Tcl/Tk 8.0

7. Selecting Directories using Tk File Selection Dialog.

8. How to shift the focus to the locator field

9. Stippled text on a canvas drawn in the wrong place using the wrong color

10. Getting X focus when getting Tk focus

11. whats wrong with using interrupts on windows NT

12. Directing non-Tk window focus?

 

 
Powered by phpBB® Forum Software