a
    ¤Â=b)  ã                   @   sŽ   d dl mZmZmZ d dlmZ g d¢ZG dd„ dejƒZG dd„ deƒZ	G dd	„ d	eƒZ
G d
d„ deƒZG dd„ deƒZG dd„ deƒZdS )é   )Ú	QtWidgetsÚQtCoreÚQt)ÚRequiredAttr)Ú
BaseWidgetÚSliderÚComboBoxÚCheckBoxÚTextÚButtonc                       s:   e Zd ZedƒZd	‡ fdd„	Zedd„ ƒZdd„ Z‡  Z	S )
r   z#Widget is not attached to a Plugin.Nc                    s*   t t| ƒ ¡  || _|| _|| _d | _d S ©N)Úsuperr   Ú__init__ÚnameÚptypeÚcallbackÚplugin)Úselfr   r   r   ©Ú	__class__© ú:lib/python3.9/site-packages/skimage/viewer/widgets/core.pyr      s
    zBaseWidget.__init__c                 C   s   d}t |ƒ‚d S )Nz.Subclass of BaseWidget requires `val` property)ÚNotImplementedError)r   Úmsgr   r   r   Úval   s    zBaseWidget.valc                 C   s   |   | j|¡ d S r   )r   r   ©r   Úvaluer   r   r   Ú_value_changed   s    zBaseWidget._value_changed)NN)
Ú__name__Ú
__module__Ú__qualname__r   r   r   Úpropertyr   r   Ú__classcell__r   r   r   r   r      s
   
r   c                       s8   e Zd Zd‡ fdd„	Zedd„ ƒZejdd„ ƒZ‡  ZS )	r
   NÚ c                    sd   t t| ƒ |¡ t ¡ | _|| _t | ¡| _|d urRt ¡ }| 	|¡ | j 
|¡ | j 
| j¡ d S r   )r   r
   r   r   ÚQLabelÚ_labelÚtextÚQHBoxLayoutÚlayoutÚsetTextÚ	addWidget)r   r   r&   Ú
name_labelr   r   r   r      s    

zText.__init__c                 C   s
   | j  ¡ S r   )r%   r&   ©r   r   r   r   r&   )   s    z	Text.textc                 C   s   | j  |¡ d S r   )r%   r)   )r   Ztext_strr   r   r   r&   -   s    )Nr#   )r   r   r    r   r!   r&   Úsetterr"   r   r   r   r   r
      s
   
r
   c                	       s\   e Zd ZdZd‡ fd
d„	Zdd„ Zdd„ Zdd„ Zdd„ Ze	dd„ ƒZ
e
jdd„ ƒZ
‡  ZS )r   aL  Slider widget for adjusting numeric parameters.

    Parameters
    ----------
    name : str
        Name of slider parameter. If this parameter is passed as a keyword
        argument, it must match the name of that keyword argument (spaces are
        replaced with underscores). In addition, this name is displayed as the
        name of the slider.
    low, high : float
        Range of slider values.
    value : float
        Default slider value. If None, use midpoint between `low` and `high`.
    value_type : {'float' | 'int'}, optional
        Numeric type of slider value.
    ptype : {'kwarg' | 'arg' | 'plugin'}, optional
        Parameter type.
    callback : callable f(widget_name, value), optional
        Callback function called in response to slider changes.
        *Note:* This function is typically set (overridden) when the widget is
        added to a plugin.
    orientation : {'horizontal' | 'vertical'}, optional
        Slider orientation.
    update_on : {'release' | 'move'}, optional
        Control when callback function is called: on slider move or release.
    ç        ç      ð?NÚfloatÚkwargé<   Ú
