a
    §ˆcS   ã                   @   sÚ   d Z ddlm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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ÚEventÚFloatÚ	HasTraitsÚIntÚ	InterfaceÚPropertyÚRangeÚTupleÚprovidesÚUnionc                   @   sd   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.
    ç        )ÚlowNc                 K   s   dS )ú= Convenience method that creates and starts a timer.
        N© ©ÚclsÚtraitsr   r   úW/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/timer/i_timer.pyÚtimerA   s    zITimer.timerc                 K   s   dS )zI Convenience method that creates and starts a single-shot timer.
        Nr   r   r   r   r   Úsingle_shotG   s    zITimer.single_shotc                 C   s   dS )ú Start the timer. Nr   ©Úselfr   r   r   ÚstartM   s    zITimer.startc                 C   s   dS )ú Stop the timer. Nr   r   r   r   r   ÚstopQ   s    zITimer.stopc                 C   s   dS )z. The method that will be called by the timer. Nr   r   r   r   r   ÚperformU   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,   Z   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.   c   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.
    r   gš™™™™™©?)r   ÚvalueNÚ_active)Zobservec                 K   s   | f i |¤Ž}|  ¡  |S )r   ©r   ©r   r   r   r   r   r   r   š   s    zBaseTimer.timerc                 K   s   | f ddi|¤Ž}|  ¡  |S )Nr(   é   r5   r6   r   r   r   r   ¢   s    zBaseTimer.single_shotc                 C   s@   | j s<| jdur| j | ¡ | jdur.tƒ | _d| _ |  ¡  dS )r   NT)r4   r(   Ú_active_timersÚaddr)   Úperf_counterÚ_start_timeÚ_startr   r   r   r   r   ¨   s    

zBaseTimer.startc                 C   s$   | j r | j | ¡ |  ¡  d| _ dS )r    FN)r4   r8   ÚdiscardÚ_stopr   r   r   r   r!   ²   s    zBaseTimer.stopc                 C   s¢   | j dur(tƒ | j | j kr(|  ¡  dS | jdur@|  jd8  _z|  ¡  W n. tyf   |  ¡  Y n8   |  ¡  ‚ Y n$0 | jdurž| jdkrž|  ¡  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.
        Nr7   r   )r)   r:   r;   r!   r(   Ú_performÚStopIterationr   r   r   r   r"   ¹   s     

zBaseTimer.performc                 C   s
   t ƒ ‚dS )zT Start the toolkit timer.

        Subclasses should overrided this method.
        N©ÚNotImplementedErrorr   r   r   r   r<   Õ   s    zBaseTimer._startc                 C   s
   t ƒ ‚dS )zS Stop the toolkit timer.

        Subclasses should overrided this method.
        NrA   r   r   r   r   r>   Ü   s    zBaseTimer._stopc                 C   s
   t ƒ ‚dS )z[ perform the appropriate action.

        Subclasses should overrided this method.
        NrA   r   r   r   r   r?   ã   s    zBaseTimer._performc                 C   s   | j S ©N)r4   r   r   r   r   Ú_get_activeñ   s    zBaseTimer._get_activec                 C   s   |r|   ¡  n|  ¡  d S rC   )r   r!   )r   r3   r   r   r   Ú_set_activeô   s    
zBaseTimer._set_active)r#   r$   r%   r&   Úsetr8   r   r'   r   r
   r(   r   r)   r   r   r*   r4   r;   r+   r   r   r   r!   r"   r<   r>   r   r?   rD   rE   r   r   r   r   r2   r   s*   






r2   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   r?     s    zMEventTimer._performN)r#   r$   r%   r&   r   r-   r?   r   r   r   r   rG   û   s   	rG   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i | j¤Ž dS )z Perform the callback. N)r/   r0   r1   r   r   r   r   r?   )  s    zMCallbackTimer._performN)r#   r$   r%   r&   r   r/   r   r0   r   r1   r?   r   r   r   r   rH     s
   rH   )r&   Úabcr   ÚtimeZ
traits.apir   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r:   r   r,   r.   r2   rG   rH   r   r   r   r   Ú<module>
   s   @2	 	