ó
 m[c           @` sº   d  Z  d d l m Z m Z m Z m Z d d l Z d d l j Z	 d d l
 Z
 e
 j e ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d S(   u0  
This provides several classes used for blocking interaction with figure
windows:

:class:`BlockingInput`
    creates a callable object to retrieve events in a blocking way for
    interactive sessions

:class:`BlockingKeyMouseInput`
    creates a callable object to retrieve key or mouse clicks in a blocking
    way for interactive sessions.
    Note: Subclass of BlockingInput. Used by waitforbuttonpress

:class:`BlockingMouseInput`
    creates a callable object to retrieve mouse clicks in a blocking way for
    interactive sessions.
    Note: Subclass of BlockingInput.  Used by ginput

:class:`BlockingContourLabeler`
    creates a callable object to retrieve mouse clicks in a blocking way that
    will then be used to place labels on a ContourSet
    Note: Subclass of BlockingMouseInput.  Used by clabel
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNt   BlockingInputc           B` sq   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d d „ Z d d „ Z	 e j e	 _ d	 d
 d „ Z
 RS(   uX   
    Class that creates a callable object to retrieve events in a
    blocking way.
    c         C` s   | |  _  | |  _ d  S(   N(   t   figt
   eventslist(   t   selfR   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyt   __init__)   s    	c         C` sn   |  j  | ƒ t j d t |  j ƒ ƒ |  j ƒ  t |  j ƒ |  j k rj |  j d k rj |  j j j	 ƒ  n  d S(   ue   
        Event handler that will be passed to the current figure to
        retrieve events.
        u   Event %ii    N(
   t	   add_eventt   _logt   infot   lent   eventst
   post_eventt   nR   t   canvast   stop_event_loop(   R   t   event(    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyt   on_event-   s
    
'c         C` s   d S(   u,   For baseclass, do nothing but collect eventsN(    (   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR   ?   s    c         C` s4   x$ |  j  D] } |  j j j | ƒ q
 Wg  |  _  d S(   u   Disconnect all callbacksN(   t	   callbacksR   R   t   mpl_disconnect(   R   t   cb(    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyt   cleanupC   s    c         C` s   |  j  j | ƒ d S(   u5   For base class, this just appends an event to events.N(   R   t   append(   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR	   J   s    iÿÿÿÿc         C` s   |  j  j | ƒ d S(   u'  
        This removes an event from the event list.  Defaults to
        removing last event, but an index can be supplied.  Note that
        this does not check that there are events, much like the
        normal pop method.  If not events exist, this will throw an
        exception.
        N(   R   t   pop(   R   t   index(    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyt	   pop_eventN   s    c         C` s   |  j  | ƒ d  S(   N(   R   (   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR   X   s    i   i   c         C` sÆ   t  | t ƒ s t d ƒ ‚ n  | |  _ g  |  _ g  |  _ t |  j j d ƒ r^ |  j j	 ƒ  n  x6 |  j
 D]+ } |  j j |  j j j | |  j ƒ ƒ qh Wz |  j j j d | ƒ Wd |  j ƒ  X|  j S(   u4   
        Blocking call to retrieve n events
        u   Requires an integer argumentu   managert   timeoutN(   t
   isinstancet   intt
   ValueErrorR   R   R   t   hasattrR   R   t   showR   R   t   mpl_connectR   t   start_event_loopR   (   R   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyt   __call__\   s    				 (    (   t   __name__t
   __module__t   __doc__R   R   R   R   R	   R   R   R$   (    (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR   $   s   				
t   BlockingMouseInputc           B` s§   e  Z d  Z d Z d Z d Z d d d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d d „ Z d d „ Z d d „ Z d d e d „ Z RS(   u;  
    Class that creates a callable object to retrieve mouse clicks in a
    blocking way.

    This class will also retrieve keyboard clicks and treat them like
    appropriate mouse clicks (delete and backspace are like mouse button 3,
    enter is like mouse button 2 and all others are like mouse button 1).
    i   i   i   c         C` s8   t  j |  d | d d ƒ| |  _ | |  _ | |  _ d  S(   NR   R   u   button_press_eventu   key_press_event(   u   button_press_eventu   key_press_event(   R   R   t
   button_addt
   button_popt   button_stop(   R   R   t	   mouse_addt	   mouse_popt
   mouse_stop(    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR   Š   s     		c         C` sV   t  |  j ƒ d k r% t j d ƒ n- |  j d j d k rH |  j ƒ  n
 |  j ƒ  d S(   u7   
        This will be called to process events
        i    u   No events yetiÿÿÿÿu   key_press_eventN(   R   R   R
   t   warningt   namet	   key_eventt   mouse_event(   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR   ’   s
    c         C` se   |  j  d } | j } | |  j k r5 |  j | ƒ n, | |  j k rT |  j | ƒ n |  j | ƒ d S(   u   Process a mouse click eventiÿÿÿÿN(   R   t   buttonR*   t   mouse_event_popR+   t   mouse_event_stopt   mouse_event_add(   R   R   R3   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR2      s    	c         C` sx   |  j  d } | j d k r  d S| j j ƒ  } | d k rK |  j | ƒ n) | d k rg |  j | ƒ n |  j | ƒ d S(	   uo   
        Process a key click event.  This maps certain keys to appropriate
        mouse click events.
        iÿÿÿÿNu	   backspaceu   deleteu   escapeu   enter(   u	   backspaceu   delete(   u   escapeu   enter(   R   t   keyt   Nonet   lowerR4   R5   R6   (   R   R   R7   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR1   ª   s    c         C` s-   | j  r |  j | ƒ n t j |  d ƒ d S(   u   
        Will be called for any event involving a button other than
        button 2 or 3.  This will add a click if it is inside axes.
        iÿÿÿÿN(   t   inaxest	   add_clickR   R   (   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR6   ¿   s    	c         C` s$   t  j |  d ƒ |  j j j ƒ  d S(   uh   
        Will be called for any event involving button 2.
        Button 2 ends blocking input.
        iÿÿÿÿN(   R   R   R   R   R   (   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR5   É   s    c         C` s<   t  j |  d ƒ t |  j ƒ d k r8 |  j | d ƒ n  d S(   uk   
        Will be called for any event involving button 3.
        Button 3 removes the last click.
        iÿÿÿÿi    N(   R   R   R   R   (   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR4   Ø   s    c         C` s¯   |  j  j | j | j f ƒ t j d t |  j  ƒ | j | j f ƒ |  j r« t j	 | j g | j g d d d d ƒ} | j
 j | ƒ |  j j | ƒ |  j j j ƒ  n  d S(   uL   
        This add the coordinates of an event to the list of clicks
        u   input %i: %f,%ft   markeru   +t   coloru   rN(   t   clicksR   t   xdatat   ydataR
   R   R   t   show_clickst   mlinest   Line2DR:   t   add_linet   marksR   R   t   draw(   R   R   t   line(    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR;   ä   s    	 	iÿÿÿÿc         C` sL   |  j  j | ƒ |  j rH |  j j | ƒ } | j ƒ  |  j j j ƒ  n  d S(   um   
        This removes a click from the list of clicks.  Defaults to
        removing the last click.
        N(   R>   R   RA   RE   t   removeR   R   RF   (   R   R   R   t   mark(    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyt	   pop_clickô   s
    	
c         C` s$   |  j  | | ƒ t j |  | ƒ d S(   u¤   
        This removes a click and the associated event from the object.
        Defaults to removing the last click, but any index can be
        supplied.
        N(   RJ   R   R   (   R   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR     s    c         C` sT   |  j  rC x |  j D] } | j ƒ  q Wg  |  _ |  j j j ƒ  n  t j |  ƒ d  S(   N(   RA   RE   RH   R   R   RF   R   R   (   R   R   RI   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR     s    		i   c         C` s;   | |  _  g  |  _ g  |  _ t j |  d | d | ƒ|  j S(   u\   
        Blocking call to retrieve n coordinate pairs through mouse
        clicks.
        R   R   (   RA   R>   RE   R   R$   (   R   R   R   RA   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR$     s
    			N(   R%   R&   R'   R)   R*   R+   R   R   R2   R1   R6   R5   R4   R;   RJ   R   R8   R   t   TrueR$   (    (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR(   |   s    				
				t   BlockingContourLabelerc           B` sP   e  Z d  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d d d d „ Z RS(	   uƒ   
    Class that creates a callable object that uses mouse clicks or key
    clicks on a figure window to place contour labels.
    c         C` s&   | |  _  t j |  d | j j ƒd  S(   NR   (   t   csR(   R   t   axt   figure(   R   RM   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR   -  s    	c         C` s   |  j  | ƒ d  S(   N(   t   button1(   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR;   1  s    iÿÿÿÿc         C` s   |  j  | ƒ d  S(   N(   t   button3(   R   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyRJ   4  s    c         C` sg   | j  |  j j k rV |  j j | j | j |  j d |  j d t ƒ|  j	 j
 j ƒ  n t j |  ƒ d S(   uŒ   
        This will be called if an event involving a button other than
        2 or 3 occcurs.  This will add a label to a contour.
        t   inline_spacingt	   transformN(   R:   RM   RN   t   add_label_neart   xt   yt   inlineRR   t   FalseR   R   RF   R   R   (   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyRP   7  s    	c         C` s3   |  j  r n# |  j j ƒ  |  j j j j j ƒ  d S(   uY  
        This will be called if button 3 is clicked.  This will 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.
        N(   RW   RM   t	   pop_labelRN   RO   R   RF   (   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyRQ   F  s    		i   c         C` s5   | |  _  | |  _ t j |  d | d | d t ƒd  S(   NR   R   RA   (   RW   RR   R(   R$   RX   (   R   RW   RR   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR$   U  s    		(	   R%   R&   R'   R   R;   RJ   RP   RQ   R$   (    (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyRL   (  s   				t   BlockingKeyMouseInputc           B` s,   e  Z d  Z d „  Z d „  Z d d „ Z RS(   u_   
    Class that creates a callable object to retrieve a single mouse or
    keyboard click
    c         C` s   t  j |  d | d d ƒd  S(   NR   R   u   button_press_eventu   key_press_event(   u   button_press_eventu   key_press_event(   R   R   (   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR   b  s    c         C` sB   t  |  j ƒ d k r% t j d ƒ n |  j d j d k |  _ d S(   u1   
        Determines if it is a key event
        i    u   No events yetiÿÿÿÿu   key_press_eventN(   R   R   R
   R/   R0   t
   keyormouse(   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR   f  s    i   c         C` s)   d |  _ t j |  d d d | ƒ|  j S(   u   
        Blocking call to retrieve a single mouse or key click
        Returns True if key click, False if mouse, or None if timeout
        R   i   R   N(   R8   R[   R   R$   (   R   R   (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyR$   o  s    	(   R%   R&   R'   R   R   R$   (    (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyRZ   ]  s   			(   R'   t
   __future__R    R   R   R   t   sixt   matplotlib.linest   linesRB   t   loggingt	   getLoggerR%   R
   t   objectR   R(   RL   RZ   (    (    (    s8   lib/python2.7/site-packages/matplotlib/blocking_input.pyt   <module>   s   "X¬5