[Rd] stuck tcltk scrollbars under Windows XP

Marc Schwartz mschwartz at medanalytics.com
Fri Jun 6 09:55:37 MEST 2003


>-----Original Message-----
>From: r-devel-bounces at stat.math.ethz.ch 
>[mailto:r-devel-bounces at stat.math.ethz.ch] On Behalf Of John Fox
>Sent: Friday, June 06, 2003 6:23 AM
>To: r-devel at stat.math.ethz.ch
>Subject: [Rd] stuck tcltk scrollbars under Windows XP
>
>
>Dear R-devel list members,
>
>I've encountered a problem with my Rcmdr package under Windows 
>XP and could 
>use some advice:
>
>The Rcmdr package uses the tcltk package to create menus and 
>dialog boxes. 
>My standard procedure when a dialog is created is to grab the 
>focus -- e.g., by
>
>     tkfocus(top)
>     tkgrab(top)
>
>(Here, top is a top-level window -- say, containing one or more 
>scrollbars.) When the window is closed, I release the focus, 
>destroy the 
>window, and return the focus to another window -- e.g.,
>
>     tkgrab.release(top)
>     tkdestroy(top)
>     . . .
>     tkfocus(.commander)
>
>(Here .commander is a top-level window residing in the global 
>environment.)
>
>This procedure works fine under Windows 2000 -- where I've 
>done most of the 
>testing of the Rcmdr package under Windows -- but I received a 
>report of a 
>problem from a Windows XP user, who noted that scrollbars tend to get

>stuck. I was able to reproduce the problem intermittently on 
>an XP system, 
>and found that the problem appears to go away when I remove 
>the calls to 
>tkgrab() and tkgrab.release().
>
>You can test for the problem with the following code:
>
>     window1 <- tktoplevel()
>     window2 <- tktoplevel()
>     xFrame <- tkframe(window2)
>     xScroll <- tkscrollbar(xFrame, repeatinterval=5, 
>command=function(...) 
>tkyview(xBox, ...))
>     xBox <- tklistbox(xFrame, height=4,
>         selectmode="single", background="white", 
>exportselection="FALSE",
>         yscrollcommand=function(...) tkset(xScroll, ...))
>     for (x in letters) tkinsert(xBox, "end", x)
>     onOK <- function() {
>         tkgrab.release(window2)
>         tkfocus(window1)
>         tkdestroy(window2)
>         }
>     OKbutton <- tkbutton(window2, text="OK", width="12", 
>command=onOK, 
>default="active")
>     tkgrid(xBox, xScroll, sticky="nw")
>     tkgrid.configure(xScroll, sticky="ns")
>     tkgrid(xFrame, sticky="w")
>     tkgrid(OKbutton, sticky="w")
>     tkselection.set(xBox, 0)
>     tkbind(window2, "<Return>", onOK)
>     tkfocus(window2)
>     tkgrab(window2)
>
>I find that I can make the scrollbar stick under Windows XP by 
>repeatedly 
>and rapidly pressing the scroll-down button. As mentioned, 
>removing the 
>calls to tkgrab() and tkgrab.release() seems to eliminate the
problem.
>
>I wonder whether anyone else has encountered this problem or has any 
>insight into its source. Am I doing something wrong here? I 
>could simply 
>remove the calls to tkgrab() and tkgrab.release() throughout 
>the package, 
>or make them optional, perhaps checking for Windows XP via 
>shell("ver", 
>intern=TRUE)[2], but I'd rather solve the problem.
>
>I've also had a report of tk windows failing to stay on top of 
>the R-GUI 
>SDI Console in Windows XP, but I haven't been able to duplicate this 
>problem, and it has never occurred in my testing under Windows 
>2000 and 
>Linux. Has anyone else experienced this behaviour?
>
>
>Thanks,
>  John


Professor Fox,

I can duplicate the scroll bar problem on WinXP Pro using R 1.7.1
Beta.

Try modifying the final lines in your code to the following and see if
it works under Win2k:

...
tkbind(window2, "<Return>", onOK)

# Here is the change
tkwm.deiconify(window2)
tkgrab.set(window2)
tkfocus(xBox)
tkwait.window(window2)

Using the above code, I seem to have eliminated the scroll bar
problem. This is the approach that I took with the tkSelectList()
function which I sent to you during our offline exchange.

Note that I have tkfocus() set to the scrollbar xBox and not to
window2, which results in the mouse scroll wheel working, whereas it
does not when the focus is set to window2.

Lastly, by using the tkwm.deiconify(...) function window2 is raised to
obtain focus.  That was a quirk that I found by experimentation.

HTH,

Marc Schwartz



More information about the R-devel mailing list