3
6Ad]âG  ã               @   s|  d Z ddlZddl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mZ ddlmZmZmZmZ ddlmZ dd	lmZ dd
lmZmZmZmZ ddlmZ ddlmZ dd„ Z 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„ 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,d'd(„ Z-e.d)k�rxe-ƒ  dS )+a­  ivtk - Interactive TVTK.

A utility module that makes VTK/TVTK easier to use from the Python
interpreter.  For a standalone application simply run this file.  To
use this under IPython (with --gui=qt) use the `viewer()` helper
function or use the `IVTK` class.  The widget can also make use of the
tvtk pipeline browser.

Here is example usage of the viewer along with tvtk under IPython:

    >>> from tvtk.tools import ivtk
    >>> from tvtk.api import tvtk
    >>> cs = tvtk.ConeSource()
    >>> m = tvtk.PolyDataMapper()
    >>> m.input = cs.output
    >>> a = tvtk.Actor()
    >>> a.mapper = m
    >>> v = ivtk.viewer()
    >>> v.scene.add_actors(a)
    >>> v.scene.reset_zoom()

é    N)Ú
FileDialogÚGUIÚOKÚPythonShell)ÚSplitApplicationWindowÚApplicationWindow)Ú
SplitPanel)ÚSceneÚDecoratedScene)ÚActionÚMenuBarManagerÚMenuManagerÚ	Separator)ÚImageResource)Úresource_path)ÚFloatÚStrÚInstanceÚCallable)Útvtk)ÚPipelineBrowserc              C   s   t jjtƒ ddƒ} t| ƒS )NÚimagesz	scene.ico)ÚosÚpathÚjoinr   r   )Z	icon_path© r   úv/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/mayavi-4.7.1-py3.6-linux-x86_64.egg/tvtk/tools/ivtk.pyÚmk_scene_icon2   s    r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
ExitActionz Exits the application. c             C   s   || _ d| _dS )z Creates a new action. zE&xitN)Ú_windowÚname)ÚselfÚwindowr   r   r   Ú__init__=   s    zExitAction.__init__c             C   s   | j jƒ  dS )z Performs the action. N)r   Úclose)r!   r   r   r   ÚperformB   s    zExitAction.performN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__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 )ÚSaveImageActionz%Saves the rendered scene to an image.c             C   s   || _ d| _d S )NzS&ave Scene)r   r    )r!   r"   r   r   r   r#   L   s    zSaveImageAction.__init__c             C   s²   ddddddddd	d
ddddddg}dddddddddddddddd g}d!}x(t ||ƒD ]\}}|d"j|||ƒ7 }qXW |d#7 }t| jjd$|d%d&�}|jƒ tkr®| jjj|j	ƒ d'S )(z4Pops up a dialog used to save the scene to an image.z*.pngz*.jpgz*.tiffz*.bmpz*.psz*.epsz*.pdfz*.texz*.ribz*.wrlz*.ooglz*.vrmlz*.objz*.ivz*.povz*.x3dZPNGZJPGZTIFFZBitmapZ
PostScriptZEPSZPDFZTexZRIBZWRLZGeomviewZVRMLZ	WavefrontzOpen InventorZPovrayÚX3DÚ z{} ({})|{}|z"Determine by extension (*.*)|(*.*)zsave aszSave scene to image)ÚparentÚactionÚwildcardÚtitleN)
ÚzipÚformatr   r   ÚcontrolÚopenr   ÚsceneÚsaver   )r!   Ú
extensionsÚdescriptionsr/   ÚdescriptionÚ	extensionZdlgr   r   r   r%   P   s$    






zSaveImageAction.performN)r&   r'   r(   r)   r#   r%   r   r   r   r   r*   J   s   r*   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚSaveToClipboardActionz( Saves rendered scene to the Clipboard. c             C   s   || _ d| _dS )z Creates a new action. z&CopyN)r   r    )r!   r"   r   r   r   r#   l   s    zSaveToClipboardAction.__init__c             C   s   | j jjƒ  dS )z Performs the action. N)r   r5   Zsave_to_clipboard)r!   r   r   r   r%   q   s    zSaveToClipboardAction.performN)r&   r'   r(   r)   r#   r%   r   r   r   r   r;   j   s   r;   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚSpecialViewActionz$Sets the scene to a particular view.c             C   s   || _ || _|| _dS )z Creates a new action. N)r   r    Úview)r!   r"   r    r=   r   r   r   r#   {   s    zSpecialViewAction.__init__c             C   s4   yt | jj| jƒ}|ƒ  W n tk
r.   Y nX dS )z Performs the action. N)Úgetattrr   r5   r=   ÚAttributeError)r!   Úmethr   r   r   r%   �   s
    
zSpecialViewAction.performN)r&   r'   r(   r)   r#   r%   r   r   r   r   r<   y   s   r<   c             C   sŒ   t tt| ƒtƒ t| ƒdd�tt| ƒdd�tt| ddƒtƒ t| ddƒt| dd	ƒt| d
dƒt| ddƒt| ddƒt| ddƒt| ddƒdd�
ƒ}|S )z¸Creates a menu bar suitable for all IVTK windows.

    Parameters
    ----------

    - obj : A Pyface application window.

      This is the window which requires the menu items.
    z&File)r    z&Editz&Reset ZoomZ
