Quote:
> I am using the BLT hiertable to present some data from a BLT tree data
> structure. How can I assign an icon to each of the tree nodes? If I
> insert nodes in the hiertable directly, e.g.:
> .h insert end "foo" -icons "$relImage $relImage"
> I have no problems, but I would rather assign the icons to the the tree
> nodes, as the tree is being displayed in several hiertables.
It's a bit cumbersome, but you can do something like this right now
with the -exec option to "find".
Here, we look for the data value "myValue". If it exists, the entry
gets a icon $image1, otherwise $image2.
proc SetIcon { widget node } {
global image1 image2
array set values [$widget entry configure $node -data]
if { [info exists values(myData)] } {
set icons $image1
} else {
set icons $image2
}
$widget entry configure $node -icons $icons
}
.h find -glob -exec { SetIcon %W %n }
I'm working on a better "find" operation that you search for nodes
given some criteria. You should be able to get a list of nodes that
contain a particular data value and then configure them as you wish.
This will work a lot like the "find" example in hiertable1.tcl. It
searches for each node with a label that ends in ".c" and colors it
green.
set nodes [.h find -glob -name *.c]
eval .h entry configure $nodes -foreground green4
Quote:
> Also, I was under the impression that the BLT hiertable was pretty
> space-efficient, but the following program:
> pack [::blt::hiertable .h -selectmode single -hideroot yes]
> for {set i 0} {$i < 100000} {incr i} {
> .h insert end "Node$i"
> }
> uses approx. 52, 10, and 5.6 MB RAM for 100000, 10000, and 1000 nodes
> respectivaly running Tcl 8.3 on Windows 2000. Am I doing something
> wrong, or is that what it is expected to use in terms of memory ?
I haven't looked at this in a while. I took your program at rearranged
it slightly to look at the different parts.
puts [exec ps au [pid]]
blt::tree create fred
set node 0
for {set i 0} {$i < 100000} {incr i} {
set node [fred insert 0 -label "Node$i" ]
}
if { [info commands tk] == "tk" } {
blt::hiertable .h -tree [fred attach]
pack .h
}
puts [exec ps au [pid]]
I used the "tree" command to create the tree so I could look at it
just through both "bltwish" and "bltsh". This let me look at the
memory consumed by just the tree also the widget.
Each node is
32 bytes for its structure
20 bytes for its hash table entry. This hashtable lets you
convert a number like 23 into a node pointer.
12 bytes for the list element holding the node.
12 bytes for each data value in the node, not including the
data itself (which is a Tcl_Obj).
? bytes for the node label
20 bytes to hash the node label.
Under the best conditions this is 54 bytes per node, or 5.4 megabytes
for 100,000 nodes. More likely it will be closer to 78+ bytes per
node. This is about what I see using Purify on a Solaris box.
There's more overhead in both the hashtables and malloc.
For 100,000 nodes malloc-ing could be improved by allocating a groups
of nodes in page sizes. But this would also mean that smaller trees
would waste the extra nodes. It's an interesting trade off that I need
to look into.
If you add the hiertable into the mix, it adds over 104 bytes per
node. This doesn't include allocations for fonts, colors, text, etc.
Purify reports around 26 megabytes used for 100,000 nodes. That
doesn't again take into account the overhead of malloc. I don't see
52 megabytes from "ps" (on my Sun it's more like 34). It starts at 6Mb
and finishes at 40Mb.
The short answer is that what you're seeing is about right. And that
I'd be happy to try to slim it down even more. There's a bit of a
trade-off in the hiertable. To display 100,000 nodes, it's too
expensive to compute the area occupied by the labels and icons
everytime you redraw. You need to cache some information in the node
itself.
Quote:
> Finally, what is the easiest way of creating a hiertable where the
> labels of the nodes can be text-edited (like the nodes in the Windows
> file explorer) ?
The functionality is there in the widget, but the bindings are broken.
Which is probably the reason there's no description of this in the
manual (There also needs to be an example too).
The "text" operation does most of this.
bind .h <ButtonPress-3> {
%W text get %x %y
focus %W.edit
}
This will popup an editing window over the entry at the current screen
coordinates. The column needs to having the -edit option set to true.
.h column configure treeView -edit yes
You can bind to editor window by its name ".h.edit" or its class
"HiertableEditor". (The bindings in ./library/bltHiertable.tcl are
broken, but you might be able to use them as a starting point.)
bind HiertableEditor <Backspace> {
if {[%W text selection present]} {
%W text delete sel.first sel.last
} else {
set index [expr [%W text index insert] - 1]
if { $index >= 0 } {
%W text delete $index $index
}
}
}
I've fixed up most the bindings, so editing will hopefully be in good
shape for the upcoming release.
Believe or not, you've been a great help to me. It really helps to
know how the widget is being used. I'm just sorry that I haven't been
much help to you.
--gah