ABU 21 Jun 2005
*** EDITING IN PROGRESS ***
This article introduces some new general operations that can be applied to a BWidget's Tree.
BWidget's Tree (from now on, "bw-tree") lacks in operations for persistance-storage and for deep (recursive) copy
This article provides a tcl-code implementation and examples aimed to overcome these lacks.
Well, I think we can start with a botanical metaphor ...
If we think at a bw-tree as a live tree, we could start thinking at a dried-tree as a synthetized clone of a bw-tree, i.e. a new kind of a copy of (a part of) a bw-tree.
This dried-tree is not a bw-tree; it is a derived from a bw-tree, but it cannot be handled with the usual bw-tree methods.
But there are many things we can do with a dried-tree :
We can graft a dried-tree in a live tree. Once grafted, the dried-tree becomes a 'live' part of the tree.
Moreover, we can also store the dried-tree in a box (a file) so that the bw-tree can be revitalized when the application re-starts ( or in a new application )
That's the leading metaphor, now let's develope the idea ...
Let's call them dried-trees.
but they can also be used for grafting, that is, they can be inserted under a node of an existing bw-tree.
Summarizing, we need new methods to:
Before looking at the core tcl-code for these new operations, I think it is important to look at some use cases:
# # this is our basic sample tree # package require BWidget pack [Tree .tree] .tree insert end root a -text Aaa .tree insert end root b -text Bbb .tree insert end root c -text Ccc .tree insert end a a1 -text Aa1 .tree insert end a a2 -text Aa2 .tree insert end c c1 -text Cc1 .tree insert end c c2 -text Cc2 # some decorations ... set font1 {Courier 10 bold} set font2 {Times 10 italic} set font3 {Helvetica 10 bold} .tree itemconfigure a -font $font1 -fill blue .tree itemconfigure a1 -font $font1 -fill blue .tree itemconfigure a2 -font $font1 -fill blue .tree itemconfigure b -font $font2 -fill gray .tree itemconfigure c -font $font3 -fill red .tree itemconfigure c1 -font $font3 -fill red .tree itemconfigure c2 -font $font3 -fill red
# clone the 'c' subtree set myDriedTree [BWidget::Tree::clone .tree c]
BWidget::Tree::graft $myDriedTree .tree "a" 1
toplevel .new ; pack [Tree .new.tree] BWidget::Tree::graft $myDriedTree .new.tree root end
BWidget::Tree::store $myDriedTree driedA.dat
set myDriedTree [BWidget::Tree::load driedA.dat] # .. then you can start grafting in a bw-tree ....
The core tcl-code
.. to do ...
#---