reset_zoomz
&IsometricZisometric_viewz&X positiveZx_plus_viewz
X negativeZx_minus_viewz&Y positiveZy_plus_viewz
Y negativeZy_minus_viewz&Z positiveZz_plus_viewz
Z negativeZz_minus_viewz&View)r   r   r*   r   r   r;   r<   )ÚobjÚmenu_bar_managerr   r   r   Úcreate_ivtk_menu‹   s$    







rC   c                   sX   e Zd ZdZedƒZedƒZee	ƒZ
eeƒZ‡ fdd„Zdd„ Zdd	„ Zd
d„ Z‡  ZS )ÚSceneWithBrowserzy Provides an Scene along with an embedded PyCrust Python shell.
    In the shell, 'scene' and 's' are bound to the Scene.g333333Ó?Zverticalc                s&   | j d k	r| j jƒ  tt| ƒjƒ  d S )N)r5   r$   ÚsuperrD   Údestroy)r!   )Ú	__class__r   r   rF   Ä   s    

zSceneWithBrowser.destroyc             C   s>   | j |ƒ t| jƒ| _|dk	r&|jƒ  | jj|d� | jjjS )z; Creates the left hand side or top depending on the style. N)r-   )Ú_create_scener   r5   ÚbrowserÚshowZ_uir3   )r!   r-   r   r   r   Ú_create_lhsÌ   s    
zSceneWithBrowser._create_lhsc             C   s   | j |ƒ d| jj_| jjS )zx Creates the right hand side or bottom depending on the
        style.  's' and 'scene' are bound to the Scene instance.ç      à?)rL   rL   rL   )rH   r5   ÚrendererÚ
backgroundr3   )r!   r-   r   r   r   Ú_create_rhsÕ   s    

zSceneWithBrowser._create_rhsc             C   s   | j dkrt|ƒ| _ dS )z, Make sure that the scene has been created. N)r5   r
   )r!   r-   r   r   r   rH   ß   s    
zSceneWithBrowser._create_scene)r&   r'   r(   r)   r   Úratior   Ú	directionr   r	   r5   r   rI   rF   rK   rO   rH   Ú__classcell__r   r   )rG   r   rD   ±   s   	
rD   c                   s\   e Zd ZdZedƒZedƒZee	ƒZ
eeƒZ‡ fdd„Z‡ fdd„Zdd	„ Zd
d„ Z‡  ZS )ÚIVTKWithCrustzy Provides an Scene along with an embedded PyCrust Python shell.
    In the shell, 'scene' and 's' are bound to the Scene.gffffffæ?Ú
horizontalc                s&   t t| ƒjf |Ž d| _t| ƒ| _dS )z Creates a new window. z
TVTK SceneN)rE   rS   r#   r0   rC   rB   )r!   Útraits)rG   r   r   r#   û   s    zIVTKWithCrust.__init__c                s&   | j d k	r| j jƒ  tt| ƒjƒ  d S )N)r5   r$   rE   rS   )r!   )rG   r   r   r$     s    

zIVTKWithCrust.closec             C   s   t |ƒ| _d| jj_| jjS )z; Creates the left hand side or top depending on the style. ç      à?)rV   rV   rV   )r
   r5   rM   rN   r3   )r!   r-   r   r   r   rK     s    

zIVTKWithCrust._create_lhsc             C   s@   t |ƒ| _| jjd| jƒ | jjd| jƒ | jjdtƒ | jjS )zx Creates the right hand side or bottom depending on the
        style.  's' and 'scene' are bound to the Scene instance.r5   Úsr   )r   Úpython_shellÚbindr5   r   r3   )r!   r-   r   r   r   rO     s
    
zIVTKWithCrust._create_rhs)r&   r'   r(   r)   r   rP   r   rQ   r   r	   r5   r   rX   r#   r$   rK   rO   rR   r   r   )rG   r   rS   è   s   rS   c                   sv   e Zd ZdZedƒZedƒZee	ƒZ
eeƒZeeƒZeeƒZ‡ fdd„Z‡ fdd„ZeeeƒZdd	„ Zd
d„ Z‡  ZS )ÚIVTKWithCrustAndBrowserzy Provides an Scene along with an embedded PyCrust Python shell.
    In the shell, 'scene' and 's' are bound to the Scene.gffffffæ?rT   c                s&   t t| ƒjf |Ž d| _t| ƒ| _dS )z Creates a new window. z
TVTK SceneN)rE   rZ   r#   r0   rC   rB   )r!   rU   )rG   r   r   r#   >  s    z IVTKWithCrustAndBrowser.__init__c                s&   | j d k	r| j jƒ  tt| ƒjƒ  d S )N)r5   r$   rE   rZ   )r!   )rG   r   r   r$   J  s    

