a
    §ˆc6;  ã                   @   sn  d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	m
Z
mZmZmZmZ ddlmZmZmZ ddlmZ G d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd „ d eƒZ G d!d"„ d"eƒZ!G d#d$„ d$eƒZ"G d%d&„ d&eƒZ#G d'd(„ d(eƒZ$G d)d*„ d*eƒZ%G d+d,„ d,e%ƒZ&G d-d.„ d.e%ƒZ'G d/d0„ d0eƒZ(da)d1d2„ Z*G d3d4„ d4e
ƒZ+eeeeeeeeeee!e"e e#e$e%e'e(e&gd5�gZ,ed6d7d8e,d9�Z-ed6d8eeeeeeeeeee!e"e e#e$e%e'e(e&gd5�ee+gd7d:egd8d;d<d<d=�gd>�Z.ee+d?e.d@�Z/dS )AzD Defines tree node classes and editors for various types of values.
é    N)Ú
itemgetter)ÚFunctionTypeÚ
MethodType)ÚAnyÚBoolÚHasPrivateTraitsÚ	HasTraitsÚInstanceÚListÚStré   )ÚObjectTreeNodeÚTreeNodeÚTreeNodeObject)Ú
TreeEditorc                   @   sŠ   e Zd ZdZeeƒZeƒ Zeƒ Z	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d„ Zdd„ Zdd„ Zdd„ ZdS )ÚSingleValueTreeNodeObjectz:A tree node for objects of types that have a single value.Fc                 C   s   dS )zVReturns whether this object can have children (False for this
        class).
        F© ©ÚselfÚnoder   r   úV/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/value_tree.pyÚtno_allows_children8   s    z-SingleValueTreeNodeObject.tno_allows_childrenc                 C   s   dS )z?Returns whether the object has children (False for this class).Fr   r   r   r   r   Útno_has_children>   s    z*SingleValueTreeNodeObject.tno_has_childrenc                 C   s   dS )z]Returns whether the object's children can be renamed (False for
        this class).
        Fr   r   r   r   r   Útno_can_renameB   s    z(SingleValueTreeNodeObject.tno_can_renamec                 C   s   dS )z[Returns whether the object's children can be copied (True for this
        class).
        Tr   r   r   r   r   Útno_can_copyH   s    z&SingleValueTreeNodeObject.tno_can_copyc                 C   s   dS )z]Returns whether the object's children can be deleted (False for
        this class).
        Fr   r   r   r   r   Útno_can_deleteN   s    z(SingleValueTreeNodeObject.tno_can_deletec                 C   s   dS )z~Returns whether the object's children can be inserted (False,
        meaning children are appended, for this class).
        Fr   r   r   r   r   Útno_can_insertT   s    z(SingleValueTreeNodeObject.tno_can_insertc                 C   s   d| j jdd…  ¡  S )z(Returns the icon for a specified object.z@icons:%s_nodeNéüÿÿÿ)Ú	__class__Ú__name__Úlower)r   r   Zis_expandedr   r   r   Útno_get_iconZ   s    z&SingleValueTreeNodeObject.tno_get_iconc                 C   s   |dkrd}|| _ dS )z&Sets the label for a specified object.ú?Ú N)Úlabel)r   r   r$   r   r   r   Útno_set_label^   s    z'SingleValueTreeNodeObject.tno_set_labelc                 C   s<   | j dkr| j S | jdkr&|  | j¡S d| j|  | j¡f S )z1Gets the label to display for a specified object.r#   z%s: %s)r$   ÚnameÚformat_valueÚvaluer   r   r   r   Útno_get_labeld   s
    

