U
    Pe                     @   s@   d Z dZddlmZ ddlmZ ddlmZ G dd deZdS )	zO
Triple Tap
==========

.. versionadded:: 1.7.0

Search touch for a triple tap
)InputPostprocTripleTap    )time)Config)Vectorc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	r   aB  
    InputPostProcTripleTap is a post-processor to check if
    a touch is a triple tap or not.
    Triple tap can be configured in the Kivy config file::

        [postproc]
        triple_tap_time = 250
        triple_tap_distance = 20

    The distance parameter is in the range 0-1000 and time is in milliseconds.
    c                 C   s6   t dd}|d | _t dd}|d | _i | _d S )NZpostproctriple_tap_distanceg     @@triple_tap_time)r   getintr   r   touches)selfdistr    r   A/tmp/pip-unpacked-wheel-xzebddm3/kivy/input/postproc/tripletap.py__init__   s
    

zInputPostprocTripleTap.__init__c                 C   s   d}d|j kr|j}| jD ]}|j|kr*q| j| \}}|js@q|dkrJq|jrRqtt|j|j	t|j
|j}|| jkr~q|js|jrqd}d|j kr|j}||krq||_|  S dS )zFind a triple tap touch within *self.touches*.
        The touch must be not be a previous triple tap and the distance
        must be be within the bounds specified. Additionally, the touch profile
        must be the same kind of touch.
        Nbuttonend)Zprofiler   r	   uidis_double_tapis_triple_tapr   distanceZsxZsyZosxZosyr   Zis_mouse_scrolling)r
   refZ
ref_buttontouchidetypetouchr   Ztouch_buttonr   r   r   find_triple_tap%   s8    




z&InputPostprocTripleTap.find_triple_tapc           
      C   s   | j dks| jdkr|S |D ]`\}}|js,q|dkrl| |}|rld|_d|_|j|j }||_|j }||_ ||f| j|j< qt	 }g }| j
 D ]8}	| j|	 \}}|dkrq||j | jk rq||	 q|D ]}	| j|	= q|S )Nr   beginFTr   )r   r   Zis_touchr   r   r   Z
time_startr	   r   r   keysappend)
r
   eventsr   r   Z
triple_tapZtap_timer   Ztime_currentZ	to_deleter   r   r   r   processH   s6    

zInputPostprocTripleTap.processN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r      s   #r   N)	r"   __all__r   Zkivy.configr   Zkivy.vectorr   objectr   r   r   r   r   <module>   s
   	