U
    P’“e  ã                   @   sŠ   d Z d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 eƒ Zd aad	d
„ ZG dd„ deƒZG dd„ deƒZe	 de¡ dS )z5
Leap Motion - finger only
=========================
)ÚLeapFingerEventProviderÚLeapFingerEventé    )Údeque)ÚLogger)ÚMotionEventProvider)ÚMotionEventFactory)ÚMotionEventNc                 C   s   | | t || ƒ S ©N)Úfloat)ÚvalueÚaÚb© r   úC/tmp/pip-unpacked-wheel-xzebddm3/kivy/input/providers/leapfinger.pyÚ	normalize   s    r   c                       s(   e Zd Z‡ fdd„Z‡ fdd„Z‡  ZS )r   c                    s0   |  dd¡ |  dd¡ tƒ j||Ž d| _d S )NZis_touchTZtype_idÚtouch)ÚposZpos3d)Ú
setdefaultÚsuperÚ__init__Zprofile)ÚselfÚargsÚkwargs©Ú	__class__r   r   r      s    zLeapFingerEvent.__init__c                    sZ   t ƒ  |¡ |d d krd S |\}}}t|ddƒ| _t|ddƒ| _t|ddƒ| _|| _d S )Nr   ijÿÿÿé–   é(   iÌ  i¢þÿÿi^  )r   Údepackr   ZsxZsyÚszÚz)r   r   ÚxÚyr   r   r   r   r      s    
zLeapFingerEvent.depack)Ú__name__Ú
__module__Ú__qualname__r   r   Ú__classcell__r   r   r   r   r      s   r   c                   @   s(   e Zd Zi Zdd„ Zdd„ Zdd„ ZdS )r   c                 C   sL   dd l a ddl ma G dd„ dt jƒ}d| _i | _|ƒ | _t  | j¡| _d S )Nr   )ÚInteractionBoxc                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )z9LeapFingerEventProvider.start.<locals>.LeapMotionListenerc                 S   s   t  d¡ d S )Nzleapmotion: Initialized©r   Úinfo©r   Ú
controllerr   r   r   Úon_init7   s    zALeapFingerEventProvider.start.<locals>.LeapMotionListener.on_initc                 S   s   t  d¡ d S )Nzleapmotion: Connectedr'   r)   r   r   r   Ú
on_connect:   s    zDLeapFingerEventProvider.start.<locals>.LeapMotionListener.on_connectc                 S   s   t  d¡ d S )Nzleapmotion: Disconnectedr'   r)   r   r   r   Úon_disconnect=   s    zGLeapFingerEventProvider.start.<locals>.LeapMotionListener.on_disconnectc                 S   s   |  ¡ }t |¡ d S r	   )ÚframeÚ_LEAP_QUEUEÚappend)r   r*   r.   r   r   r   Úon_frame@   s    zBLeapFingerEventProvider.start.<locals>.LeapMotionListener.on_framec                 S   s   d S r	   r   r)   r   r   r   Úon_exitD   s    zALeapFingerEventProvider.start.<locals>.LeapMotionListener.on_exitN)r"   r#   r$   r+   r,   r-   r1   r2   r   r   r   r   ÚLeapMotionListener5   s
   r3   )ÚLeapr&   ZListenerÚuidÚtouchesZlistenerZ
Controllerr*   )r   r3   r   r   r   Ústart.   s    zLeapFingerEventProvider.startc                 C   sD   z*t  ¡ }|  |¡}|D ]}||Ž  qqW n tk
r>   Y nX d S r	   )r/   ÚpopleftÚprocess_frameÚ
IndexError)r   Zdispatch_fnr.   ÚeventsZevr   r   r   ÚupdateL   s    
zLeapFingerEventProvider.updatec                 C   sâ   g }| j }g }|jD ]Ž}|jD ]‚}d |j|j¡}| |¡ |j}|j|j|j	f}	||kr€t
| j||	ƒ}
| d|
f¡ |
||< q|| }
|
 |	¡ | d|
f¡ qqt| ¡ ƒd d … D ]$}||kr¸| d|| f¡ ||= q¸|S )Nz{0}:{1}Úbeginr<   Úend)r6   ZhandsZfingersÚformatÚidr0   Ztip_positionr    r!   r   r   ZdeviceÚmoveÚlistÚkeys)r   r.   r;   r6   Zavailable_uidÚhandZfingerr5   Úpositionr   r   Úkeyr   r   r   r9   V   s*    




z%LeapFingerEventProvider.process_frameN)r"   r#   r$   Z__handlers__r7   r<   r9   r   r   r   r   r   *   s   
r   Z
leapfinger)Ú__doc__Ú__all__Úcollectionsr   Zkivy.loggerr   Zkivy.input.providerr   Zkivy.input.factoryr   Zkivy.input.motioneventr   r/   r4   r&   r   r   r   Úregisterr   r   r   r   Ú<module>   s   G