horizontalÚreleasec                    s  t t| ƒ |||¡ |d u r(|| d }|	dkr\t tj¡| _tjj	}tjj	}t 
| ¡| _nD|	dkrt tj¡| _tjj}tjj}t | ¡| _nd}t||	 ƒ‚|dkrÔd}t|| ƒ| | _| j d|¡ d| _n.|d	krò| j ||¡ d
| _nd}t|| ƒ‚|| _|| _|| _|| _|
dkr6| jj | j¡ n(|
dkrR| jj | j¡ ntd|
 ƒ‚| j tjj¡ t ¡ | _ | j  !| j"¡ | j  #|¡ t $¡ | _%| j% &|¡ | j% !| j| j ¡ | j% #|¡ | j%j' | j(¡ | j )| j ¡ | j )| j¡ | j )| j%¡ d S )Ng       @Zverticalr3   z%Unexpected value %s for 'orientation'r0   iè  é    z%2.2fÚintz%dz:Expected `value_type` to be 'float' or 'int'; received: %sZmover4   z#Unexpected value %s for 'update_on')*r   r   r   r   ZQSliderr   ZVerticalÚsliderr   ZAlignHCenterZQVBoxLayoutr(   Z
HorizontalÚ	AlignLeftÚ
AlignRightr'   Ú
ValueErrorr0   Ú_scaleZsetRangeZ	value_fmtÚ
value_typeÚ_lowÚ_highr   ZvalueChangedÚconnectÚ_on_slider_changedZsliderReleasedZsetFocusPolicyZStrongFocusr$   r+   r)   r   ÚsetAlignmentZ	QLineEditÚeditboxZsetMaximumWidthZeditingFinishedÚ_on_editbox_changedr*   )r   r   ZlowZhighr   r<   r   r   Zmax_edit_widthZorientationZ	update_onZ
align_textZalign_valuer   Z
slider_maxr   r   r   r   N   s\    



zSlider.__init__c                 C   s0   | j }| j t|ƒdd… ¡ |  | j|¡ dS )zACall callback function with slider's name and value as parametersNé   )r   rB   r)   Ústrr   r   r   r   r   r   r@   “   s    zSlider._on_slider_changedc                 C   sv   zt | j ¡ ƒ}W n ty.   |  ¡  Y dS 0 | j|  krH| jksVn |  ¡  dS || _|  ¡  |  	| j
|¡ dS )z#Validate input and set slider valueN)r0   rB   r&   r:   Ú_bad_editbox_inputr=   r>   r   Ú_good_editbox_inputr   r   r   r   r   r   rC   ™   s    zSlider._on_editbox_changedc                 C   s   | j  d¡ d S )Nz$background-color: rgb(255, 255, 255)©rB   ZsetStyleSheetr,   r   r   r   rG   ¨   s    zSlider._good_editbox_inputc                 C   s   | j  d¡ d S )Nz$background-color: rgb(255, 200, 200)rH   r,   r   r   r   rF   «   s    zSlider._bad_editbox_inputc                 C   s(   | j  ¡ }| jdkr$|| j | j }|S ©Nr0   )r7   r   r<   r;   r=   r   r   r   r   r   ®   s    

z
Slider.valc                 C   s.   | j dkr|| j | j }| j t|ƒ¡ d S rI   )r<   r=   r;   r7   ZsetValuer6   r   r   r   r   r   µ   s    
)	r.   r/   Nr0   r1   Nr2   r3   r4   )r   r   r    Ú__doc__r   r@   rC   rG   rF   r!   r   r-   r"   r   r   r   r   r   2   s      þE
r   c                       sH   e Zd ZdZd‡ fdd„	Zedd„ ƒZedd	„ ƒZejd
d	„ ƒZ‡  Z	S )r   aÙ  ComboBox widget for selecting among a list of choices.

    Parameters
    ----------
    name : str
        Name of ComboBox parameter. If this parameter is passed as a keyword
        argument, it must match the name of that keyword argument (spaces are
        replaced with underscores). In addition, this name is displayed as the
        name of the ComboBox.
    items: list of str
        Allowed parameter values.
    ptype : {'arg' | 'kwarg' | 'plugin'}, optional
        Parameter type.
    callback : callable f(widget_name, value), optional
        Callback function called in response to combobox changes.
        *Note:* This function is typically set (overridden) when the widget is
        added to a plugin.
    r1   Nc                    s’   t t| ƒ |||¡ t ¡ | _| j | j¡ | j t	j
