The version of BLT used in Wize has been extensively modified to fix problems, fill in missing
functionality, and enhancing features.
3. Graphs
Graphs in should work unchanged from version 2.4 of BLT.
The only possible exception is for graphs using vectors.
Vectors
are now created in the current namespace (see below).
4. Vector
BLT vectors provide access to an array of doubles.
Several changes have been made to vector:
Vectors now uses current namespace on creation.
Add 2d matrix/array indexes (to work with tktable).
Add a new shift N expression for accessing a shifted vector.
Vector functions assume current vector if given no arg in expr.
Add a vector configure subcommand to change default options.
Honor setting -command {} to not create a command.
Add the op subcommand for accessing non-command vectors.
4.1 Matrix Vectors
The matrix feature supports 2d indexing of arrays.
There are 2 ways to create a matrix:
create a vector with dimensions like aVec(10,3) or
use the subcommand matrix numcols.
Either way results in a 2d matrix view into 1d data.
Matrix provides operations for columns such as delete,
and move.
It also supports matrix multiply and transpose.
Moreover, a matrix vector can be used with Tktable, eg:
vector create aVec(10,3)
pack [Table new .t -variable aVec -rows 10 -cols 3]
vector op seq aVec 1 end; # Now fill it!
It is also possible to display a vector in a TreeView.
This lets you take advantage of autosizing columns and enhanced
display options.
The first 2 screenshots show Tk Table being used to display
a vector and the 3rd TreeView with autoloading cell data.
The main difference is that TreeView autosizes columns and
the drop shadowing is used in column 0:
Here is the source:
# Demo comparing display of a vector in Tktable and TreeView.
proc valid {vec cell str} {
# Validate that a user edit is actually entering a double.
set rc 0
if {[set s [string trim $str]] == {} ||
[string match - $s] || [string is double $s]} { set rc 1; }
if {!$rc} { bell }
return $rc
}
proc FillTableCell {idx args} {
# Return vector value for Table cell.
variable v2
if {[string first -1 $idx]>=0} {
if {[string equal -1,-1 $idx]} {
return R\\C
}
if {[string match -1,* $idx]} {
return [string range $idx 3 end]
}
if {[string match *,-1 $idx]} {
return [string range $idx 0 end-3]
}
}
return $v2($idx)
}
proc RowTag {r} {
if {$r%2} { return altrow }
}
proc VecVarTable {} {
# Display vector in a Tktable.
set rows 10000
set cols 20
vector create v0([expr {$cols*$rows}])
vector op matrix numcols v0 $cols
vector op seq v0 1 end
Toplevel new .v
wm title .v "Vector Variable Table: v0"
set t .v.t
pack [Scrollbar new .v.sh -command "$t xview" -orient horizontal] -side bottom -fill x
pack [Scrollbar new .v.sv -command "$t yview"] -side right -fill y
Table new $t -rowtagcommand {RowTag} -anchor e -variable ::v0 \
-bg White -autoclear 1 \
-yscrollcommand ".v.sv set" -xscrollcommand ".v.sh set"
pack $t -side right -fill both -expand y
Table tag conf $t altrow -bg LightBlue
Table tag conf $t title -anchor c -relief raised -bd 1 -bg \
LightGrey -fg Black -font {Helvetica -12 bold}
}
proc VecTable {} {
# Display vector in a Tktable.
wm title . "Vector Table: v1"
set rows 10000
set cols 20
vector create v1([expr {$cols*$rows}])
vector op matrix numcols v1 $cols
vector op seq v1 1 end
set t .t
pack [Scrollbar new .sh -command "$t xview" -orient horizontal] -side bottom -fill x
pack [Scrollbar new .sv -command "$t yview"] -side right -fill y
Table new $t -anchor e -colorigin -1 -roworigin -1 \
-bg White -command {FillTableCell %C} -autoclear 1 \
-validate 1 -validatecommand {valid ::v1 %C %S} \
-usecommand 1 -cols $cols -rows $rows \
-yscrollcommand ".sv set" -xscrollcommand ".sh set" \
-titlerows 1 -titlecols 1
pack $t -side right -fill both -expand y
Table tag conf $t altcol -bg LightBlue
for {set i 0} {$i<$cols} { incr i 2} {
Table tag coltag $t altcol $i
}
Table tag conf $t title -anchor c -relief raised -bd 1 \
-bg LightGrey -fg Black -font {Helvetica -12 bold}
}
proc FillTreeCell {c r args} {
# Return vector value for TreeView cell.
variable v2
set val $v2($r,$c)
if {0 && [string first 4 $val]>0} {
return [list @img $val]
}
return $val
}
proc VecTree {} {
# Display vector in a TreeView.
set rows 10000
set cols 20
vector create v2([expr {$cols*$rows}])
vector op matrix numcols v2 $cols
vector op seq v2 1 end
Toplevel new .x
wm title .x "Vector TreeView: v2"
set t .x.t
pack [Scrollbar new .x.sh -command "$t xview" -orient horizontal] -side bottom -fill x
pack [Scrollbar new .x.sv -command "$t yview"] -side right -fill y
TreeView new $t -bg White -width 700 \
-yscrollcommand ".x.sv set" -xscrollcommand ".x.sh set"
pack $t -side right -fill both -expand y
for {set i 0} {$i<$cols} { incr i} {
TreeView column insert $t end c$i -justify right -title \
$i -bd 1 -relief raised -fillcmd [list FillTreeCell $i]
}
set cf [lindex [TreeView column names $t] 0]
TreeView style create textbox $t alt -bg LightBlue
TreeView style create textbox $t trow -bg DarkGray -fg White\
-shadow Black -priority 2 -font [TreeView cget $t -titlefont]
TreeView column conf $t $cf -style trow -title R\\C
TreeView column conf $t $cf -relief raised -bd 1
TreeView conf $t -altstyle alt -hideicons 1 -flat 1 -underline 1
for {set r 0} {$r<$rows} { incr r} {
$t insert end $r
}
}
proc Main {} {
VecVarTable
VecTable
VecTree
}
eval Main
See the matrix section of the
vector manpage for more details.
5. Trees
BLT provides a tree data structure.
Trees are used implicitly by TreeView.
Explicit use of a tree can allow multiple
widgets to display the same (or a subset of the same) tree data.
The only real change to tree in Wize
is the addition of an op
sub-command for providing non-command access.