[R-gui] Tk/Windows focus problems

wettenhall at wehi.EDU.AU wettenhall at wehi.EDU.AU
Thu Apr 8 18:06:42 CEST 2004


Hi,

I'm posting ONLY TO THE R-SIG-GUI LIST in case I was boring anyone.

It seems that there is interest in some more details about my
investigations of tktoplevel(use=RGuiWindowID), so here goes...

In this investigation, I'm only focusing (get it?) on plain Tk windows with
nothing in them.  I can still reproduce annoying behaviour under Windows OS
with these simple Tk windows, although some users of my R-Tcl/Tk GUI claim
that the annoying focus problems occur when they get up to one particular
entry box or listbox in the GUI. I have not tested that sort of thing yet.

To clarify how I am getting window IDs, I have installed (in Windows XP),
R 1.8.1, ActivePerl-5.6.1, the Win32:GuiTest perl module (on CPAN),
and the spy.pl script from
http://triumvir.org/prog/perl/guitest/guitest-spy.html

Firstly, I begin an RGui 1.8.1 MDI (Multiple Document Interface) session.

Then from a DOS window:

C:\>perl spy.pl | grep R
...
+0x00050112, 'RGui', Rgui Workspace
+++0x0004014C, 'R Console', Rgui Document
++0x00040102, 'TOOLBAR', Rgui
+++0x00040104, '', Rgui
+++0x000400F4, '', Rgui
+++0x000400F2, '', Rgui
+++0x0004010E, '', Rgui
+++0x00040108, '', Rgui
+++0x00050106, '', Rgui
+++0x000400E8, '', Rgui
+++0x000600F0, '', Rgui
...
C:\>

library(tcltk)
tt1 <- tktoplevel(use="0x00050112")  # The RGui Workspace Window ID

Result: If RGui is maximized, it goes back to "normal/unmaximized" size. 
No "Tk" window appears, i.e. tt1 now points to the main RGui window.

To confirm this:
tkwm.title(tt1,"Hello")
"Hello" now appears in the title bar of the main RGui window.

tt1a <- tktoplevel(tt1)

A normal Tk window appears.  Now if I set my Taskbar on autohide, and move
the mouse from the taskbar up to Rgui, the tt1a window will hide behind
RGui.  If I turn off taskbar-autohide, then I cannot get tt1a to disappear
just by moving the mouse, but if I click on the console window within RGui,
then tt1a will hide behind the RGui window.


Now I'm trying SDI (Single Document Interface) mode instead of MDI.
(I have to restart RGui).

C:\>perl spy.pl | grep R
...
+0x00060112, 'R Console', Rgui
...

library(tcltk)
tt1 <- tktoplevel(use="0x00060112")
Now tt1 now points to the main RGui window/Console window.
(They are THE SAME THING for SDI).

To confirm that tt1 points to the RGui/Console window:
tkwm.title(tt1,"Hello")
Now Hello appears in the title bar of the RGui/Console window.

tt1a <- tktoplevel(tt1)

OK, now I don't have the same problem. I can move my mouse up from the
autohide-taskbar to the RGui/RConsole SDI window and tt1a stays there
happily.  But maybe getting the window handle/ID/pointer with spy.pl
wasn't necessary.  Maybe it was just SDI that solved it.  Let's see:

tt2 <- tktoplevel()

OK, this behaves just the same as tt1a, i.e. in SDI when just using a
plain Tk window with nothing in it, I find it hard to show evidence of
the Tk/Windows-focus annoying behaviour I've been complaining about.


OK, now back to MDI mode...

C:\>perl spy.pl | grep R
...
+0x000C0112, 'RGui', Rgui Workspace
+++0x000900F4, 'R Console', Rgui Document
++0x001F0292, 'TOOLBAR', Rgui
+++0x00150252, '', Rgui
+++0x001301AA, '', Rgui
+++0x0016026E, '', Rgui
+++0x000A027A, '', Rgui
+++0x00060276, '', Rgui
+++0x001F024C, '', Rgui
+++0x00150204, '', Rgui
+++0x000E01A4, '', Rgui
...

OK, now here's where things start to get interesting...

Now I use the R Console ID in tktoplevel(use=...) instead of
the RGui ID :

library(tcltk)
tt2 <- tktoplevel(use="0x000900F4")
The first time I did this (above), it took quite a while
(a couple of seconds), but didn't give an error or warning.

tt2a <- tktoplevel(tt2)

OK, now I can happily move my mouse from the autohiding-taskbar onto
the RGui workspace window and/or Console window while RGui is in MDI
mode and my tt2a window doesn't disappear behind RGui.

When I drag tt2a around with the mouse and release it so that it is
half-overlapping with RGui, it seems to be random which window is on top
after I release the mouse (tt2a or RGui).  Reminds me of a lecture on
flip-flops: "Avoid race-conditions at all costs!"  I don't claim this is
reproducible on all Windows systems - I haven't tried.  But I should say
that this happens in all the cases above too, I was just trying extra hard
to find annoying focus behaviour in this case, because moving the mouse
from the taskbar didn't cause a problem.

When I tried using the console window ID a second time,
RGui crashed.  Maybe I was asking for too much here...

tt3 <- tktoplevel(use="0x000900F4")

R for Windows GUI front-end has encountered a problem and needs to close. 
We are sorry for the inconvenience.
...
Please tell Microsoft about this problem.


Hope this hasn't bored you to tears!

Regards,
James



More information about the R-SIG-GUI mailing list