Hi, I've been playing with the tcltk package. It's very nice to have access to buttons, menus etc. now. Thank you! Alas, I also have questions: In Tcl everything is a string [*]. This is not the case in R, of course. So why are return values of tk commands still strings? (Is there any other reason than speed or "package is work in progress"?) Example: > tt <- tktoplevel () > tkwinfo ("width", tt) [1] "200" Could (Should?) be: > tt <- tktoplevel () > tkwinfo ("width", tt) [1] 200 with > tkwidth <- function (widget) as.numeric (tkcmd ("winfo", "width", widget)) Maybe a better example is the use of logical results: > if (tkwinfo ("exists", tt)) cat ("exists\n") Error in if (tkwinfo("exists", tt)) cat("exists\n") : argument of if(*) is not interpretable as logical Huh? Here you might have expected: > if (tkexists (tt)) cat ("exists\n") exists with > tkexists <- function (widget) (tkcmd ("winfo", "exists", widget) == "1") One problem is that the number of functions just explodes, so it might be better to wrap them into one enchillada? > tkwinfo <- function (widget, what="exists", ...) switch (what, exists=tkcmd("winfo", "exists", widget)=="1", ismapped=tkcmd("winfo", "ismapped", widget)=="1", width=as.numeric (tkcmd("winfo", "width", widget)), height=as.numeric (tkcmd("winfo", "height", widget)), tkcmd ("winfo", what, widget, ...)) (The other problem is that tkcmd("winfo",...) may fail.) Oh, while I'm at it: There is no tkupdate: > tkupdate <- function (idletasks=FALSE) if (idletasks) tkcmd ("update", "idletasks") else tkcmd ("update") (which is essential to making sure that a window is mapped before its width or height is queried.) That's trivial if you have hacked Tcl/Tk before -- so who is the package tlctk aimed at? Regards, -tom [*] Nowadays, they have glorified strings into objects. Anywho... -- mailto:tov@ece.cmu.edu (Tom Vogels) Tel: (412) 268-6638 FAX: -3204 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2001-Feb-03 20:05 UTC
[Rd] tk non-widget commands (esp. update and winfo)
Thomas Vogels <tov@ece.cmu.edu> writes:> Hi, > > I've been playing with the tcltk package. It's very nice to have > access to buttons, menus etc. now. Thank you! > > Alas, I also have questions: In Tcl everything is a string [*]. This > is not the case in R, of course. So why are return values of tk > commands still strings? (Is there any other reason than speed or > "package is work in progress"?)The latter. Also to some extent the fact that it requires more knowledge about the content of the return value. The argument passing scheme is as you can see quite general and essentially ignorant of the routines that are called. In essence the issue is that it is fairly easy to convert whatever to strings, but harder the other way around. So for the first iteration of the package, the idea would be to have the user do the necessary as.xxx conversions of return values.> One problem is that the number of functions just explodes, so it might > be better to wrap them into one enchillada? > > > tkwinfo <- function (widget, what="exists", ...) > switch (what, > exists=tkcmd("winfo", "exists", widget)=="1", > ismapped=tkcmd("winfo", "ismapped", widget)=="1", > width=as.numeric (tkcmd("winfo", "width", widget)), > height=as.numeric (tkcmd("winfo", "height", widget)), > tkcmd ("winfo", what, widget, ...)) > > (The other problem is that tkcmd("winfo",...) may fail.) > > Oh, while I'm at it: There is no tkupdate: > > tkupdate <- function (idletasks=FALSE) > if (idletasks) tkcmd ("update", "idletasks") else tkcmd ("update") > > (which is essential to making sure that a window is mapped before its > width or height is queried.) That's trivial if you have hacked Tcl/Tk > before -- so who is the package tlctk aimed at?Tcl/Tk hackers of course, the author of the package not being one... Basically, the plan is to add stuff as it becomes necessary to do useful things, so feedback and suggestions from developers are always welcome. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._