3
XIÃ\¼t  ã               @   sŽ  d 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 ddlmZmZmZmZmZmZm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 dd
lm Z  dd„ Z!dd„ 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+d(d"d#„Z,e-d$k�rŠdd%l.m/Z/ e/ƒ Z0e,d&d'�\Z1Z2Z3e0j4ƒ  dS ))aƒ  A tvtk pipeline browser.

An abstract `TreeGenerator` class defines the interface of a tree
generator.  This class is responsible for generating the list of
children.  Often tvtk object's children are collections of various
objects, some sequences and some simple objects.  In order to provide
a unified interface to all children, all of these objects are wrapped
using the `CompositeIterable` which presents all children as a single
iterable.

`SimpleTreeGenerator` does not do extensive analysis of the passed
object in order to compute the children.  `FullTreeGenerator` however
uses the algorithm that MayaVi-1.x uses and therefore generates a
large number of objects.

The `PipelineBrowser` class presents the view of the pipeline as a
tree.  It allows one to specify the TreeGenerator instance.  The
`TreeEditor` from the traits package is used to represent the view.  A
`TVTKLeafNode` defines a node that has no children.  A
`TVTKBranchNode` is a node that has children.  The nodes basically
wrap up the tvtk object and present an interface suitable for the
TreeEditor.

TODO:

 * When a node is selected, the actor involved could be highlighted.

é    N)
Ú	HasTraitsÚPropertyÚAnyÚInstanceÚEventÚTraitÚListÚStrÚDictÚPython)Ú
TreeEditorÚTreeNodeObjectÚObjectTreeNodeÚViewÚItemÚGroupÚVSplit)ÚMenuÚAction)Útvtk)Ú	messenger)ÚTVTKBase)ÚTVTKBaseHandler)Úcamel2enthoughtc             C   s
   t | dƒS )NÚ__iter__)Úhasattr)Úx© r   úX/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/tvtk/pipeline/browser.pyÚis_iterable5   s    r   c             C   sP   ddddddddd	d
ddddddœ}| j ƒ }x|D ]}|j|ƒr2|| S q2W dS )z“Given the name of the object, this function returns an
    appropriate icon image name.  If no icon is appropriate it returns
    the empty string.z	actor.pngz
camera.pngzcoordinate.pngz
filter.pngzlookuptable.pngz
mapper.pngzpolydata.pngzproperty.pngz
reader.pngzrenderer.pngzrendererwindowinteractor.pngz
source.pngztexture.pngz
window.pngz
writer.png)ZactorÚcameraZ
coordinateÚfilterZlookuptableÚmapperZpolydataÚpropertyÚreaderÚrendererZrendererwindowinteractorÚsourceÚtextureÚwindowÚwriterÚ )ÚlowerÚendswith)Úobject_nameZicon_mapÚnameÚkeyr   r   r   Úget_icon9   s(    

r0   c               @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚTreeGeneratorzREncapsulates the methods that generate the tree via the
    `get_children` method.c             C   s   t ‚dS )z*Returns True if object `obj` has children.N)ÚNotImplementedError)ÚselfÚobjr   r   r   Úhas_childrenb   s    zTreeGenerator.has_childrenc             C   s   t ‚dS )zIReturns a dictionary containing the children of the object
        `obj`.N)r2   )r3   r4   r   r   r   Úget_childrenf   s    zTreeGenerator.get_childrenc             C   s   t ‚dS )z+Get a node object representing this object.N)r2   )r3   r4   r   r   r   Úget_nodek   s    zTreeGenerator.get_nodec             C   s   t ‚dS )zqReturns a list of nodes for the tree editor.  The menu
        entries to use for the nodes are passed as `menu`.N)r2   )r3   Úmenur   r   r   Ú	get_nodeso   s    zTreeGenerator.get_nodesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r5   r6   r7   r9   r   r   r   r   r1   ^   s
   r1   c               @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚSimpleTreeGeneratorzmThis particular class generates a simple pipeline
    representation.  Not every possible object is obtained.c             C   s:   t |tjtjtjfƒrdS xdD ]}t||ƒr dS q W dS )zfReturns true of the object has children, false if not.  This is
        very specific to tvtk objects.Tr&   Ú	get_inputÚinputr"   r#   r'   Útext_propertyÚvolume_propertyÚlookup_tableÚproducer_portÚproducerÚget_input_algorithmF)r&   r?   r@   r"   r#   r'   rA   rB   rC   rD   rE   rF   )Ú
