a
    «ˆc½:  ã                   @   s@  d Z ddlZddlZddl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mZmZmZ ddlmZ ddlmZ ddlmZ d\aaaadd	„ Zd
d„ Zdd„ Z dd„ Z!dd„ Z"dd„ Z#dd„ Z$dd„ Z%G dd„ de&ƒZ'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,d#d$„ Z-e.d%k�r<e-ƒ  dS )&a8  

Utility code that provides classes helpful in choosing a suitable TVTK
class.  It does this by providing a list of all the classes along with
the option to be able to search for the documentation.

The nice thing about the UI is that it performs some kind of completion
on names typed by the user, plus it allows users to search through the
TVTK class docs very easily.  Once a search string is typed the
completion and available lists are modified so you can do completion of
the searched class names.  If a unique enough string is typed the class
docs are shown.

é    N)Ú	HasTraitsÚPropertyÚListÚStrÚInstanceÚButtonÚInt)ÚViewÚGroupÚItemÚ
EnumEditorÚ
ListEditorÚ
TextEditor)Útvtk©Úget_tvtk_name)NNNNc               
   C   s¾  t j} |  ¡ }|  d¡ tj}tj}t dd¡ 	¡ dv }g }g }g }g }g }	t  
¡ }
|
 ¡ |
 ¡ fdkrr|	 d¡ tt ƒD �]}| d¡rz| d¡sz||	vrztt |ƒ}|r¾td	|› �tjd
� z*|ƒ }tj|ksÚtj|kræ|t_|t_W n ttf�y   Y qzY n0 t|ƒ}| |¡ d }}t|dƒ�r>| ¡ dk�r>d}t|dƒ�r\| ¡ dk�r\d}|�r€|�rt| |¡ n
| |¡ qz|rz| |¡ qz|  |¡ ||||f}|D ]}| ¡  �qª|S )a  Returns 4 lists:

     1. A list of all the TVTK class names that are not abstract.

     2. A list of the TVTK sources (have only outputs and no inputs)

     3. A list of the TVTK filters (both inputs and outputs)

     4. A list of the TVTK sinks (only inputs and no outputs)

    r   ZTVTK_VERBOSEÚ )Ú1Útrue)é	   é   ZvtkOpenGLAvatarÚvtkZvtkQtzTrying )ÚfileFÚGetNumberOfInputPortsTÚGetNumberOfOutputPorts)r   Z	vtkObjectZGetGlobalWarningDisplayZSetGlobalWarningDisplayÚsysÚstdoutÚstderrÚosÚgetenvÚlowerZ
vtkVersionZGetVTKMajorVersionZGetVTKMinorVersionÚappendÚdirÚ
startswithÚgetattrÚprintÚ
__stdout__Ú	TypeErrorÚNotImplementedErrorr   Úhasattrr   r   Úsort)ÚoÚwZ
old_stdoutZ
old_stderrÚverboseÚallÚsrcÚfilterZsinkZ	bad_namesÚverÚnameÚklassÚcZ	tvtk_nameZ	has_inputZ
has_outputÚresultÚx© r7   úV/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/tvtk/tools/tvtk_doc.pyÚget_tvtk_class_names(   s`    

ÿ




r9   c           	      C   sx   t  | ¡r| }nt  | ¡r"| j}ndS t  |j¡\}}}|j}|t  ||||¡ }t  | ¡}|durt|d| d 7 }|S )zReturns function documentation.r   Nz

)	ÚinspectÚ
isfunctionÚismethodÚ__func__ÚgetargsÚ__code__Ú__defaults__ÚformatargspecÚgetdoc)	ÚfuncÚfnameZfunc_objÚargsZvargsZvkwÚdefaultsÚdocÚdr7   r7   r8   Úget_func_docq   s    


rI   c                 C   sÖ   | j d }ddg}|  ¡  ¡ D ]D\}}| d¡s| d¡s||v rDq|d||jpZ|jpZ|jf 7 }q|d7 }|  ¡ }t	| ƒD ]T}||v s|| d¡r”q|| 
d¡dkr¬|d	kr¬q|t| |ƒ}t|ƒr||d
t||ƒ 7 }q||S )z#Return's the objects documentation.z
Traits:
-------------------

Ztrait_addedZtrait_modifiedÚ_z
%s: %sz"
Methods:
----------------------

ÚtraitéÿÿÿÿZupdate_traitsÚ
)Ú__doc__ÚtraitsÚitemsr#   ÚendswithZtooltipÚdescÚhelpZtrait_namesr"   Úfindr$   ÚcallablerI   )ÚobjrG   ÚignoreÚkeyrK   rO   r2   rC   r7   r7   r8   Úget_tvtk_class_doc‚   s"    
 
rY   c                  C   s   t d u rtƒ } | \a aaad S ©N)ÚTVTK_CLASSESr9   ÚTVTK_SOURCESÚTVTK_FILTERSÚ
TVTK_SINKS)Úrr7   r7   r8   Ú_setup_tvtk_namesš   s    r`   c                   C   s
   t ƒ  tS rZ   )r`   r[   r7   r7   r7   r8   Úget_tvtk_classes¡   s    ra   c                   C   s
   t ƒ  tS rZ   )r`   r\   r7   r7   r7   r8   Úget_tvtk_sources¦   s    rb   c                   C   s
   t ƒ  tS rZ   )r`   r]   r7   r7   r7   r8   Úget_tvtk_filters«   s    rc   c                   C   s
   t ƒ  tS rZ   )r`   r^   r7   r7   r7   r8   Úget_tvtk_sinks°   s    rd   c                   @   s0   e Zd ZdZg Zg Zdd„ Zdd„ Zdd„ ZdS )	Ú	DocSearchz‰A simple class that provides a method to search through class
    documentation.  This code is taken from mayavi-1.x's ivtk.VtkHelp

    c                 C   s*   | j | _| j| _t| j ƒdkr&|  ¡  d S ©Nr   )ÚVTK_CLASSESÚvtk_classesÚVTK_CLASS_DOCÚ	vtk_c_docÚlenÚ_setup_data©Úselfr7   r7   r8   Ú__init__Ä   s    zDocSearch.__init__c              	   C   sx   dd„ t tƒD ƒ| _t| jƒ}dg| | _t|ƒD ]@}| j| }ztt|ƒj ¡ }|| j|< W q2 t	yp   Y q20 q2d S )Nc                 S   s   g | ]}|  d ¡r|‘qS )r   ©r#   ©Ú.0r6   r7   r7   r8   Ú
