a
    §ˆc¡ý  ã                   @   s\  d Z ddlZddlZddlmZ ddlmZ ddlZddl	m
Z
mZ ddlmZ ddlmZ ddlmZ dd	lmZmZmZ dd
lmZmZmZmZmZmZ ddlmZmZm Z m!Z! ddl"m#Z#m$Z$m%Z% ddl&m'Z' ddl(m)Z) ddl*m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 e 2e3¡Z4e1ƒ Z5G dd„ de-ƒZ6G dd„ dej7ƒZ8G dd„ dej9ƒZ:dS )z> Defines the tree editor for the PyQt user interface toolkit.
é    N)Úpartial)Úzip_longest)ÚQtCoreÚQtGui)ÚImageResource)Úconvert_image)Údo_later)ÚAnyÚEventÚInt)Ú
CopyActionÚ	CutActionÚDeleteActionÚ	NewActionÚPasteActionÚRenameAction)ÚITreeNodeAdapterBridgeÚMultiTreeNodeÚObjectTreeNodeÚTreeNode)ÚMenuÚActionÚ	Separator)ÚSequenceTypes)ÚListUndoItemé   )Ú	clipboardÚ
PyMimeData)ÚEditor)Úpixmap_cache)ÚWordWrapRendererc                       s  e Zd ZdZdZeƒ Zeƒ Zeƒ Z	eƒ Z
eƒ Zeƒ Zeƒ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z‡ fdd„Zd¦dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd§dd„Zd¨dd „Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Z d+d,„ Z!d-d.„ Z"e#j$j%j&e#j$j%j'e#j$j%j(d/œZ)d©d1d2„Z*d3d4„ Z+d5d6„ Z,d7d8„ Z-dªd:d;„Z.d«d<d=„Z/d>d?„ Z0d@dA„ Z1dBdC„ Z2dDdE„ Z3dFdG„ Z4dHdI„ Z5d¬dJdK„Z6d­dLdM„Z7dNdO„ Z8d®dPdQ„Z9dRdS„ Z:e;dTdU„ ƒZ<e;dVdW„ ƒZ=dXdY„ Z>d¯dZd[„Z?d°d\d]„Z@d^d_„ ZAd`da„ ZBdbdc„ ZCddde„ ZDdfdg„ ZEdhdi„ ZFdjdk„ ZGdldm„ ZHdndo„ ZIdpdq„ ZJdrds„ ZKdtdu„ ZLdvdw„ ZMdxdy„ ZNdzd{„ ZOd±d|d}„ZPd~d„ ZQd€d�„ ZRd‚dƒ„ ZSd„d…„ ZTd²d†d‡„ZUdˆd‰„ ZVdŠd‹„ ZWdŒd�„ ZXdŽd�„ ZYd�d‘„ ZZd’d“„ Z[d”d•„ Z\d–d—„ Z]d³d˜d™„Z^d´dšd›„Z_dœd�„ Z`dždŸ„ Zad d¡„ Zbd¢d£„ Zcd¤d¥„ Zd‡  ZeS )µÚSimpleEditorzSimple style of tree editor.Tc                 C   s0  | j }d| _|j�r–|jrö|j}|du rž| |_t ¡  | _}| tj	j
j¡ | d¡ d | j_| j_|j}|durš|jD ]}|j| ju rz| j|_qzd|_dS |j}|du s¸|j| jurÜ|j}|du rÐg  |_}| | ¡ n|j| _t| ƒ | _| _nžt| ƒ| _t ¡  | _}| tj	j
j¡ | d¡ d |_|_|jdk�rLtjjj}n
tjjj}t |¡ | _}	|	 tjjjtjjj¡ |	 | j¡ |	 |¡ nt| ƒ | _| _t ƒ }
| |
_| j !|
¡ |
| _"i | _#g | _$|  %|j&d¡ |  %|j'd¡ |  %|j(dd¡ |  %|j)dd¡ |  %|j*d	d¡ |  %|j+d
d¡ dS )z\Finishes initializing the editor by creating the underlying toolkit
        widget.
        NTZ
horizontalÚrefreshÚselectedÚ	activatedÚtoÚclickÚdclickÚvetoÚfrom),ÚfactoryÚ_editorÚeditableZshared_editorÚeditorr   ZQScrollAreaÚcontrolZsetFrameShapeZQFrameZShapeZNoFrameZsetWidgetResizableÚ_node_uiÚ_editor_nidZ_shared_editorsÚuiÚappendÚ_TreeWidgetÚ_treeZorientationr   ÚQtZOrientationZ
HorizontalZVerticalÚ	QSplitterZsetSizePolicyZQSizePolicyÚPolicyZ	ExpandingZ	addWidgetÚTreeItemDelegateZsetItemDelegateZ_item_delegateÚ_mapÚ	_undoableZ
sync_valuer"   r#   r$   r&   r'   r(   )ÚselfÚparentr*   Zfactory_editorÚsaZeditorsr-   Zshared_editorsZorientZsplitterZdelegate© r>   ú[/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/tree_editor.pyÚinitf   sj    






ÿzSimpleEditor.initc                 C   s¬   zˆ| j }t|tƒsrt|tjjƒrrt ¡ }|D ],}|  |¡d }| 	|¡}| 
t |¡¡ q,| ¡  |tjjj¡ n| |  |¡d ¡ W n   ddlm} |ƒ  Y n0 dS )z Handles the **selection** event.é   r   ©Úraise_to_debugN)r4   Ú
isinstanceÚstrÚcollectionsÚabcÚIterabler   ZQItemSelectionÚ_object_infoÚindexFromItemr2   ZQItemSelectionRangeZselectionModelÚselectZQItemSelectionModelZSelectionFlagZClearAndSelectÚsetCurrentItemÚtraitsui.apirC   )r;   Ú	selectionÚtreeZitem_selectionÚselÚitemÚidxrC   r>   r>   r?   Ú_selection_changedÏ   s"    ÿ

