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 [[alternative HTML version deleted]]
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 <ddalthorp at 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 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
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 <ddalthorp at 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]]