a
    §ˆcN­  ã                   @   sì   d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlm Z m!Z! e "e#¡Z$G dd„ dej%ƒZ&G dd„ deƒZ'dS )ú. A tree control with a model/ui architecture. é    N)ÚAnyÚBoolÚCallableÚEnumÚEventÚInstanceÚIntÚListÚPropertyÚStrÚTuple)ÚFilter)ÚKeyPressedEvent)ÚSorter)Ú	TreeModel)ÚGUI)Ú	ImageList)ÚLayoutWidget)ÚPythonDropSourceÚPythonDropTargetc                       s,   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡  ZS )Ú_Treez¤ The wx tree control that we delegate to.

    We use this derived class so that we can detect the destruction of the
    tree and remove model listeners etc.

    c                    s   t ƒ j|||d� || _dS )z Creates a new tree. )ÚstyleN)ÚsuperÚ__init__Ú_tree)ÚselfÚtreeÚparentÚwxidr   ©Ú	__class__© úY/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/ui/wx/tree/tree.pyr   5   s    z_Tree.__init__c                    s   | j  | j j¡ tƒ  ¡  dS )z Destructor. N)r   Ú_remove_model_listenersÚmodelr   ÚDestroy©r   r    r"   r#   r&   >   s    z_Tree.Destroy)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r&   Ú__classcell__r"   r"   r    r#   r   )   s   	r   c                       s”  e Zd ZdZejejB ejB Ze	e
eƒƒZedddƒZe
edƒZeeƒZe	eƒZeddƒZedƒZedƒZedƒZe
eƒZeZee
eƒƒZeZ eZ!eZ"eZ#eZ$eZ%e&d	ƒZ'e(Z)ed
ƒZ*e+e,e,ƒZ-d}‡ fdd„	Z.dd„ Z/dd„ Z0dd„ Z1dd„ Z2d~dd„Z3dd„ Z4dd„ Z5dd„ Z6dd „ Z7d!d"„ Z8d#d$„ Z9d%d&„ Z:d'd(„ Z;d)d*„ Z<d+d,„ Z=d-d.„ Z>d/d0„ Z?d1d2„ Z@d3d4„ ZAd5d6„ ZBd7d8„ ZCd9d:„ ZDd;d<„ ZEd=d>„ ZFd?d@„ ZGdAdB„ ZHdCdD„ ZIdEdF„ ZJdGdH„ ZKdIdJ„ ZLdKdL„ ZMddMdN„ZNd€dOdP„ZOdQdR„ ZPdSdT„ ZQdUdV„ ZRdWdX„ ZSdYdZ„ ZTd[d\„ ZUd]d^„ ZVd_d`„ ZWdadb„ ZXdcdd„ ZYdedf„ ZZdgdh„ Z[didj„ Z\dkdl„ Z]dmdn„ Z^dodp„ Z_dqdr„ Z`dsdt„ Zadudv„ Zbdwdx„ Zcdydz„ Zdd{d|„ Ze‡  ZfS )�ÚTreer   Ú
appearanceÚonÚoffr"   ÚsingleÚextendedTzAnonymous treeF©é   r4   c                    s@   |  dd¡}tƒ jf ||dœ|¤Ž |r<|  ¡  t dt¡ dS )a   Creates a new tree.

        'parent' is the toolkit-specific control that is the tree's parent.

        'image_size' is a tuple in the form (int width, int height) that
        specifies the size of the images (if required) displayed in the tree.

        ÚcreateT)r   Ú_image_sizezšautomatic widget creation is deprecated and will be removed in a future Pyface version, use create=False and explicitly call create() for future behaviourN)Úpopr   r   r5   ÚwarningsÚwarnÚPendingDeprecationWarning)r   r   Z