ÿzSimpleEditor._selection_changedc                 C   s   | j s|  |¡ dS )z-Handles the **selected** trait being changed.N)Ú_no_update_selectedrS   )r;   r#   r>   r>   r?   Ú_selected_changedç   s    zSimpleEditor._selected_changedc                 C   s
   d| _ dS )z%Handles the 'veto' event being fired.TN)Ú_veto©r;   r>   r>   r?   Ú_veto_changedì   s    zSimpleEditor._veto_changedc                 C   s   | j  ¡  ¡  dS )zUpdate the viewport.N)r4   ÚviewportÚupdaterW   r>   r>   r?   Ú_refresh_changedð   s    zSimpleEditor._refresh_changedc                    s:   | j dur,| j  d¡ |  | j  ¡ ¡ d| _ tƒ  ¡  dS )z&Disposes of the contents of an editor.NT)r4   ÚblockSignalsÚ_delete_nodeÚinvisibleRootItemÚsuperÚdisposerW   ©Ú	__class__r>   r?   r`   ô   s
    
zSimpleEditor.disposec                 C   s`   |dkr\|   |¡\}}}|  ||¡r\|  |¡ |r<| d¡ |  |¡D ]}|  ||d ¡ qFdS )zCExpands from the specified node the specified number of sub-levels.r   Tr   N)Ú_get_node_dataÚ_has_childrenÚ_expand_nodeÚsetExpandedÚ
_nodes_forÚexpand_levels)r;   ÚnidÚlevelsÚexpandÚexpandedÚnodeÚobjectÚcnidr>   r>   r?   rh      s    

zSimpleEditor.expand_levelsc                 C   sZ   t  | j¡}| ¡ rV| ¡ }|  |¡\}}}|  ||¡rL|  |¡ | d¡ |d7 }qdS )z›Expands all expandable nodes in the tree.

        Warning: If the Tree contains a large number of items, this function
        will be very slow.
        Tr   N)r   ZQTreeWidgetItemIteratorr4   Úvaluerc   rd   re   rf   )r;   ÚiteratorrQ   rl   rm   rn   r>   r>   r?   Ú
expand_all  s    

zSimpleEditor.expand_allc           	      C   s|  | j }|du rdS i }|  | j¡\}}|  || |¡¡}|rF|  |¡ |  | j¡\}}|  || |¡¡}|rv|  |¡ | ¡  i | _|  | j¡\}}|du�rH| j	j
r°| ¡ }n|  |||¡}| |¡|fg| jt|ƒ< |  ||¡ |  |d||f¡ | j	j
�s|  ||¡�r6|  |¡ | j	j
�s6| d¡ | |¡ |  || j	jd¡ | j  ¡ }|dk�rxt|ƒD ]}| j  |¡ �qddS )z[Updates the editor when the object trait changes externally to the
        editor.
        NFTr   )r4   Ú	_node_forÚ	old_valueÚ_get_object_nidÚget_children_idr]   Úclearr9   rp   r*   Ú	hide_rootr^   Ú_create_itemÚidÚ_add_listenersÚ_set_node_datard   re   rf   rL   rh   Ú	auto_openZcolumnCountÚrangeZresizeColumnToContents)	r;   rO   Úsaved_statern   rm   Zold_nidri   ZncolumnsÚir>   r>   r?   Úupdate_editor  s@    









zSimpleEditor.update_editorc                 C   s   | j S )z9Returns the editor's control for indicating error status.)r4   rW   r>   r>   r?   Úget_error_controlI  s    zSimpleEditor.get_error_controlc                 C   s*   t |tƒrtj|Ž }n
t |¡}t |¡S ©N)rD   r   r   ÚQColorZQBrush)r;   ÚcolorZq_colorr>   r>   r?   Ú
_get_brushM  s    

zSimpleEditor._get_brushc           
      C   s€   |  |¡}tt| jjdd… |ƒdƒD ]T\}\}}| ||¡}|rH|jnd}	|du s`|du s`|	rn| |d¡ q&| ||¡ q&dS )zSet the column labels.r   NFÚ )Zget_column_labelsÚ	enumerater   r*   Úcolumn_headersÚget_rendererÚhandles_textÚsetText)
r;   ri   rm   rn   Zcolumn_labelsr€   ÚheaderÚlabelÚrendererr‹   r>   r>   r?   Ú_set_column_labelsT  s    
ÿzSimpleEditor._set_column_labelsNc           
      C   sä   |du rt  |¡}nt  ¡ }| ||¡ | |¡}t|ddƒ}t|ddƒ}| jjsh|sh| d| |¡¡ |s€| 	d|  
||¡¡ | d| |¡¡ |  |||¡ | |¡}	|	rÀ| d|  |	¡¡ | |¡}	|	rà| d|  |	¡¡ |S )z¦Create  a new TreeWidgetItem as per word_wrap policy.

        Index is the index of the new node in the parent:
            None implies append the child to the end.Nr‹   FÚhandles_iconr   )r   ÚQTreeWidgetItemÚinsertChildrŠ   Úgetattrr*   Ú	word_wraprŒ   Ú	get_labelÚsetIconÚ	_get_iconZ
setToolTipZget_tooltipr�   Zget_backgroundZsetBackgroundr†   Zget_foregroundZsetForeground)
r;   ri   rm   rn   Úindexro   r�   r‹   r‘   r…   r>   r>   r?   ry   b  s(    


zSimpleEditor._create_itemr   c                 C   sb   |dkrdS |   |¡\}}}| |¡}t|ddƒ}| jjs>|rL| |d¡ n| || |¡¡ dS )z#Set the label of the specified itemr   Nr‹   Fr‡   )rc   rŠ   r”   r*   r•   rŒ   r–   )r;   ri   Úcolrl   rm   rn   r�   r‹   r>   r>   r?   Ú
_set_label�  s    
zSimpleEditor._set_labelc                 C   s   |   |d||¡S )z)Appends a new node to the specified node.N)Ú_insert_node)r;   ri   rm   rn   r>   r>   r?   Ú_append_nodeŽ  s    zSimpleEditor._append_nodec                 C   s†   |   ||||¡}|  ||¡}|  |d||f¡ | j t|ƒg ¡ | |¡|f¡ |  ||¡ |r‚| 	|¡rv| 
d¡ nt |¡|_|S )zeInserts a new node before a specified index into the children of the
        specified node.
        FT)ry   rd   r|   r9   Ú
