[R] How to use the options "usecommand" and "command" of tktable?

Cleber N.Borges klebyn at yahoo.com.br
Fri Dec 18 01:07:34 CET 2015


How to capture the output from the "command" option of tktable and how 
to send input to it?

As far as I understand, the most appropriate way to use the tktable is 
through the flag usecommand and command.

It fires the string information and cell coordinates and wait for a new 
string to set a new value.

It's I understood by example in pure TCL given in reference [1].

Is there how to translate this code to R?

I believe that the signs of tktable not reach the level of R and will 
need to be accessed by the lower level commands. But how?

Thank you in advance for dedicated attention.

cleber

###
[1] - http://dbaspot.com/object/showthread.php?t=785221&pagenumber=

### my R code
library( tcltk )
tclRequire( "Tktable" )
tclServiceMode( FALSE )
top <- tktoplevel()

TableCommand <- function( x=NULL ) {
     cat( class( x ), '\n' )
     cat( x , '\n' )
}

tab <- tkwidget( top, 'table', rows=2, cols=2, usecommand=TRUE, 
command=TableCommand )
tcl('pack', tab, expand=TRUE, fill='both' )
tclServiceMode( TRUE )

### TCL from [1]
package require Tktable

namespace eval ::test {}

proc ::test::build_table {} {

catch {destroy .test}
variable top [toplevel .test]

variable myarray
array unset myarray

variable table [table $top.table \
-rows 5 \
-height 5 \
-cols 2 \
-command "[namespace current]::TableCommand %S %r %c"]

pack $table -expand true -fill both
$table tag config complete -background blue
}

proc ::test::TableCommand {S r c} {

variable table
variable myarray

if {$S != ""} {
# I only want integers in my cells!
puts "\"$S\" into $r,$c ?"

if {[string is integer -strict $S]} {
$table tag cell complete "$r,$c"
set myarray($r,$c) $S
} else {
$table tag cell !complete "$r,$c"
array unset myarray $r,$c
}
}
if {[info exists myarray($r,$c)]} {
return $myarray($r,$c)
}
return "$r,$c"
}

::test::build_table




---
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus



More information about the R-help mailing list