a
    ¨ˆc  ã                   @   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u rd}n
t| j ƒ}|S )z; Returns the informal string representation of the object. NÚ )ÚdataÚstr)ÚselfÚs© r   úd/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/apptools/preferences/ui/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_childrenM   s    zTreeItem._get_has_childrenc                 C   s   |   t| jƒ|¡S )zpAppends a child to this item.

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

        )Úinsertr   r   ©r   Úchildr   r   r   ÚappendT   s    zTreeItem.appendc                 C   s.   |j dur|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   ]   s
    
zTreeItem.insertc                 C   s   d|_ | j |¡ |S )z! Removes a child from this item. N)r   r   r   r   r   r   r   r   l   s    zTreeItem.removec                 C   s    | 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_beforet   s    zTreeItem.insert_beforec                 C   s$   | 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   Ú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    