|
From: Joe E. <jen...@fl...> - 2004-09-25 07:11:06
|
Bryan Oakley wrote:
> Joe English wrote:
> > The Tk way of doing this would be a linked -variable;
> > but for the tree widget the contents of the variable
> > would have to be a fairly complicated structure.
>
> Couldn't it just be an array (or dict)?
>
> array set data {
> 0 "/"
> 0,0 "usr"
> 0,0,0 "local"
> 0,0,0,0 "bin"
> 0,0,0,0,1 "tclkit"
> 0,0,0,0,2 "tclsh"
> 0,0,0,0,3 "wish"
> 0,0,0,1 "lib"
> 0,1 "etc"
> 0,1,0 "hosts"
> 0,1,1 "passwd"
> ...
> }
There's also the column -values, plus auxilliary data like
the open/closed state and the -image (those might be part of
the display model instead of the data model).
Also: tree location paths don't make for good keys (as the
above example seems to do), since they change when earlier
items are inserted and deleted.
The tree data model *might* fit in a nested dictionary,
with distinguished keys -text and -children and column names
as the remaining keys. But you don't get variable traces
on individual dictionary elements (that's the whole point
of dicts), so you'd have to reconstitute the entire
display model whenever the linked -variable changes.
An array -variable would probably work better. But no matter
what scheme is used to wedge the tree structure into an array,
it's highly unlikely to match any application data structures so
it'll still take work to schlep data in and out. IOW, it's not
like an [entry] or a [checkbutton] where the linked -variable
is directly usable. (At least that's been my experience with
Tktable -- I *never* have data in the exact form that it wants,
it always requires a simple transformation of some sort.)
Any compelling use cases for this?
--Joe English
jen...@fl...
|