Yes, Peter's suggestion worked just right. Here's an example that prints out the proposed cell content and will not allow 'w' or '\n' to be entered into the table:
require(tcltk2) tt<-tktoplevel(); tfr<-tkframe(tt); tkgrid(tfr) tableData<-tclArray() valChar<-function(S){ print(S); flush.console() if (length(grep("\n",S))>0){ # return(tcl("expr", FALSE)) } else if (length(grep("w",S))>0){ # return(tcl("expr", FALSE)) } else { return(tcl("expr", TRUE))# but other kinds of space are not--> error-checking if good value is added } } table1<-tk2table(tfr, rows = 1,cols = 1, variable = tableData, validate = T, vcmd = valChar ) tcl(table1, "tag", "configure", "active", fg='black', bg='yellow') tkgrid(table1) # I believe when you define vcmd, it has the effect of reserving the % arguments for their meanings as defined "in the manual" # there's no need to think about the %'s thereafter. # for some arguments, it doesn't seem to work as expected -Dan On Thu, Nov 17, 2016 at 3:12 PM, Cleber N.Borges via R-help < r-help@r-project.org> wrote: > Hi Dan > Were you able to find a way to access the % S values ?? > > Do you have any examples of how this works? > > Thank you for your attention. > Cleber > > > Em 25/01/2016 08:21, peter dalgaard escreveu: > > It's been so long that I have forgotten how to get the package with the > table widget installed on OSX, so I cannot check things for you. However, > the canonical way to handle %S type arguments is to pass them as formal > arguments to the callback, e.g. > > > >> .Tcl.callback(function(x,y)x+y) > > [1] "R_call 0x7f9a34806ca0 %x %y" > > > > so I would assume that you should just define your > > > > CellValidation <- function(S){....} > > > > and then just access S as a variable inside the function. > > > > As far as I remember, this only works at entry completion, though. That > does sort of make sense since not every prefix of a valid entry is valid > ("1e-2" is a double, "1e-" is not). If you want to actually disable certain > keys during entry, then you have a larger task on your hand. > > > > -pd > > > > On 22 Jan 2016, at 21:25 , Dalthorp, Daniel <ddalth...@usgs.gov> wrote: > > > >> I'd like to allow users to edit data in tcltk tables and to use vcmd to > >> validate data entry, e.g., not allowing non-numbers to be entered in > >> numeric cells and not allowing '\n' to be entered in text cells. > >> > >> The problem is that I can't figure out how to "see" their data entry > before > >> it is entered, although it looks like %S can be somehow used in vcmd to > get > >> this information. > >> > >> Example: to disallow '\n' to be entered into a cell in an editable > table: > >> > >> require(tcltk2) > >> tt<-tktoplevel(); tfr<-tkframe(tt); tkgrid(tfr) > >> tableData<-tclArray() > >> tableData[[0,0]]<-"junk" > >> > >> CellValidation<-function(){ > >> > >> ## http://www.tcl.tk/community/hobbs/tcl/capp/tkTable/tkTable.html > says: > >> ## *%S* For *ValidateCommand*, it is the potential new value of the cell > >> being validated. > >> ## which is exactly what I want, but I can't figure out how to do that. > >> ## The following allows one bad character and then disallows further > edits > >> > >> testval<-tclvalue(tcl(table1,"curvalue")) > >> > >> if (length(grep("\n",testval))>0) return(tcl("expr", FALSE)) else > >> return(tcl("expr", TRUE)) > >> } > >> > >> table1<<-tk2table(tfr, > >> rows=1,cols=1, > >> selectmode="extended", > >> variable=tableData, > >> validate=T, > >> vcmd=CellValidation > >> ) > >> > >> tcl(table1,"tag","configure", "active", fg='black',bg=colors()[411]) > >> tkgrid(table1) > >> > >> How can I get the %S value rather than the tcl(table1,"curvalue")? > >> > >> Much thanks for any help. > >> > >> -Dan > >> > > > --- > Este email foi escaneado pelo Avast antivĂrus. > https://www.avast.com/antivirus > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Dan Dalthorp, PhD USGS Forest and Rangeland Ecosystem Science Center Forest Sciences Lab, Rm 189 3200 SW Jefferson Way Corvallis, OR 97331 ph: 541-750-0953 ddalth...@usgs.gov [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.