3
ÐÆ‘[  ã               @   s¸   d Z ddl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	lmZ d
dlmZ eƒ Zeje_dd„ ZG dd„ deƒZeƒ ZejZejZejZejZdS )z)
Central registry for figures with mlab.
é    N)Ú	HasTraitsÚInstance)Úpreference_manager)Úregistry)ÚEngine)ÚOffScreenEngine)Ú
NullEngine)Úprocess_ui_eventsé   )ÚPreferencesMirrorc              C   sV   ddl m}  ddlm} ddlm} | ƒ  |jdkrR|j rR|jd
krRd}t|ƒ‚d	S )zf Check if either we are in test mode, or if there is a
        suitable traits backend installed.
    r   )Útoolkit)Ú	ETSConfig)ÚoptionsÚtestÚnullÚ zˆCould not import backend for traitsui.  Make sure you
        have a suitable UI toolkit like PyQt/PySide or wxPython
        installed.N)r   r   )	Útraitsui.toolkitr   Útraits.etsconfig.apir   Úmayavi.tools.engine_managerr   ÚbackendÚ	offscreenÚImportError)r   r   r   Úmsg© r   ú^/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/mayavi/tools/engine_manager.pyÚcheck_backend   s    
r   c               @   sJ   e Zd ZdZeeƒZdd„ Zdd„ Zdd„ Z	dd	„ Z
d
d„ Zddd„ZdS )ÚEngineManageraF   Central registry for figures with mlab.

        This is a container for a list of engines having declared
        themselves as usable by mlab.

        This object is meant to be a thin wrapper on top of the different
        Engine classes, making sure that mlab knows how to start an
        engine and get a figure.
    c             C   sø   | j }|dk	r*|j s$|tjjƒ kr*d| _ | j dk	rBt| j fƒ}ntƒ }|jttjjƒ ƒƒ tjdkrvdd„ |D ƒ}nXtjdkr�dd„ |D ƒ}n>tj	r¦dd„ |D ƒ}n(tjdkrÀd	d„ |D ƒ}nd
d„ |D ƒ}t
|ƒdkrâ| jƒ S |d | _ |d S dS )z: Returns an engine in agreement with the options.
        NÚenvisagec             S   s   g | ]}|j jd kr|‘qS )ÚEnvisageEngine)Ú	__class__Ú__name__)Ú.0Úer   r   r   ú
<listcomp>L   s    z,EngineManager.get_engine.<locals>.<listcomp>r   c             S   s   g | ]}|j jd kr|‘qS )r   )r   r    )r!   r"   r   r   r   r#   O   s    c             S   s   g | ]}|j jd kr|‘qS )r   )r   r    )r!   r"   r   r   r   r#   R   s    Úautoc             S   s   g | ]}|j jdkr|‘qS )r   r   )r   r   )r   r    )r!   r"   r   r   r   r#   U   s    c             S   s   g | ]}|j jd kr|‘qS )r   )r   r    )r!   r"   r   r   r   r#   Y   s    r   r
   éÿÿÿÿr%   )Úcurrent_engineÚrunningr   ÚenginesÚvaluesÚlistÚextendr   r   r   ÚlenÚ
new_engine)ÚselfÚcer(   Úsuitabler   r   r   Ú
get_engine;   s*    




zEngineManager.get_enginec             C   sœ   | j }|dk	r*|j s$|tjjƒ kr*d| _ | j dk	rBt| j fƒ}ntƒ }|jttjjƒ ƒƒ d}x0|D ]}|jjdkrf|}P qfW t	dd�}|j
ƒ  || _ |S )zPReturn a suitable null engine and make that the current
        engine.
        Nr   zNull Mlab Engine)Úname)r&   r'   r   r(   r)   r*   r+   r   r    r   Ústart)r.   r/   r(   Úenginer"   r   r   r   Úget_null_engineb   s"    


zEngineManager.get_null_enginec             C   s(   |j stjddd� || _tj|ƒ dS )z Sets the mlab engine.
        zEngine is not runningé   )Ú
stacklevelN)r'   ÚwarningsÚwarnr&   r   Úregister_engine)r.   r4   r   r   r   Ú
set_engine}   s    zEngineManager.set_enginec             C   sž   t ƒ  tjdkrJddlm} |dd�}|jƒ  tƒ  |jjj	}|j
tƒ}nJtjdkrhtdd�}|jƒ  n,tjr‚td	d�}|jƒ  ntd
d�}|jƒ  || _|S )zU Creates a new engine, envisage or not depending on the
            options.
        r   r   )ÚMayaviF)Ústart_gui_event_loopr   zNull Mlab Engine)r2   zMlab offscreen EnginezMlab Engine)r   r   r   Úmayavi.plugins.appr<   Úmainr	   ÚapplicationÚ	workbenchÚactive_windowÚget_servicer   r   r3   r   r   r&   )r.   r<   ÚmÚwindowr4   r   r   r   r-   …   s$    








zEngineManager.new_enginec             C   s.   x(t jjƒ D ]}||jkr|S qW tdƒ‚dS )z@ Find the engine corresponding to a given mayavi scene.
        z'Figure not attached to a mayavi engine.N)r   r(   r)   ÚscenesÚ	TypeError)r.   Úfigr4   r   r   r   Úfind_figure_enginež   s    
z EngineManager.find_figure_engineNTc             C   s�   |dkr| j ƒ }|jjdksŒtjdkr(nd|rhddlm} |j}||d�}|dkrVd}n|j}|j	|d�S ddl
m} |j}||d�}|jƒ S dS )	z¦ Show a dialog with the mayavi pipeline. This dialog allows to
            edit graphicaly the properties of the different objects on
            the scenes.
        Nr   r   r   )ÚEngineRichView)r4   )Úscene)Ú
EngineView)r1   r   r    r   r   Úmayavi.core.ui.engine_rich_viewrJ   Úcurrent_scenerK   Úscene_editing_viewÚmayavi.core.ui.engine_viewrL   Úedit_traits)r.   r4   Ú	rich_viewrJ   ÚfigureÚviewrK   rL   r   r   r   Úshow_engine§   s"    


zEngineManager.show_engine)NT)r    Ú
__module__Ú__qualname__Ú__doc__r   r   r&   r1   r5   r;   r-   rI   rU   r   r   r   r   r   .   s   	'	r   )rX   r8   Ú
traits.apir   r   Úmayavi.preferences.apir   Úmayavi.core.registryr   Úmayavi.core.enginer   Úmayavi.core.off_screen_enginer   Úmayavi.core.null_enginer   Úmayavi.core.commonr	   Úpreferences_mirrorr   r   ÚmlabÚpreferencesr   r   Úengine_managerr1   r5   r;   rU   Úshow_pipeliner   r   r   r   Ú<module>   s&    