B
    ¶‰\e	  ã               @   sV   d dl ZddlmZ ddlmZ ddlmZmZ ddl	m
Z
 dgZG d	d„ de
ƒZdS )
é    Né   )ÚQtGui)Únew_plot)ÚBlitManagerÚEventManageré   )ÚPluginÚ
PlotPluginc                   sZ   e Zd ZdZd‡ fdd„	Z‡ fdd„Zd	d
„ Zdd„ Z‡ fdd„Zdd„ Z	dd„ Z
‡  ZS )r	   zæPlugin for ImageViewer that contains a plot canvas.

    Base class for plugins that contain a Matplotlib plot canvas, which can,
    for example, display an image histogram.

    See base Plugin class for additional details.
    Né–   é  c                s@   t t| ƒjf |||dœ|—Ž || _|| _d | _g | _d | _d S )N)Úimage_filterÚheightÚwidth)Úsuperr	   Ú__init__Ú_heightÚ_widthÚ_blit_managerÚ_toolsÚ_event_manager)Úselfr   r   r   Úkwargs)Ú	__class__© ú@lib/python3.7/site-packages/skimage/viewer/plugins/plotplugin.pyr      s    zPlotPlugin.__init__c                s:   t t| ƒ |¡ |  ¡  |jr*t| jƒ| _t| jƒ| _	d S )N)
r   r	   ÚattachÚadd_plotZuseblitr   Úaxr   r   r   )r   Zimage_viewer)r   r   r   r      s
    zPlotPlugin.attachc             C   s   | j  ¡  dS )zRedraw plot.N)ÚcanvasZ	draw_idle)r   r   r   r   Úredraw'   s    zPlotPlugin.redrawc             C   sª   t ƒ \| _| _| j | jt| jjƒ ¡ | j | jt| jjƒ ¡ | jj	| _	t
 ¡ }| t
jj¡}| ¡  ¡ }t |¡r„t|d ƒ}| jj |¡ | j | j	| jd¡ d S )Ng     ào@r   )r   Zfigr   Zset_figwidthr   ÚfloatZdpiZset_figheightr   r   r   ZQPaletteZcolorZWindowZtoRgbÚvalueÚnpZisscalarÚstrZpatchZset_facecolorZlayoutZ	addWidgetÚrow)r   ZqpaletteZqcolorZbgcolorr   r   r   r   +   s    

zPlotPlugin.add_plotc                s   t t| ƒ |¡ |  ¡  d S )N)r   r	   Ú_update_original_imager   )r   Zimage)r   r   r   r%   :   s    z!PlotPlugin._update_original_imagec             C   s0   | j r| j  |j¡ | j |¡ | j |¡ d S )N)r   Zadd_artistsÚartistsr   Úappendr   r   )r   Útoolr   r   r   Úadd_tool>   s    zPlotPlugin.add_toolc             C   s>   || j krd S | jr"| j |j¡ | j  |¡ | j |¡ d S )N)r   r   Zremove_artistsr&   Úremover   Údetach)r   r(   r   r   r   Úremove_toolD   s    
zPlotPlugin.remove_tool)Nr
   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r%   r)   r,   Ú__classcell__r   r   )r   r   r	      s   
)Znumpyr"   Zqtr   Zutilsr   Zutils.canvasr   r   Úbaser   Ú__all__r	   r   r   r   r   Ú<module>   s   