| 1 |
#!/usr/bin/env wize |
| 2 |
|
| 3 |
variable Users { |
| 4 |
tom { Name "Tom Brown" Sex M Age 19 Class {4 5} Rate {A 1 B 2}} |
| 5 |
mary { Name "Mary Brown" Sex F Age 16 Class {5} Rate {A 2}} |
| 6 |
sam { Name "Sam Spade" Sex M Age 19 Class {3 4} Rate {B 3}} |
| 7 |
} |
| 8 |
set t [tree create] |
| 9 |
foreach {i d} $Users { |
| 10 |
$t insert 0 -tags $i -data $d -label $i |
| 11 |
} |
| 12 |
|
| 13 |
tree op update $t tom Sex F Name "Tomi Brown" |
| 14 |
|
| 15 |
$t update tom Sex F Name "Tomi Brown" |
| 16 |
$t append sam Name " Jr" |
| 17 |
$t lappend sam Class 5 |
| 18 |
$t incr mary Age |
| 19 |
$t update tom Rate(A) 2 |
| 20 |
$t set tom Sax F |
| 21 |
$t set sam Rate(C) 0 |
| 22 |
$t incr 0->mary Age; # Address via label instead of tag. |
| 23 |
|
| 24 |
puts [time { tree op incr $t mary Age } 1000] |
| 25 |
|
| 26 |
proc ::Aupd {keys t id key op} { |
| 27 |
tclLog "AA: $t $id $key $op" |
| 28 |
if {[lsearch -exact $keys $key]<0} { error "bad key '$key' not in: $keys" } |
| 29 |
} |
| 30 |
$t trace create all * w [list ::Aupd [$t keys all]] |
| 31 |
$t incr mary Age |
| 32 |
$t set mary Sex M |
| 33 |
|
| 34 |
pack [treeview .t -tree $t] -fill both -expand y |
| 35 |
eval .t column insert end [$t keys all] |
| 36 |
puts [$t dump 0] |
| 37 |
console show |
| 38 |
|
| 39 |
|
| 40 |
variable Info { |
| 41 |
system { |
| 42 |
sol { OS Linux Version 3.4 } |
| 43 |
bing { OS Win Version 7 } |
| 44 |
gui { OS Mac Version 8 } |
| 45 |
} |
| 46 |
network { |
| 47 |
intra { Address 192.168.1 Netmask 255.255.255.0 } |
| 48 |
dmz { Address 192.168.10 Netmask 255.255.255.0 } |
| 49 |
wan { Address 0.0.0.0 Netmask 0.0.0.0 Class {A 1 B 4}} |
| 50 |
} |
| 51 |
admin { |
| 52 |
sully { Name "Sully Van Damme" Level 3 } |
| 53 |
maverick { Name "Maverick Gump" Level 1 } |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
set s [tree create] |
| 58 |
foreach {n vals} $Info { |
| 59 |
set ind [$s insert 0 -label $n] |
| 60 |
foreach {i d} $vals { |
| 61 |
if {[$s index $ind->$i]>=0} { error "Duplicate label: $i" } |
| 62 |
$s insert $ind -label $i -data $d |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
set old [$s get 0->system->bing] |
| 67 |
$s update 0->system->bing OS Linux Version 3.4 |
| 68 |
$s update 0->network->dmz Address 192.168.11 |
| 69 |
$s update 0->network->wan Class(A) 2 |
| 70 |
eval $s set 0->system->bing $old |
| 71 |
$s insert 0->admin -label linus -data { Name "Linus Torvalds" Level 9 } |
| 72 |
$s delete 0->admin->sully |
| 73 |
|
| 74 |
|
| 75 |
pack [treeview .s -tree $s -width 600] -fill both -expand y |
| 76 |
eval .s column insert end [$s keys all] |