3
8ßL]\l  ã               @   s‚  d Z ddlm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 ddl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 d0d1„ d1eƒZ+da,d2d3„ Z-G d4d5„ d5eƒZ.eeeeeeee e!e"e$e%e#e&e'e(e*e+e)gd6�gZ/ed7d8d9e/d:�Z0ed7d9eeeeeeee e!e"e$e%e#e&e'e(e*e+e)gd6�ee.gd8d;egd9d<d=d=d>�gd?�Z1ee.f e1d@�Z2dS )AzD Defines tree node classes and editors for various types of values.
é    )Úabsolute_importN)Ú
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 )zW Returns whether this object can have children (False for this
        class).
        F© )ÚselfÚnoder   r   ú9/tmp/pip-install-5sebvq2j/traitsui/traitsui/value_tree.pyÚtno_allows_childrenG   s    z-SingleValueTreeNodeObject.tno_allows_childrenc             C   s   dS )zI Returns whether the object has children (False for this class).
        Fr   )r   r   r   r   r   Útno_has_childrenQ   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   r   Útno_can_renameZ   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   r   Útno_can_copyd   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   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   r   Útno_can_inserty   s    z(SingleValueTreeNodeObject.tno_can_insertc             C   s   d| j jdd… jƒ  S )z2 Returns the icon for a specified object.
        z@icons:%s_nodeNé   éüÿÿÿ)Ú	__class__Ú__name__Úlower)r   r   Zis_expandedr   r   r   Útno_get_iconƒ   s    z&SingleValueTreeNodeObject.tno_get_iconc             C   s   |dkrd}|| _ dS )z0 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| jƒS d| j| j| jƒf S )z; Gets the label to display for a specified object.
        r$   z%s: %s)r%   ÚnameÚformat_valueÚvalue)r   r   r   r   r   Útno_get_label—   s
    

z'SingleValueTreeNodeObject.tno_get_labelc             C   s   t |ƒS )z5 Returns the formatted version of the value.
        )Úrepr)r   r)   r   r   r   r(   ¦   s    z&SingleValueTreeNodeObject.format_valuec             C   sT   x@t ƒ D ]\}}t||ƒrP qW t}tj|ƒr4t}nt|dƒrBt}|| ||| jd�S )z> Returns the correct node type for a specified value.
        r   )Úparentr'   r)   Úreadonly)	Úbasic_typesÚ
isinstanceÚ	OtherNodeÚinspectÚisclassÚ	ClassNodeÚhasattrÚ
ObjectNoder-   )r   r'   r)   Útyper   r   r   r   Únode_for¯   s    


z"SingleValueTreeNodeObject.node_forN)r    Ú
__module__Ú__qualname__Ú__doc__r
   r   r,   r   r'   r%   r   r)   r   r-   r   r   r   r   r   r   r"   r&   r*   r(   r7   r   r   r   r   r   ,   s"   
	


		r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚMultiValueTreeNodeObjectzA A tree node for objects of types that have multiple values.
    c             C   s   dS )zN Returns whether this object can have children (True for this class).
        Tr   )r   r   r   r   r   r   Ï   s    z,MultiValueTreeNodeObject.tno_allows_childrenc             C   s   dS )zH Returns whether the object has children (True for this class).
        Tr   )r   r   r   r   r   r   Ø   s    z)MultiValueTreeNodeObject.tno_has_childrenN)r    r8   r9   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 )z5 Returns the formatted version of the value.
        éP   z%s...%sNé*   é#   z%s [%d]iÝÿÿÿ)Úlenr+   )r   r)   Únr   r   r   r(   ê   s    zStringNode.format_valueN)r    r8   r9   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    r8   r9   r:   r   r   r   r   rB   ø   s   rB   c               @   s   e Zd ZdZdS )ÚBoolNodez% A tree node for Boolean values.
    N)r    r8   r9   r:   r   r   r   r   rC     s   rC   c               @   s   e Zd ZdZdS )ÚIntNodez% A tree node for integer values.
    N)r    r8   r9   r:   r   r   r   r   rD     s   rD   c               @   s   e Zd ZdZdS )Ú	FloatNodez, A tree node for floating point values.
    N)r    r8   r9   r:   r   r   r   r   rE     s   rE   c               @   s   e Zd ZdZdS )ÚComplexNodez, A tree node for complex number values.
    N)r    r8   r9   r:   r   r   r   r   rF      s   rF   c               @   s   e Zd ZdZdS )r0   zV A tree node for single-value types for which there is not another
    node type.
    N)r    r8   r9   r:   r   r   r   r   r0   *  s   r0   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 )z5 Returns the formatted version of the value.
        z	Tuple(%d))r@   )r   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   )r@   r)   )r   r   r   r   r   r   E  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 )z% Gets the object's children.
        iô  c                s   g | ]\}}ˆ d | |ƒ‘qS )z[%d]r   )Ú.0ÚiÚx)r7   r   r   ú