image_sizeZtraitsr5   r    r"   r#   r   ¦   s    	üzTree.__init__c                 C   sH  t | |tj|  ¡ d� | _}| tj| j¡ | tj| j	¡ | tj
| j¡ | tj| j¡ | tj| j¡ | tj| j¡ | tj| j¡ | tj| j¡ | tj| j¡ | tj| j¡ | tj| j¡ | tj| j¡ | tj| j¡ |  t!| ƒ¡ t"| j#Ž | _$| j%�r| &| j$¡ i | _'| j(d u�r8|  )| j(¡ |  *| j+¡ |S )N)r   r   ),r   ÚwxZID_ANYÚ
_get_styleÚcontrolZBindÚEVT_CHARÚ_on_charÚEVT_LEFT_DOWNÚ_on_left_downÚEVT_RIGHT_DOWNÚ_on_right_downÚEVT_LEFT_DCLICKÚ_on_tree_item_activatedÚEVT_TREE_ITEM_COLLAPSINGÚ_on_tree_item_collapsingÚEVT_TREE_ITEM_COLLAPSEDÚ_on_tree_item_collapsedÚEVT_TREE_ITEM_EXPANDINGÚ_on_tree_item_expandingÚEVT_TREE_ITEM_EXPANDEDÚ_on_tree_item_expandedÚEVT_TREE_BEGIN_LABEL_EDITÚ_on_tree_begin_label_editÚEVT_TREE_END_LABEL_EDITÚ_on_tree_end_label_editÚEVT_TREE_BEGIN_DRAGÚ_on_tree_begin_dragÚEVT_TREE_SEL_CHANGEDÚ_on_tree_sel_changedÚEVT_TREE_DELETE_ITEMÚ_on_tree_delete_itemZSetDropTargetr   r   r6   Ú_image_listÚshow_imagesZAssignImageListÚ_node_to_id_mapÚrootÚ_add_root_nodeÚ_add_model_listenersr%   )r   r   r   r"   r"   r#   Ú_create_control½   s2    ÿzTree._create_controlc                 C   s   | j jS )z$ Returns the root node of the tree. ©r%   r[   r'   r"   r"   r#   Ú	_get_rootö   s    zTree._get_rootc                 C   s   || j _dS )z! Sets the root node of the tree. Nr_   )r   r[   r"   r"   r#   Ú	_set_rootû   s    zTree._set_rootc                 C   s"   |   |¡}|dur| j |¡ dS )z Collapses the specified node. N)Ú	_get_wxidr=   ÚCollapse©r   Únoder   r"   r"   r#   Úcollapse  s    
zTree.collapseNc                 C   s(   |   |¡}|dur$|| _| j |¡ dS )a   Edits the label of the specified node.

        If a callback is specified it will be called when the label edit
        completes WHETHER OR NOT the label was actually changed.

        The callback must take exactly 3 arguments:- (tree, node, label)

        N)rb   Ú_label_edit_callbackr=   Z	EditLabel)r   re   Úcallbackr   r"   r"   r#   Ú
edit_label  s    

zTree.edit_labelc                 C   s"   |   |¡}|dur| j |¡ dS )z Expands the specified node. N)rb   r=   ÚExpandrd   r"   r"   r#   Úexpand  s    
zTree.expandc                 C   s@   | j r|  |  | j¡¡ n"|  | j¡D ]}|  |  |¡¡ q&dS )z! Expands every node in the tree. N)Ú	show_rootÚ_expand_itemrb   r[   Ú_get_children)r   Úchildr"   r"   r#   Ú
expand_all!  s    zTree.expand_allc                 C   s8   |   |¡}|dur0| j |¡}| j |¡\}}nd}|S )zŸ Returns the parent of a node.

        This will only work iff the node has been displayed in the tree.  If it
        hasn't then None is returned.

        N)rb   r=   ZGetItemParentÚGetItemData)r   re   r   ÚpidÚ	populatedr   r"   r"   r#   Ú
get_parent+  s    	
zTree.get_parentc                 C   s>   |   |¡}|dur6|| ju r(| js(d}q:| j |¡}nd}|S )z8 Returns True if the node is expanded, otherwise False. NTF)rb   r[   rl   r=   Ú
IsExpanded)r   re   r   Úis_expandedr"   r"   r#   rv   B  s    
zTree.is_expandedc                 C   s(   |   |¡}|dur | j |¡}nd}|S )z8 Returns True if the node is selected, otherwise False. NF)rb   r=   Z
IsSelected)r   re   r   Úis_selectedr"   r"   r#   rw   S  s
    