<listcomp>Ì   ó    z)DocSearch._setup_data.<locals>.<listcomp>r   )
r"   r   rh   rk   rj   Úranger$   rN   r    ÚAttributeError)rn   ÚnÚir4   rG   r7   r7   r8   rl   Ë   s    

zDocSearch._setup_datac                 C   s’  t |ƒtu sJ d| ƒ‚t| ¡ ƒdkr,g S | ¡  ¡ }| ¡ }g }d}|D ]X}| ¡ }|dv r†|r¤|dvr¤| |¡ | |¡ |}qL|r |dvr |d | }qL|}qL|dv r¶|d= n|rÄ| |¡ g }d}	| j}
| j}t|
ƒ}|	|k �r„d}d}|D ]n}|dk�r
d}qö|dk�rd}qö||	  	|¡dk}|dk�rB|�o>|}qö|dk�rX|�pT|}qö|dkrö|}qö|�rz| |
|	 ¡ |	d	 }	qàd
d„ |D ƒS )a†   Search for word in class documentation and return matching
        classes.  This is also case insensitive.  The searching
        supports the 'and' and 'or' keywords that allow for fairly
        complex searches.  A space between words assumes that the two
        words appear one after the other.

        Parameters
        ----------
            word -- name to search for.
        z+Sorry, passed argument, %s is not a string.r   r   )ÚandÚorú rL   ry   rz   é   c                 S   s   g | ]}t |ƒ‘qS r7   r   rq   r7   r7   r8   rs     rt   z$DocSearch.search.<locals>.<listcomp>)
ÚtypeÚstrrk   Ústripr    Úsplitr!   rh   rj   rT   )rn   ÚwordZlwordZtmp_listZwlistÚprevr,   ÚzÚretrx   rh   rj   ÚNZstored_testZdo_testÚtestr7   r7   r8   ÚsearchÚ   s^    ÿ








zDocSearch.searchN)	Ú__name__Ú
__module__Ú__qualname__rN   rg   ri   ro   rl   r‡   r7   r7   r7   r8   re   ¸   s   re   a±  
                        Help on Searching
           ---------------------------------------

To search for a particular TVTK class, type in the 'class_name' text entry
widget.  The class names are all case sensitive.   You may also select
the class from the list of available class names at the top.

As you type you will see completion options in the completions
list, the instant a complete match is found the class documentation will
be show in the bottom.

You can also search the TVTK class documentation for strings (case
insensitive).  The search option supports the 'and' and 'or' keywords to
do advanced searches.  Press <Enter>/<Return> to perform the search.

The top 25 hits will show up in the completions, to view a particular
hit either select the choice from the available ones or type in the
name in the 'class_name' entry box.  To clear the search string click
the 'Clear search' button or erase the search string manually.

