U
    \	¸a°	  ã                   @   s<   d Z ddlmZ ddlmZ dd„ Zddd„Zdd	d
„ZdS )z¢
========================
Widget testing utilities
========================
Functions that are useful for testing widgets.
See also matplotlib.tests.test_widgets
é    N)Úmockc                  C   s>   t  dd¡\} }| ddgddg¡ | d¡ |jj ¡  |S )z!Creates plot and returns its axesé   r   éÈ   g      ð?)ÚpltZsubplotsZplotZ
set_aspectÚfigureÚcanvasZdraw)ZfigÚax© r	   ú>/tmp/pip-unpacked-wheel-wjyw_3jo/matplotlib/testing/widgets.pyÚget_ax   s
    
r   r   c                 C   sl   t  ¡ }||_| j ||f||fg¡d \|_|_|| |_|_| |_	| j
j|_||_||_d|_d|_|S )a  
    Create a mock event that can stand in for `.Event` and its subclasses.

    This event is intended to be used in tests where it can be passed into
    event handling functions.

    Parameters
    ----------
    ax : `matplotlib.axes.Axes`
        The axes the event will be in.
    xdata : int
        x coord of mouse in data coords.
    ydata : int
        y coord of mouse in data coords.
    button : None or `MouseButton` or {'up', 'down'}
        The mouse button pressed in this event (see also `.MouseEvent`).
    key : None or str
        The key pressed when the mouse event triggered (see also `.KeyEvent`).
    step : int
        Number of scroll steps (positive for 'up', negative for 'down').

    Returns
    -------
    event
        A `.Event`\-like Mock instance.
    r   NZCustom)r   ZMockÚbuttonZ	transDataZ	transformÚxÚyÚxdataÚydataZinaxesr   r   ÚkeyÚstepZguiEventÚname)r   r   r   r   r   r   Úeventr	   r	   r
   Ú
mock_event   s    ÿÿ
r   c           	      C   s*   t | j|||||ƒ}t| |ƒ}||ƒ dS )aW  
    Trigger an event on the given tool.

    Parameters
    ----------
    tool : matplotlib.widgets.RectangleSelector
    etype : str
        The event to trigger.
    xdata : int
        x coord of mouse in data coords.
    ydata : int
        y coord of mouse in data coords.
    button : None or `MouseButton` or {'up', 'down'}
        The mouse button pressed in this event (see also `.MouseEvent`).
    key : None or str
        The key pressed when the mouse event triggered (see also `.KeyEvent`).
    step : int
        Number of scroll steps (positive for 'up', negative for 'down').
    N)r   r   Úgetattr)	ZtoolÚetyper   r   r   r   r   r   Úfuncr	   r	   r
   Údo_event>   s    
r   )r   r   r   Nr   )r   r   r   Nr   )	Ú__doc__Zmatplotlib.pyplotZpyplotr   Zunittestr   r   r   r   r	   r	   r	   r
   Ú<module>   s
   	
)