zTree.is_selectedc                 C   sž   |   |¡}|durš| j |¡ | j |d|f¡ |  |¡}| j ||¡ || ju rv| jsv|  |¡D ]}|  	||¡ qbn$| j 
|¡rŽ| j |¡ | j |¡ dS )zŒ Refresh the tree starting from the specified node.

        Call this when the structure of the content has changed DRAMATICALLY.

        NF)rb   r=   ÚDeleteChildrenÚSetItemDataÚ_has_childrenÚSetItemHasChildrenr[   rl   rn   Ú	_add_noderu   rc   rj   )r   re   rr   Úhas_childrenro   r"   r"   r#   Úrefresh_  s    

zTree.refreshc                 C   s"   |   |¡}|dur| j |¡ dS )z Selects the specified node. N)rb   r=   Z
SelectItemrd   r"   r"   r#   Úselect€  s    
zTree.selectc                 C   sd   t  d|| ¡ d| _| j ¡  |D ],}z|  |¡ W q"   t  d|¡ Y q"0 q"d| _|  ¡ | _dS )z& Selects the specified list of nodes. z*Setting selection to [%s] within Tree [%s]TzUnable to select node [%s]FN)	ÚloggerÚdebugÚ_ignore_selection_eventsr=   ZUnselectAllr   Ú	exceptionÚ_get_selectionÚ	selection)r   Úlistre   r"   r"   r#   Úset_selection‡  s    
zTree.set_selectionc                 C   s0   t j}|  ||¡}|dur,| j ||¡r,|}|S )z. Called when a node is dragged over the tree. N)r;   ZDragNoneÚ_get_drag_drop_noder%   Zcan_drop)r   ÚxÚyÚobjÚdefault_drag_resultÚresultre   r"   r"   r#   Úon_drag_overŸ  s    zTree.on_drag_overc                 C   s&   |   ||¡}|dur"| j ||¡ |S )z, Called when a node is dropped on the tree. N)rˆ   r%   Zdrop)r   r‰   rŠ   r‹   rŒ   re   r"   r"   r#   Úon_drop®  s    zTree.on_dropc                 C   s   | j  |¡}| j |d¡S )zw Returns the wxid for the specified node.

        Returns None if the node has not yet appeared in the tree.

        N)r%   Úget_keyrZ   Úget©r   re   Úkeyr"   r"   r#   rb   ¼  s    	zTree._get_wxidc                 C   s   | j  |¡}|| j|< dS )z' Sets the wxid for the specified node. N)r%   r�   rZ   )r   re   r   r“   r"   r"   r#   Ú	_set_wxidÉ  s    zTree._set_wxidc                 C   sB   | j  |¡}z| j|= W n$ ty<   t dt|ƒ ¡ Y n0 dS )z* Removes the wxid for the specified node. zremoving node: %sN)r%   r�   rZ   ÚKeyErrorr€   ÚwarningÚstrr’   r"   r"   r#   Ú_remove_wxidÒ  s
    zTree._remove_wxidc                 C   sd   | j }| jdkr tjdkr d| _| js0|tjB }| jsF|tjB tj	B }| j