c                       s  e Zd ZeZeddd�Zeddd�ZeZ	ee
ƒZeeƒZeZeeƒZedƒZeeededd�d	�edd
d�eded
dd�d	�eddd�edƒededd�dd�edd
ddd�ƒdd
ddddd gd!�Z‡ fd"d#„Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Z d.d/„ Z!‡  Z"S )0ÚTVTKClassChooserr   z)class name of TVTK class (case sensitive))rR   z‹string to search in TVTK class documentation supports the "and" and "or" keywords. press <Enter> to start search. This is case insensitive.é   Ú
class_nameÚ	available)r2   )r2   ÚeditorT)r2   Z	has_focusr‡   F)Z	enter_setZauto_setÚclear_search)r2   Z
show_labelrJ   Úcompletionsé   )ÚcolumnsÚreadonly)r2   r�   ÚstylerG   ZDocumentationZcustom)r2   Ú	resizableÚlabelr•   Ztvtk_doci   iX  zTVTK class chooserÚOKZCancel)Úidr–   ÚwidthÚheightÚtitleZbuttonsc                    s&   t t| ƒjf i |¤Ž t| jƒ| _d S rZ   )Úsuperr‹   ro   ÚlistrŽ   Ú_orig_available)rn   rO   ©Ú	__class__r7   r8   ro   y  s    zTVTKClassChooser.__init__c              	   C   s@   d }t | jƒdkr<ztt| jƒƒ }W n ttfy:   Y n0 |S rf   )rk   r�   r$   r   rv   r'   )rn   r+   r7   r7   r8   Ú_get_object€  s    zTVTKClassChooser._get_objectc                    sn   | j }‡ fdd„|D ƒ}|d | j… | _t|ƒdkrJˆ |d krJ|d | _| j}|d urdt|ƒ| _nt| _d S )Nc                    s   g | ]}|  ˆ ¡r|‘qS r7   rp   rq   ©Úvaluer7   r8   rs   ‹  rt   z8TVTKClassChooser._class_name_changed.<locals>.<listcomp>r|   r   )	rŽ   Ún_completionr‘   rk   r�   ÚobjectrY   rG   Ú_search_help_doc)rn   r¤   ÚavÚcompr+   r7   r£   r8   Ú_class_name_changed‰  s    
z$TVTKClassChooser._class_name_changedc                 C   s   t ƒ S rZ   )re   rm   r7   r7   r8   Ú_finder_default–  s    z TVTKClassChooser._finder_defaultc                 C   s
   d| _ d S )Nr   )r‡   rm   r7   r7   r8   Ú_clear_search_fired™  s    z$TVTKClassChooser._clear_search_firedc                 C   st   t |ƒdk r| j| _d S | j}| t|ƒ¡}t |ƒdkrB| j| _n.t |ƒdkrZ|d | _n|| _|d | j… | _d S )Nr’   r   r|   )	rk   rŸ   rŽ   Úfinderr‡   r~   r�   r¥   r‘   )rn   r¤   Úfr5   r7   r7   r8   Ú_search_changedœ  s    
z TVTKClassChooser._search_changedc                 C   s   t ƒ S rZ   )ra   rm   r7   r7   r8   Ú_available_default«  s    z#TVTKClassChooser._available_default)#rˆ   r‰   rŠ   r   r¦   r   r�   r‡   r   r�   r§   rG   r   r‘   rŽ   r   re   r­   r   r¥   r	   r
   r   r   r   r   Úviewro   r¢   rª   r«   r¬   r¯   r°   Ú__classcell__r7   r7   r    r8   r‹   6  s`   ÿÿÿÿÿþýðæ	r‹   c                   @   s   e Zd ZeZdd„ ZdS )ÚTVTKSourceChooserc                 C   s   t ƒ S rZ   )rb   rm   r7   r7   r8   r°   µ  s    z$TVTKSourceChooser._available_defaultN©rˆ   r‰   rŠ   r   rŽ   r°   r7   r7   r7   r8   r³   ²  s   r³   c                   @   s   e Zd ZeZdd„ ZdS )ÚTVTKFilterChooserc                 C   s   t ƒ S rZ   )rc   rm   r7   r7   r8   r°   ¿  s    z$TVTKFilterChooser._available_defaultNr´   r7   r7   r7   r8   rµ   ¼  s   rµ   c                   @   s   e Zd ZeZdd„ ZdS )ÚTVTKSinkChooserc                 C   s   t ƒ S rZ   )rd   rm   r7   r7   r8   r°   É  s    z"TVTKSinkChooser._available_defaultNr´   r7   r7   r7   r8   r¶   Æ  s   r¶   c                  C   s   t ƒ } |  ¡  dS )zXPops up a class chooser which doubles as a nice help search
    documentation tool.
    N)r‹   Zconfigure_traits)Úsr7   r7   r8   ÚmainÍ  s    r¸   Ú__main__)/rN   r:   r   r   Z
traits.apir   r   r   r   r   r   r   Ztraitsui.apir	   r
   r   r   r   r   Ztvtk.apir   Ztvtk.commonr   Ztvtk.vtk_moduleZ
vtk_moduler   r[   r\   r]   r^   r9   rI   rY   r`   ra   rb   rc   rd   r¦   re   r§   r‹   r³   rµ   r¶   r¸   rˆ   r7   r7   r7   r8   Ú<module>   s4   $ Ic|