isinstancer   ÚRenderWindowÚRendererÚ
Collectionr   )r3   r4   Ú	attributer   r   r   r5   |   s    
  
z SimpleTreeGenerator.has_childrenc                s^  i ‰ ‡ fdd„}t ˆtjƒr&dˆjiS t ˆtjƒrXtˆdƒrJˆjˆjdœS ˆjˆjdœS x&dD ]}tˆ|ƒr^||t	ˆ|ƒƒ q^W tˆdƒr®‡fdd„t
ˆjƒD ƒ}|d|ƒ ntˆdƒrÄ|dˆjƒ tˆdƒ�r*g }tˆdƒ� rú‡fdd„t
ˆjƒD ƒ}n$tˆdƒ�r‡fdd„t
ˆjƒD ƒ}|d|ƒ ntˆdƒ�rB|dˆjƒ tˆdƒ�rZ|dˆjƒ ˆ S )z§Returns the child objects of a particular tvtk object in a
        dictionary, the keys are the trait names.  This is used to
        generate the tree in the browser.c                s\   |d krd ˆ | < nFt |ƒt g ƒt f ƒfkrFdd„ |D ƒ}|rX|ˆ | < nt|tƒrX|ˆ | < d S )Nc             S   s   g | ]}t |tƒr|‘qS r   )rG   r   )Ú.0Úir   r   r   ú
<listcomp>–   s    zFSimpleTreeGenerator.get_children.<locals>._add_kid.<locals>.<listcomp>)ÚtyperG   r   )r/   r   Úx1)Úkidsr   r   Ú_add_kid‘   s    


z2SimpleTreeGenerator.get_children.<locals>._add_kidÚ	renderersÚ
view_props)rT   Úactive_camera)ÚpropsrU   r"   r#   r'   rA   rB   rC   rE   Únumber_of_sourcesc                s   g | ]}ˆ j |ƒ‘qS r   )Ú
get_source)rL   rM   )r4   r   r   rN   ²   s   z4SimpleTreeGenerator.get_children.<locals>.<listcomp>r&   rF   Únumber_of_input_portsc                s,   g | ]$}t ˆ j|ƒƒD ]}ˆ j||ƒ‘qqS r   )ÚrangeÚget_number_of_input_connectionsrF   )rL   rM   Új)r4   r   r   rN   »   s   r?   c                s   g | ]}ˆ j |ƒ‘qS r   )r?   )rL   rM   )r4   r   r   rN   À   s   r@   rD   )r"   r#   r'   rA   rB   rC   rE   )rG   r   rH   rS   rI   r   rT   rU   rV   ÚgetattrrZ   rW   r&   rY   Únumber_of_inputsr@   rD   )r3   r4   rR   rK   ÚsrcsÚinputsr   )rQ   r4   r   r6   Œ   sF    



 





z SimpleTreeGenerator.get_childrenc             C   s$   | j |ƒrt|| d�S t|d�S dS )z1Get a node object representing the object passed.)ÚobjectÚtree_generator)ra   N)r5   ÚTVTKBranchNodeÚTVTKLeafNode)r3   r4   r   r   r   r7   Ë   s    
zSimpleTreeGenerator.get_nodec             C   s€   t tgtttddd�dd�ƒddd|ddddd�
t tgtttddd�dd�ƒdd|ddddd	�	t tgd
dd|ddddd�	g}|S )zaReturns a list of nodes for the tree editor.  The menu
        entries to use are given as `menu`ra   Úcustom)ÚstyleF)Úshow_labelsÚchildrenr.   )