dkr`|tjB tjB }|S )z; Returns the wx style flags for creating the tree control. r.   ÚposixFr1   )ÚSTYLEÚ
lines_modeÚosÚnameÚ
show_linesr;   ZTR_NO_LINESrl   ZTR_HIDE_ROOTZTR_LINES_AT_ROOTÚselection_modeZTR_MULTIPLEZTR_EXTENDED)r   r   r"   r"   r#   r<   á  s    

zTree._get_stylec                 C   sX   |  | jd¡ |  | jd¡ |  | jd¡ |  | jd¡ |  | jd¡ |  | jd¡ dS )z# Adds listeners for model changes. r[   Únodes_changedÚnodes_insertedÚnodes_removedÚnodes_replacedÚstructure_changedN)ÚobserveÚ_on_root_changedÚ_on_nodes_changedÚ_on_nodes_insertedÚ_on_nodes_removedÚ_on_nodes_replacedÚ_on_structure_changed)r   r%   r"   r"   r#   r]   û  s    zTree._add_model_listenersc                 C   s  |j | jddd� |j | jddd� |j | jddd� |j | jddd� |j | jddd� |j | jddd� | j}| t	j
¡ | t	j¡ | t	j¡ | t	j¡ | t	j¡ | t	j¡ | t	j¡ | t	j¡ | t	j¡ | t	j¡ | t	j¡ | t	j¡ | t	j¡ | t	j¡ d	S )
z& Removes listeners for model changes. r[   T)Úremover    r¡   r¢   r£   r¤   N)r¥   r¦   r§   r¨   r©   rª   r«   r=   ZUnbindr;   r>   r@   rB   rD   ZEVT_TREE_ITEM_ACTIVATEDrF   rH   rJ   rL   rN   rP   rR   rT   rV   )r   r%   r   r"   r"   r#   r$     s.    ÿzTree._remove_model_listenersc                 C   s¨   |   |¡}|  |¡}| j |||¡}| j |¡ | jsR|  |¡D ]}|  ||¡ q@|  	|¡}| j 
||¡ | jr†| j || j |f¡ |  ||¡ | jr¤| j |¡ dS )z Adds the root node. N)Ú_get_image_indexÚ	_get_textr=   ZAddRootr%   Úadd_listenerrl   rn   r|   rz   r{   ry   r”   rj   )r   re   Úimage_indexÚtextr   ro   r}   r"   r"   r#   r\   3  s    


zTree._add_root_nodec                 C   sl   |   |¡}|  |¡}| j ||||¡}| j |¡ |  |¡}| j ||¡ | j |d|f¡ |  	||¡ dS )z~ Adds 'node' as a child of the node identified by 'pid'.

        If 'pid' is None then we are adding the root node.

        FN)
r­   r®   r=   Z
AppendItemr%   r¯   rz   r{   ry   r”   )r   rr   re   r°   r±   r   r}   r"   r"   r#   r|   X  s    


zTree._add_nodec                 C   sp   |   |¡}|  |¡}| jj |||||¡}| j |¡ |  |¡}| j ||¡ | j 	|d|f¡ |  
||¡ dS )z� Inserts 'node' as a child of the node identified by 'pid'.

        If 'pid' is None then we are adding the root node.

        FN)r­   r®   r=   ZSizerZInsertBeforer%   r¯   rz   r{   ry   r”   )r   rr   re   Úindexr°   r±   r   r}   r"   r"   r#   Ú_insert_nodev  s    


ÿ
zTree._insert_nodec                 C   s(   | j  |¡ |  |¡ | j |d¡ dS )z Removes a node from the tree. N)r%   Úremove_listenerr˜   r=   ry   )r   r   re   r"   r"   r#   Ú_remove_node–  s    
zTree._remove_nodec                 C   sJ   |   |¡}| j ||tj¡ | j ||tj¡ |  |¡}| j ||¡ dS )z3 Updates the image and text of the specified node. N)r­   r=   ZSetItemImager;   ZTreeItemIcon_NormalZTreeItemIcon_Selectedr®   ZSetItemText)r   r   re   r°   r±   r"   r"   r#   Ú_update_node   s
    

zTree._update_nodec                 C   s   | j  |¡S )z& Returns True if a node has children. )r%   r}   )r   re   r"   r"   r#   rz   ¬  s    	zTree._has_childrenc                 C   s`   | j  |¡}g }|D ],}| jD ]}| | ||¡s qq| |¡ q| jdur\| j | ||¡ |S )z Get the children of a node. N)r%   Zget_childrenÚfiltersr   ÚappendÚsorterÚsort)r   re   ÚchildrenZfiltered_childrenro   Úfilterr"   r"   r#   rn   ·  s    

zTree._get_childrenc                 C   sB   |   |¡}|  |¡}| j |||¡}|dur:| j |¡}nd}|S )z/ Returns the tree item image index for a node. Néÿÿÿÿ)rv   rw   r%   Z	get_imagerX   ZGetIndex)r   re   ÚexpandedÚselectedÚimager°   r"   r"   r#   r­   Ì  s    