setdefaultrz   r2   rv   r{   Úcan_auto_openrf   r   r’   Ú_dummy)r;   ri   r™   rm   rn   ro   Úhas_childrenr>   r>   r?   rœ   ’  s    ÿ
zSimpleEditor._insert_nodec                 C   s,  |   |¡D ]}|  |¡ q
| ¡ }|durLt|ddƒ|u rL| |¡ |`dS z|  |¡\}}}W n tyr   Y nd0 t|ƒ}| j	| }t
|ƒD ]&\}	}
t|ƒt|
d ƒkrŽ||	=  q¶qŽt|ƒdkrÖ|  ||¡ | j	|= |du rô| j | j |¡¡ n
| |¡ | jdu�r(t|ƒt| jjƒk�r(|  ¡  dS )z3Deletes a specified tree node and all its children.Nr    r   r   )rg   r]   r<   r”   ÚremoveChildr    rc   ÚAttributeErrorrz   r9   rˆ   ÚlenÚ_remove_listenersr4   ZtakeTopLevelItemZindexOfTopLevelItemr+   r0   Ú_clear_editor)r;   ri   ro   Úpnidrl   rm   rn   Z	id_objectZobject_infor€   Úinfor>   r>   r?   r]   ®  s6    


ÿzSimpleEditor._delete_nodec                 C   s€   |   |¡\}}}|s|t|ddƒ}|dur6| |¡ |`| |¡D ](}|  |¡\}}|dur@|  |||¡ q@|  |d||f¡ dS )z7Expands the contents of a specified node (if required).r    NT)rc   r”   r¢   r    Úget_childrenrs   r�   r|   )r;   ri   rl   rm   rn   ÚdummyÚchildÚ
child_noder>   r>   r?   re   Ù  s    
zSimpleEditor._expand_nodec                    s   ‡ fdd„t ˆ  ¡ ƒD ƒS )z2Returns all child node ids of a specified node id.c                    s   g | ]}ˆ   |¡‘qS r>   )r«   )Ú.0r€   ©ri   r>   r?   Ú
<listcomp>ï  ó    z+SimpleEditor._nodes_for.<locals>.<listcomp>)r~   Ú
childCount©r;   ri   r>   r®   r?   rg   í  s    zSimpleEditor._nodes_forc                 C   sp   |  ¡ }|d u r.| jjr"| j ¡ }|d u r.dS t| ¡ ƒD ]0}| |¡|u r:|  |¡\}}}|||f  S q:dS )N)NNN)	r<   r*   rx   r4   r^   r~   r±   r«   rc   )r;   ri   r§   r€   Ú_ZpnodeZpobjectr>   r>   r?   Ú_node_indexñ  s    
zSimpleEditor._node_indexc                 C   s   |  |¡o| |¡S )z4Returns whether a specified object has any children.)Úallows_childrenr¡   ©r;   rm   rn   r>   r>   r?   rd     s    zSimpleEditor._has_children)z<item>z<group>z<open>Fc           
      C   s"  | j jst ¡ S | ||¡}t|tƒrš| d¡rBt|dƒ}| 	¡ S || j
v rf| j
| }| j ¡  |¡S | |¡}t|tƒr„||g}n
||g }t||ƒ}ntt|tƒrª|}ndt|tƒrät|ƒdkrÎtjj|Ž }ntjj|Ž }|  |¡S t|tjƒ� rü|  |¡S tdd |¡ ƒ‚|j}	t t|	ƒ¡S )z/Returns the index of the specified object icon.ú@é   g      ð?zPIcon value must be a string or color or color tuple or IImageResource instance: z
given {!r})r*   Z
show_iconsr   ÚQIconZget_iconrD   rE   Ú
startswithr   Zcreate_iconÚSTD_ICON_MAPr4   ÚstyleZstandardIconZget_icon_pathr   ÚtupleÚmaxr„   ZfromRgbFZfromRgbÚ_icon_from_colorÚ
ValueErrorÚformatZabsolute_pathr   )
r;   rm   rn   Zis_expandedZ	icon_nameZimage_resourceZiconÚpathr…   Ú	file_namer>   r>   r?   r˜     s>    












þÿzSimpleEditor._get_iconc                 C   s$   t  | j ¡ ¡}| |¡ t  |¡S )z1Create a square icon filled with the given color.)r   ÚQPixmapr4   ZiconSizeÚfillr¹   )r;   r…   Zpixmapr>   r>   r?   r¿   >  s    
zSimpleEditor._icon_from_colorc                 C   sN   |  |¡r*| || jd¡ | || jd¡ | || jd¡ | || jd¡ dS )z0Adds the event listeners for a specified object.FN©	rµ   Zwhen_children_replacedÚ_children_replacedZwhen_children_changedÚ_children_updatedZwhen_label_changedÚ_label_updatedZwhen_column_labels_changeÚ_column_labels_updatedr¶   r>   r>   r?   r{   D  s    
ÿzSimpleEditor._add_listenersc                 C   sN   |  |¡r*| || jd¡ | || jd¡ | || jd¡ | || jd¡ dS )z4Removes any event listeners from a specified object.TNrÆ   r¶   r>   r>   r?   r¥   P  s    
ÿzSimpleEditor._remove_listenersr‡   c           	      C   sN   | j t|ƒ }|D ]\}}||kr q4q|d d }|  |¡\}}}|||fS )zgReturns the tree node data for a specified object in the form
        ( expanded, node, nid ).
        r   r   )r9   rz   rc   )	r;   rn   Únamer¨   Úname2ri   rl   rm   Úignorer>   r>   r?   rI   \  s    zSimpleEditor._object_infoc           	      C   sH   g }| j t|ƒ D ]0\}}||kr|  |¡\}}}| |||f¡ q|S )z{Returns the tree node data for a specified object as a list of the
        form: [ ( expanded, node, nid ), ... ].
        )r9   rz   rc   r2   )	r;   rn   rË   ÚresultrÌ   ri   rl   rm   rÍ   r>   r>   r?   Ú_object_info_fork  s    zSimpleEditor._object_info_forc           	         s$  t ˆtƒr(tˆƒdkr(t ˆd tƒr(ˆS | j}‡fdd„|jD ƒ}t|ƒdkrZˆ|d fS t|ƒdkrtˆtˆd�fS |d j‰ ‡ fdd„|D ƒ}t|ƒdkr¨ˆ|d fS d}t|ƒD ] \}}|j	d	kr´|}||=  qÞq´|d }|ft|ƒ }||j
v �rˆ|j
| fS t||d
� |j
|< }ˆ|fS )z8Returns the TreeNode associated with a specified object.rA   r   c                    s   g | ]}|  ˆ ¡r|‘qS r>   )Zis_node_for©r­   rm   )rn   r>   r?   r¯   ‚  r°   z*SimpleEditor._node_for.<locals>.<listcomp>r   )Úadapterc                    s   g | ]}ˆ |j kr|‘qS r>   )Únode_forrÐ   )Úbaser>   r?   r¯   �  r°   Nr‡   )Ú	root_nodeÚnodes)rD   r½   r¤   r   r*   rÕ   r   rÒ   rˆ   ÚchildrenZmulti_nodesr   )	r;   rn   r*   rÕ   rÔ   r€   rm   ÚkeyZ
multi_noder>   )rÓ   rn   r?   rs   w  s>    ÿ
þý

