a
    ëÝEb‘+  ã                   @   s˜   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z
 ejdedd� e e¡ZG d	d
„ d
ƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )aä  
Classes used for blocking interaction with figure windows:

`BlockingInput`
    Creates a callable object to retrieve events in a blocking way for
    interactive sessions.  Base class of the other classes listed here.

`BlockingKeyMouseInput`
    Creates a callable object to retrieve key or mouse clicks in a blocking
    way for interactive sessions.  Used by `~.Figure.waitforbuttonpress`.

`BlockingMouseInput`
    Creates a callable object to retrieve mouse clicks in a blocking way for
    interactive sessions.  Used by `~.Figure.ginput`.

`BlockingContourLabeler`
    Creates a callable object to retrieve mouse clicks in a blocking way that
    will then be used to place labels on a `.ContourSet`.  Used by
    `~.Axes.clabel`.
é    N)ÚIntegral)Ú_api)ÚMouseButtonz3.5Úmodule)ÚnameÚobj_typec                   @   sR   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zddd„Z	e	Z
ddd„ZdS )ÚBlockingInputz1Callable for retrieving events in a blocking way.© c                 C   s   || _ || _d S ©N©ÚfigÚ
eventslist)Úselfr   r   r	   r	   úY/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/matplotlib/blocking_input.pyÚ__init__$   s    zBlockingInput.__init__c                 C   sT   |   |¡ t dt| jƒ¡ |  ¡  t| jƒ| j  kr@dkrPn n| jj 	¡  dS )zY
        Event handler; will be passed to the current figure to retrieve events.
        zEvent %ir   N)
Ú	add_eventÚ_logÚinfoÚlenÚeventsÚ
post_eventÚnr   ÚcanvasÚstop_event_loop©r   Úeventr	   r	   r   Úon_event(   s
    
 zBlockingInput.on_eventc                 C   s   dS )z-For baseclass, do nothing but collect events.Nr	   ©r   r	   r	   r   r   8   s    zBlockingInput.post_eventc                 C   s$   | j D ]}| jj |¡ qg | _ dS )zDisconnect all callbacks.N)Ú	callbacksr   r   Zmpl_disconnect)r   Úcbr	   r	   r   Úcleanup;   s    
zBlockingInput.cleanupc                 C   s   | j  |¡ dS )z5For base class, this just appends an event to events.N)r   Úappendr   r	   r	   r   r   A   s    zBlockingInput.add_eventéÿÿÿÿc                 C   s   | j  |¡ dS )zè
        Remove an event from the event list -- by default, the last.

        Note that this does not check that there are events, much like the
        normal pop method.  If no events exist, this will throw an exception.
        N)r   Úpop)r   Úindexr	   r	   r   Ú	pop_eventE   s    zBlockingInput.pop_eventé   é   c                    sr   t jt|d� |ˆ _g ˆ _ˆ jjjr.ˆ j ¡  ‡ fdd„ˆ j	D ƒˆ _
zˆ jjj|d� W ˆ  ¡  n
ˆ  ¡  0 ˆ jS )z%Blocking call to retrieve *n* events.)r   c                    s   g | ]}ˆ j j |ˆ j¡‘qS r	   )r   r   Zmpl_connectr   )Ú.0r   r   r	   r   Ú
<listcomp>Z   s   ÿz*BlockingInput.__call__.<locals>.<listcomp>)Útimeout)r   Zcheck_isinstancer   r   r   r   r   ÚmanagerÚshowr   r   Zstart_event_loopr    )r   r   r*   r	   r   r   Ú__call__P   s    


ÿzBlockingInput.__call__N)r	   )r"   )r&   r'   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    r   r%   r#   r-   r	   r	   r	   r   r   !   s   

	r   c                       s¬   e Zd ZdZejZejZej	Z
ejejej	f‡ fdd„	Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ Zddd„Zd ‡ fdd„	Zd!‡ fdd„	Zd"‡ fdd„	Z‡  ZS )#ÚBlockingMouseInputa  
    Callable for retrieving mouse clicks in a blocking way.

    This class will also retrieve keypresses and map them to mouse clicks:
    delete and backspace are a right click, enter is like a middle click,
    and all others are like a left click.
    c                    s&   t ƒ j|dd� || _|| _|| _d S ©N)Zbutton_press_eventÚkey_press_eventr   )Úsuperr   Ú