zTree._get_image_indexc           	      C   s0   |   ||f¡\}}}}|dur(|\}}nd}|S )zŠ Returns the node that is being dragged/dropped on.

        Returns None if the cursor is not over the icon or label of a node.

        N)Ú	_hit_test)	r   r‰   rŠ   Údatar   ÚflagsÚpointrs   re   r"   r"   r#   rˆ   Ü  s
    
zTree._get_drag_drop_nodec                 C   s   | j  |¡}|du rd}|S )z( Returns the tree item text for a node. NÚ )r%   Zget_text)r   re   r±   r"   r"   r#   r®   ì  s    zTree._get_textc                 C   s.   z|  ¡ }W n   | ¡ }Y n0 |  ||¡S )z< Unpacks the event to see whether a tree item was involved. )ÚGetPositionZGetPointrÁ   )r   Úeventr   rÄ   r"   r"   r#   Ú_unpack_eventõ  s
    zTree._unpack_eventc                 C   sh   t j}|du s| ¡ s&| j |¡\}}|t j@ r6d}n&|t j@ sJ|t j@ rX| j |¡}nd}||||fS )z> Determines whether a point is within a node's label or icon. N)r;   ZTREE_HITTEST_ONITEMLABELÚIsOkr=   ÚHitTestZTREE_HITTEST_NOWHEREZTREE_HITTEST_ONITEMICONrq   )r   rÄ   r   rÃ   rÂ   r"   r"   r#   rÁ      s    
ÿþzTree._hit_testc                 C   sF   g }| j  ¡ D ]2}| j  |¡}|dur|\}}| | j |¡¡ q|S )z& Returns a list of the selected nodes N)r=   ZGetSelectionsrq   r¸   r%   Zget_selection_value)r   r…   r   rÂ   rs   re   r"   r"   r#   r„     s    zTree._get_selectionc                 C   sF   | j  |¡ | j  |¡\}}| ¡ rB|  |¡ | j  ||¡\}}qdS )z! Recursively expand a tree item. N)r=   rj   ZGetFirstChildrÉ   rm   ZGetNextChild)r   r   ÚcidÚcookier"   r"   r#   rm   &  s    
zTree._expand_itemc                 C   s6   |j }| jdur2| j ¡  i | _|dur2|  |¡ dS )z0 Called when the root of the model has changed. N)Únewr=   ZDeleteAllItemsrZ   r\   )r   rÇ   r[   r"   r"   r#   r¦   4  s    

zTree._on_root_changedc                 C   sJ   |j }|  |  |j¡|j¡ |jD ]"}|  |¡}|dur"|  ||¡ q"dS )z& Called when nodes have been changed. N)rÍ   r¶   rb   re   r»   )r   rÇ   Ú
node_eventro   rË   r"   r"   r#   r§   A  s    

zTree._on_nodes_changedc                 C   s   |j }|j}|j}|j}|  |¡}|durü| js:|| jurL| j |¡\}}nd}|sr|  	|¡D ]}	|  
||	¡ q^n6|dkrˆ| j |d¡}|D ]}	|  ||	|¡ |d7 }qŒ| js¸|| jurÊ| j |d|f¡ | j |¡dk}
| j ||
¡ |  |¡sü|  |¡ dS )z' Called when nodes have been inserted. NTr½   Fé   r   )rÍ   re   r»   r²   rb   rl   r[   r=   rq   rn   r|   ÚGetChildrenCountr³   ry   r{   rv   rk   )r   rÇ   rÎ   r   r»   r²   rr   rs   re   ro   r}   r"   r"   r#   r¨   J  s.    


zTree._on_nodes_insertedc                 C   sj   |j }|j}|  |¡}|durf|jD ]"}|  |¡}|dur$| j |¡ q$| j |¡dk}| j ||¡ dS )z& Called when nodes have been removed. Nr   )rÍ   re   rb   r»   r=   ÚDeleterÐ   r{   )r   rÇ   rÎ   r   rr   ro   rË   r}   r"   r"   r#   r©   y  s    