<listcomp>U  s   z.TupleNode.tno_get_children.<locals>.<listcomp>Néú   z...T)r)   r-   c                s   g | ]\}}ˆ d | |ƒ‘qS )z[%d]r   )rH   rI   rJ   )r7   r   r   rK   X  s   c                s   g | ]\}}ˆ d | |ƒ‘qS )z[%d]r   )rH   rI   rJ   )r7   r   r   rK   [  s    iÿÿÿ)r7   r)   r@   Ú	enumerater<   )r   r   r)   r   )r7   r   Útno_get_childrenO  s    *
zTupleNode.tno_get_childrenN)r    r8   r9   r:   r(   r   rN   r   r   r   r   rG   5  s   	
rG   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 )z5 Returns the formatted version of the value.
        zList(%d))r@   )r   r)   r   r   r   r(   j  s    zListNode.format_valuec             C   s   | j  S )z? Returns whether the object's children can be deleted.
        )r-   )r   r   r   r   r   r   s  s    zListNode.tno_can_deletec             C   s   | j  S )zW Returns whether the object's children can be inserted (vs.
        appended).
        )r-   )r   r   r   r   r   r   }  s    zListNode.tno_can_insertN)r    r8   r9   r:   r(   r   r   r   r   r   r   rO   b  s   	
rO   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 )z5 Returns the formatted version of the value.
        zSet(%d))r@   )r   r)   r   r   r   r(   �  s    zSetNode.format_valueN)r    r8   r9   r:   r(   r   r   r   r   rP   ˆ  s   rP   c               @   s   e Zd ZdZdd„ ZdS )Ú	ArrayNodez A tree node for arrays.
    c             C   s   ddj dd„ |jD ƒƒ S )z5 Returns the formatted version of the value.
        z	Array(%s)ú,c             S   s   g | ]}t |ƒ‘qS r   )Ústr)rH   rA   r   r   r   rK   ¥  s    z*ArrayNode.format_value.<locals>.<listcomp>)ÚjoinÚshape)r   r)   r   r   r   r(   ¢  s    zArrayNode.format_valueN)r    r8   r9   r:   r(   r   r   r   r   rQ   š  s   rQ   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 )z5 Returns the formatted version of the value.
        zDict(%d))r@   )r   r)   r   r   r   r(   ´  s    zDictNode.format_valuec                sŠ   | j ‰ dd„ | j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 )z% Gets the object's children.
        c             S   s   g | ]\}}t |ƒ|f‘qS r   )r+   )rH   ÚkÚvr   r   r   rK   Á  s    z-DictNode.tno_get_children.<locals>.<listcomp>r   )Úkeyiô  c                s   g | ]\}}ˆ d | |ƒ‘qS )z[%s]r   )rH   rW   rX   )r7   r   r   rK   Ä  s    NrL   z...T)r)   r-   c                s   g | ]\}}ˆ d | |ƒ‘qS )z[%s]r   )rH   rW   rX   )r7   r   r   rK   Æ  s    c                s   g | ]\}}ˆ d | |ƒ‘qS )z[%s]r   )rH   rW   rX   )r7   r   r   rK   È  s    iÿÿÿ)r7   r)   ÚitemsÚsortr   r@   r<   )r   r   rZ   r   )r7   r   rN   ½  s    &zDictNode.tno_get_childrenc             C   s   | j  S )z? Returns whether the object's children can be deleted.
        )r-   )r   r   r   r   r   r   Î  s    zDictNode.tno_can_deleteN)r    r8   r9   r:   r(   rN   r   r   r   r   r   rV   ¬  s   	rV   c               @   s   e Zd ZdZdd„ ZdS )ÚFunctionNodez A tree node for functions
    c             C   s
   d|j  S )z5 Returns the formatted version of the value.
        zFunction %s())r    )r   r)   r   r   r   r(   à  s    zFunctionNode.format_valueN)r    r8   r9   r:   r(   r   r   r   r   r\   Ø  s   r\   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú
MethodNodec             C   s*   d}|j dkrd}d||j jj|jjf S )z5 Returns the formatted version of the value.
        ÚBNZUnbz%sound method %s.%s())Ú__self__r   r    Ú__func__)r   r)   r6   r   r   r   r(   ð  s    
zMethodNode.format_valuec             C   s   | j jdk	S )z2 Returns whether the object has children.
        N)r)   r`   )r   r   r   r   r   r      s    zMethodNode.tno_has_childrenc             C   s   | j d| jjƒgS )z% Gets the object's children.
        ZObject)r7   r)   r_   )r   r   r   r   r   rN   	  s    zMethodNode.tno_get_childrenN)r    r8   r9   r(   r   rN   r   r   r   r   r]   ê  s   	r]   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r5   z A tree node for objects.
    c          
   C   s.   y|j j}W n   d}Y nX d|t|ƒf S )z5 Returns the formatted version of the value.
        z???z
%s(0x%08X))r   r    Úid)r   r)   Úklassr   r   r   r(     s
    
zObjectNode.format_valuec          	   C   s    yt | jjƒdkS    dS dS )z2 Returns whether the object has children.
        r   FN)r@   r)   Ú__dict__)r   r   r   r   r   r   (  s    zObjectNode.tno_has_childrenc                s8   dd„ ˆ j jjƒ D ƒ}|jtdƒd� ‡ fdd„|D ƒS )z% Gets the object's children.
        c             S   s   g | ]\}}||f‘qS r   r   )rH   rW   rX   r   r   r   rK   7  s    z/ObjectNode.tno_get_children.<locals>.<listcomp>r   )rY   c                s    g | ]\}}ˆ j d | |ƒ‘qS )Ú.)r7   )rH   rW   rX   )r   r   r   rK   9  s    )r)   rc   rZ   r[   r   )r   r   rZ   r   )r   r   rN   4  s    zObjectNode.tno_get_childrenN)r    r8   r9   r:   r(   r   rN   r   r   r   r   r5     s   r5   c               @   s   e Zd ZdZdd„ ZdS )r3   z A tree node for classes.
    c             C   s   |j S )z5 Returns the formatted version of the value.
        )r    )r   r)   r   r   r   r(   H  s    zClassNode.format_valueN)r    r8   r9   r:   r(   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d	„ Zd
d„ Zdd„ Z	dS )Ú
TraitsNodez A tree node for traits.
    c             C   s   t | jƒ ƒdkS )z2 Returns whether the object has children.
        r   )r@   Ú
_get_names)r   r   r   r   r   r   Z  s    zTraitsNode.tno_has_childrenc       	      C   s~   t | jƒ ƒ}| j}| j}g }x\|D ]T}yt||dƒ}W n* tk
r` } zd| }W Y dd}~X nX |j|d| |ƒƒ q"W |S )z% Gets the object's children.
        z	<unknown>z<%s>Nrd   )Úsortedrf   r)   r7   ÚgetattrÚ	ExceptionÚappend)	r   r   Únamesr)   r7   Únodesr'   Z
