
    G8c+                         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        ej                  e      Z G d	 d
      Z G d de      Z G d de      Z G d de      Zy)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                   D    e Zd ZdZd
dZd Zd Zd Zd ZddZ	e	Z
ddZy	)BlockingInputz1Callable for retrieving events in a blocking way.c                      || _         || _        y Nfig
eventslist)selfr   r   s      ;/usr/lib/python3/dist-packages/matplotlib/blocking_input.py__init__zBlockingInput.__init__$   s    $    c                 8   | j                  |       t        j                  dt        | j                               | j                          t        | j                        | j                  cxk\  rdkD  r(n y| j                  j                  j                          yy)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   events     r   on_eventzBlockingInput.on_event(   sh     	u		*c$++./ 	 t{{tvv))HHOO++- *r   c                      y)z-For baseclass, do nothing but collect events.N r   s    r   r   zBlockingInput.post_event8   s    r   c                 ~    | j                   D ]'  }| j                  j                  j                  |       ) g | _         y)zDisconnect all callbacks.N)	callbacksr   r   mpl_disconnect)r   cbs     r   cleanupzBlockingInput.cleanup;   s2    .. 	/BHHOO**2.	/r   c                 :    | j                   j                  |       y)z5For base class, this just appends an event to events.N)r   appendr   s     r   r   zBlockingInput.add_eventA   s    5!r   c                 :    | j                   j                  |       y)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   indexs     r   	pop_eventzBlockingInput.pop_eventE   s     	r   c                    t        j                  t        |       || _        g | _        | j
                  j                  j                  r| j
                  j                          | j                  D cg c]2  }| j
                  j                  j                  || j                        4 c}| _        	 | j
                  j                  j                  |       | j                          | j                  S c c}w # | j                          w xY w)z%Blocking call to retrieve *n* events.)r   )timeout)r   check_isinstancer   r   r   r   r   managershowr   mpl_connectr    r%   start_event_loopr(   )r   r   r0   r   s       r   __call__zBlockingInput.__call__P   s    h!,88??""HHMMO '+oo7" ((//55dDMMJ 7	HHOO,,W,= LLN{{7 LLNs   27C42&C9 9DN)r"   )      )__name__
