o
    :ήc%                     @   sH   d dl Zd dlmZ ddgZdd ZG dd deZG dd deZdS )	    N)linesCanvasToolBaseToolHandlesc                  G      d S N )argsr   r   F/tmp/pip-target-vg8gfxp4/lib/python/skimage/viewer/canvastools/base.py_pass      r
   c                   @   sz   e Zd ZdZ		d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 Zdd Zdd Zedd ZdS )r   a  Base canvas tool for matplotlib axes.

    Parameters
    ----------
    manager : Viewer or PlotPlugin.
        Skimage viewer or plot plugin object.
    on_move : function
        Function called whenever a control handle is moved.
        This function must accept the end points of line as the only argument.
    on_release : function
        Function called whenever the control handle is released.
    on_enter : function
        Function called whenever the "enter" key is pressed.
    NTc                 C   sZ   || _ |j| _g | _d| _|d u rtn|| _|d u rtn|| _|d u r(t| _d S || _d S )NT)manageraxartistsactiver
   callback_on_movecallback_on_entercallback_on_release)selfr   on_moveon_enter
on_releaseuseblitr   r   r   r	   __init__   s   zCanvasToolBase.__init__c                 C   s   | j  S )zReturn True if event should be ignored.

        This method (or a version of it) should be called at the beginning
        of any event callback.
        )r   r   eventr   r   r	   ignore&   s   zCanvasToolBase.ignorec                 C      dS )NFr   r   r   r   r	   hit_test.   r   zCanvasToolBase.hit_testc                 C   s   | j   d S r   )r   redrawr   r   r   r	   r   1   s   zCanvasToolBase.redrawc                 C   s   | j D ]}|| qd S r   )r   set_visible)r   valartistr   r   r	   r    4   s   
zCanvasToolBase.set_visiblec                 C   s2   |j dkr| | j | d | j  d S d S )NenterF)keyr   geometryr    r   r   r   r   r   r	   on_key_press8   s
   

zCanvasToolBase.on_key_pressc                 C   r   r   r   r   r   r   r	   on_mouse_press>   r   zCanvasToolBase.on_mouse_pressc                 C   r   r   r   r   r   r   r	   on_mouse_releaseA   r   zCanvasToolBase.on_mouse_releasec                 C   r   r   r   r   r   r   r	   r   D   r   zCanvasToolBase.on_movec                 C   r   r   r   r   r   r   r	   	on_scrollG   r   zCanvasToolBase.on_scrollc                 C   s   | j |  d S r   )r   remove_toolr   r   r   r	   removeJ      zCanvasToolBase.removec                 C   r   )z<Geometry information that gets passed to callback functions.Nr   r   r   r   r	   r%   M   s   zCanvasToolBase.geometry)NNNTN)__name__
__module____qualname____doc__r   r   r   r   r    r&   r'   r(   r   r)   r+   propertyr%   r   r   r   r	   r      s"    
c                   @   sT   e Zd ZdZdddZedd Zedd	 Zdd
dZdd Z	dd Z
dd ZdS )r   a  Control handles for canvas tools.

    Parameters
    ----------
    ax : :class:`matplotlib.axes.Axes`
        Matplotlib axes where tool handles are displayed.
    x, y : 1D arrays
        Coordinates of control handles.
    marker : str
        Shape of marker used to display handle. See `matplotlib.pyplot.plot`.
    marker_props : dict
        Additional marker properties. See :class:`matplotlib.lines.Line2D`.
    oNc                 C   sd   || _ t|dddddd}||d ur|ni  tj||fddi|| _| j | j | j| _d S )	N   wnoneg      ?F)marker
markersizemfclsalphavisibleanimatedT)r   dictupdater   Line2D_markersadd_liner"   )r   r   xyr6   marker_propspropsr   r   r	   r   a   s   
zToolHandles.__init__c                 C   
   | j  S r   )r@   	get_xdatar   r   r   r	   rB   k      
zToolHandles.xc                 C   rF   r   )r@   	get_ydatar   r   r   r	   rC   o   rH   zToolHandles.yc                 C   s*   |dur|}t ||g}| j| dS )z Set x and y positions of handlesN)nparrayr@   set_data)r   ptsrC   rB   r   r   r	   rL   s   s   zToolHandles.set_datac                 C      | j | d S r   )r@   r    r   r!   r   r   r	   r    z   r,   zToolHandles.set_visiblec                 C   rN   r   )r@   set_animatedrO   r   r   r	   rP   }   r,   zToolHandles.set_animatedc                 C   sX   t | j| jf}| jj|}|||f }t t j|d dd}t 	|t 
|fS )z1Return index and pixel distance to closest index.      )axis)rJ   	transposerB   rC   r   	transData	transformsqrtsumargminmin)r   rB   rC   rM   diffdistr   r   r	   closest   s
   zToolHandles.closest)r2   Nr   )r-   r.   r/   r0   r   r1   rB   rC   rL   r    rP   r]   r   r   r   r	   r   S   s    




)	numpyrJ   
matplotlibr   __all__r
   objectr   r   r   r   r   r	   <module>   s    H