B
    ¶‰\%  ã               @   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   s   d S )N© )Úargsr   r   ú>lib/python3.7/site-packages/skimage/viewer/canvastools/base.pyÚ_pass   s    r   c               @   sv   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   sT   || _ |j| _g | _d| _|d kr&tn|| _|d kr8tn|| _|d krJtn|| _d S )NT)ÚmanagerÚaxÚartistsÚactiver   Zcallback_on_moveÚcallback_on_enterZcallback_on_release)Úselfr	   Úon_moveZon_enterZ
on_releaseZuseblitr
   r   r   r   Ú__init__   s    zCanvasToolBase.__init__c             C   s   | j  S )z›Return 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   s   dS )NFr   )r   r   r   r   r   Úhit_test.   s    zCanvasToolBase.hit_testc             C   s   | j  ¡  d S )N)r	   Úredraw)r   r   r   r   r   1   s    zCanvasToolBase.redrawc             C   s   x| j D ]}| |¡ qW d S )N)r   Úset_visible)r   ÚvalÚartistr   r   r   r   4   s    zCanvasToolBase.set_visiblec             C   s.   |j dkr*|  | j¡ |  d¡ | j ¡  d S )NZenterF)Úkeyr   Úgeometryr   r	   r   )r   r   r   r   r   Úon_key_press8   s    

zCanvasToolBase.on_key_pressc             C   s   d S )Nr   )r   r   r   r   r   Úon_mouse_press>   s    zCanvasToolBase.on_mouse_pressc             C   s   d S )Nr   )r   r   r   r   r   Úon_mouse_releaseA   s    zCanvasToolBase.on_mouse_releasec             C   s   d S )Nr   )r   r   r   r   r   r   D   s    zCanvasToolBase.on_movec             C   s   d S )Nr   )r   r   r   r   r   Ú	on_scrollG   s    zCanvasToolBase.on_scrollc             C   s   | j  | ¡ d S )N)r	   Zremove_tool)r   r   r   r   ÚremoveJ   s    zCanvasToolBase.removec             C   s   dS )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 k	r*|ni ¡ tj||fddi|—Ž| _| j  | j¡ | j| _d S )	Né   ÚwZnoneg      à?F)ÚmarkerZ
markersizeZmfcZlsZalphaZvisibleZanimatedT)r
   ÚdictÚupdater   ZLine2DÚ_markersZadd_liner   )r   r
   ÚxÚyr'   Zmarker_propsZpropsr   r   r   r   a   s    

zToolHandles.__init__c             C   s
   | j  ¡ S )N)r*   Z	get_xdata)r   r   r   r   r+   k   s    zToolHandles.xc             C   s
   | j  ¡ S )N)r*   Z	get_ydata)r   r   r   r   r,   o   s    zToolHandles.yc             C   s*   |dk	r|}t  ||g¡}| j |¡ dS )z Set x and y positions of handlesN)ÚnpZarrayr*   Úset_data)r   Úptsr,   r+   r   r   r   r.   s   s    zToolHandles.set_datac             C   s   | j  |¡ d S )N)r*   r   )r   r   r   r   r   r   z   s    zToolHandles.set_visiblec             C   s   | j  |¡ d S )N)r*   Úset_animated)r   r   r   r   r   r0   }   s    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.é   é   )Zaxis)r-   Z	transposer+   r,   r
   Z	transDataZ	transformZsqrtÚsumZargminÚmin)r   r+   r,   r/   ZdiffZdistr   r   r   Úclosest€   s
    zToolHandles.closest)r$   N)N)r   r    r!   r"   r   r#   r+   r,   r.   r   r0   r5   r   r   r   r   r   S   s   


)	Znumpyr-   Z
matplotlibr   Ú__all__r   Úobjectr   r   r   r   r   r   Ú<module>   s
   H