[Rd] tclServiceMode: stop Tcl/Tk from updating
Duncan Murdoch
murdoch at stats.uwo.ca
Tue Apr 26 19:18:32 CEST 2005
John Fox wrote:
> Dear Duncan,
>
> I hope that some follow-up questions are in order:
>
> In the Rcdmr package, there is a pair of functions for initializing and
> completing dialogs:
>
> initializeDialog <- defmacro(window=top, title="", offset=10,
> expr={
> window <- tktoplevel(borderwidth=10)
> tkwm.title(window, title)
> position <- if (is.SciViews()) -1 else commanderPosition() # +PhG
> position <- if (any(position < 0)) "-50+50"
> else paste("+", paste(offset + position, collapse="+"), sep="")
> tkwm.geometry(window, position)
> }
> )
>
> dialogSuffix <- defmacro(window=top, onOK=onOK, rows=1, columns=1,
> focus=top,
> bindReturn=TRUE, preventGrabFocus=FALSE, preventDoubleClick=FALSE,
> expr={
> for (row in 0:(rows-1)) tkgrid.rowconfigure(window, row, weight=0)
> for (col in 0:(columns-1)) tkgrid.columnconfigure(window, col,
> weight=0)
> .Tcl("update idletasks")
> tkwm.resizable(window, 0, 0)
> if (bindReturn) tkbind(window, "<Return>", onOK)
> if (getRcmdr("double.click") && (!preventDoubleClick))
> tkbind(window, "<Double-ButtonPress-1>", onOK)
> tkwm.deiconify(window)
> # focus grabs appear to cause problems for some dialogs
> if (GrabFocus() && (!preventGrabFocus)) tkgrab.set(window)
> tkfocus(focus)
> tkwait.window(window)
> }
> )
>
> (Both of these are "macro-like" in the sense of Thomas Lumley's R-news
> article.)
>
> If I understand you correctly, I could improve the R Commander's stability
> under windows by putting tclServiceMode(on = FALSE) at the beginning of
> initializeDialog(), and tclServiceMode(on = TRUE) at the end of
> dialogSuffix(). Is that correct?
I don't know that it will affect stability. What it is intended to do
is to make your dialogs appear on screen fully drawn, rather than
letting the user see you add each widget. (In fact I hope it has no
effect on stability, because I'm worried it would only make things worse...)
The only change I would make to your suggestion (assuming I understand
what your code does) is to save the return value from the first call,
and use it as the value in the second, i.e.
.savemode <- tclServiceMode(on = FALSE)
...
tclServiceMode(on = .savemode)
This would allow you to nest these calls, if you did it in a way that
didn't stomp on .savemode.
>If so, is there any harm in doing this on
> other platforms, or should I test for Windows? Finally, do you mind if I put
> tclServiceMode() in the Rcmdr package for the time-being, or would it just
> be better to wait for R 2.1.1?
As Peter said, this should be harmless on other platforms. Copying the
code into Rcmdr would be fine in the short term, but I expect there'll
be a 2.1.1 release soon, which will have it.
Duncan Murdoch
More information about the R-devel
mailing list