z'SingleValueTreeNodeObject.tno_get_labelc                 C   s   t |ƒS ©ú+Returns the formatted version of the value.©Úrepr©r   r(   r   r   r   r'   n   s    z&SingleValueTreeNodeObject.format_valuec                 C   sR   t ƒ D ]\}}t||ƒr q@qt}t |¡r2t}nt|dƒr@t}|| ||| jd�S )z4Returns the correct node type for a specified value.r   )Úparentr&   r(   Úreadonly)	Úbasic_typesÚ
isinstanceÚ	OtherNodeÚinspectÚisclassÚ	ClassNodeÚhasattrÚ
ObjectNoder0   )r   r&   r(   Útyper   r   r   r   Únode_forr   s    



ÿz"SingleValueTreeNodeObject.node_forN)r   Ú
__module__Ú__qualname__Ú__doc__r	   r   r/   r   r&   r$   r   r(   r   r0   r   r   r   r   r   r   r!   r%   r)   r'   r:   r   r   r   r   r   "   s"   
r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚMultiValueTreeNodeObjectz;A tree node for objects of types that have multiple values.c                 C   s   dS )zDReturns whether this object can have children (True for this class).Tr   r   r   r   r   r   ‡   s    z,MultiValueTreeNodeObject.tno_allows_childrenc                 C   s   dS )z>Returns whether the object has children (True for this class).Tr   r   r   r   r   r   ‹   s    z)MultiValueTreeNodeObject.tno_has_childrenN)r   r;   r<   r=   r   r   r   r   r   r   r>   „   s   r>   c                   @   s   e Zd ZdZdd„ ZdS )Ú
StringNodezA tree node for strings.c                 C   s@   t |ƒ}t |ƒdkr0d|dd… |dd… f }dt|ƒ|f S )r+   éP   z%s...%sNé*   iÝÿÿÿz%s [%d])Úlenr-   )r   r(   Únr   r   r   r'   “   s    zStringNode.format_valueN©r   r;   r<   r=   r'   r   r   r   r   r?   �   s   r?   c                   @   s   e Zd ZdZdS )ÚNoneNodezA tree node for None values.N©r   r;   r<   r=   r   r   r   r   rE   œ   s   rE   c                   @   s   e Zd ZdZdS )ÚBoolNodezA tree node for Boolean values.NrF   r   r   r   r   rG   ¢   s   rG   c                   @   s   e Zd ZdZdS )ÚIntNodezA tree node for integer values.NrF   r   r   r   r   rH   ¨   s   rH   c                   @   s   e Zd ZdZdS )Ú	FloatNodez&A tree node for floating point values.NrF   r   r   r   r   rI   ®   s   rI   c                   @   s   e Zd ZdZdS )ÚComplexNodez&A tree node for complex number values.NrF   r   r   r   r   rJ   ´   s   rJ   c                   @   s   e Zd ZdZdS )r3   zUA tree node for single-value types for which there is not another
    node type.
    NrF   r   r   r   r   r3   º   s   r3   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú	TupleNodezA tree node for tuples.c                 C   s   dt |ƒ S )r+   z	Tuple(%d)©rB   r.   r   r   r   r'   Å   s    zTupleNode.format_valuec                 C   s   t | jƒdkS )z[Returns whether the object has children, based on the length of
        the tuple.
        r   )rB   r(   r   r   r   r   r   É   s    zTupleNode.tno_has_childrenc                    sx   | j ‰ | j}t|ƒdkrb‡ fdd„t|dd… ƒD ƒtddd�g ‡ fd	d„t|d
