RE: [Rd] tclServiceMode: stop Tcl/Tk from updating

2005-04-26 Thread John Fox
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? 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?

Thanks,
 John


John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Duncan Murdoch
 Sent: Saturday, April 23, 2005 10:21 AM
 To: r-devel@stat.math.ethz.ch
 Subject: [Rd] tclServiceMode: stop Tcl/Tk from updating
 
 In Windows, Tcl/Tk programs running under the tcltk package 
 can update too frequently:  for exmaple, we might go through 
 a long sequence of operations to construct a complex display, 
 and in Windows each addition will be shown separately.
 
 To work around this, I've added a function tclServiceMode 
 which serves as an R interface to the Tcl_SetServiceMode 
 function in the TCL API.
 Calling tclServiceMode(on = FALSE) will stop Tcl/Tk from 
 responding to any events (redraws in particular) until 
 tclServiceMode(on = TRUE) is called. As far as I know, 
 events are queued, not lost, when handling is turned off.
 
 So far this function is only in R-devel, but I'll commit it 
 to R-patched the next chance I get.
 
 Duncan Murdoch
 
 __
 R-devel@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel

__
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] tclServiceMode: stop Tcl/Tk from updating

2005-04-26 Thread Peter Dalgaard
John Fox [EMAIL PROTECTED] writes:

 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? 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?

It's a horrible kludge (I can say so because I suggested it) and a
sign that we don't really understand the way the Tk event loop runs on
Windows. 

However, as far as I can tell, it should be harmless to use
tclServiceMode() on other platforms, as long as you ensure that
on=TRUE is used whenever you do want to process events. Mostly, you'll
just be disabling event processing at points where you weren't
handling events anyway.

If you use things like tkwait.variable() when on=FALSE, then you're in
trouble, but that goes for all platforms.

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] tclServiceMode: stop Tcl/Tk from updating

2005-04-23 Thread Duncan Murdoch
In Windows, Tcl/Tk programs running under the tcltk package can update
too frequently:  for exmaple, we might go through a long sequence of
operations to construct a complex display, and in Windows each addition
will be shown separately.
To work around this, I've added a function tclServiceMode which serves
as an R interface to the Tcl_SetServiceMode function in the TCL API.
Calling tclServiceMode(on = FALSE) will stop Tcl/Tk from responding to
any events (redraws in particular) until tclServiceMode(on = TRUE) is
called. As far as I know, events are queued, not lost, when handling is
turned off.
So far this function is only in R-devel, but I'll commit it to R-patched
the next chance I get.
Duncan Murdoch
__
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel