[R] tcltk table "validateCommand"

Dalthorp, Daniel ddalthorp at usgs.gov
Fri Jan 22 21:25:49 CET 2016


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



More information about the R-help mailing list