ÿzSimpleEditor._node_forc                 C   s*   | j jD ]}t|t|jƒƒr|  S qdS )z7Returns the TreeNode associated with a specified class.N)r*   rÕ   Ú
issubclassr½   rÒ   )r;   Úklassrm   r>   r>   r?   Ú_node_for_class®  s    
zSimpleEditor._node_for_classc                 C   sT   |   |¡\}}}| |¡}|du s(|js@| d|  |||¡¡ n| dt ¡ ¡ dS )z&Updates the icon for a specified node.Nr   )rc   rŠ   r‘   r—   r˜   r   r¹   )r;   ri   rl   rm   rn   r�   r>   r>   r?   Ú_update_iconµ  s
    
zSimpleEditor._update_iconc                 C   s6   | j }| j |j¡ |jdkr2|jdur2|jj|_dS )z!Begins an "undoable" transaction.éÿÿÿÿN)r1   r:   r2   ÚhistoryÚnow)r;   r1   r>   r>   r?   Ú_begin_undo¾  s    zSimpleEditor._begin_undoc                 C   s   | j  ¡ dkrd| j_ d S )NrÜ   )r:   Úpopr1   rW   r>   r>   r?   Ú	_end_undoÅ  s    zSimpleEditor._end_undoc                 C   s   t |||j|j|jd�S )N)rn   rË   r™   ÚaddedÚremoved)r   r™   râ   rã   )r;   rn   rË   Úeventr>   r>   r?   Ú_get_undo_itemÉ  s    ûzSimpleEditor._get_undo_itemc                 C   s>   z.|   ¡  |rt |¡}| ||¡ W |  ¡  n
|  ¡  0 dS )z&Performs an undoable append operation.N)rß   ÚcopyÚdeepcopyZappend_childrá   )r;   rm   rn   ÚdataÚ	make_copyr>   r>   r?   Ú_undoable_appendÒ  s    
zSimpleEditor._undoable_appendc                 C   s@   z0|   ¡  |rt |¡}| |||¡ W |  ¡  n
|  ¡  0 dS )z&Performs an undoable insert operation.N)rß   ræ   rç   Zinsert_childrá   )r;   rm   rn   r™   rè   ré   r>   r>   r?   Ú_undoable_insertÜ  s    
zSimpleEditor._undoable_insertc                 C   s0   z |   ¡  | ||¡ W |  ¡  n
|  ¡  0 dS )z&Performs an undoable delete operation.N)rß   Zdelete_childrá   )r;   rm   rn   r™   r>   r>   r?   Ú_undoable_deleteæ  s    zSimpleEditor._undoable_deletec                 C   sF   | j  t|ƒ¡}|du rdS |D ]\}}||kr |  S q |d d S )z8Gets the ID associated with a specified object (if any).Nr   r   )r9   Úgetrz   )r;   rn   rË   r¨   rÌ   ri   r>   r>   r?   ru   î  s    
zSimpleEditor._get_object_nidc                 C   s4   | j }|jdur0| d¡ |j ¡  d |_|_dS )z(Clears the current editor pane (if any).N)r+   r/   Ú	setWidgetr`   r0   )r;   r-   r>   r>   r?   r¦   ù  s
    


zSimpleEditor._clear_editorc                 C   s   | j S )zGets the node specific data.©Z_py_datar®   r>   r>   r?   rc     s    zSimpleEditor._get_node_datac                 C   s
   || _ dS )zSets the node specific data.Nrï   )ri   rè   r>   r>   r?   r|   
  s    zSimpleEditor._set_node_datac                 C   s   |   |¡d S )z1Gets the object associated with a specified node.rA   ©rc   r²   r>   r>   r?   Ú
get_object  s    zSimpleEditor.get_objectc                 C   s8   |   ||¡}|dur4| ¡ }|| j ¡ ur4|  |¡S dS )zdReturns the object that is the immmediate parent of a specified
        object in the tree.
        N)ru   r<   r4   r^   rñ   )r;   rn   rË   ri   r§   r>   r>   r?   Ú
get_parent  s    
zSimpleEditor.get_parentc                 C   s&   |   ||¡}|dur"|  |¡d S dS )z4Returns the node associated with a specified object.Nr   )ru   rc   )r;   rn   rË   ri   r>   r>   r?   Úget_node   s    zSimpleEditor.get_nodec                 C   sd   |   |¡\}}}| |¡rL| ¡ }|durL|  |¡D ]}||ur4| d¡ q4|  |¡ |  |¡ dS )z#Handles a tree node being expanded.NF)rc   Zcan_auto_closer<   rg   rf   re   rÛ   )r;   ri   rl   rm   rn   r<   Zsnidr>   r>   r?   Ú_on_item_expanded)  s    

zSimpleEditor._on_item_expandedc                 C   s   |   |¡ dS )z$Handles a tree node being collapsed.N)rÛ   r²   r>   r>   r?   Ú_on_item_collapsed=  s    zSimpleEditor._on_item_collapsedc                 C   sF   |   |¡\}}}| |¡du r<| jjdur<| j | jj|¡ || _dS )z"Handles a tree item being clicked.TN)rc   r&   r*   Zon_clickr1   Úevaluate©r;   ri   rš   r³   rm   rn   r>   r>   r?   Ú_on_item_clickedA  s    zSimpleEditor._on_item_clickedc                 C   sT   |   |¡\}}}| |¡du rD| jjdurJ| j | jj|¡ d| _nd| _|| _dS )z)Handles a tree item being double-clicked.TN)rc   r'   r*   Z	on_dclickr1   rö   rV   r÷   r>   r>   r?   Ú_on_item_dclickedK  s    zSimpleEditor._on_item_dclickedc                 C   sT   |   |¡\}}}| |¡du rD| jjdurJ| j | jj|¡ d| _nd| _|| _dS )z$Handles a tree item being activated.TN)rc   r$   r*   Zon_activatedr1   rö   rV   r÷   r>   r>   r?   Ú_on_item_activatedY  s    zSimpleEditor._on_item_activatedc                    s¤  ˆ j  ¡ }g }d}t|ƒdkrf‡ fdd„|D ƒ}|D ].}ˆ  |¡\}}}|r4|}|}	| |¡}
d}q4nd}d}	d}
ˆ jjdkr’dˆ _|	ˆ _dˆ _ndˆ _|ˆ _dˆ _|
du r¾ˆ j	 
ˆ jj|	¡ ˆ j}|du�r | d¡ ˆ  ¡  |	du�r–| |	¡}|du �s
t|tƒ�r|	 |¡}ˆ j	jdu�s.|jdk�r@|	j||dd	�}n|	j||d
d	�}ˆ j	|_||_||_|j ¡ du�rŠ|j ¡  dddd¡ | |j¡ | d¡ dS )z#Handles a tree node being selected.Tr   c                    s   g | ]}ˆ   |¡d  ‘qS )rA   rð   )r­   ri   rW   r>   r?   r¯   o  r°   z5SimpleEditor._on_tree_sel_changed.<locals>.<listcomp>FNÚsingleZsubpanel)r<   ÚviewÚkindZpanel)r4   ZselectedItemsr¤   rc   rK   r*   Úselection_moderT   r#   r1   rö   Z	on_selectr+   ZsetUpdatesEnabledr¦   Zget_viewrD   rE   Z
trait_viewrÝ   rý   Úedit_traitsr<   r/   r0   r.   ZlayoutZsetContentsMarginsrî   )r;   Únidsr#   Úfirstri   rl   Zsel_nodeZ
sel_objectrm   rn   Znot_handledr-   rü   r1   r>   rW   r?   Ú_on_tree_sel_changedg  s\    






ÿÿz!SimpleEditor._on_tree_sel_changedc                 C   sb  | j  |¡}|du rdS |  |¡\}}}|||f| _|| || jj| jjdœ| _| ¡ }|du sl|| j  	¡ u rvd }}n|  |¡\}}}|| _
|| _|| _| |¡}	|	du r¸|  ||¡}	n^t|	tƒ�r|	 t¡}
|
du�r|
 ¡  |  ||¡}t|ƒdk�r|
 dt|ddiŽ¡ nd}	|	du�r@|	 | j | ¡}| | j  |¡¡ d | _ | _ | _
 | _| _dS )z:Handles the user requesting a context menu on a tree node.N©rn   r-   rm   r¨   Úhandlerr   rË   ÚNew)r4   ÚitemAtrc   Ú_datar1   r¨   r  Ú_contextr<   r^   Ú
_menu_nodeÚ_menu_parent_nodeÚ_menu_parent_objectZget_menuÚ_standard_menurD   r   Z
find_groupr   rw   Ú_new_actionsr¤   ÚinsertZcreate_menuÚexec_ZmapToGlobal)r;   Úposri   r³   rm   rn   r§   Zparent_nodeZparent_objectÚmenuÚgroupÚactionsZqmenur>   r>   r?   Ú_on_context_menu¶  sP    û	




üÿýüzSimpleEditor._on_context_menuc                 C   sR   t tttƒ ttƒ tg}|  ||¡}t|ƒdkrJt|ddiŽtƒ g|dd…< t|Ž S )z,Returns the standard contextual pop-up menu.r   rË   r  )	r   r   r   r   r   r   r  r¤   r   )r;   rm   rn   r  Úitemsr>   r>   r?   r  ö  s    ùzSimpleEditor._standard_menuc                    sÜ   ˆ j d }g }| |¡}t|ƒdkr(|S |D ]ª}d}d}t|tƒrnt|ƒdkrX|\}}nt|ƒdkrn|\}}}ˆ  |¡}|du r‚q,|j}	| |¡}
|
dkrž|	}
|du rª|}‡ fdd	„}t|||d
�}| 	t
|
|d�¡ q,|S )z7Returns a list of Actions that will create new objects.r   r   FNrA   é   r‡   c                    s   ˆ   ||¡ d S rƒ   )Ú_menu_new_node)rn   r*   ÚpromptrW   r>   r?   Úperform_add$  s    z.SimpleEditor._new_actions.<locals>.perform_add)r*   r  )rË   Ú
on_perform)r  Zget_addr¤   rD   r½   rÚ   Ú__name__Úget_namer   r2   r   )r;   rm   rn   r  ÚaddrÙ   r  r*   Úadd_nodeÚ
class_namerË   r  r  r>   rW   r?   r  	  s4    






zSimpleEditor._new_actionsc                 C   s.   | j }t|tƒr| | j¡S |d uo,| |¡S rƒ   )r
  rD   r   Úcan_copyr  )r;   rn   r<   r>   r>   r?   Ú_is_copyable/  s    
zSimpleEditor._is_copyablec                 C   sV   | j }t|tƒr*| | j¡o&| | j¡}n|d uoD| |¡oD| |¡}|oT| j |¡S rƒ   )r
  rD   r   r   r  Ú
can_deleter	  Úcan_delete_me)r;   rn   r<   Zcan_cutr>   r>   r?   Ú_is_cutable5  s    
ÿ
þÿýzSimpleEditor._is_cutablec                 C   s   | j  |tj¡S rƒ   )r	  Úcan_addr   Zinstance_type)r;   rn   r>   r>   r?   Ú_is_pasteableC  s    zSimpleEditor._is_pasteablec                 C   s@   | j }t|tƒr| | j¡}n|d uo.| |¡}|o>| j |¡S rƒ   )r
  rD   r   r"  r  r	  r#  )r;   rn   r<   r"  r>   r>   r?   Ú_is_deletableF  s
    
zSimpleEditor._is_deletablec                 C   s„   | j }t|tƒr| | j¡}n|d uo.| |¡}|o>| j |¡}|  |¡}| ¡ }|rf|t	j
jjO }n|t	j
jj M }| |¡ |S rƒ   )r
  rD   r   Ú
can_renamer  r	  Zcan_rename_meru   Úflagsr   r5   ZItemFlagZItemIsEditableZsetFlags)r;   rn   r<   r(  ri   r)  r>   r>   r?   Ú_is_renameableN  s    


zSimpleEditor._is_renameablec                 C   s   |r|  |¡sdS | ||¡S )z8Returns whether a given object is droppable on the node.F)Z
can_insertr%  )r;   rm   rn   Ú
add_objectZ
for_insertr>   r>   r?   Ú_is_droppableb  s    zSimpleEditor._is_droppablec                 C   s&   |  ||¡}||us|s|S t |¡S )z2Returns a droppable version of a specified object.)Zdrop_objectræ   rç   )r;   rm   rn   Zdropped_objectré   Ú
new_objectr>   r>   r?   Ú_drop_objecti  s    zSimpleEditor._drop_objectc                 C   s,   |j j}|  |j|d¡ |  |j|d¡ dS )z3Adds a menu item to the menu bar being constructed.ZenabledÚcheckedN)rQ   ÚactionÚ	eval_whenZenabled_whenZchecked_when)r;   Z	menu_itemr0  r>   r>   r?   Úadd_to_menus  s    zSimpleEditor.add_to_menuc                 C   s   |   |¡ dS )z5Adds a toolbar item to the toolbar being constructed.N)r2  )r;   Ztoolbar_itemr>   r>   r?   Úadd_to_toolbary  s    zSimpleEditor.add_to_toolbarc                 C   sD   |j dkr t|j tƒ | jƒs dS |jdkr@t|jtƒ | jƒs@dS dS )zCReturns whether the action should be defined in the user interface.r‡   FT)Zdefined_whenÚevalÚglobalsr  Zvisible_when©r;   r0  r>   r>   r?   Úcan_add_to_menu}  s    

zSimpleEditor.can_add_to_menuc                 C   s
   |   |¡S )z\Returns whether the toolbar action should be defined in the user
        interface.
        )r7  r6  r>   r>   r?   Úcan_add_to_toolbar‰  s    zSimpleEditor.can_add_to_toolbarc                 C   s   | j  | j|¡ dS )z;Performs the action described by a specified Action object.N)r1   Zdo_undoableÚ_perform)r;   r0  Zaction_eventr>   r>   r?   Úperform�  s    zSimpleEditor.performc           
   	   C   sÂ   | j \}}}|j}| jj}| jj}| d¡dkrˆ| d¡dk rF|d7 }zt|tƒ || |||dœƒ W n   ddlm	} |ƒ  Y n0 d S t
||d ƒ}	|	d urª|	||ƒ d S |jd ur¾| |¡ d S )NÚ.r   ú(z()r  rB   )r  r0  r1   r¨   r  Úfindr4  r5  rM   rC   r”   r  )
r;   r0  rm   rn   ri   Úmethod_namer¨   r  rC   Úmethodr>   r>   r?   r9  “  s8    ûý

zSimpleEditor._performc              
   C   sl   |dkrhd}zt |tƒ | jƒs"d}W n6 tyZ } zt d||f ¡ W Y d}~n
d}~0 0 t|||ƒ dS )z¡Evaluates a condition within a defined context, and sets a
        specified object trait based on the result, which is assumed to be a
        Boolean.
        r‡   TFzGException (%s) raised when evaluating the condition %s. Returning True.N)r4  r5  r  Ú	ExceptionÚloggerÚwarningÚsetattr)r;   Ú	conditionrn   Ztraitrp   Úer>   r>   r?   r1  ¸  s    ÿÿzSimpleEditor.eval_whenc                 C   s   | j d t_d| _ dS )z8Copies the current tree node object to the paste buffer.r   N)r  r   ÚinstancerW   r>   r>   r?   Ú_menu_copy_nodeË  s    zSimpleEditor._menu_copy_nodec                 C   s,   | j \}}}|t_d| _ | j|  |¡Ž  dS )z8Cuts the current tree node object into the paste buffer.N)r  r   rF  rì   r´   ©r;   rm   rn   ri   r>   r>   r?   Ú_menu_cut_nodeÐ  s    zSimpleEditor._menu_cut_nodec                 C   s(   | j \}}}d| _ |  ||tjd¡ dS )zWPastes the current contents of the paste buffer into the current
        node.
        NT)r  rê   r   rF  rH  r>   r>   r?   Ú_menu_paste_node×  s    zSimpleEditor._menu_paste_nodec                 C   sŒ   | j \}}}d| _ | |¡}|durˆ|durx| jjdu rxtj | jdd| |¡ tjj	j
tjj	jB ¡}|tjj	j
krxdS | j|  |¡Ž  dS )z'Deletes the current node from the tree.NFTzConfirm Deletionz#Are you sure you want to delete %s?)r  Zconfirm_deleter1   rÝ   r   ZQMessageBoxZquestionr4   r–   ZStandardButtonZYesZNorì   r´   )r;   rm   rn   ri   ÚrcZbutnr>   r>   r?   Ú_menu_delete_nodeß  s"    
ÿûzSimpleEditor._menu_delete_nodec                 C   s"   | j \}}}d| _ | j |¡ dS )zRename the current node.N)r  r4   ZeditItem)r;   r³   ri   r>   r>   r?   Ú_menu_rename_nodeô  s    zSimpleEditor._menu_rename_nodec                 C   sj   z|   |¡\}}}W n   Y dS 0 t| |¡ƒ}| |¡}||krf|dkrZ| ||¡ n|  ||¡ dS )z Handle changes to a widget item.Nr‡   )rc   rE   Útextr–   Z	set_labelr›   )r;   ri   rš   r³   rm   rn   Z	new_labelZ	old_labelr>   r>   r?   Ú_on_nid_changedú  s    
zSimpleEditor._on_nid_changedc                 C   sp   | j \}}}d| _ |ƒ }|du r$dS |r:|j| jdd�jrl|  |||d¡ | jjrl| j | 	| 
¡ d ¡¡ dS )z&Adds a new object to the current node.NZ	livemodal)r<   rý   Fr   )r  rÿ   r.   rÎ   rê   r*   r,   r4   rL   r«   r±   )r;   r*   r  rm   rn   ri   r-  r>   r>   r?   r    s    ÿzSimpleEditor._menu_new_nodec                 C   sÞ   | j }|  ||¡D ]Æ\}}}| |¡}|rt|  |¡D ]}	|  |	¡ q4|D ](}
|  |
¡\}
}|durH|  |||
¡ qHnPt|ddƒ}|du r¢t|ƒdkr¢t	 
|¡|_n"|durÄt|ƒdkrÄ| |¡ |`| |¡r| d¡ qdS )z9Handles the children of a node being completely replaced.Nr    r   T)r4   rÏ   r©   rg   r]   rs   r�   r”   r¤   r   r’   r    r¢   rŸ   rf   )r;   rn   rË   ÚnewrO   rl   rm   ri   rÖ   ro   r«   r¬   rª   r>   r>   r?   rÇ     s$    