d… ƒD ƒ S ‡ fdd„t|ƒD ƒS )úGets the object's children.éô  c                    s   g | ]\}}ˆ d | |ƒ‘qS ©z[%d]r   ©Ú.0ÚiÚx©r:   r   r   Ú
<listcomp>Õ   ó    z.TupleNode.tno_get_children.<locals>.<listcomp>Néú   ú...T©r(   r0   c                    s   g | ]\}}ˆ d | |ƒ‘qS rO   r   rP   rT   r   r   rU   ×   rV   éÿÿÿc                    s   g | ]\}}ˆ d | |ƒ‘qS rO   r   rP   rT   r   r   rU   Ú   rV   )r:   r(   rB   Ú	enumerater?   )r   r   r(   r   rT   r   Útno_get_childrenÏ   s    ÿþÿzTupleNode.tno_get_childrenN©r   r;   r<   r=   r'   r   r\   r   r   r   r   rK   Â   s   rK   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚListNodezA tree node for lists.c                 C   s   dt |ƒ S )r+   zList(%d)rL   r.   r   r   r   r'   à   s    zListNode.format_valuec                 C   s   | j  S ©z5Returns whether the object's children can be deleted.©r0   r   r   r   r   r   ä   s    zListNode.tno_can_deletec                 C   s   | j  S )zVReturns whether the object's children can be inserted (vs.
        appended).
        r`   r   r   r   r   r   è   s    zListNode.tno_can_insertN)r   r;   r<   r=   r'   r   r   r   r   r   r   r^   Ý   s   r^   c                   @   s   e Zd ZdZdd„ ZdS )ÚSetNodezA tree node for sets.c                 C   s   dt |ƒ S )r+   zSet(%d)rL   r.   r   r   r   r'   ò   s    zSetNode.format_valueNrD   r   r   r   r   ra   ï   s   ra   c                   @   s   e Zd ZdZdd„ ZdS )Ú	ArrayNodezA tree node for arrays.c                 C   s   dd  dd„ |jD ƒ¡ S )r+   z	Array(%s)ú,c                 S   s   g | ]}t |ƒ‘qS r   )Ústr)rQ   rC   r   r   r   rU   ü   rV   z*ArrayNode.format_value.<locals>.<listcomp>)ÚjoinÚshaper.   r   r   r   r'   ú   s    zArrayNode.format_valueNrD   r   r   r   r   rb   ÷   s   rb   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚDictNodezA tree node for dictionaries.c                 C   s   dt |ƒ S )r+   zDict(%d)rL   r.   r   r   r   r'     s    zDictNode.format_valuec                    sŠ   | j ‰ dd„ | j ¡ D ƒ}|jtdƒd� t|ƒdkrx‡ fdd„|dd… D ƒtd	d
d�g ‡ fdd„|dd… D ƒ S ‡ fdd„|D ƒS )rM   c                 S   s   g | ]\}}t |ƒ|f‘qS r   r,   ©rQ   ÚkÚvr   r   r   rU   	  rV   z-DictNode.tno_get_children.<locals>.<listcomp>r   ©ÚkeyrN   c                    s   g | ]\}}ˆ d | |ƒ‘qS ©z[%s]r   rh   rT   r   r   rU     rV   NrW   rX   TrY   c                    s   g | ]\}}ˆ d | |ƒ‘qS rm   r   rh   rT   r   r   rU     rV   rZ   c                    s   g | ]\}}ˆ d | |ƒ‘qS rm   r   rh   rT   r   r   rU     rV   )r:   r(   ÚitemsÚsortr   rB   r?   ©r   r   rn   r   rT   r   r\     s    ÿþÿzDictNode.tno_get_childrenc                 C   s   | j  S r_   r`   r   r   r   r   r     s    zDictNode.tno_can_deleteN)r   r;   r<   r=   r'   r\   r   r   r   r   r   rg   ÿ   s   rg   c                   @   s   e Zd ZdZdd„ ZdS )ÚFunctionNodezA tree node for functionsc                 C   s
   d|j  S )r+   zFunction %s()©r   r.   r   r   r   r'     s    zFunctionNode.format_valueNrD   r   r   r   r   rq     s   rq   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú
MethodNodec                 C   s*   d}|j du rd}d||j jj|jjf S )r+   ÚBNZUnbz%sound method %s.%s())Ú__self__r   r   Ú__func__)r   r(   r9   r   r   r   r'   '  s    
ýzMethodNode.format_valuec                 C   s   | j jduS )ú(Returns whether the object has children.N)r(   rv   r   r   r   r   r   3  s    zMethodNode.tno_has_childrenc                 C   s   |   d| jj¡gS )rM   ZObject)r:   r(   ru   r   r   r   r   r\   7  s    zMethodNode.tno_get_childrenN)r   r;   r<   r'   r   r\   r   r   r   r   rs   &  s   rs   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r8   zA tree node for objects.c                 C   s.   z|j j}W n   d}Y n0 d|t|ƒf S )r+   z???z
%s(0x%08X))r   r   Úid)r   r(   Úklassr   r   r   r'   ?  s
    
zObjectNode.format_valuec                 C   s&   zt | jjƒdkW S    Y dS 0 dS )rw   r   FN)rB   r(   Ú__dict__r   r   r   r   r   G  s    zObjectNode.tno_has_childrenc                    s8   dd„ ˆ j j ¡ D ƒ}|jtdƒd� ‡ fdd„|D ƒS )rM   c                 S   s   g | ]\}}||f‘qS r   r   rh   r   r   r   rU   P  rV   z/ObjectNode.tno_get_children.<locals>.<listcomp>r   rk   c                    s    g | ]\}}ˆ   d | |¡‘qS )Ú.rT   rh   ©r   r   r   rU   R  rV   )r(   rz   rn   ro   r   rp   r   r|   r   r\   N  s    zObjectNode.tno_get_childrenNr]   r   r   r   r   r8   <  s   r8   c                   @   s   e Zd ZdZdd„ ZdS )r6   zA tree node for classes.c                 C   s   |j S r*   rr   r.   r   r   r   r'   X  s    zClassNode.format_valueNrD   r   r   r   r   r6   U  s   r6   c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )Ú
TraitsNodezA tree node for traits.c                 C   s   t |  ¡ ƒdkS )rw   r   )rB   Ú
_get_namesr   r   r   r   r   `  s    zTraitsNode.tno_has_childrenc           	      C   s|   t |  ¡ ƒ}| j}| j}g }|D ]V}zt||dƒ}W n, ty` } zd| }W Y d}~n
d}~0 0 | |d| |ƒ¡ q |S )rM   z	<unknown>z<%s>Nr{   )Úsortedr~   r(   r:   ÚgetattrÚ	ExceptionÚappend)	r   r   Únamesr(   r:   Únodesr&   Z
item_valueZexcpr   r   r   r\   d  s    zTraitsNode.tno_get_childrenc                 C   sL   | j }i }|jdd„ d�D ]}d||< q|j ¡ D ]}d||< q2t| ¡ ƒS )z3Gets the names of all defined traits or attributes.c                 S   s   | dkS )NÚeventr   )rS   r   r   r   Ú<lambda>w  rV   z'TraitsNode._get_names.<locals>.<lambda>)r9   N)r(   Ztrait_namesrz   ÚkeysÚlist)r   r(   rƒ   r&   r   r   r   r~   s  s    