Únode_forÚviewÚ	auto_openrh   Úlabelr8   ÚrenameÚdeleteÚcopyÚinsert)	ri   rj   rk   rl   r8   rm   rn   ro   rp   T)	ri   rk   rh   rl   r8   rm   rn   ro   rp   )r   rc   r   r   r   rd   ÚTVTKCollectionNode)r3   r8   Únodesr   r   r   r9   Ò   s$    
zSimpleTreeGenerator.get_nodesN)r:   r;   r<   r=   r5   r6   r7   r9   r   r   r   r   r>   x   s
   ?r>   c                   s<   e Zd ZdZ‡ fdd„Zdd„ Z‡ fdd„Zdd	„ Z‡  ZS )
ÚFullTreeGeneratorzŒThis particular class picks up a lot more children in the
    pipeline and is similar to the code used in MayaVi-1.x's pipeline
    browser.c                s   t t| ƒjf |Ž d| _d S )Nr   )Úsuperrs   Ú__init__Úlast_transform)r3   Útraits)Ú	__class__r   r   ru   ò   s    zFullTreeGenerator.__init__c       	         s<  t jˆƒ}| j|ƒ}i ‰ ‡ fdd„}x2|D ]*}t|d ƒ}tˆ|ƒr*||tˆ|ƒƒ q*W tˆdƒr†‡fdd„tˆjƒD ƒ}|d|ƒ ntˆdƒrœ|dˆjƒ tˆdƒrØg }tˆd	ƒrÌ‡fd
d„tˆj	ƒD ƒ}|d|ƒ nHtˆdƒ�r‡fdd„tˆj
ƒD ƒ}|d|ƒ ntˆdƒ�r |dˆjƒ tˆdƒ�r8|dˆjƒ ˆ S )z§Returns the child objects of a particular tvtk object in a
        dictionary, the keys are the trait names.  This is used to
        generate the tree in the browser.c                sŽ   |d krd ˆ | < nxt |ƒt g ƒt f ƒfkrFdd„ |D ƒ}|rŠ|ˆ | < nDt|tƒrŠt|dƒr‚tt|ƒƒrŠtt|ƒd tƒrŠ|ˆ | < n|ˆ | < d S )Nc             S   s   g | ]}t |tƒr|‘qS r   )rG   r   )rL   rM   r   r   r   rN     s    zDFullTreeGenerator.get_children.<locals>._add_kid.<locals>.<listcomp>r   r   )rO   rG   r   r   ÚlenÚlist)r/   r   rP   )rQ   r   r   rR   ÿ   s    




z0FullTreeGenerator.get_children.<locals>._add_kidr   rW   c                s   g | ]}ˆ j |ƒ‘qS r   )rX   )rL   rM   )r4   r   r   rN     s   z2FullTreeGenerator.get_children.<locals>.<listcomp>r&   rF   rY   c                s,   g | ]$}t ˆ j|ƒƒD ]}ˆ j||ƒ‘qqS r   )rZ   r[   rF   )rL   rM   r\   )r4   r   r   rN      s   r@   r?   c                s   g | ]}ˆ j |ƒ‘qS r   )r?   )rL   rM   )r4   r   r   rN   &  s   rD   )r   Úto_vtkÚ_get_methodsr   r   r]   rZ   rW   r&   rY   r^   r@   rD   )	r3   r4   Úvtk_objÚmethodsrR   ÚmethodÚattrr_   r`   r   )rQ   r4   r   r6   ö   s:    










zFullTreeGenerator.get_childrenc                s(   t t| ƒj|ƒ}| r$| j|ƒr$dS |S )zfReturns true of the object has children, false if not.  This is
        very specific to tvtk objects.T)rt   rs   r5   r6   )r3   r4   Úresult)rx   r   r   r5   1  s    zFullTreeGenerator.has_childrenc       
      C   s  dd„ }t |dƒsg S t|ƒ}|jdƒ}|d= tjdƒ}x`|dd… D ]P}|j|ƒrŒ|jdƒd)krn|j|ƒ q–|d	 jd