item_valueZexcpr   r   r   rN   c  s    
zTraitsNode.tno_get_childrenc             C   sT   | j }i }x |jdd„ d�D ]}d||< qW x|jjƒ D ]}d||< q8W t|jƒ ƒS )z= Gets the names of all defined traits or attributes.
        c             S   s   | dkS )NÚeventr   )rJ   r   r   r   Ú<lambda>|  s    z'TraitsNode._get_names.<locals>.<lambda>)r6   N)r)   Ztrait_namesrc   ÚkeysÚlist)r   r)   rk   r'   r   r   r   rf   w  s    zTraitsNode._get_namesc             C   s   || _ | jj| j|dd� dS )zb Sets up or removes a listener for children being replaced on a
        specified object.
        Úui)ÚremoveÚdispatchN)Ú	_listenerr)   Zon_trait_changeÚ_children_replaced)r   r   Úlistenerrr   r   r   r   Útno_when_children_replaced‡  s    z%TraitsNode.tno_when_children_replacedc             C   s   | j | ƒ d S )N)rt   )r   r   r   r   ru   �  s    zTraitsNode._children_replacedc             C   s   dS )za Sets up or removes a listener for children being changed on a
        specified object.
        Nr   )r   r   rv   rr   r   r   r   Útno_when_children_changed—  s    z$TraitsNode.tno_when_children_changedN)