zTree._on_nodes_removedc                 C   s²   |j }t|j|jƒ}|D ]Š\}}|  |¡}|dur| j |¡ | j |¡ |  	||¡ | j 
|d|f¡ |  |¡ |  ||¡ | j |¡ |  |¡}| j ||¡ q|  ¡ | _dS )z' Called when nodes have been replaced. NF)rÍ   ÚzipZold_childrenr»   rb   r%   r´   r=   rx   r¶   ry   r˜   r”   r¯   rz   r{   r„   r…   )r   rÇ   rÎ   Zold_new_childrenZ	old_childÚ	new_childrË   r}   r"   r"   r#   rª   Š  s    
	

zTree._on_nodes_replacedc                 C   s   |j }|  |j¡ dS )z> Called when the structure of a node has changed drastically. N)rÍ   r~   re   )r   rÇ   rÎ   r"   r"   r#   r«   ´  s    zTree._on_structure_changedc                 C   s&   t |j|j|j|jd�| _| ¡  dS )z7 Called when a key is pressed when the tree has focus. )Zalt_downZcontrol_downZ
shift_downZkey_codeN)r   ZaltDownZcontrolDownZ	shiftDownZKeyCodeÚkey_pressedÚSkip©r   rÇ   r"   r"   r#   r?   ½  s    üzTree._on_charc                 C   s>   |   |¡\}}}}|| _|dur2|\}}||f| _| ¡  dS )z; Called when the left mouse button is clicked on the tree. N)rÈ   Z_point_left_clickedÚnode_left_clickedrÕ   ©r   rÇ   rÂ   ÚidrÃ   rÄ   rs   re   r"   r"   r#   rA   É  s    
zTree._on_left_downc                 C   s@   |   |¡\}}}}|dur.|\}}||f| _n|| _| ¡  dS )z< Called when the right mouse button is clicked on the tree. N)rÈ   Únode_right_clickedÚcontrol_right_clickedrÕ   rØ   r"   r"   r#   rC   Ý  s    zTree._on_right_downc                 C   s2   |  ¡ }| j |¡\}}| j |¡\}}|| _dS )z> Called when a tree item is activated (i.e., double clicked). N)rÆ   r=   rÊ   rq   Únode_activated)r   rÇ   rÄ   r   rÃ   rs   re   r"   r"   r#   rE   ð  s    
zTree._on_tree_item_activatedc                 C   s0   |  ¡ }| j |¡\}}| j |¡s,| ¡  dS )z/ Called when a tree item is about to collapse. N)ÚGetItemr=   rq   r%   Zis_collapsibleÚVeto©r   rÇ   r   rs   re   r"   r"   r#   rG     s    zTree._on_tree_item_collapsingc                 C   s.   |  ¡ }| j |¡\}}|  ||¡ || _dS )z- Called when a tree item has been collapsed. N)rÝ   r=   rq   r¶   Únode_collapsedrß   r"   r"   r#   rI     s    zTree._on_tree_item_collapsedc                 C   sd   |  ¡ }| j |¡\}}| j |¡rX|s`|  |¡D ]}|  ||¡ q2| j |d|f¡ n| ¡  dS )z- Called when a tree item is about to expand. TN)	rÝ   r=   rq   r%   Zis_expandablern   r|   ry   rÞ   )r   rÇ   r   rs   re   ro   r"   r"   r#   rK   %  s    zTree._on_tree_item_expandingc                 C   s.   |  ¡ }| j |¡\}}|  ||¡ || _dS )z, Called when a tree item has been expanded. N)rÝ   r=   rq   r¶   Únode_expandedrß   r"   r"   r#   rM   >  s    zTree._on_tree_item_expandedc                 C   s0   |  ¡ }| j |¡\}}| j |¡s,| ¡  dS )z; Called when the user has started editing an item's label. N)rÝ   r=   rq   r%   Úis_editablerÞ   rß   r"   r"   r#   rO   O  s    zTree._on_tree_begin_label_editc                    s‚   |  ¡ }ˆj |¡\}‰| ¡ ‰ ˆ dur^tˆ ƒdkr^ˆj ˆˆ ¡r^‡ ‡‡fdd„}t |¡ n | 	¡  ˆj
dur~ˆ 
ˆˆˆ ¡ dS )z< Called when the user has finished editing am item's label. Nr   c                      s*   ˆj  ˆˆ ¡ ˆjdur&ˆ ˆˆˆ ¡ dS )z$ Called to complete the label edit. N)r%   Zset_textrg   r"   ©Úlabelre   r   r"   r#   Úend_label_editr  s    
z4Tree._on_tree_end_label_edit.<locals>.end_label_edit)rÝ   r=   rq   ZGetLabelÚlenr%   Zcan_set_textr   Zinvoke_laterrÞ   rg   )r   rÇ   r   rs   rå   r"   rã   r#   rQ   ]  s    ÿ
þý
zTree._on_tree_end_label_editc           
      C   s¨   |   || ¡ ¡\}}}}|dkr@| j}|  |¡\}}| j |¡}|dur¤|\}}| j |¡rœ| j |¡}ddl	m
}	 |g|	_|  ¡ | _t| j|| ƒ || _n| ¡  dS )z: Called when a drag operation is starting on a tree item. )r   r   Nr   ©Ú	clipboard)rÈ   rÝ   Zpoint_left_clickedrÊ   r=   rq   r%   Zis_draggableZget_drag_valueÚpyface.wx.drag_and_droprè   re   r„   r…   r   Únode_begin_dragrÞ   )
r   rÇ   rÂ   r   rÃ   rÄ   rs   re   Z
drag_valuerè   r"   r"   r#   rS   Ž  s     
zTree._on_tree_begin_dragc                 C   s   ddl m} d|_dS )z< Callback invoked when a drag/drop operation has completed. r   rç   N)ré   rè   re   )r   rè   r"   r"   r#   Ú
on_dropped¼  s    zTree.on_droppedc                 C   s   | j s|  ¡ | _dS )z' Called when the selection is changed. N)r‚   r„   r…   rÖ   r"   r"   r#   rU   Ã  s    zTree._on_tree_sel_changedc                 C   s^   |  ¡ }| jdu rdS z| j |¡}W n ty<   d}Y n0 |durZ|\}}|  ||¡ dS )z0 Called when a tree item is being been deleted. N)rÝ   r=   rq   Ú	Exceptionrµ   )r   rÇ   r   rÂ   rs   re   r"   r"   r#   rW   Í  s    	

