o
    :Î®c*  ã                   @   s€   d dl mZ ddlmZmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZ d
dgZG dd
„ d
e
ƒZG dd„ de
ƒZdd„ ZdS )é    )Údedenté   )ÚQtCoreÚ	QtWidgetsé   )Úio)Úimg_as_ubyteé   )Ú
BaseWidget)ÚdialogsÚOKCancelButtonsÚSaveButtonsc                       s2   e Zd ZdZd	‡ fdd„	Zdd„ Zdd„ Z‡  ZS )
r   zœButtons that close the parent plugin.

    OK will replace the original image with the current (filtered) image.
    Cancel will just close the plugin.
    éP   c                    sº   d}t t| ƒ |¡ t d¡| _| jj | j¡ | j 	|¡ | j 
tjj¡ t d¡| _| jj | j¡ | j 	|¡ | j 
tjj¡ t | ¡| _| j ¡  | j | j¡ | j | j¡ d S )Nz	OK/CancelÚOKÚCancel)Úsuperr   Ú__init__r   ÚQPushButtonÚokÚclickedÚconnectÚupdate_original_imageÚsetMaximumWidthÚsetFocusPolicyr   ÚQtÚNoFocusÚcancelÚclose_pluginÚQHBoxLayoutÚlayoutÚ
addStretchÚ	addWidget)ÚselfÚbutton_widthÚname©Ú	__class__© úE/tmp/pip-target-vg8gfxp4/lib/python/skimage/viewer/widgets/history.pyr      s   
zOKCancelButtons.__init__c                 C   s"   | j jj}|| j j_| j  ¡  d S ©N)ÚpluginÚimage_viewerÚimageÚoriginal_imageÚclose)r"   r,   r'   r'   r(   r   '   s   

z%OKCancelButtons.update_original_imagec                 C   s   | j  ¡  d S r)   )r*   r.   )r"   r'   r'   r(   r   ,   s   zOKCancelButtons.close_plugin)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Ú__classcell__r'   r'   r%   r(   r      s
    c                       s4   e Zd ZdZd‡ fdd„	Zdd„ Zdd	d
„Z‡  ZS )r   z/Buttons to save image to io.stack or to a file.úSave to:Úpngc                    s¾   t t| ƒ |¡ || _t ¡ | _| j |¡ t d¡| _	| j	j
 | j¡ | j	 tjj¡ t d¡| _| jj
 | j¡ | j tjj¡ t | ¡| _| j | j¡ | j | j¡ | j | j	¡ d S )NÚFileÚStack)r   r   r   Údefault_formatr   ÚQLabelÚ
name_labelÚsetTextr   Ú	save_filer   r   Úsave_to_filer   r   r   r   Ú
save_stackÚsave_to_stackr   r   r!   )r"   r$   r8   r%   r'   r(   r   4   s   
zSaveButtons.__init__c                 C   s*   | j j ¡ }t |¡ tdƒ}t|ƒ d S )Nz¾            The image has been pushed to the io stack.
            Use io.pop() to retrieve the most recently pushed image.
            NOTE: The io stack only works in interactive sessions.)r*   Úfiltered_imageÚcopyr   Úpushr   Únotify)r"   r,   Úmsgr'   r'   r(   r?   H   s   
zSaveButtons.save_to_stackNc                 C   s>   |st  ¡ }|s
d S | jj}|jtkrt|ƒ}t ||¡ d S r)   )	r   Úsave_file_dialogr*   r@   ÚdtypeÚboolr   r   Úimsave)r"   Úfilenamer,   r'   r'   r(   r=   R   s   
zSaveButtons.save_to_file)r4   r5   r)   )r/   r0   r1   r2   r   r?   r=   r3   r'   r'   r%   r(   r   1   s
    
c                 C   sr   t  | ¡}t  ¡ }t  d|¡}|j |j¡ | d¡ t  |¡|_	|j	 
|dddd¡ |j	 
|dd¡ | ¡  d S )Nr   Tr   r	   r   )r   r9   ÚQDialogr   r   r   ÚacceptÚ
setDefaultÚQGridLayoutr   r!   Úexec_)rD   ÚmsglabelÚdialogr   r'   r'   r(   rC   ^   s   

rC   N)Útextwrapr   Úqtr   r   Ú r   Úutilr   Úcorer
   Úutilsr   Ú__all__r   r   rC   r'   r'   r'   r(   Ú<module>   s    #-