j¡ t ¡ | _| j t|ƒ¡ t | ¡| _| j | j¡ | j | j¡ | jj | j¡ d S r   )r   r   r   r   r$   r+   r)   r   rA   r   r   r8   Z	QComboBoxÚ
_combo_boxZaddItemsÚlistr'   r(   r*   ZcurrentIndexChangedr?   r   )r   r   Úitemsr   r   r   r   r   r   Ð   s    

zComboBox.__init__c                 C   s
   | j  ¡ S r   )rK   ZcurrentTextr,   r   r   r   r   à   s    zComboBox.valc                 C   s
   | j  ¡ S r   )rK   ZcurrentIndexr,   r   r   r   Úindexä   s    zComboBox.indexc                 C   s   | j  |¡ d S r   )rK   ZsetCurrentIndex©r   Úir   r   r   rN   è   s    )r1   N)
r   r   r    rJ   r   r!   r   rN   r-   r"   r   r   r   r   r   ¼   s   

r   c                       s<   e Zd ZdZd‡ fdd„	Zedd	„ ƒZejd
d	„ ƒZ‡  ZS )r	   a  CheckBox widget

    Parameters
    ----------
    name : str
        Name of CheckBox parameter. If this parameter is passed as a keyword
        argument, it must match the name of that keyword argument (spaces are
        replaced with underscores). In addition, this name is displayed as the
        name of the CheckBox.
    value: {False, True}, optional
        Initial state of the CheckBox.
    alignment: {'center','left','right'}, optional
        Checkbox alignment
    ptype : {'arg' | 'kwarg' | 'plugin'}, optional
        Parameter type
    callback : callable f(widget_name, value), optional
        Callback function called in response to checkbox changes.
        *Note:* This function is typically set (overridden) when the widget is
        added to a plugin.
    FÚcenterr1   Nc                    sÀ   t t| ƒ |||¡ t ¡ | _| j |¡ | j | j¡ t 	| ¡| _
|dkr^| j
 tjj¡ n@|dkrx| j
 tjj¡ n&|dkr’| j
 tjj¡ ntd| ƒ‚| j
 | j¡ | jj | j¡ d S )NrQ   ÚleftÚrightz#Unexpected value %s for 'alignment')r   r	   r   r   Z	QCheckBoxÚ
_check_boxÚ
setCheckedr)   r   r'   r(   rA   r   r   ZAlignCenterr8   r9   r:   r*   ZstateChangedr?   r   )r   r   r   Z	alignmentr   r   r   r   r   r     s    
zCheckBox.__init__c                 C   s
   | j  ¡ S r   )rT   Z	isCheckedr,   r   r   r   r     s    zCheckBox.valc                 C   s   | j  |¡ d S r   )rT   rU   rO   r   r   r   r     s    )FrQ   r1   N)	r   r   r    rJ   r   r!   r   r-   r"   r   r   r   r   r	   í   s     ÿ
r	   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )r   z¿Button which calls callback upon click.

    Parameters
    ----------
    name : str
        Name of button.
    callback : callable f()
        Function to call when button is clicked.
    c                    sH   t t| ƒ | ¡ t |¡| _| jj |¡ t | ¡| _	| j	 
| j¡ d S r   )r   r   r   r   ZQPushButtonZ_buttonZclickedr?   r'   r(   r*   )r   r   r   r   r   r   r   -  s
    zButton.__init__)r   r   r    rJ   r   r"   r   r   r   r   r   "  s   
r   N)Zqtr   r   r   Zutilsr   Ú__all__ZQWidgetr   r
   r   r   r	   r   r   r   r   r   Ú<module>   s    15