3
<Ad]A  ã               @   s8   d Z ddlmZmZmZmZmZmZ G dd„ deƒZdS )a1   A generic base-class for items in a tree data structure.

An example:-

root = TreeItem(data='Root')

fruit = TreeItem(data='Fruit')
fruit.append(TreeItem(data='Apple', allows_children=False))
fruit.append(TreeItem(data='Orange', allows_children=False))
fruit.append(TreeItem(data='Pear', allows_children=False))
root.append(fruit)

veg = TreeItem(data='Veg')
veg.append(TreeItem(data='Carrot', allows_children=False))
veg.append(TreeItem(data='Cauliflower', allows_children=False))
veg.append(TreeItem(data='Sprout', allows_children=False))
root.append(veg)

é    )ÚAnyÚBoolÚ	HasTraitsÚInstanceÚListÚPropertyc               @   sp   e Zd ZdZedƒZeed ƒƒZe	Z
eeƒZed ƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ ZdS )ÚTreeItemz: A generic base-class for items in a tree data structure. Tc             C   s   | j dkrd}n
t| j ƒ}|S )z; Returns the informal string representation of the object. NÚ )ÚdataÚstr)ÚselfÚs© r   úq/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/pyface-6.1.2-py3.6.egg/pyface/viewer/tree_item.pyÚ__str__?   s    

zTreeItem.__str__c             C   s   t | jƒdkS )z! True iff the item has children. r   )ÚlenÚchildren)r   r   r   r   Ú_get_has_childrenQ   s    zTreeItem._get_has_childrenc             C   s   | j t| jƒ|ƒS )zq Appends a child to this item.

        This removes the child from its current parent (if it has one).

        )Úinsertr   r   )r   Úchildr   r   r   ÚappendX   s    zTreeItem.appendc             C   s.   |j dk	r|j j|ƒ | |_ | jj||ƒ |S )zŠ Inserts a child into this item at the specified index.

        This removes the child from its current parent (if it has one).

        N)ÚparentÚremover   r   )r   Úindexr   r   r   r   r   a   s
    
zTreeItem.insertc             C   s   d|_ | jj|ƒ |S )z! Removes a child from this item. N)r   r   r   )r   r   r   r   r   r   p   s    zTreeItem.removec             C   s    | j j|ƒ}| j||ƒ ||fS )z� Inserts a child into this item before the specified item.

        This removes the child from its current parent (if it has one).

        )r   r   r   )r   Úbeforer   r   r   r   r   Úinsert_beforex   s    zTreeItem.insert_beforec             C   s$   | j j|ƒ}| j|d |ƒ ||fS )zŒ Inserts a child into this item after the specified item.

        This removes the child from its current parent (if it has one).

        é   )r   r   r   )r   Úafterr   r   r   r   r   Úinsert_after…   s    zTreeItem.insert_afterN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Zallows_childrenr   r   r   r   r
   r   Zhas_childrenr   r   r   r   r   r   r   r   r   r   r   r   r   '   s   	r   N)	r"   Z
traits.apir   r   r   r   r   r   r   r   r   r   r   Ú<module>    s    