ƒd*kr–|j|ƒ qF|j|ƒ qFW xz|dd… D ]j}|jƒ dd… dkràt |dƒrÞ|j|ƒ |j	dƒ q¨|jƒ dd… dkr¨t |dƒr¨|j|ƒ |j	dƒ q¨W g }xHt
dt|ƒƒD ]6}|| jddƒ}|jdƒ||< |j	|| d ƒ �q*W tjd|jƒ ƒ�r„|j	ddgƒ tjd|jƒ ƒ�rÀ|j	ddgƒ |j	ddgƒ |j	ddgƒ |jdƒ�rö| jdk�ræ|d||ƒ n|  jd	7  _nd| _xd+D ]}	||	||ƒ �qW |S ),z2Obtain the various methods from the passed object.c             S   s8   y|j | ƒ}W n tk
r"   Y nX ||= ||= ||fS )z/Removes methods if they have a particular name.)ÚindexÚ
ValueError)r.   r~   Úmethod_namesÚidxr   r   r   Ú_remove_methodA  s    z6FullTreeGenerator._get_methods.<locals>._remove_methodÚGetClassNameÚ
r   z  \SNú:é   Únoneé   zProps:ÚGetViewPropszViewProps: é   zProp:ÚGetViewPropz
ViewProp: ú r*   zvtk\w*RendererZActiveCamerazvtk\w*AssemblyZPartsZVolumesZActorsÚvtkAbstractTransformÚInverseÚOutputÚ	FieldDataÚCellDataÚ	PointDataÚSourceÚInputÚExtentTranslatorÚProgressTextÚ
InteractorÚLightsÚInformationÚ	ExecutiveéÿÿÿÿrŸ   )r“   r”   r•   r–   r—   r˜   r™   rš   r›   rœ   r�   rž   )r   ÚstrÚsplitÚreÚcompileÚmatchÚfindÚremoveÚstripÚappendrZ   ry   Úreplacer‡   ÚIsArv   )
r3   r}   r†   r~   Úpatnr   r„   rM   Zstrngr.   r   r   r   r|   >  sX    







 zFullTreeGenerator._get_methods)	r:   r;   r<   r=   ru   r6   r5   r|   Ú__classcell__r   r   )rx   r   rs   í   s
   ;rs   c                   s8   e Zd ZdZeeƒZ‡ fdd„Zdd„ Zdd„ Z	‡  Z
S )ÚCompositeIterablezõThis class allows one to iterate over a bunch of disparate
    objects treating them as one single iterable.  Each of the
    iterated objects is wrapped with a suitable Node class so that the
    object may be used in a Traits Tree Editor.
    c                s   t t| ƒjf |Ž || _d S )N)rt   r­   ru   Úargs)r3   r®   rw   )rx   r   r   ru   œ  s    zCompositeIterable.__init__c             c   sJ   | j }x>| jD ]4}t|ƒr6x&|D ]}|j|ƒV  q W q|j|ƒV  qW d S )N)rb   r®   r   r7   )r3   ÚtgÚargr   r   r   r   r      s    
zCompositeIterable.__iter__c             C   s6   d}x,| j D ]"}t|ƒr&|t|ƒ7 }q|d7 }qW |S )Nr   rŠ   )r®   r   ry   )r3   r   r°   r   r   r   Ú__len__©  s    zCompositeIterable.__len__)r:   r;   r<   r=   r   r1   rb   ru   r   r±   r¬   r   r   )rx   r   r­   ’  s
   	r­   c                   s@   e Zd ZdZeeƒZeZe	Z
dd„ Zdd„ Z‡ fdd„Z‡  ZS )rd   z#Represents a leaf in the tree view.c             C   s   t tj| jƒƒS )N)Úhashr   r{   ra   )r3   r   r   r   Ú__hash__Á  s    zTVTKLeafNode.__hash__c             C   s
   | j jjS )N)ra   rx   r:   )r3   r   r   r   Ú	_get_nameÄ  s    zTVTKLeafNode._get_namec                s(   t | jƒ}|r|S tt| ƒj||ƒS dS )z2 Returns the icon for a specified object.
        N)r0   r.   rt   rd   Útno_get_icon)r3   ÚnodeÚis_expandedÚicon)rx   r   r   rµ   Ê  s    