zSimpleEditor._children_replacedc                 C   sb  |dd… }|   | j|||¡ |j}t|jƒ}|t|jƒ }| j}|  ||¡D �]\}}	}
|	 |¡}|rð|  	|
¡||… D ]}|  
|¡ qzt|ƒt|jƒ }d}|jD ]F}|  |¡\}}|dur¦||krÐ|| nd}|  |
|||¡ |d7 }q¦nXt|
ddƒ}|du �r"t|ƒdk�r"t |
¡|
_n&|du�rHt|ƒdk�rH|
 |¡ |
`|	 |¡rN|
 d¡ qNdS )z-Handles the children of a node being changed.Niúÿÿÿr   r   r    T)Z
log_changerå   r™   r¤   râ   rã   r4   rÏ   r©   rg   r]   rs   rœ   r”   r   r’   r    r¢   rŸ   rf   )r;   rn   rË   rä   ÚstartÚnÚendrO   rl   rm   ri   rÖ   ro   Ú	remainingZchild_indexr«   r¬   Zinsert_indexrª   r>   r>   r?   rÈ   ?  s<    

	
ÿ
ý

zSimpleEditor._children_updatedc           	   	   C   s‚   | j  d¡}zbg }| jt|ƒ D ]>\}}||vr | |¡ |  |¡d }|  |d¡ |  |¡ q W | j  |¡ n| j  |¡ 0 dS )z-Handles the label of an object being changed.Tr   r   N)r4   r\   r9   rz   r2   rc   r›   rÛ   )	r;   rn   rË   rŽ   Úblkr   rÌ   ri   rm   r>   r>   r?   rÉ   v  s    
zSimpleEditor._label_updatedc           	   	   C   sz   | j  d¡}zZg }| jt|ƒ D ]6\}}||vr | |¡ |  |¡d }|  |||¡ q W | j  |¡ n| j  |¡ 0 dS )z5Handles the column labels of an object being changed.Tr   N)r4   r\   r9   rz   r2   rc   r�   )	r;   rn   rË   rP  rU  r   rÌ   ri   rm   r>   r>   r?   rÊ   ‰  s    
z#SimpleEditor._column_labels_updatedc                 C   sp   t | jtjƒr4t |tƒr$| d¡}n|}| j |¡ | j ¡ }| j 	| j
j¡ |durld|v rl| |d ¡ dS )z[Restores any saved user preference information associated with the
        editor.
        Ú	structureNÚcolumn_state)rD   r.   r   r6   Údictrí   ZrestoreStater4   r�   ZsetExpandsOnDoubleClickr*   Zexpands_on_dclick)r;   ÚprefsrV  r�   r>   r>   r?   Úrestore_prefs™  s    

zSimpleEditor.restore_prefsc                 C   sJ   i }t | jtjƒr$| j ¡  ¡ |d< | j ¡ }|durF| ¡  ¡ |d< |S )zCReturns any user preference information associated with the editor.rV  NrW  )rD   r.   r   r6   Z	saveStaterè   r4   r�   )r;   rY  r�   r>   r>   r?   Ú
save_prefsª  s    
zSimpleEditor.save_prefs)T)N)r   )F)r‡   )r‡   )T)T)r‡   )r‡   )r‡   )T)N)F)r‡   N)fr  Ú
__module__Ú__qualname__Ú__doc__Z
scrollabler
   rN   r	   r#   r$   r&   r'   r(   r"   r@   rS   rU   rX   r[   r`   rh   rr   r�   r‚   r†   r�   ry   r›   r�   rœ   r]   re   rg   r´   rd   r   ÚQStyleZStandardPixmapZSP_FileIconZSP_DirClosedIconZSP_DirOpenIconr»   r˜   r¿   r{   r¥   rI   rÏ   rs   rÚ   rÛ   rß   rá   rå   rê   rë   rì   ru   r¦   Ústaticmethodrc   r|   rñ   rò   ró   rô   rõ   rø   rù   rú   r  r  r  r  r!  r$  r&  r'  r*  r,  r.  r2  r3  r7  r8  r:  r9  r1  rG  rI  rJ  rL  rM  rO  r  rÇ   rÈ   rÉ   rÊ   rZ  r[  Ú__classcell__r>   r>   ra   r?   r!   F   s¼   i
-

+	ý
/

7		








	
O@&


%

 7r!   c                       sR   e Zd ZdZddd„Z‡ fdd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
‡  ZS )r3   zœThe _TreeWidget class is a specialised QTreeWidget that reimplements
    the drag'n'drop support so that it hooks into the provided Traits
    support.
    Nc                 C   sT  t j | |¡ |  tjjj¡ |  d¡ |  	d¡ |  
