#> table trk Tktable #. -rows 16 -cols 8 -height 16 -width 8 #. -colwidth 3 -drawmode slow -sparsearray 0 -titlerows 0 -titlecols 1 #. -selectmode extended -selecttype row -resizeborders none #. -colstretchmode unset -rowstretchmode none -rowtagcommand {t_rowtags} #. -coltagcommand {t_coltags} -autoclear 1 -command {t_command %r %c %s} #. -validate 1 -validatecommand {t_validate %S} #. @element t_set proc t_set {r c v} { } array set table { rows 16 cols 8 wid .- msgid {} cmdset {element %r %c %s} cmdget {element %r %c} coltype {t1 t0 t0 t0 t0 t0 t0 t0} colw {3 3 3 3 3 3 3 3} valmin 0 valmax 127 data {} } proc clip_val {v} { global table if {$v < $table(valmin)} {return $table(valmin)} if {$v > $table(valmax)} {return $table(valmax)} return $v } proc t_resize_data {} { global table set old $table(data) set table(data) [list] for {set x 0} {$x < $table(cols)} {incr x} { for {set y 0} {$y < $table(rows)} {incr y} { lappend table(data) "" } } } proc t_rowtags {row} { if {$row%4==0} { return oddrow } } proc t_coltags {col} { global table if {$col == [expr $table(cols)-1]} { return disabled } elseif {$col >= 1} { return [lindex $table(coltype) [expr $col-1]] } } proc t_command {r c v} { global table set index [expr $r * $table(cols) + $c] if {$v == ""} { if {$c == 0} { return [expr $r+1]; } else { .< [t_do_cmd cmdget $r $c $v] .> return [lindex $table(data) $index] } } else { .< [t_do_cmd cmdset [expr $r+1] $c $v] .> lset table(data) $index $v } } proc t_do_cmd {cmd r c v} { global table set m [list] lappend m $table(msgid) foreach vv $table($cmd) { if {"$vv" == "%r"} { lappend m $r } elseif {"$vv" == "%c"} { lappend m $c } elseif {"$vv" == "%s"} { lappend m $v } else { lappend m $vv } } return "[join $m { }];" } proc t_validate {new} { global CURRENT set clipped [clip_val $new] if {$new == {}} { return 1 } elseif {$new != $clipped} { set CURRENT $clipped return 0 } else { return 1 } } set colw [list] ; set j 0 lappend colw 0 ; lappend colw 2 foreach {w} $table(colw) {incr j; lappend colw $j; lappend colw $w} eval $table(wid) width $colw $table(wid) tag config oddrow -bg gray -fg black $table(wid) tag config t0 $table(wid) tag config t1 -bg green $table(wid) tag config sel -bg blue -fg white $table(wid) tag config active -bg blue -fg white $table(wid) tag config disabled -state disabled grid $table(wid) -row 0 -column 0 -sticky news grid columnconfig . 0 -weight 1 grid rowconfig . 0 -weight 1 entry .cmd grid .cmd -row 1 -sticky ew bind $table(wid) {focus .cmd; break} bind $table(wid) {break} bind .cmd \ {focus $table(wid); event generate $table(wid) ; focus .cmd; break} bind .cmd \ {focus $table(wid); event generate $table(wid) ; focus .cmd; break} t_resize_data