zTVTKLeafNode.tno_get_icon)r:   r;   r<   r=   r   r   ra   r   r.   r   Ú__r³   r´   rµ   r¬   r   r   )rx   r   rd   ¶  s   rd   c                   s–   e Zd ZdZeeƒZeZeZ	ee
ƒZeZeZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zddd„Zdd„ Zdd„ Z‡ fdd„Z‡  ZS )rc   z…Represents a branch in the tree view.  The `children` trait
    produces an iterable that represents the children of the branch.
    c                s   t t| ƒjf |Ž d S )N)rt   rc   ru   )r3   rw   )rx   r   r   ru   é  s    zTVTKBranchNode.__init__c          	   C   s   y| j ƒ  W n   Y nX d S )N)Ú_remove_listners)r3   r   r   r   Ú__del__ì  s    zTVTKBranchNode.__del__c             C   s   t tj| jƒƒS )N)r²   r   r{   ra   )r3   r   r   r   r³   ò  s    zTVTKBranchNode.__hash__c             C   s   dd„ | j jƒ D ƒS )Nc             S   s   g | ]}|d k	r|‘qS )Nr   )rL   r   r   r   r   rN   ö  s    z;TVTKBranchNode._get_children_from_cache.<locals>.<listcomp>)Úchildren_cacheÚvalues)r3   r   r   r   Ú_get_children_from_cacheõ  s    z'TVTKBranchNode._get_children_from_cachec             C   s    | j j| jƒ}|| _| jƒ  d S )N)rb   r6   ra   r¼   Ú_setup_listners)r3   rQ   r   r   r   Ú_create_childrenø  s    zTVTKBranchNode._create_childrenc             C   s\   | j }| j}xJ|jƒ D ]>\}}t|tjƒrFtj|ƒ}tj|d| j	ƒ q|j
| j	|ƒ qW d S )NÚModifiedEvent)ra   r¼   ÚitemsrG   r   rJ   r{   r   ÚconnectÚ_notify_childrenÚon_trait_change)r3   ra   rQ   r/   Úvalr}   r   r   r   r¿   ý  s    