zTree._on_tree_delete_item)r3   )N)N)N)gr(   r)   r*   r+   r;   ZTR_EDIT_LABELSZTR_HAS_BUTTONSZCLIP_CHILDRENrš   r
   r   r   r·   r   r›   r   r%   r   r   r[   r…   rŸ   r   rY   rž   rl   r   r¹   r   rÛ   r   rÔ   rÜ   rê   rà   rá   r×   rÚ   r   Ú_namer   rg   r‚   r   r	   r6   r   r^   r`   ra   rf   ri   rk   rp   rt   rv   rw   r~   r   r‡   rŽ   r�   rb   r”   r˜   r<   r]   r$   r\   r|   r³   rµ   r¶   rz   rn   r­   rˆ   r®   rÈ   rÁ   r„   rm   r¦   r§   r¨   r©   rª   r«   r?   rA   rC   rE   rG   rI   rK   rM   rO   rQ   rS   rë   rU   rW   r,   r"   r"   r    r#   r-   G   s    


9	

!	-% 
	

	/*	1.
r-   )(r+   Úloggingrœ   r8   r;   Z
traits.apir   r   r   r   r   r   r	   r
   r   r   r   Zpyface.filterr   Zpyface.key_pressed_eventr   Zpyface.sorterr   Zpyface.tree.tree_modelr   Zpyface.ui.wx.guir   Zpyface.ui.wx.image_listr   Zpyface.ui.wx.layout_widgetr   ré   r   r   Ú	getLoggerr(   r€   ZTreeCtrlr   r-   r"   r"   r"   r#   Ú<module>   s    4