r    r8   r9   r:   r   rN   rf   rw   ru   rx   r   r   r   r   re   R  s   	re   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 )z5 Returns the formatted version of the value.
        r$   r   )r   r)   r   r   r   r(   ª  s    zRootNode.format_valuec             C   s   | j d| jƒgS )z% Gets the object's children.
        r$   )r7   r)   )r   r   r   r   r   rN   ³  s    zRootNode.tno_get_childrenN)r    r8   r9   r:   r(   rN   r   r   r   r   ry   ¢  s   	ry   c              C   s¨   t d kr¤td ƒtfttftj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 y(ddlm}  t jt| dgƒƒt fƒ W n t!k
r¢   Y nX t S )Nr   )Úarrayr   )"Ú_basic_typesr6   rB   rS   r<   ÚsixÚ	text_typeÚboolrC   ÚintrD   ÚfloatrE   ÚcomplexrF   ÚtuplerG   rp   rO   ÚsetrP   ÚdictrV   r   r\   r   r]   r	   re   Znumpyrz   rj   rQ   ÚImportError)rz   r   r   r   r.   ¿  s*    

r.   c               @   s   e Zd ZeeƒZdS )Ú
_ValueTreeN)r    r8   r9   r   r   Úvaluesr   r   r   r   r†   ã  s   r†   )r7   é   TF)Ú	auto_openZ	hide_rootÚeditablerl   r‡   z=ValuesZtraits_node)r7   r‰   ÚchildrenÚmoveÚcopyr%   Z
icon_groupZ	icon_open)r‰   rŠ   rl   )Úeditor)3r:   Ú
__future__r   r1   Úoperatorr   Útypesr   r   Z
traits.apir   r   r   r	   r
   r   r   Z	tree_noder   r   r   Zeditors.tree_editorr   r|   r   r;   r<   rB   rC   rD   rE   rF   r0   rG   rO   rP   rQ   rV   r\   r]   r5   r3   re   ry   r{   r.   r†   Zvalue_tree_nodesZvalue_tree_editorZvalue_tree_editor_with_rootZ	ValueTreer   r   r   r   Ú<module>   sv   $ 




-&,)-P$




	