button_addÚ
button_popÚbutton_stop)r   r   Z	mouse_addZ	mouse_popZ
mouse_stop©Ú	__class__r	   r   r   s   s    ÿzBlockingMouseInput.__init__c                 C   s@   t | jƒdkrt d¡ n"| jd jdkr4|  ¡  n|  ¡  dS )zProcess an event.r   zNo events yetr"   r4   N)r   r   r   Úwarningr   Ú	key_eventÚmouse_eventr   r	   r	   r   r   }   s
    
zBlockingMouseInput.post_eventc                 C   sT   | j d }|j}|| jkr&|  |¡ n*|| jkr<|  |¡ n|| jkrP|  |¡ dS )zProcess a mouse click event.r"   N)r   Úbuttonr7   Úmouse_event_popr8   Úmouse_event_stopr6   Úmouse_event_add)r   r   r>   r	   r	   r   r=   †   s    



zBlockingMouseInput.mouse_eventc                 C   sR   | j d }|jdu rdS |jdv r.|  |¡ n |jdv rD|  |¡ n
|  |¡ dS )zV
        Process a key press event, mapping keys to appropriate mouse clicks.
        r"   N)Z	backspaceÚdelete)ÚescapeZenter)r   Úkeyr?   r@   rA   r   r	   r	   r   r<   ‘   s    



