a
    «ˆcî
  ã                   @   s`   d dl Z d dlmZ d dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlmZ G dd„ deƒZdS )é    N)Úglob)Úcontextmanager)ÚBoolÚ	DirectoryÚ	HasTraitsÚInstanceÚIntÚStr)Úget_home_directoryc                   @   sŒ   e Zd Zeddd�Zeddd�ZeZe	dƒZ
eddd�Ze	Zed	ƒZd
d„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZdd„ Zdd„ Zdd„ ZdS )Ú
MovieMakerFzif a movie should be recorded)Údescz tvtk.pyface.tvtk_scene.TVTKScene)Úrecordzanim%05d.pngTz*if the saved images should be anti-aliasedr   c                 C   s2   ddl m}m} ||dƒ|dƒ|dƒ|dƒƒ}|S )Nr   )ÚItemÚViewr   Ú
anti_aliasÚfilenameÚ	directory)Ztraitsui.apir   r   )Úselfr   r   Úview© r   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/tvtk/pyface/movie_maker.pyÚdefault_traits_view   s    üzMovieMaker.default_traits_viewc                 C   s$   | j r |  ¡  d| _|  | j¡ d S )Nr   )r   Ú_update_subdirÚ_countÚ_save_scene©r   r   r   r   Úanimation_start   s    zMovieMaker.animation_startc                 C   s$   | j r |  jd7  _|  | j¡ d S )Né   )r   r   r   r   r   r   r   Úanimation_step%   s    zMovieMaker.animation_stepc                 C   s   d S ©Nr   r   r   r   r   Úanimation_stop*   s    zMovieMaker.animation_stopc                 c   s<   d| _ |  ¡  z| V  W |  ¡  d| _ n|  ¡  d| _ 0 dS )aý  Context manager to record a movie.  Using this will turn on the
        recording automatically and also shut it off after it is done.

        For example::

            >>> s = mlab.test_simple_surf()
            >>> ms = s.mlab_source
            >>> x = ms.x
            >>> with s.scene.movie_maker.record_movie() as mm:
            ...     for i in range(10):
            ...         ms.scalars = numpy.asarray(x * 0.1 * (i + 1), 'd')
            ...         mm.animation_step()
            ...
        TFN)r   r   r    r   r   r   r   Úrecord_movie-   s    ÿzMovieMaker.record_moviec                 C   sh   t j | j| j¡}t j |¡s(t  |¡ t j || j| ¡}| jsJ| j	j
}| j	 |¡ | jsd|| j	_
d S r   )ÚosÚpathÚjoinr   Ú_subdirÚexistsÚmakedirsr   r   ÚsceneZanti_aliasing_framesÚsave)r   ÚcountÚdirÚfnameZorig_aar   r   r   r   E   s    
zMovieMaker._save_scenec                 C   s   t ƒ }tj |dd¡S )NZ	DocumentsZmayavi_movies)r
   r"   r#   r$   )r   Úhomer   r   r   Ú_directory_defaultQ   s    zMovieMaker._directory_defaultc                 C   sX   t j | jd¡}tdd„ t|ƒD ƒƒ}d}|rJ|d }t|dd … ƒd }d| | _d S )Nzmovie*c                 S   s   g | ]}t j |¡r|‘qS r   )r"   r#   Úisdir)Ú.0Úxr   r   r   Ú
<listcomp>W   ó    z-MovieMaker._update_subdir.<locals>.<listcomp>r   éÿÿÿÿéýÿÿÿz	movie%03d)r"   r#   r$   r   Úsortedr   Úintr%   )r   ÚpatternÚexistingÚ
last_indexÚlastr   r   r   r   U   s    zMovieMaker._update_subdirN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r(   r   r   r	   r   r   r%   r   r   r   r   r   r    r   r!   r   r.   r   r   r   r   r   r   	   s    

r   )r"   r   Ú
contextlibr   Z
traits.apir   r   r   r   r   r	   Ztraits.util.home_directoryr
   r   r   r   r   r   Ú<module>   s
    