Prev: ANNOUNCE: Plotchart 1.8.3
Next: Announce: BWidget 1.9.2
From: Zhang Weiwu on 7 Jun 2010 04:10 Is there a way to tell if an item is detached? For use of detach: manual of ttk::treeview(3tk) pathname detach itemList Unlinks all of the specified items in itemList from the tree. The items and all of their descendants are still present and may be reinserted at another point in the tree but will not be dis‐ played. The root item may not be detached. See also: delete. I first tried $treeview exists item and found it returns true for both detached items and regular items. Then I tried $treeview parent item Realized detached item always returns empty string {}, but then, regular items who are direct children of root item also returns empty string, thus not distinguished. Then I tried $treeview index item hoping detached item returns some special value. It returns zero. But since index start from zero, the first children item also returns zero, thus not distinguished. Of course I tried to google and look up tcl.tk wiki pages before all these studies. So it seems I did pretty much home work and had to left this to the wisdom of usenet. As a last resort, I can always keep a variable to hold list of detached items the moment I detach them, but then it's not very good programming, because then the program who uses the widget knows a bit too much how the widget works. Thanks in advance!
From: Joe English on 7 Jun 2010 12:48 Zhang Weiwu wrote: > > Is there a way to tell if an item is detached? For use of detach: > [...] > I first tried > $treeview exists item > and found it returns true for both detached items and regular items. > > Then I tried > $treeview parent item > Realized detached item always returns empty string {}, but then, regular > items who are direct children of root item also returns empty string, > thus not distinguished. There is at present no way to distinguish detached items from direct children of the root. [$tv parent item] returns "" for "no parent", but "" is also the name of the root node. (Known problem, I just didn't recognize it as a problem until it was too late to fix.) > Then I tried > $treeview index item > hoping detached item returns some special value. It returns zero. That's a possibility I hadn't considered -- that'd probably work. Which would work better: returning -1 or the empty string for the index of detached items? Also note that items can be children of a detached item. Those won't count as "detached", but will not be viewable either. Do you need to detect that condition as well? A side question: what are you using detached items for? I added that method mostly because I thought it might be useful and it was to implement, but I haven't found a use case for them myself. --Joe English
From: hae on 7 Jun 2010 14:16 On 7 Jun., 18:48, Joe English <jengl...(a)fdip.bad-monkeys.org> wrote: > Zhang Weiwu wrote: > > > Is there a way to tell if an item is detached? For use of detach: > > [...] > > I first tried > > $treeview exists item > > and found it returns true for both detached items and regular items. > > > Then I tried > > $treeview parent item > > Realized detached item always returns empty string {}, but then, regular > > items who are direct children of root item also returns empty string, > > thus not distinguished. > > There is at present no way to distinguish detached items from > direct children of the root. [$tv parent item] returns "" for > "no parent", but "" is also the name of the root node. > (Known problem, I just didn't recognize it as a problem > until it was too late to fix.) > > > Then I tried > > $treeview index item > > hoping detached item returns some special value. It returns zero. > > That's a possibility I hadn't considered -- that'd probably work. > > Which would work better: returning -1 or the empty string > for the index of detached items? > > Also note that items can be children of a detached item. > Those won't count as "detached", but will not be viewable either. > Do you need to detect that condition as well? > > A side question: what are you using detached items for? > I added that method mostly because I thought it might be > useful and it was to implement, but I haven't found a use > case for them myself. > > --Joe English Hello Joe, although I am using treectrl, I would use it to set nodes visible/ invisible according to a filter criteria. Ruediger
From: hae on 7 Jun 2010 14:19 On 7 Jun., 20:16, hae <r_haer...(a)gmx.de> wrote: > On 7 Jun., 18:48, Joe English <jengl...(a)fdip.bad-monkeys.org> wrote: > > > > > > > Zhang Weiwu wrote: > > > > Is there a way to tell if an item is detached? For use of detach: > > > [...] > > > I first tried > > > $treeview exists item > > > and found it returns true for both detached items and regular items. > > > > Then I tried > > > $treeview parent item > > > Realized detached item always returns empty string {}, but then, regular > > > items who are direct children of root item also returns empty string, > > > thus not distinguished. > > > There is at present no way to distinguish detached items from > > direct children of the root. [$tv parent item] returns "" for > > "no parent", but "" is also the name of the root node. > > (Known problem, I just didn't recognize it as a problem > > until it was too late to fix.) > > > > Then I tried > > > $treeview index item > > > hoping detached item returns some special value. It returns zero. > > > That's a possibility I hadn't considered -- that'd probably work. > > > Which would work better: returning -1 or the empty string > > for the index of detached items? > > > Also note that items can be children of a detached item. > > Those won't count as "detached", but will not be viewable either. > > Do you need to detect that condition as well? > > > A side question: what are you using detached items for? > > I added that method mostly because I thought it might be > > useful and it was to implement, but I haven't found a use > > case for them myself. > > > --Joe English > > Hello Joe, > > although I am using treectrl, I would use it to set nodes visible/ > invisible according to a filter criteria. > > Ruediger Just a bit more info: So the filter ('*CUR*') would select the all nodes that have this string in it. All other nodes shall still be managed by the treeview and showed again when they match a new filter string.
From: Thomas MENEZ on 7 Jun 2010 15:31
> A side question: what are you using detached items for? > I added that method mostly because I thought it might be > useful and it was to implement, but I haven't found a use > case for them myself. > Simple use case : imagine and application featuring an undo/redo operation. Tree deletion and undoing tree deletion is easier (and faster !) to manage using detached elements instead of really destroying / recreating nodes. Been there, done that. I had to manage the list of detached elements myself :( |