zTVTKBranchNode._setup_listnersc             C   s`   | j }| j}xN|jƒ D ]B\}}t|tjƒrFtj|ƒ}tj|d| j	ƒ q|j
| j	|dd� qW d S )NrÁ   T)r¦   )ra   r¼   rÂ   rG   r   rJ   r{   r   Z
disconnectrÄ   rÅ   )r3   ra   rQ   r/   rÆ   r}   r   r   r   rº     s    

zTVTKBranchNode._remove_listnersNc             C   s2   | j ƒ }| jƒ  | jƒ  | j ƒ }| jd||ƒ d S )Nrh   )r¾   rº   rÀ   Útrait_property_changed)r3   r4   r.   ÚoldÚnewÚold_valÚnew_valr   r   r   rÄ     s
    zTVTKBranchNode._notify_childrenc             C   s(   | j s| jƒ  | jƒ }| j}t||d�S )N)rb   )r¼   rÀ   r¾   rb   r­   )r3   rQ   r¯   r   r   r   Ú_get_children  s
    zTVTKBranchNode._get_childrenc             C   s
   | j jjS )N)ra   rx   r:   )r3   r   r   r   r´   !  s    zTVTKBranchNode._get_namec                s(   t | jƒ}|r|S tt| ƒj||ƒS dS )z2 Returns the icon for a specified object.
        N)r0   r.   rt   rc   rµ   )r3   r¶   r·   r¸   )rx   r   r   rµ   '  s    
zTVTKBranchNode.tno_get_icon)NNNN)r:   r;   r<   r=   r   r   ra   r   rh   r.   r1   rb   r
   r¼   r   r¹   ru   r»   r³   r¾   rÀ   r¿   rº   rÄ   rÌ   r´   rµ   r¬   r   r   )rx   r   rc   ×  s$   
rc   c                   sD   e Zd ZdZeeƒZeZe	Z
eeƒZeZ‡ fdd„Zdd„ Z‡  ZS )rq   zQRepresents a collection of typically unconnected roots in the
    tree view.
    c                s   t t| ƒjf |Ž d S )N)rt   rq   ru   )r3   rw   )rx   r   r   ru   D  s    zTVTKCollectionNode.__init__c             C   s   | j }t| j|d�S )N)rb   )rb   r­   ra   )r3   r¯   r   r   r   rÌ   G  s    z TVTKCollectionNode._get_children)r:   r;   r<   r=   r   r   ra   r   rh   r	   r.   r   r1   rb   r   r¹   ru   rÌ   r¬   r   r   )rx   r   rq   4  s   rq   c               @   s   e Zd ZdZeZdd„ ZdS )ÚUICloseHandlerz;This class cleans up after the UI for the object is closed.c             C   s   |j }|j| jjdd� dS )z3This method is invoked when the user closes the UI.T)r¦   )ra   rÅ   ÚbrowserÚrender)r3   ÚinfoÚis_okr4   r   r   r   ÚcloseT  s    zUICloseHandler.closeN)r:   r;   r<   r=   r   rÎ   rÒ   r   r   r   r   rÍ   O  s   rÍ   c                   s¤   e Zd Zeeƒ eeƒƒZeZ	ee
ƒZee
ƒZeZeZeZd‡ fdd„	Zdd„ Zddd„Zd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‡  ZS )ÚPipelineBrowserNc                s>   t t| ƒjf |Ž d| _d| _|r.| jj|ƒ | j| jƒ dS )zìInitializes the object.

        Parameters
        ----------

        - renwin: `Scene` instance.  Defaults to None.

          This may be passed in addition to the renwins attribute
          which can be a list of scenes.

        N)	rt   rÓ   ru   Ú_uirj   Úrenwinsr¨   Ú_root_object_changedÚroot_object)r3   Zrenwinrw   )rx   r   r   ru   z  s    zPipelineBrowser.__init__c          
   C   sˆ   t tddd�tddd�ƒ}|| _| jj|ƒ}t|ddd| j| jd	�| _t	t
ttd
| jdd�tdddd�ddd�ƒdddddddd�}|S )NÚRefreshzeditor.update_editor)r.   Úactionz
Expand allzeditor.expand_allFÚverticalT)rr   ÚeditableÚorientationÚ	hide_rootÚ	on_selectÚ	on_dclickÚ_root)r.   ÚeditorÚ	resizableÚselectedre   )r.   rf   râ   )rg   Úshow_borderzPipeline browserg333333Ó?)ÚtitleÚhelprâ   ÚundoÚrevertÚwidthÚheight)r   r   r8   rb   r9   r   Ú
_on_selectÚ
_on_dclickÚtree_editorr   r   r   r   )r3   r8   rr   rj   r   r   r   Údefault_traits_viewŽ  s.    

z#PipelineBrowser.default_traits_viewc             C   sz   | j dk	rB| j jdk	rBy| j jjƒ  W n tk
r:   Y qvX dS n4| jƒ }|dk	rf|j| |dd�| _ n|j| |d�| _ dS )z–Show the tree view if not already show.  If optional
        `parent` widget is passed, the tree is displayed inside the
        passed parent widget.NÚsubpanel)ÚparentÚkind)rð   )rÔ   ÚcontrolÚRaiseÚAttributeErrorrî   Úui)r3   rð   rj   r   r   r   Úshow¬  s    zPipelineBrowser.showc             C   sX   | j dk	rT| j jdk	rTy$| j jd }|jƒ  | j jjƒ  W n ttfk
rR   Y nX dS )zUpdate the tree view.Nr   )rÔ   rò   Ú_editorsÚupdate_editorrØ   rô   Ú
IndexError)r3   Úedr   r   r   ÚupdateÀ  s    zPipelineBrowser.updatec             C   s"   d| _ x| jD ]}|jƒ  qW dS )zHCalls render on all render windows associated with this
        browser.TN)Úobject_editedrÕ   rÏ   )r3   Úrwr   r   r   rÏ   Í  s    zPipelineBrowser.renderc             C   s(   | j }dd„ | jD ƒ}t|d|d�}|S )Nc             S   s   g | ]
}|j ‘qS r   )Zrender_window)rL   r   r   r   r   rN   Ù  s    z6PipelineBrowser._make_default_root.<locals>.<listcomp>ÚRoot)ra   r.   rb   )rb   rÕ   rq   )r3   Útree_genÚobjsr¶   r   r   r   Ú_make_default_root×  s
    z"PipelineBrowser._make_default_rootc             C   sf   | j r| j j}n| j}|r@|}t|dƒs.|g}t|d|d�| _ n
| jƒ | _ |j| jƒ| j_	| j
ƒ  dS )zTraits event handler.r±   rþ   )ra   r.   rb   N)rà   ra   r×   r   rq   r  r9   r8   rí   rr   rû   )r3   rÿ   Úroot_objÚror   r   r   Ú_tree_generator_changedÞ  s    


z'PipelineBrowser._tree_generator_changedc             C   s<   | j }|rt|d|d�| _n| jƒ | _| jj| _| jƒ  dS )z9Trait handler called when the root object is assigned to.rþ   )ra   r.   rb   N)rb   rq   rà   r  ra   r×   rû   )r3   r  r¯   r   r   r   rÖ   ò  s    

z$PipelineBrowser._root_object_changedc             C   s   | j | jƒ dS )z7Trait handler called when the items of the list change.N)rÖ   r×   )r3   Z
list_eventr   r   r   Ú_root_object_items_changedý  s    z*PipelineBrowser._root_object_items_changedc             C   sL   t |dƒrHt |jdƒrH|j}|jƒ }t| d�|_|j| jƒ |j|d�}dS )z6Callback that is called when nodes are double-clicked.ra   Úedit_traits)rÎ   )rj   N)r   ra   Ú
trait_viewrÍ   ÚhandlerrÅ   rÏ   r  )r3   r4   ra   rj   rõ   r   r   r   rì     s    zPipelineBrowser._on_dclickc             C   s`   t |dƒr\t |jdƒr\|j}| j}||kr0|| _|d k	rH|j| jdd� |d k	r\|j| jƒ d S )Nra   r  T)r¦   )r   ra   rã   rÅ   rÏ   )r3   r4   rÉ   rÈ   r   r   r   rë   
  s    zPipelineBrowser._on_select)N)N)r:   r;   r<   r   rs   r   r1   rb   r   rÕ   r   r×   rã   r   rü   r   rà   rÔ   ru   rî   rö   rû   ÚrefreshrÏ   r  r  rÖ   r  rì   rë   r¬   r   r   )rx   r   rÓ   ^  s(   


	rÓ   Tc             C   sn   ddl m} |jd| d�}tjƒ }tj|jd�}tj|d�}|jj	|ƒ |jj
ƒ  t|jƒ}|jƒ  |||fS )zSimple test case.r   )ÚivtkF)rÎ   Úinstantiate_gui)Úinput_connection)r"   )Z
tvtk.toolsr
  Zviewerr   Z
ConeSourceZPolyDataMapperÚoutput_portZActorÚsceneZ	add_actorÚ
reset_zoomrÓ   rö   )r  r
  ÚvÚcsÚmÚaÚbr   r   r   Úmain  s    

r  Ú__main__)ÚGUIF)r  )T)5r=   r¢   Ú
traits.apir   r   r   r   r   r   r   r	   r
   r   Útraitsui.apir   r   r   r   r   r   r   Ztraitsui.menur   r   Útvtk.apir   r   Útvtk.tvtk_baser   Ztvtk.tvtk_base_handlerr   Ztvtk.commonr   r   r0   r1   r>   rs   r­   rd   rc   rq   rÍ   rÓ   r  r:   Ú
pyface.apir  Úguir  r  r  Zstart_event_loopr   r   r   r   Ú<module>   s8   0$%u &$!] =