zBlockingMouseInput.key_eventc                 C   s    |j r|  |¡ n
t | ¡ dS )z�
        Process an button-1 event (add a click if inside axes).

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        N)ÚinaxesÚ	add_clickr   r#   r   r	   r	   r   rA       s    z"BlockingMouseInput.mouse_event_addc                 C   s   t  | ¡ | jj ¡  dS )z•
        Process an button-2 event (end blocking input).

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        N)r   r#   r   r   r   r   r	   r	   r   r@   ­   s    	
z#BlockingMouseInput.mouse_event_stopc                 C   s   t  | ¡ | jr|  |¡ dS )z˜
        Process an button-3 event (remove the last click).

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        N)r   r#   r   r   r	   r	   r   r?   ¼   s    	
z"BlockingMouseInput.mouse_event_popc                 C   sv   | j  |j|jf¡ t dt| j ƒ|j|j¡ | jrrtj	|jg|jgddd�}|j
 |¡ | j |¡ | jj ¡  dS )zœ
        Add the coordinates of an event to the list of clicks.

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        zinput %i: %f, %fú+Úr)ÚmarkerÚcolorN)Úclicksr!   ZxdataZydatar   r   r   Úshow_clicksÚmlinesZLine2DrE   Úadd_lineÚmarksr   r   Údraw)r   r   Úliner	   r	   r   rF   Ê   s    ÿÿzBlockingMouseInput.add_clickr"   c                 C   s2   | j  |¡ | jr.| j |¡ ¡  | jj ¡  dS )z¤
        Remove a click (by default, the last) from the list of clicks.

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        N)rK   r#   rL   rO   Úremover   r   rP   ©r   r   r$   r	   r	   r   Ú	pop_clickÝ   s    zBlockingMouseInput.pop_clickc                    s   |   ||¡ tƒ  |¡ dS )zw
        Remove a click and the associated event from the list of clicks.

        Defaults to the last click.
        N)rT   r5   r#   rS   r9   r	   r   r#   ê   s    zBlockingMouseInput.popNc                    s:   | j r,| jD ]}| ¡  qg | _| jj ¡  tƒ  ¡  dS )z{
        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`, optional
            Not used
        N)rL   rO   rR   r   r   rP   r5   r    )r   r   Úmarkr9   r	   r   r    ó   s    

zBlockingMouseInput.cleanupr&   r'   Tc                    s(   || _ g | _g | _tƒ j||d� | jS )zV
        Blocking call to retrieve *n* coordinate pairs through mouse clicks.
        ©r   r*   )rL   rK   rO   r5   r-   )r   r   r*   rL   r9   r	   r   r-     s
    zBlockingMouseInput.__call__)r"   )r"   )N)r&   r'   T)r.   r/   r0   r1   r   ÚLEFTr6   ÚRIGHTr7   ZMIDDLEr8   r   r   r=   r<   rA   r@   r?   rF   rT   r#   r    r-   Ú__classcell__r	   r	   r9   r   r2   f   s&   ý
	
	r2   c                       sP   e Zd ZdZ‡ fdd„Zdd„ Zddd„Zd	d
„ Zdd„ Zd‡ fdd„	Z	‡  Z
S )ÚBlockingContourLabelerzt
    Callable for retrieving mouse clicks and key presses in a blocking way.

    Used to place contour labels.
    c                    s   || _ tƒ j|jjd� d S )N)r   )Úcsr5   r   ZaxesÚfigure)r   r[   r9   r	   r   r     s    zBlockingContourLabeler.__init__c                 C   s   |   |¡ d S r
   )Úbutton1r   r	   r	   r   rF     s    z BlockingContourLabeler.add_clickr"   c                 C   s   |   |¡ d S r
   )Úbutton3rS   r	   r	   r   rT     s    z BlockingContourLabeler.pop_clickc                 C   sH   |j | jjkr:| jj|j|j| j| jdd� | jj	 
¡  n
t | ¡ dS )z›
        Process an button-1 event (add a label to a contour).

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        F)Úinline_spacingZ	transformN)rE   r[   ÚaxZadd_label_nearÚxÚyÚinliner_   r   r   rP   r   r#   r   r	   r	   r   r]     s    	þzBlockingContourLabeler.button1c                 C   s&   | j rn| j ¡  | jjjj ¡  dS )aŠ  
        Process an button-3 event (remove a label if not in inline mode).

        Unfortunately, if one is doing inline labels, then there is currently
        no way to fix the broken contour - once humpty-dumpty is broken, he
        can't be put back together.  In inline mode, this does nothing.

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        N)rc   r[   Z	pop_labelr`   r\   r   rP   r   r	   r	   r   r^   0  s    
zBlockingContourLabeler.button3é   c                    s"   || _ || _tƒ j||dd� d S )NF)r   r*   rL   )rc   r_   r5   r-   )r   rc   r_   r   r*   r9   r	   r   r-   B  s    zBlockingContourLabeler.__call__)r"   )rd   r"   r"   )r.   r/   r0   r1   r   rF   rT   r]   r^   r-   rY   r	   r	   r9   r   rZ     s   
rZ   c                       s6   e Zd ZdZ‡ fdd„Zdd„ Zd	‡ fdd„	Z‡  ZS )
ÚBlockingKeyMouseInputzQ
    Callable for retrieving mouse clicks and key presses in a blocking way.
    c                    s   t ƒ j|dd� d S r3   )r5   r   )r   r   r9   r	   r   r   M  s    ÿzBlockingKeyMouseInput.__init__c                 C   s(   | j r| j d jdk| _n
t d¡ dS )zDetermine if it is a key event.r"   r4   zNo events yet.N)r   r   Ú
keyormouser   r;   r   r	   r	   r   r   Q  s    z BlockingKeyMouseInput.post_eventr'   c                    s   d| _ tƒ jd|d� | j S )z²
        Blocking call to retrieve a single mouse click or key press.

        Returns ``True`` if key press, ``False`` if mouse click, or ``None`` if
        timed out.
        Nr&   rV   )rf   r5   r-   )r   r*   r9   r	   r   r-   X  s    zBlockingKeyMouseInput.__call__)r'   )r.   r/   r0   r1   r   r   r-   rY   r	   r	   r9   r   re   H  s   re   )r1   ÚloggingÚnumbersr   Z
matplotlibr   Zmatplotlib.backend_basesr   Zmatplotlib.linesÚlinesrM   Zwarn_deprecatedr.   Ú	getLoggerr   r   r2   rZ   re   r	   r	   r	   r   Ú<module>   s   
E ):