tj|jjŽ ¡ t|jjƒ}|dkr~|  d¡ |  |¡ |  |jj¡ n
|  d¡ |  |jj¡ |jj}|dkr¸|  d||f ¡ |jjdkrÔ|  t jjj¡ | j |j¡ | j |j ¡ | j! |j"¡ | j# |j$¡ | j% |j&¡ | j' |j(¡ | j) |j*¡ | j+ |j,¡ || _-d| _.dS )zInitialise the tree widget.Tr   Fz‚
            QTreeView::item {
                padding-top: %spx;
                padding-bottom: %spx;
            }
            ÚextendedN)/r   ÚQTreeWidgetÚ__init__ZsetContextMenuPolicyr   r5   ZContextMenuPolicyZCustomContextMenuZsetDragEnabledZsetAcceptDropsZsetIconSizeÚQSizer*   Z	icon_sizer¤   r‰   ZsetHeaderHiddenZsetColumnCountZsetHeaderLabelsZsetAlternatingRowColorsZalternating_row_colorsZvertical_paddingZsetStyleSheetrþ   ZsetSelectionModeZQAbstractItemViewZSelectionModeZExtendedSelectionZitemExpandedÚconnectrô   ZitemCollapsedrõ   ZitemClickedrø   ZitemDoubleClickedrù   ZitemActivatedrú   ZitemSelectionChangedr  ZcustomContextMenuRequestedr  ZitemChangedrO  r+   Ú	_dragging)r;   r-   r<   Zcolumn_countÚpaddingr>   r>   r?   rd  ¿  s>    




