a
    §ˆc™&  ã                   @   s@   d Z ddlmZmZ ddlmZ ddlmZ G dd„ deƒZdS )	ú: The model for a tree control with extensible node types. é    )ÚDictÚInstanceé   )ÚNodeManager)Ú	TreeModelc                   @   sð   e Zd ZdZeedƒZeƒ 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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/d0„ Zd1d2„ Z d3d4„ Z!d5d6„ Z"d7S )8ÚNodeTreeModelr   © c                 C   s*   | j  |¡}| |¡r"| |¡}nd}|S )a   Returns True if a node has children, otherwise False.

        This method is provided in case the model has an efficient way to
        determine whether or not a node has any children without having to
        actually get the children themselves.

        F)Únode_managerÚget_node_typeÚallows_childrenÚhas_children)ÚselfÚnodeÚ	node_typer   r	   r	   ú^/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/tree/node_tree_model.pyr   &   s
    

zNodeTreeModel.has_childrenc                 C   s*   | j  |¡}| |¡r"| |¡}ng }|S )z! Returns the children of a node. )r
   r   r   Úget_children)r   r   r   Úchildrenr	   r	   r   r   :   s
    
zNodeTreeModel.get_childrenc                 C   s   | j  |¡}| |¡S )z( Returns the default action for a node. )r
   r   Úget_default_action©r   r   r   r	   r	   r   r   K   s    z NodeTreeModel.get_default_actionc                 C   s   | j  |¡}| |¡S )zk Get the value that is dragged for a node.

        By default the drag value is the node itself.

        )r
   r   Úget_drag_valuer   r	   r	   r   r   S   s    zNodeTreeModel.get_drag_valuec                 C   s   | j  |¡}| ||¡S )z@ Returns True if a node allows an object to be dropped onto it. )r
   r   Úcan_drop©r   r   Údatar   r	   r	   r   r   _   s    zNodeTreeModel.can_dropc                 C   s   | j  |¡}| ||¡ dS )z Drops an object onto a node. N)r
   r   Údropr   r	   r	   r   r   g   s    zNodeTreeModel.dropc                 C   s   | j  |¡}| |||¡S )zj Returns the label image for a node.

        Return None (the default) if no image is required.

        )r
   r   Ú	get_image)r   r   ÚselectedÚexpandedr   r	   r	   r   r   o   s    zNodeTreeModel.get_imagec                 C   s   | j  |¡S )z# Generate a unique key for a node. )r
   Úget_key)r   r   r	   r	   r   r   {   s    zNodeTreeModel.get_keyc                 C   s   | j  |¡}| |¡S )zz Get the value that is used when a node is selected.

        By default the selection value is the node itself.

        )r
   r   Úget_selection_valuer   r	   r	   r   r   €   s    z!NodeTreeModel.get_selection_valuec                 C   s   | j  |¡}| |¡S )z} Returns the label text for a node.

        Return None if no text is required.  By default we return 'str(node)'.

        )r
   r   Úget_textr   r	   r	   r   r    Œ   s    zNodeTreeModel.get_textc                 C   s   | j  |¡}| ||¡S )z. Returns True if the node's label can be set. )r
   r   Úcan_set_text©r   r   Útextr   r	   r	   r   r!   ˜   s    zNodeTreeModel.can_set_textc                 C   s   | j  |¡}| ||¡S )z! Sets the label text for a node. )r
   r   Úset_textr"   r	   r	   r   r$       s    zNodeTreeModel.set_textc                 C   s   | j  |¡}| |¡S )z; Returns True if the node is collapsible, otherwise False. )r
   r   Úis_collapsibler   r	   r	   r   r%   ¨   s    zNodeTreeModel.is_collapsiblec                 C   s   | j  |¡}| |¡S )z9 Returns True if the node is draggable, otherwise False. )r
   r   Úis_draggabler   r	   r	   r   r&   °   s    zNodeTreeModel.is_draggablec                 C   s   | j  |¡}| |¡S )zƒ Returns True if the node is editable, otherwise False.

        If the node is editable, its text can be set via the UI.

        )r
   r   Úis_editabler   r	   r	   r   r'   ¸   s    zNodeTreeModel.is_editablec                 C   s   | j  |¡}| |¡S )z; Returns True if the node is expandanble, otherwise False. )r
   r   Úis_expandabler   r	   r	   r   r(   Ä   s    zNodeTreeModel.is_expandablec                 C   s>   | j  |¡}| |¡}|dur:|  |¡ || j| j  |¡< dS )z( Adds a listener for changes to a node. N)r
   r   Zget_monitorÚ_start_monitorÚ	_monitorsr   )r   r   r   Úmonitorr	   r	   r   Úadd_listenerÌ   s
    

zNodeTreeModel.add_listenerc                 C   s6   | j  |¡}| j |¡}|dur2|  |¡ | j|= dS )z+ Removes a listener for changes to a node. N)r
   r   r*   ÚgetÚ_stop_monitor)r   r   Úkeyr+   r	   r	   r   Úremove_listenerØ   s    
zNodeTreeModel.remove_listenerc                 C   s   | j  |¡}| |¡S )z& Returns the context menu for a node. )r
   r   Úget_context_menur   r	   r	   r   r1   è   s    zNodeTreeModel.get_context_menuc                 C   sR   |  | jd¡ |  | jd¡ |  | jd¡ |  | jd¡ |  | jd¡ | ¡  dS )z Starts a monitor. Únodes_changedÚnodes_insertedÚnodes_removedÚnodes_replacedÚstructure_changedN)ÚobserveÚ_on_nodes_changedÚ_on_nodes_insertedÚ_on_nodes_removedÚ_on_nodes_replacedÚ_on_structure_changedÚstart©r   r+   r	   r	   r   r)   ô   s    zNodeTreeModel._start_monitorc                 C   sf   |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� | ¡  dS )	z Stops a monitor. r2   T)Úremover3   r4   r5   r6   N)r7   r8   r9   r:   r;   r<   Ústopr>   r	   r	   r   r.     s    ÿzNodeTreeModel._stop_monitorc                 C   s   |j | _dS )z! Called when nodes have changed. N)Únewr2   ©r   Úeventr	   r	   r   r8   +  s    zNodeTreeModel._on_nodes_changedc                 C   s   |j | _dS )z' Called when nodes have been inserted. N)rA   r3   rB   r	   r	   r   r9   0  s    z NodeTreeModel._on_nodes_insertedc                 C   s   |j | _dS )z& Called when nodes have been removed. N)rA   r4   rB   r	   r	   r   r:   5  s    zNodeTreeModel._on_nodes_removedc                 C   s   |j | _dS )z' Called when nodes have been replaced. N)rA   r5   rB   r	   r	   r   r;   :  s    z NodeTreeModel._on_nodes_replacedc                 C   s   |j | _dS )z> Called when the structure of a node has changed drastically. N)rA   r6   rB   r	   r	   r   r<   ?  s    z#NodeTreeModel._on_structure_changedN)#Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r
   r   r*   r   r   r   r   r   r   r   r   r   r    r!   r$   r%   r&   r'   r(   r,   r0   r1   r)   r.   r8   r9   r:   r;   r<   r	   r	   r	   r   r      s:   
(r   N)	rG   Z
traits.apir   r   r
   r   Z
tree_modelr   r   r	   r	   r	   r   Ú<module>   s   