3
5Ad]  ã               @   sP   d Z ddlmZmZ ddlmZ ddlmZ dd„ Zdd„ Z	G d	d
„ d
eƒZ
dS )z²This represents the scripting API for MayaVi.

The Script class provides a scriptable view of the MayaVi Engine.  It is
safe to instantiate as many Script instances as desired.

é    )Ú	HasTraitsÚInstance)ÚEngine)Ú	exceptionc             C   s
   | j tƒS )zBReturns the MayaVi Engine given the Envisage worbench window.
    )Úget_servicer   )Úwindow© r   ú|/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/mayavi-4.7.1-py3.6-linux-x86_64.egg/mayavi/plugins/script.pyÚget_imayavi_engine   s    r
   c             C   s
   | j tƒS )z†Given the Envisage workbench window, returns the
    mayavi.script.Script instance (registered as
    `mayavi.services.IMAYAVI`).
    )r   ÚScript)r   r   r   r	   Úget_imayavi   s    r   c               @   sn   e Zd ZdZedƒZeeƒZddd„Zddd„Z	ddd	„Z
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r   zâThis class basically presents a scriptable 'view' of the MayaVi
    Engine.  It is registered as the IMayaVi service (via an
    ApplicationObject) because this is the interface users should be
    using when they script.
    z$pyface.workbench.api.WorkbenchWindowNc          
   C   s,   y| j j||d� W n   tƒ  Y nX dS )z4Adds a given source to the MayaVi pipeline.
        )ÚsceneN)ÚengineÚ
add_sourcer   )ÚselfÚsrcr   r   r   r	   r   7   s    zScript.add_sourcec          
   C   s,   y| j j||d� W n   tƒ  Y nX dS )zŒAdds a given module to the MayaVi pipeline. Adds it to the selected
        object, or to an object passed thought the kwarg `obj`.
        )ÚobjN)r   Ú
add_moduler   )r   Úmodr   r   r   r	   r   ?   s    zScript.add_modulec          
   C   s,   y| j j||d� W n   tƒ  Y nX dS )zŒAdds a given filter to the MayaVi pipeline. Adds it to the selected
        object, or to an object passed thought the kwarg `obj`.
        )r   N)r   Ú
add_filterr   )r   Zfilr   r   r   r	   r   H   s    zScript.add_filterc             C   s
   | j jƒ S )z(Creates a new VTK scene window.
        )r   Ú	new_scene)r   r   r   r	   r   Q   s    zScript.new_scenec          	   C   s(   y| j j|ƒ W n   tƒ  Y nX dS )z=Given a file/file name this loads the visualization.
        N)r   Úload_visualizationr   )r   Úfnamer   r   r	   r   V   s    zScript.load_visualizationc          	   C   s(   y| j j|ƒ W n   tƒ  Y nX dS )z_Given a file or a file name, this saves the current
        visualization to the file.
        N)r   Úsave_visualizationr   )r   r   r   r   r	   r   ^   s    zScript.save_visualizationc             C   s   | j S )z Get the currently active window.)r   )r   r   r   r	   Úget_active_windowg   s    zScript.get_active_windowc          	   C   s$   y| j j|ƒS    tƒ  Y nX dS )z&Open a data file if possible.
        N)r   Úopenr   )r   Úfilenamer   r   r	   r   k   s    zScript.openc             C   s   t |ƒ| _dS )z3Traits handler for changes to application.
        N)r
   r   )r   r   r   r   r	   Ú_window_changedv   s    zScript._window_changed)N)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r   '   s   

	
		r   N)r!   Z
traits.apir   r   Zmayavi.core.enginer   Zmayavi.core.commonr   r
   r   r   r   r   r   r	   Ú<module>   s   