BLT hiertable questions 
Author Message
 BLT hiertable questions

Hi,

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.

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 ?

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) ?

Thanks for your help!

Cheers, Michael...
--
-----------------------------------------------------------------------
  Michael Thomsen  --  Managing Director, M.Sc. Computer Science

  Ideogramic ApS, Science Park Aarhus, DK-8000 Aarhus C, Denmark

  Direct phone: +45 86 20 20 11 #2703    Mobile: +45 22 63 02 75
-----------------------------------------------------------------------



Sun, 04 May 2003 03:00:00 GMT  
 BLT hiertable questions

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



Mon, 05 May 2003 03:00:00 GMT  
 BLT hiertable questions

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".

> [...]

Yep, I can see how that is possible. But I would still have to invoke
the find operation for all hiertables that display the data tree just
after having inserted a new node into the data tree. And since this
would have to be done everewhere in the code where I add tree nodes, its
not really ideal.

What I would prefer would be some kind of event hooks on the hiertable
itself, somewhat like the trace operations on the tree. Assume e.g. that
the hiertable would allow me to give it a procedure that it would
evaluate every time a node was inserted into the hiertable. I could then
in this proc write my own code that would read a data field on the tree
node, look for an icon in this field, and then set the icon if one was
present. This would allow me to setup up this code once for all, and
icons would then be handled automatically when tree nodes were created.

Quote:

> > Also, I was under the impression that the BLT hiertable was pretty
> > space-efficient, but the following program:
> > [...]

> 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.
> [...]

OK. I can understand that. And the most important thing for me is still
that it is fast.

- Show quoted text -

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

I tried the following:

    package require BLT

    ::blt::hiertable .h
    pack .h

    .h column configure treeView -edit yes
    bind .h <ButtonPress-3> {
       %W text get %x %y
       focus %W.edit
    }

But that causes my Wish shut down abruptly when I right-click the node!
What am I doing wrong?

Quote:

> I've fixed up most the bindings, so editing will hopefully be in good
> shape for the upcoming release.

Great. Do you have a prognosis on when will that release be ready?

Quote:
> 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

Oh, no. You have been very helpful!

Thanks, Michael...
--
-----------------------------------------------------------------------
  Michael Thomsen  --  Managing Director, M.Sc. Computer Science

  Ideogramic ApS, Science Park Aarhus, DK-8000 Aarhus C, Denmark

  Direct phone: +45 86 20 20 11 #2703    Mobile: +45 22 63 02 75
-----------------------------------------------------------------------



Mon, 19 May 2003 03:00:00 GMT  
 BLT hiertable questions
One more question regarding layout: It it possible to make the selection
in a hiertable look like the selection in a Windows treeview? That is,
only the area surrounding the text, and not the whole "line", should be
marked (somewhat like in a hierbox), and the mark should consist of a
filled blue backgound.

Regards, Michael...
--
-----------------------------------------------------------------------
  Michael Thomsen  --  Managing Director, M.Sc. Computer Science

  Ideogramic ApS, Science Park Aarhus, DK-8000 Aarhus C, Denmark

  Direct phone: +45 86 20 20 11 #2703    Mobile: +45 22 63 02 75
-----------------------------------------------------------------------



Mon, 19 May 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. BLT hiertable questions

2. blt::hiertable question

3. editing data in blt's hiertable widget

4. Problem with BLT hiertable

5. Changing background colour of BLT hiertable

6. BLT 2.4s: hiertable problems

7. BLT2.4u Hiertable core dumps

8. BLT2.4o Hiertable

9. BLT: the instruction order is surprisingly relevant ( BLT 2.4 tk 8.0.5 windows NT)

10. ANNOUNCE: BLT busy for Windows, Tk 8.0, BLT 8.0 unofficial

11. BLT Zoom Stack question

12. BLT graph question - tilting at axis labels...

 

 
Powered by phpBB® Forum Software