3
<Ad]§   ã               @   s  d Z ddlmZ ddlZddlZddlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZ ejdd… dk r‚ddlZejZnejZG dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZeeƒG dd„ deƒƒZeeƒG dd„ deƒƒZeeƒG dd„ deƒƒZdS )a  
Interfaces and base classes for cross-toolkit timers

This module defines interfaces for toolkit event-loop based timers.  It also
provides a base implementation that can be easily specialized for a particular
back-end, and mixins that provide additional capabilities.
é    )ÚabstractmethodN)ÚABCHasTraitsÚBoolÚCallableÚDictÚEitherÚEventÚFloatÚ	HasTraitsÚIntÚ	InterfaceÚPropertyÚRangeÚTupleÚprovidesé   é   c               @   sb   e Zd ZdZedd�ZedeƒZede	ƒZ
eZedd„ ƒZedd„ ƒZd	d
„ Zdd„ Zdd„ ZdS )ÚITimerz� Interface for timer classes.

    This is a base interface which doesn't specify any particular notification
    mechanism.
    g        )ÚlowNc             K   s   dS )z= Convenience method that creates and starts a timer.
        N© )ÚclsÚtraitsr   r   ún/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/pyface-6.1.2-py3.6.egg/pyface/timer/i_timer.pyÚtimer<   s    zITimer.timerc             K   s   dS )zI Convenience method that creates and starts a single-shot timer.
        Nr   )r   r   r   r   r   Úsingle_shotB   s    zITimer.single_shotc             C   s   dS )z Start the timer. Nr   )Úselfr   r   r   ÚstartH   s    zITimer.startc             C   s   dS )z Stop the timer. Nr   )r   r   r   r   ÚstopL   s    zITimer.stopc             C   s   dS )z. The method that will be called by the timer. Nr   )r   r   r   r   ÚperformP   s    zITimer.perform)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úintervalr   r   Úrepeatr	   Úexpirer   ÚactiveÚclassmethodr   r   r   r   r   r   r   r   r   r   #   s   


r   c               @   s   e Zd ZdZeZdS )ÚIEventTimerz= Interface for timers which fire a trait event periodically. N)r   r    r!   r"   r   Útimeoutr   r   r   r   r(   U   s   r(   c               @   s   e Zd ZdZeZeZeZ	dS )ÚICallbackTimerz: Interface for timers which call a callback periodically. N)
r   r    r!   r"   r   Úcallbackr   Úargsr   Úkwargsr   r   r   r   r*   ^   s   r*   c               @   s¦   e Zd ZdZeƒ Zeddd�Zede	ƒZ
edeƒZeedd�ZeZeZedd	„ ƒZed
d„ ƒZd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S )Ú	BaseTimerzó Base class for timer classes.

    This class has a class variable which tracks active timers to prevent
    failures caused by garbage collection.  A timer is added to this tracker
    when it is started if the repeat value is not None.
    g        gš™™™™™©?)r   ÚvalueNÚ_active)Z
depends_onc             K   s   | f |Ž}|j ƒ  |S )z= Convenience method that creates and starts a timer.
        )r   )r   r   r   r   r   r   r   •   s    
zBaseTimer.timerc             K   s   | f ddi|—Ž}|j ƒ  |S )Nr$   é   )r   )r   r   r   r   r   r   r   �   s    zBaseTimer.single_shotc             C   s@   | j s<| jdk	r| jj| ƒ | jdk	r.tƒ | _d| _ | jƒ  dS )z Start the timer. NT)r0   r$   Ú_active_timersÚaddr%   Úperf_counterÚ_start_timeÚ_start)r   r   r   r   r   £   s    

zBaseTimer.startc             C   s$   | j r | jj| ƒ | jƒ  d| _ dS )z Stop the timer. FN)r0   r2   ÚdiscardÚ_stop)r   r   r   r   r   ­   s    zBaseTimer.stopc             C   s¤   | j dk	r(tƒ | j | j kr(| jƒ  dS | jdk	r@|  jd8  _y| jƒ  W n0 tk
rh   | jƒ  Y n8   | jƒ  ‚ Y n$X | jdk	r | jdkr | jƒ  d| _dS )zž Perform the callback.

        The timer will stop if repeats is not None and less than 1, or if
        the `_perform` method raises StopIteration.
        Nr1   r   )r%   r4   r5   r   r$   Ú_performÚStopIteration)r   r   r   r   r   ´   s     

zBaseTimer.performc             C   s
   t ƒ ‚dS )zT Start the toolkit timer.

        Subclasses should overrided this method.
        N)ÚNotImplementedError)r   r   r   r   r6   Ð   s    zBaseTimer._startc             C   s
   t ƒ ‚dS )zS Stop the toolkit timer.

        Subclasses should overrided this method.
        N)r;   )r   r   r   r   r8   ×   s    zBaseTimer._stopc             C   s
   t ƒ ‚dS )z[ perform the appropriate action.

        Subclasses should overrided this method.
        N)r;   )r   r   r   r   r9   Þ   s    zBaseTimer._performc             C   s   | j S )N)r0   )r   r   r   r   Ú_get_activeì   s    zBaseTimer._get_activec             C   s   |r| j ƒ  n| jƒ  d S )N)r   r   )r   r/   r   r   r   Ú_set_activeï   s    
zBaseTimer._set_active)r   r    r!   r"   Úsetr2   r   r#   r   r   r$   r	   r%   r   r   r&   r0   r5   r'   r   r   r   r   r   r6   r8   r   r9   r<   r=   r   r   r   r   r.   m   s$   


r.   c               @   s   e Zd ZdZeZdd„ ZdS )ÚMEventTimerz{ Mixin for event timer classes.

    Other code can listen to the `timeout` event using standard traits
    listeners.
    c             C   s
   d| _ dS )z Fire the event. TN)r)   )r   r   r   r   r9   	  s    zMEventTimer._performN)r   r    r!   r"   r   r)   r9   r   r   r   r   r?   ö   s   r?   c               @   s$   e Zd ZdZeZeZeZ	dd„ Z
dS )ÚMCallbackTimerz' Mixin for callback timer classes.
    c             C   s   | j | j| jŽ dS )z Perform the callback. N)r+   r,   r-   )r   r   r   r   r9   $  s    zMCallbackTimer._performN)r   r    r!   r"   r   r+   r   r,   r   r-   r9   r   r   r   r   r@     s
   r@   )r   r   )r"   Úabcr   ÚsysÚtimeZ
traits.apir   r   r   r   r   r   r	   r
   r   r   r   r   r   r   Úversion_infoZtimeitZdefault_timerr4   r   r(   r*   r.   r?   r@   r   r   r   r   Ú<module>   s$   @2	 	