a
    ¤Â=b*  ã                   @   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ÚOKZCancel)Úsuperr   Ú__init__r   ÚQPushButtonÚokÚclickedÚconnectÚupdate_original_imageZsetMaximumWidthÚsetFocusPolicyr   ÚQtÚNoFocusZcancelÚclose_pluginÚQHBoxLayoutÚlayoutZ
addStretchÚ	addWidget)ÚselfZbutton_widthÚname©Ú	__class__© ú=lib/python3.9/site-packages/skimage/viewer/widgets/history.pyr      s    
zOKCancelButtons.__init__c                 C   s"   | j jj}|| j j_| j  ¡  d S ©N)ÚpluginZimage_viewerÚimageZ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 )NZFileZStack)r   r   r   Údefault_formatr   ÚQLabelZ
name_labelZsetTextr   Z	save_filer   r   Úsave_to_filer   r   r   r   Z
save_stackÚsave_to_stackr   r   r   )r   r   r/   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#   r2   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   Zsave_file_dialogr%   r3   ZdtypeÚboolr   r   Zimsave)r   Úfilenamer&   r"   r"   r#   r1   R   s    
zSaveButtons.save_to_file)r-   r.   )N)r(   r)   r*   r+   r   r2   r1   r,   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   r0   ZQDialogr   r   r   ZacceptZ
setDefaultZQGridLayoutr   r   Zexec_)r7   ZmsglabelZdialogr   r"   r"   r#   r6   ^   s    

r6   N)Útextwrapr   Zqtr   r   Ú r   Úutilr   Zcorer
   Zutilsr   Ú__all__r   r   r6   r"   r"   r"   r#   Ú<module>   s   #-