zIVTKWithCrustAndBrowser.closec             C   s&   t |ƒ| _| jj| _| jj| _| jjS )z; Creates the left hand side or top depending on the style. )rD   Úbrowser_scener5   rI   r3   )r!   r-   r   r   r   rK   V  s    


z#IVTKWithCrustAndBrowser._create_lhsc             C   s`   t |ƒ| _| jjd| jƒ | jjd| jƒ | jjd| jƒ | jjd| jƒ | jjdtƒ | jjS )zx Creates the right hand side or bottom depending on the
        style.  's' and 'scene' are bound to the Scene instance.r5   rW   rI   Úbr   )r   rX   rY   r5   rI   r   r3   )r!   r-   r   r   r   rO   ]  s    
z#IVTKWithCrustAndBrowser._create_rhs)r&   r'   r(   r)   r   rP   r   rQ   r   r	   r5   r   rI   rD   r[   r   rX   r#   r$   r   Ú
scene_iconÚiconrK   rO   rR   r   r   )rG   r   rZ   %  s   

rZ   c                   sN   e Zd ZdZeeƒZeeƒZ	‡ fdd„Z
‡ fdd„ZeeeƒZdd„ Z‡  ZS )ÚIVTKz� Provides an Scene along without an embedded Python shell.
    This is useful when scripting from the vanilla Python or IPython
    interpreter.c                s&   t t| ƒjf |Ž d| _t| ƒ| _dS )z# Creates a new application window. z
TVTK SceneN)rE   r_   r#   r0   rC   rB   )r!   rU   )rG   r   r   r#   |  s    zIVTK.__init__c                s&   | j d k	r| j jƒ  tt| ƒjƒ  d S )N)r5   r$   rE   r_   )r!   )rG   r   r   r$   ‡  s    

z
IVTK.closec             C   s   | j |ƒ| _| jjS )z$ Create the contents of the window. )Ú_scene_factoryr5   r3   )r!   r-   r   r   r   Ú_create_contents“  s    zIVTK._create_contents)r&   r'   r(   r)   r   r	   r5   r   r
   r`   r#   r$   r   r]   r^   ra   rR   r   r   )rG   r   r_   n  s   

r_   c                   sV   e Zd ZdZeeƒZeeƒZee	ƒZ
‡ fdd„Z‡ fdd„ZeeeƒZdd„ Z‡  ZS )ÚIVTKWithBrowserz� Provides an Scene along without an embedded Python shell.
    This is useful when scripting from the vanilla Python or IPython
    interpreter.c                s&   t t| ƒjf |Ž d| _t| ƒ| _dS )z# Creates a new application window. z
TVTK SceneN)rE   rb   r#   r0   rC   rB   )r!   rU   )rG   r   r   r#   ®  s    zIVTKWithBrowser.__init__c                s&   | j d k	r| j jƒ  tt| ƒjƒ  d S )N)r5   r$   rE   rb   )r!   )rG   r   r   r$   ¹  s    

zIVTKWithBrowser.closec             C   s&   t |ƒ| _| jj| _| jj| _| jjS )z$ Create the contents of the window. )rD   r[   r5   rI   r3   )r!   r-   r   r   r   ra   Å  s    


z IVTKWithBrowser._create_contents)r&   r'   r(   r)   r   r	   r5   r   rI   rD   r[   r#   r$   r   r]   r^   ra   rR   r   r   )rG   r   rb   �  s   

rb   TFc             C   s0   |r
t ƒ }| rtdd�}n
tdd�}|jƒ  |S )a«  Creates an IVTK instance, opens the window and returns the
    embedded scene inside it.  This is useful from an IPython/vanilla
    Python shell.  It returns the viewer window instance.

    Parameters
    ----------

    - browser : `bool` (default, True)

      If True, creates an IVTK scene with an embedded PipelineBrowser.
      If False, does not create it.

    - instantiate_gui : `bool` (default: False)

      If True, create an instance of GUI().  This is useful when this
      function is invoked from within an IPython shell.  OTOH, if this
      is called from within a wxPython app (or with ipython --gui=qt)
      you don't want to start another GUI instance.
    éX  )Úsize)rc   rc   )rc   rc   )r   rb   r_   r4   )rI   Zinstantiate_guiÚguiÚvr   r   r   ÚviewerÑ  s    
rg   c              C   s$   t ƒ } tdd�}|jƒ  | jƒ  d S )Né   éX  )rd   )rh   ri   )r   rZ   r4   Zstart_event_loop)re   r"   r   r   r   Úmainï  s    
rj   Ú__main__)TF)/r)   Úos.pathr   Z
pyface.apir   r   r   r   r   r   r   Ztvtk.pyface.apir	   r
   Zpyface.action.apir   r   r   r   Zpyface.image_resourcer   Zpyface.resource.apir   Z
traits.apir   r   r   r   Ztvtk.apir   Ztvtk.pipeline.browserr   r   r]   r   r*   r;   r<   rC   rD   rS   rZ   r_   rb   rg   rj   r&   r   r   r   r   Ú<module>   s6    &7=I/4


