TreeEditor/TreeNode

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

TreeEditor/TreeNode

Thomas Wiecki
Hi,

I was wondering whether I could have an Instance be a child of a root
TreeNode (instead of a list).

E.g.:

class Root(HasTraits):
    child1 = Instance(Child1)
    child2 = Instance(Child2)

Child itself has a List and other stuff that displays fine in a tree.

Normally I would create a TreeNode with children='child1' but it
expects a list. I want to create the following tree from this:

Root
+- child1
    +-...
+- child2
    +-...

How could I do this? Please let me know if my question isn't clear.

Thanks,
Thomas
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: TreeEditor/TreeNode

Brennan Williams
On 28/03/2012 3:40 a.m., Thomas Wiecki wrote:

> Hi,
>
> I was wondering whether I could have an Instance be a child of a root
> TreeNode (instead of a list).
>
> E.g.:
>
> class Root(HasTraits):
>      child1 = Instance(Child1)
>      child2 = Instance(Child2)
>
> Child itself has a List and other stuff that displays fine in a tree.
>
> Normally I would create a TreeNode with children='child1' but it
> expects a list. I want to create the following tree from this:
>
> Root
> +- child1
>      +-...
> +- child2
>      +-...
>
> How could I do this? Please let me know if my question isn't clear.
You could put child1 into a child1list=List(Instance(child1))and
similarly for child2. They would just be lists of only one item.
Then you could use

TreeNode(
     node_for = [ parent],
     children='child1list',
     label='treename',
     menu=Menu(....),
     view=View(....),
     add=[child1],
),
TreeNode(
     node_for=[child1],
     children='child1offspringlist',
     label='treename',
     menu=Menu(....),
     view=View(....),
     add=[child1offspring],
),

etc etc.

where treename is a Property or Str in each HasTraits object that
provides the name you want to see for that node in the tree.

Does this help?

Brennan
> Thanks,
> Thomas
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: TreeEditor/TreeNode

ericjmcd
I've come upon the same issue.  I don't want to modify a model to put an Instance in a List-of-one just for the TreeEditor, especially since I've gone through a lot of trouble to keep the model and view code very separate.  For a very brief moment, I looked at creating a TreeNodeInstance class (or something) that allowed for such cases but realized I don't have the time to invest in even finding out if a hack like that would work.

Any chance Enthought has considered adding an option for this case?

Thanks,
Eric