__module____qualname____doc__r   r    r   r(   r   r.   r,   r6   r"   r   r   r
   r
   !   s/    ;%. <" Cr   r
   c                       e Zd ZdZej
                  Zej                  Zej                  Z
ej
                  ej                  ej                  f fd	Zd Zd Zd Zd Zd Zd Zd	 Zdd
Zd fd	Zd fd	Zd fd	Z x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                 R    t         |   |d       || _        || _        || _        y N)button_press_eventkey_press_eventr   )superr   
button_add
button_popbutton_stop)r   r   	mouse_add	mouse_pop
mouse_stop	__class__s        r   r   zBlockingMouseInput.__init__s   s3     	S$M 	 	O##%r   c                     t        | j                        dk(  rt        j                  d       y| j                  d   j                  dk(  r| j                          y| j                          y)zProcess an event.r   zNo events yetr8   rD   N)r   r   r   warningr   	key_eventmouse_eventr#   s    r   r   zBlockingMouseInput.post_event}   sL    t{{q LL)[[_!!%66NNr   c                     | j                   d   }|j                  }|| j                  k(  r| j                  |       y|| j                  k(  r| j                  |       y|| j                  k(  r| j                  |       yy)zProcess a mouse click event.r8   N)r   buttonrG   mouse_event_poprH   mouse_event_stoprF   mouse_event_add)r   r   rR   s      r   rP   zBlockingMouseInput.mouse_event   sm    BT__$  't'''!!%(t&  ' 'r   c                     | j                   d   }|j                  y|j                  dv r| j                  |       y|j                  dv r| j                  |       y| j	                  |       y)zV
        Process a key press event, mapping keys to appropriate mouse clicks.
        r8   N)	backspacedelete)escapeenter)r   keyrS   rT   rU   r   s     r   rO   zBlockingMouseInput.key_event   sb     B9999//  'YY--!!%(  'r   c                 j    |j                   r| j                  |       yt        j                  |        y)z
        Process an button-1 event (add a click if inside axes).

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        N)inaxes	add_clickr
   r,   r   s     r   rU   z"BlockingMouseInput.mouse_event_add   s%     <<NN5!d#r   c                 v    t         j                  |        | j                  j                  j	                          y)z
        Process an button-2 event (end blocking input).

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        N)r
   r,   r   r   r   r   s     r   rT   z#BlockingMouseInput.mouse_event_stop   s(     	$ 	'')r   c                 j    t         j                  |        | j                  r| j                  |       yy)z
        Process an button-3 event (remove the last click).

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        N)r
   r,   r   r   s     r   rS   z"BlockingMouseInput.mouse_event_pop   s)     	$;;HHUO r   c                    | j                   j                  |j                  |j                  f       t        j                  dt        | j                         |j                  |j                         | j                  rt        j                  |j                  g|j                  gdd      }|j                  j                  |       | j                  j                  |       | j                  j                  j                          yy)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*   xdataydatar   r   r   show_clicksmlinesLine2Dr]   add_linemarksr   r   draw)r   r   lines      r   r^   zBlockingMouseInput.add_click   s     	EKK56		$dkk"EKK	> ==%++(+38DLL!!$'JJd#HHOO  " r   c                     | j                   j                  |       | j                  rN| j                  j                  |      j	                          | j
                  j                  j                          yy)z
        Remove a click (by default, the last) from the list of clicks.

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        N)rf   r,   ri   rm   remover   r   rn   r   r   r-   s      r   	pop_clickzBlockingMouseInput.pop_click   sO     	JJNN5!((*HHOO  " r   c                 H    | j                  ||       t        | 	  |       y)zw
        Remove a click and the associated event from the list of clicks.

        Defaults to the last click.
        N)rs   rE   r,   )r   r   r-   rL   s      r   r,   zBlockingMouseInput.pop   s     	ue$Er   c                     | j                   rL| j                  D ]  }|j                           g | _        | j                  j                  j                          t        |           y)z{
        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`, optional
            Not used
        N)ri   rm   rq   r   r   rn   rE   r(   )r   r   markrL   s      r   r(   zBlockingMouseInput.cleanup   sO     

 DJHHOO  "r   c                 h    || _         g | _        g | _        t        |   ||       | j                  S )zV
        Blocking call to retrieve *n* coordinate pairs through mouse clicks.
        r   r0   )ri   rf   rm   rE   r6   )r   r   r0   ri   rL   s       r   r6   zBlockingMouseInput.__call__  s7     '
1g.{{r   r7   r   )r9   r:   T)r;   r<   r=   r>   r   LEFTrF   RIGHTrG   MIDDLErH   r   r   rP   rO   rU   rT   rS   r^   rs   r,   r(   r6   __classcell__rL   s   @r   r@   r@   f   s     !!J""J$$K '++&,,'..&	(($*#&#  r   r@   c                   H     e Zd ZdZ fdZd ZddZd Zd Zd	 fd	Z	 xZ
S )
BlockingContourLabelerzt
    Callable for retrieving mouse clicks and key presses in a blocking way.

    Used to place contour labels.
    c                 \    || _         t        | 	  |j                  j                         y )N)r   )csrE   r   axesfigure)r   r   rL   s     r   r   zBlockingContourLabeler.__init__  s"    RWW^^,r   c                 &    | j                  |       y r   )button1r   s     r   r^   z BlockingContourLabeler.add_click      Ur   c                 &    | j                  |       y r   )button3rr   s      r   rs   z BlockingContourLabeler.pop_click  r   r   c                 N   |j                   | j                  j                  k(  rm| j                  j                  |j                  |j
                  | j                  | j                  d       | j                  j                  j                          yt        j                  |        y)z
        Process an button-1 event (add a label to a contour).

        Parameters
        ----------
        event : `~.backend_bases.MouseEvent`
        F)inline_spacing	transformN)r]   r   axadd_label_nearxyinliner   r   r   rn   r
   r,   r   s     r   r   zBlockingContourLabeler.button1  sq     <<477::%GG""577EGGT[[262E2E-2 # 4 HHOO  "d#r   c                     | j                   ry| j                  j                          | j                  j                  j                  j
                  j                          y)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)r   r   	pop_labelr   r   r   rn   r   s     r   r   zBlockingContourLabeler.button30  s>     ;;GGGGJJ$$))+r   c                 F    || _         || _        t        |   ||d       y )NF)r   r0   ri   )r   r   rE   r6   )r   r   r   r   r0   rL   s        r   r6   zBlockingContourLabeler.__call__B  s&    ,1g5Ar   r7   )   r8   r8   )r;   r<   r=   r>   r   r^   rs   r   r   r6   r|   r}   s   @r   r   r     s-    -$",$B Br   r   c                   4     e Zd ZdZ fdZd Zd fd	Z xZS )BlockingKeyMouseInputzQ
    Callable for retrieving mouse clicks and key presses in a blocking way.
    c                 (    t         |   |d       y rB   )rE   r   )r   r   rL   s     r   r   zBlockingKeyMouseInput.__init__M  s    S$M 	 	Or   c                     | j                   r"| j                   d   j                  dk(  | _        yt        j	                  d       y)zDetermine if it is a key event.r8   rD   zNo events yet.N)r   r   
keyormouser   rN   r#   s    r   r   z BlockingKeyMouseInput.post_eventQ  s1    ;;"kk"o226GGDOLL)*r   c                 L    d| _         t        | 	  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.
        Nr9   rx   )r   rE   r6   )r   r0   rL   s     r   r6   zBlockingKeyMouseInput.__call__X  s(     1g.r   )r:   )r;   r<   r=   r>   r   r   r6   r|   r}   s   @r   r   r   H  s    O+
 
r   r   )r>   loggingnumbersr   
matplotlibr   matplotlib.backend_basesr   matplotlib.lineslinesrj   warn_deprecatedr;   	getLoggerr   r
   r@   r   r   r"   r   r   <module>r      sy   *    0 !   UH =w"B BJe eP7B/ 7BtM r   