zTraitsNode._get_namesc                 C   s   || _ | jj| j|dd� dS )zaSets up or removes a listener for children being replaced on a
        specified object.
        Zui)ÚremoveÚdispatchN)Ú	_listenerr(   Zon_trait_changeÚ_children_replaced©r   r   Zlistenerr‰   r   r   r   Útno_when_children_replaced}  s    ÿz%TraitsNode.tno_when_children_replacedc                 C   s   |   | ¡ d S )N)r‹   r|   r   r   r   rŒ   †  s    zTraitsNode._children_replacedc                 C   s   dS )z`Sets up or removes a listener for children being changed on a
        specified object.
        Nr   r�   r   r   r   Útno_when_children_changed‰  s    z$TraitsNode.tno_when_children_changedN)
r   r;   r<   r=   r   r\   r~   rŽ   rŒ   r�   r   r   r   r   r}   ]  s   
	r}   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚRootNodezA root node.c                 C   s   dS )r+   r#   r   r.   r   r   r   r'   “  s    zRootNode.format_valuec                 C   s   |   d| j¡gS )rM   r#   )r:   r(   r   r   r   r   r\   —  s    zRootNode.tno_get_childrenN)r   r;   r<   r=   r'   r\   r   r   r   r   r�   �  s   r�   c                  C   s¤   t d u r td ƒtfttfttfttfttft	t
fttfttfttfttfttfttfttfttfga z(ddlm}  t  t| dgƒƒtf¡ W n tyž   Y n0 t S )Nr   ©Úarrayr   ) Ú_basic_typesr9   rE   rd   r?   ÚboolrG   ÚintrH   ÚfloatrI   ÚcomplexrJ   ÚtuplerK   rˆ   r^   Úsetra   Údictrg   r   rq   r   rs   r   r}   Únumpyr’   r‚   rb   ÚImportErrorr‘   r   r   r   r1   £  s,    
òr1   c                   @   s   e Zd ZeeƒZdS )Ú
_ValueTreeN)r   r;   r<   r
   r   Úvaluesr   r   r   r   r�   Ã  s   r�   rT   é   TF)Ú	auto_openZ	hide_rootÚeditabler„   rž   z=ValuesZtraits_node)r:   r    ÚchildrenÚmoveÚcopyr$   Z
icon_groupZ	icon_open)r    r¡   r„   r   )Zeditor)0r=   r4   Úoperatorr   Útypesr   r   Z
traits.apir   r   r   r   r	   r
   r   Z	tree_noder   r   r   Zeditors.tree_editorr   r   r>   r?   rE   rG   rH   rI   rJ   r3   rK   r^   ra   rb   rg   rq   rs   r8   r6   r}   r�   r“   r1   r�   Zvalue_tree_nodesZvalue_tree_editorZvalue_tree_editor_with_rootZ	ValueTreer   r   r   r   Ú<module>   s¶   $
b3 îÿÿÿîÿøéý,