Cleber N.Borges
2015-Dec-18 00:07 UTC
[R] How to use the options "usecommand" and "command" of tktable?
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
Cleber Borges
2015-Dec-18 10:31 UTC
[R] How to use the options "usecommand" and "command" of tktable?
# only a update the R code (with strange behavior) library( tcltk ); tclRequire( "Tktable" ) top <- tktoplevel() tcl('variable', 'myarray') tcl('array', 'unset', 'myarray') x <- 0 tabCmd <- function() { x <<- x + 1 return( as.tclObj( paste(x) ) ) } tab <- tkwidget( top, 'table', rows=2, cols=2, command=tabCmd ) tcl('pack', tab, expand=TRUE, fill='both' ) tcl( tab, 'index', 'topleft' ) tcl( tab, 'index', 'bottomright' ) tcl( tab, 'get', '0,0' ) tcl( tab, 'get', '0,1' ) tcl( tab, 'get', '1,0' ) tcl( tab, 'get', '1,1' ) x Em 17/12/2015 22:07, Cleber N.Borges escreveu:> 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 > > ______________________________________________ > 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. >--- Este email foi escaneado pelo Avast antiv?rus. https://www.avast.com/antivirus