úÿ
z_TreeWidget.__init__c                    sX   | j jjrBt|  ¡ ƒD ]*}|  |  |¡¡}|  |¡}|j 	|¡ qt
| j| ƒ |¡ dS )z?Overridden to emit sizeHintChanged() of items for word wrappingN)r+   r*   r•   r~   ZtopLevelItemCountrJ   ZtopLevelItemÚitemDelegateÚsizeHintChangedÚemitr_   rb   ÚresizeEvent)r;   rä   r€   Úmirz   ra   r>   r?   rl  í  s    

z_TreeWidget.resizeEventc                 C   s6  |   ¡ }|du rdS || _|  |¡}|  ¡  tj ¡ ¡| ¡  }| j	 
|¡\}}}| |¡}t |¡}	| |  ¡  ¡ ¡}
t |
 ¡ ¡}| |  ¡  ¡  ¡ ¡ t |¡}|  ¡ }| jtjjjO  _t | ¡ |
 ¡  | ¡ ¡|_|  ¡  |||   |¡¡ | !¡  t "| ¡}| #|	¡ | $|¡ | %|¡ | &|¡ dS )z6Reimplemented to start the drag of a tree widget item.N)'ZcurrentItemrg  ZvisualItemRectrY   ZmapFromGlobalr   ZQCursorr  ZtopLeftr+   rc   Zget_drag_objectr   ÚcoerceZintersectedÚrectrÄ   ÚsizerÅ   ZpaletterÓ   r…   ZQPainterZviewOptionsÚstater_  Z	StateFlagZState_Selectedr   ZQRectri  ÚpaintrJ   rS  ZQDragZsetMimeDataZ	setPixmapZ
