a
    «ˆc�  ã                   @   sê   d Z ddlmZ ddl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lmZ dd„ ZG dd„ de
ƒZG dd„ de
ƒZejD ]>Zeejƒdkr¦ejejedœZeejefeƒZ e e!ƒ ej< q¦dS )z)An action to open various source files.

é    )Úisfile)ÚInstanceÚStr)Ú
FileDialogÚOK)ÚAction)Úget_imayavi)Úerror)ÚMetadata)Úregistryé   )Ú	new_classc                 C   s&   | j j}|du r"| j  ¡  | j j}|S )zgGiven a mayavi script instance, get the current scene.  If none
    is available create a new one.
    N)ÚengineZcurrent_sceneZ	new_scene)ZmayaviÚs© r   úX/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/action/sources.pyÚ	get_scene   s
    
r   c                   @   s(   e Zd ZdZdZdZedƒZdd„ ZdS )ÚOpenFilezN An action that opens a data file depending on the supported
    extensions.  zOpen a supported data filezOpen any supported data filezMenuBar/File/LoadDataMenuc                 C   sÎ   t | jƒ}t|ƒ}|du rdS d}tjD ]B}t|jƒdkr(| d¡sP|j 	d¡r\||j7 }q(|d|j 7 }q(| jj
}t|dd|d�}| ¡ tkrÊt|jƒs®td|j |ƒ dS | |j¡}|durÊ||j_dS )	z Performs the action. NzAll files (*.*)|*.*r   ú|zOpen supported data fileÚopen)ÚparentÚtitleÚactionÚwildcardzFile '%s' does not exist!)r   Úwindowr   r   ÚsourcesÚlenÚ
extensionsÚendswithr   Ú
startswithÚcontrolr   r   r   r   Úpathr	   r   Úcurrent_selection)ÚselfÚeventÚmvr   r   Úsrcr   Údialogr   r   r   Úperform7   s0    



ÿþ
zOpenFile.performN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚtooltipÚdescriptionr   r!   r(   r   r   r   r   r   )   s
   r   c                   @   s   e Zd ZeeƒZdd„ ZdS )ÚSourceActionc                 C   sD   t | jƒ}t|ƒ}|d u rd S | j ¡ }|ƒ }| |¡ ||j_d S )N)r   r   r   ÚmetadataZget_callableZ
add_sourcer   r"   )r#   r$   r%   r   ÚcallableÚobjr   r   r   r(   _   s    


zSourceAction.performN)r)   r*   r+   r   r
   r0   r(   r   r   r   r   r/   Z   s   r/   )r-   r.   r0   N)"r,   Úos.pathr   Z
traits.apir   r   Z
pyface.apir   r   Zpyface.action.apir   Zmayavi.plugins.scriptr   Zmayavi.core.commonr	   Zmayavi.core.metadatar
   Zmayavi.core.registryr   Úfiltersr   r   r   r/   r   r&   r   r   r-   ÚdescÚdÚidr   Úglobalsr   r   r   r   Ú<module>   s(   1
þ