o
    :Î®c)  ã                   @   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__© úB/tmp/pip-target-vg8gfxp4/lib/python/skimage/viewer/widgets/core.pyr      s
   
zBaseWidget.__init__c                 C   s   d}t |ƒ‚)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r)t ¡ }| 	|¡ | 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   ó
   | j  ¡ S r   )r%   r&   ©r   r   r   r   r&   )   ó   
z	Text.textc                 C   ó   | j  |¡ d S r   )r%   r)   )r   Útext_strr   r   r   r&   -   ó   )Nr#   )r   r   r    r   r!   r&   Úsetterr"   r   r   r   r   r
      s    
r
   c                       sb   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 
| ¡| _n"|	dkrHt tj¡| _tjj}tjj}t | ¡| _nd}t||	 ƒ‚|dkrjd}t|| ƒ| | _| j d|¡ d| _n|d	kry| j ||¡ d
| _nd}t|| ƒ‚|| _|| _|| _|| _|
dkrš| jj | j¡ n|
dkr§| 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       @Úverticalr8   z%Unexpected value %s for 'orientation'r5   iè  é    z%2.2fÚintz%dz:Expected `value_type` to be 'float' or 'int'; received: %sÚmover9   z#Unexpected value %s for 'update_on')*r   r   r   r   ÚQSliderr   ÚVerticalÚsliderr   ÚAlignHCenterÚQVBoxLayoutr(   Ú
HorizontalÚ	AlignLeftÚ
AlignRightr'   Ú
ValueErrorr5   Ú_scaleÚsetRangeÚ	value_fmtÚ
value_typeÚ_lowÚ_highr   ÚvalueChangedÚconnectÚ_on_slider_changedÚsliderReleasedÚsetFocusPolicyÚStrongFocusr$   r+   r)   r   ÚsetAlignmentÚ	QLineEditÚeditboxÚsetMaximumWidthÚeditingFinishedÚ_on_editbox_changedr*   )r   r   ÚlowÚhighr   rJ   r   r   Úmax_edit_widthÚorientationÚ	update_onÚ
align_textÚalign_valuer   Ú
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   rU   r)   Ústrr   r   r   r   r   r   rO   “   s   zSlider._on_slider_changedc                 C   sv   z	t | j ¡ ƒ}W n ty   |  ¡  Y dS w | j|  kr$| jks+n |  ¡  dS || _|  ¡  |  	| j
|¡ dS )z#Validate input and set slider valueN)r5   rU   r&   rF   Ú_bad_editbox_inputrK   rL   r   Ú_good_editbox_inputr   r   r   r   r   r   rX   ™   s   þzSlider._on_editbox_changedc                 C   ó   | j  d¡ d S )Nz$background-color: rgb(255, 255, 255)©rU   ÚsetStyleSheetr-   r   r   r   rd   ¨   ó   zSlider._good_editbox_inputc                 C   re   )Nz$background-color: rgb(255, 200, 200)rf   r-   r   r   r   rc   «   rh   zSlider._bad_editbox_inputc                 C   s(   | j  ¡ }| jdkr|| j | j }|S ©Nr5   )r@   r   rJ   rG   rK   r   r   r   r   r   ®   s   

z
Slider.valc                 C   s.   | j dkr|| j | j }| j t|ƒ¡ d S ri   )rJ   rK   rG   r@   ÚsetValuer<   r   r   r   r   r   µ   s   
)	r3   r4   Nr5   r6   Nr7   r8   r9   )r   r   r    Ú__doc__r   rO   rX   rd   rc   r!   r   r2   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.
    r6   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   rS   r   r   rD   Ú	QComboBoxÚ
_combo_boxÚaddItemsÚlistr'   r(   r*   ÚcurrentIndexChangedrN   r   )r   r   Úitemsr   r   r   r   r   r   Ð   s   

zComboBox.__init__c                 C   r,   r   )rm   ÚcurrentTextr-   r   r   r   r   à   r.   zComboBox.valc                 C   r,   r   )rm   ÚcurrentIndexr-   r   r   r   Úindexä   r.   zComboBox.indexc                 C   r/   r   )rm   ÚsetCurrentIndex©r   Úir   r   r   rt   è   r1   )r6   N)
r   r   r    rk   r   r!   r   rt   r2   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Úcenterr6   Nc                    sÀ   t t| ƒ |||¡ t ¡ | _| j |¡ | j | j¡ t 	| ¡| _
|dkr/| j
 tjj¡ n |dkr<| j
 tjj¡ n|dkrI| j
 tjj¡ ntd| ƒ‚| j
 | j¡ | jj | j¡ d S )Nrx   ÚleftÚrightz#Unexpected value %s for 'alignment')r   r	   r   r   Ú	QCheckBoxÚ
_check_boxÚ
setCheckedr)   r   r'   r(   rS   r   r   ÚAlignCenterrD   rE   rF   r*   ÚstateChangedrN   r   )r   r   r   Ú	alignmentr   r   r   r   r   r     s   
zCheckBox.__init__c                 C   r,   r   )r|   Ú	isCheckedr-   r   r   r   r     r.   zCheckBox.valc                 C   r/   r   )r|   r}   rv   r   r   r   r     r1   )Frx   r6   N)	r   r   r    rk   r   r!   r   r2   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   ÚQPushButtonÚ_buttonÚclickedrN   r'   r(   r*   )r   r   r   r   r   r   r   -  s
   zButton.__init__)r   r   r    rk   r   r"   r   r   r   r   r   "  s    
r   N)Úqtr   r   r   Úutilsr   Ú__all__ÚQWidgetr   r
   r   r   r	   r   r   r   r   r   Ú<module>   s     15