setHotSpotr  )r;   r  ri   Znid_rectZhsposr³   rm   rn   Zdrag_objectZmdro  ZpmÚpainterÚoptionZdragr>   r>   r?   Ú	startDragö  s8    
ÿÿ


ÿ



z_TreeWidget.startDragc                 C   s2   |  ¡  t | ¡ ¡ ¡ }|du r&dS | ¡  dS )zUReimplemented to see if the current drag can be handled by the
        tree.
        N)rÍ   r   rn  ÚmimeDatarF  ÚacceptProposedAction)r;   rE  rè   r>   r>   r?   ÚdragEnterEvent"  s
    z_TreeWidget.dragEnterEventc                 C   s0   |  ¡  |  |¡\}}}}}|dur,| ¡  dS )z‚Reimplemented to see if the current drag can be handled by the
        particular tree widget item underneath the cursor.
        N)rÍ   Ú_get_actionrw  )r;   rE  r0  Úto_nodeÚ	to_objectÚto_indexrè   r>   r>   r?   ÚdragMoveEvent2  s    z_TreeWidget.dragMoveEventc                 C   s   |  ¡  | j}| j}d| _|  |¡\}}}}}|dkrÄ|durš| j |||d¡}|durÂz4| ¡  |j| |¡Ž  | |||d¡ W | 	¡  qÂ| 	¡  0 n(| |||d¡}|durÂ| |||d¡ nÐ|dk�r�|du�r`| |||d¡}|du�rŽ| |¡\}	}
}||
u �r||k�r|d8 }z4| ¡  | |	|
|¡ | 
||||d¡ W | 	¡  n
| 	¡  0 n.| j |||d¡}|du�r”| 
||||d¡ ndS | ¡  dS )z+Reimplemented to update the model and tree.Nr2   FTr  r   )rÍ   r+   rg  ry  r.  rß   rì   r´   rê   rá   rë   rw  )r;   rE  r-   Zdraggingr0  rz  r{  r|  rè   Z	from_nodeZfrom_objectZ
from_indexr>   r>   r?   Ú	dropEvent>  s`    ÿÿ


ÿ
ÿ
ÿÿ

ÿz_TreeWidget.dropEventc                 C   s>  d}d}d}d}d}| j }|  | ¡ ¡}|du rP|jjrB|  ¡ }n|||||fS | jdurˆ|}	|	durˆ|	| ju r~|||||fS |	 ¡ }	q^t 	| 
¡ ¡ ¡ }| |¡\}
}}| ¡ tjjjkrÞ| |||d¡rÞd}|}|}d}nR| |¡\}}}|du rüd}n4| |||d¡�rd}n| |||d¡�r,d}nd}|||||fS )z?Work out what action on what object to perform for a drop eventNFr2   Tr  )r+   r  r  r*   rx   r^   rg  r<   r   rn  rv  rF  rc   ZproposedActionr   r5   Z
DropActionZ
MoveActionr,  r´   )r;   rä   r0  rz  r{  r|  rè   r-   ri   r§   r³   rm   rn   r>   r>   r?   ry  |  sH    



ÿþz_TreeWidget._get_action)N)r  r\  r]  r^  rd  rl  ru  rx  r}  r~  ry  ra  r>   r>   ra   r?   r3   ¹  s   
.	,>r3   c                       s4   e Zd ZdZ‡ fdd„Zdd„ Z‡ fdd„Z‡  ZS )r8   z,A delegate class to draw wrapped text labelsc                    s’   |  ¡ }| jj |¡}| j |¡\}}}|  ¡ }|jt|d�}|du rTtƒ  ||¡S ||f}	| 	| j||||	¡}
|
du r„t
 dd¡S t
j|
Ž S dS )zreturns area taken by the text.©ÚcolumnNr   é   )r€  r-   r4   ÚitemFromIndexrc   rŠ   rn   r_   ÚsizeHintrp  r   re  )r;   rt  r™   r€  rQ   rl   rm   rF  r�   Zsize_contextrp  ra   r>   r?   rƒ  Ã  s    zTreeItemDelegate.sizeHintc                 C   s   |  |j¡ dS )zUpdate the editor's geometry.N)ZsetGeometryro  )r;   r-   rt  r™   r>   r>   r?   ÚupdateEditorGeometryÕ  s    z%TreeItemDelegate.updateEditorGeometryc                    s´   | j j |¡}| j  |¡\}}}| ¡ }|jt|d�}	|	du rL| j jjrLt	}	|	du rft
ƒ  |||¡ nJ|	js|t
ƒ  |||¡ |||f}
|	 | j ||||
¡}|dur°t| jj|ƒ dS )z Render the contents of the item.r  N)r-   r4   r‚  rc   r€  rŠ   rn   r*   r•   ÚDEFAULT_WRAP_RENDERERr_   rr  Zhandles_allr   rj  rk  )r;   rs  rt  r™   rQ   rl   rm   rF  r€  r�   Zpaint_contextrp  ra   r>   r?   rr  Ù  s     
ÿzTreeItemDelegate.paint)r  r\  r]  r^  rƒ  r„  rr  ra  r>   r>   ra   r?   r8   ·  s   r8   );r^  ræ   Úcollections.abcrF   Ú	functoolsr   Ú	itertoolsr   ÚloggingZ	pyface.qtr   r   Z
pyface.apir   Zpyface.ui_traitsr   Zpyface.timer.apir   Z
traits.apir	   r
   r   Ztraitsui.editors.tree_editorr   r   r   r   r   r   Ztraitsui.tree_noder   r   r   r   Ztraitsui.menur   r   r   Ztraitsui.ui_traitsr   Ztraitsui.undor   r   r   r-   r   Úhelperr   Ztree_node_renderersr    Ú	getLoggerr  rA  r…  r!   rc  r3   ZQStyledItemDelegater8   r>   r>   r>   r?   Ú<module>   sH    
          }   