B
    p[&6                 @   sT  d Z ddlmZmZmZmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZmZ ddlmZ ddlmZmZ ddlmZ dd	lmZmZ G d
d deeeZG dd deZG dd deZeG dd deZeG dd deZeG dd deZeG dd deZ eG dd deZ!G dd deZ"G dd de"Z#eG dd de#Z$d S )!z<Float class.

Represents an unbounded float using a widget.
    )	InstanceUnicodeCFloatBoolCaselessStrEnumTuple
TraitErrorvalidatedefault   )DescriptionWidget)InstanceDictNumberFormat)ValueWidget)registerwidget_serialization)
CoreWidget)ProgressStyleSliderStylec                   s2   e Zd ZedddjddZd	 fdd	Z  ZS )
_Floatg        zFloat value)helpT)syncNc                s&   |d k	r||d< t t| jf | d S )Nvalue)superr   __init__)selfr   kwargs)	__class__ >lib/python3.7/site-packages/ipywidgets/widgets/widget_float.pyr      s    z_Float.__init__)N)__name__
__module____qualname__r   tagr   r   __classcell__r   r   )r   r   r      s   r   c               @   sd   e Zd ZedddjddZedddjddZedd	d
 Zeddd Z	eddd Z
dS )_BoundedFloatg      Y@z	Max value)r   T)r   g        z	Min valuer   c             C   s4   |d }| j |ks| j|k r0t t|| j | j}|S )zCap and floor valuer   )minmax)r   proposalr   r   r   r   _validate_value!   s    z_BoundedFloat._validate_valuer&   c             C   s.   |d }|| j krtd|| jkr*|| _|S )zEnforce min <= value <= maxr   zSetting min > max)r'   r   r   )r   r(   r&   r   r   r   _validate_min)   s    

z_BoundedFloat._validate_minr'   c             C   s.   |d }|| j k rtd|| jk r*|| _|S )zEnforce min <= value <= maxr   zsetting max < min)r&   r   r   )r   r(   r'   r   r   r   _validate_max3   s    

z_BoundedFloat._validate_maxN)r    r!   r"   r   r#   r'   r&   r	   r)   r*   r+   r   r   r   r   r%      s
   
r%   c               @   s   e Zd ZedddjddZedddjddZedd	djddZed
ddjddZe	ddd Z
e	ddd Ze	ddd ZdS )_BoundedLogFloatg      @zMax value for the exponent)r   T)r   g        zMin value for the exponentg      $@zBase of valueg      ?zFloat valuer   c             C   sL   |d }| j | j |ks(| j | j |k rHtt|| j | j | j | j }|S )zCap and floor valuer   )baser&   r'   )r   r(   r   r   r   r   r)   C   s      z _BoundedLogFloat._validate_valuer&   c             C   s:   |d }|| j krtd| j| | jkr6| j| | _|S )z+Enforce base ** min <= value <= base ** maxr   zSetting min > max)r'   r   r-   r   )r   r(   r&   r   r   r   r*   K   s    
z_BoundedLogFloat._validate_minr'   c             C   s:   |d }|| j k rtd| j| | jk r6| j| | _|S )z+Enforce base ** min <= value <= base ** maxr   zsetting max < min)r&   r   r-   r   )r   r(   r'   r   r   r   r+   U   s    
z_BoundedLogFloat._validate_maxN)r    r!   r"   r   r#   r'   r&   r-   r   r	   r)   r*   r+   r   r   r   r   r,   =   s   
r,   c               @   sn   e Zd ZdZedjddZedjddZedddjddZ	edd	djddZ
ed
dddjddZd
S )	FloatTextaj   Displays a float value within a textbox. For a textbox in
    which the value must be within a specific range, use BoundedFloatText.

    Parameters
    ----------
    value : float
        value displayed
    step : float
        step of the increment (if None, any step is allowed)
    description : str
        description displayed next to the text box
    FloatTextViewT)r   ZFloatTextModelFzEnable or disable user changes)r   zlUpdate the value as the user types. If False, update on submission, e.g., pressing Enter or navigating away.Nz#Minimum step to increment the value)
allow_noner   )r    r!   r"   __doc__r   r#   
_view_name_model_namer   disabledcontinuous_updater   stepr   r   r   r   r.   `   s   r.   c               @   sn   e Zd ZdZedjddZedjddZedddjddZ	edd	djddZ
ed
dddjddZd
S )BoundedFloatTexta8   Displays a float value within a textbox. Value must be within the range specified.

    For a textbox in which the value doesn't need to be within a specific range, use FloatText.

    Parameters
    ----------
    value : float
        value displayed
    min : float
        minimal value of the range of possible values displayed
    max : float
        maximal value of the range of possible values displayed
    step : float
        step of the increment (if None, any step is allowed)
    description : str
        description displayed next to the textbox
    r/   T)r   ZBoundedFloatTextModelFzEnable or disable user changes)r   zlUpdate the value as the user types. If False, update on submission, e.g., pressing Enter or navigating away.Nz#Minimum step to increment the value)r0   r   )r    r!   r"   r1   r   r#   r2   r3   r   r4   r5   r   r6   r   r   r   r   r7   u   s   r7   c               @   s   e Zd ZdZedjddZedjddZedddjddZ	e
d	d
gd	ddjddZedddjddZedddjddZedddjddZedddjddZeejf ddieZdS )FloatSlidera   Slider/trackbar of floating values with the specified range.

    Parameters
    ----------
    value : float
        position of the slider
    min : float
        minimal position of the slider
    max : float
        maximal position of the slider
    step : float
        step of the trackbar
    description : str
        name of the slider
    orientation : {'horizontal', 'vertical'}
        default is 'horizontal', orientation of the slider
    readout : {True, False}
        default is True, display the current value of the slider next to it
    readout_format : str
        default is '.2f', specifier for the format function used to represent
        slider value for human consumption, modeled after Python 3's format
        specification mini-language (PEP 3101).
    ZFloatSliderViewT)r   ZFloatSliderModelg?z#Minimum step to increment the value)r   
horizontalverticalzVertical or horizontal.)valuesdefault_valuer   z3Display the current value of the slider next to it.z.2fzFormat for the readoutzAUpdate the value of the widget as the user is holding the slider.FzEnable or disable user changesr   N)r    r!   r"   r1   r   r#   r2   r3   r   r6   r   orientationr   readoutr   readout_formatr5   r4   r   r   r   styler   r   r   r   r8      s   r8   c               @   s   e Zd ZdZedjddZedjddZedddjddZ	e
d	d
gd	ddjddZedddjddZedddjddZedddjddZedddjddZedddjddZeejf ddieZdS )FloatLogSlidera   Slider/trackbar of logarithmic floating values with the specified range.

    Parameters
    ----------
    value : float
        position of the slider
    base : float
        base of the logarithmic scale. Default is 10
    min : float
        minimal position of the slider in log scale, i.e., actual minimum is base ** min
    max : float
        maximal position of the slider in log scale, i.e., actual maximum is base ** max
    step : float
        step of the trackbar, denotes steps for the exponent, not the actual value
    description : str
        name of the slider
    orientation : {'horizontal', 'vertical'}
        default is 'horizontal', orientation of the slider
    readout : {True, False}
        default is True, display the current value of the slider next to it
    readout_format : str
        default is '.3g', specifier for the format function used to represent
        slider value for human consumption, modeled after Python 3's format
        specification mini-language (PEP 3101).
    ZFloatLogSliderViewT)r   ZFloatLogSliderModelg?z3Minimum step in the exponent to increment the value)r   r9   r:   zVertical or horizontal.)r;   r<   r   z3Display the current value of the slider next to it.z.3gzFormat for the readoutzAUpdate the value of the widget as the user is holding the slider.FzEnable or disable user changesg      $@zBase for the logarithmr   N)r    r!   r"   r1   r   r#   r2   r3   r   r6   r   r=   r   r>   r   r?   r5   r4   r-   r   r   r   r@   r   r   r   r   rA      s   rA   c               @   s   e Zd ZdZedjddZedjddZeddgddd	jddZ	ed
ddddgddddjddZ
eejf ddieZdS )FloatProgressad   Displays a progress bar.

    Parameters
    -----------
    value : float
        position within the range of the progress bar
    min : float
        minimal position of the slider
    max : float
        maximal position of the slider
    description : str
        name of the progress bar
    orientation : {'horizontal', 'vertical'}
        default is 'horizontal', orientation of the progress bar
    bar_style: {'success', 'info', 'warning', 'danger', ''}
        color of the progress bar, default is '' (blue)
        colors are: 'success'-green, 'info'-light blue, 'warning'-orange, 'danger'-red
    ZProgressViewT)r   ZFloatProgressModelr9   r:   zVertical or horizontal.)r;   r<   r   ZsuccessinfoZwarningZdanger z-Use a predefined styling for the progess bar.)r;   r<   r0   r   r   N)r    r!   r"   r1   r   r#   r2   r3   r   r=   Z	bar_styler   r   r   r@   r   r   r   r   rB      s   rB   c               @   sl   e Zd Zee e dddjddZedd Zej	dd Zed	d
 Z
e
j	dd
 Z
eddd ZdS )_FloatRange)g        g      ?zTuple of (lower, upper) bounds)r<   r   T)r   c             C   s
   | j d S )Nr   )r   )r   r   r   r   lower  s    z_FloatRange.lowerc             C   s   || j d f| _ d S )Nr   )r   )r   rF   r   r   r   rF     s    c             C   s
   | j d S )Nr   )r   )r   r   r   r   upper  s    z_FloatRange.upperc             C   s   | j d |f| _ d S )Nr   )r   )r   rG   r   r   r   rG     s    r   c             C   s$   |d \}}||k rt d||fS )Nr   zsetting lower > upper)r   )r   r(   rF   rG   r   r   r   r)     s    z_FloatRange._validate_valueN)r    r!   r"   r   r   r#   r   propertyrF   setterrG   r	   r)   r   r   r   r   rE      s   rE   c                   s~   e Zd ZedddjddZedddjddZedd	djddZ fd
dZe	dddd Z
e	d fddZ  ZS )_BoundedFloatRangeg      ?z<Minimum step that the value can take (ignored by some views))r   T)r   g      Y@z	Max valueg        z	Min valuec                s`   | dd| dd }}| dd sJd| d|  d| d|  f|d< tt| j|| d S )Nr&   g        r'   g      Y@r   g      ?g      ?)getr   rJ   r   )r   argsr   r&   r'   )r   r   r   r   !  s
    z_BoundedFloatRange.__init__r&   r'   c             C   s   |d }|d }|j dkr,|| jkr,td|j dkrH|| jk rHtd|j dkrtt|| jd t|| jd f| _|j dkrt|| jd t|| jd f| _|S )	Ntraitr   r&   zsetting min > maxr'   zsetting max < minr   r   )namer'   r   r&   r   )r   r(   rM   newr   r   r   _validate_bounds(  s    
"
"z#_BoundedFloatRange._validate_boundsr   c                sP   t t| |\}}t|| jt|| j }}t|| jt|| j }}||fS )N)r   rJ   r)   r&   r'   )r   r(   rF   rG   )r   r   r   r)   6  s    z"_BoundedFloatRange._validate_value)r    r!   r"   r   r#   r6   r'   r&   r   r	   rP   r)   r$   r   r   )r   r   rJ     s   rJ   c               @   s   e Zd ZdZedjddZedjddZedddjddZ	e
d	d
gd	ddjddZedddjddZedddjddZedddjddZedddjddZeejf ddieZdS )FloatRangeSlidera   Slider/trackbar that represents a pair of floats bounded by minimum and maximum value.

    Parameters
    ----------
    value : float tuple
        range of the slider displayed
    min : float
        minimal position of the slider
    max : float
        maximal position of the slider
    step : float
        step of the trackbar
    description : str
        name of the slider
    orientation : {'horizontal', 'vertical'}
        default is 'horizontal'
    readout : {True, False}
        default is True, display the current value of the slider next to it
    readout_format : str
        default is '.2f', specifier for the format function used to represent
        slider value for human consumption, modeled after Python 3's format
        specification mini-language (PEP 3101).
    ZFloatRangeSliderViewT)r   ZFloatRangeSliderModelg?z#Minimum step to increment the value)r   r9   r:   zVertical or horizontal.)r;   r<   r   z3Display the current value of the slider next to it.z.2fzFormat for the readoutzAUpdate the value of the widget as the user is sliding the slider.FzEnable or disable user changesr   N)r    r!   r"   r1   r   r#   r2   r3   r   r6   r   r=   r   r>   r   r?   r5   r4   r   r   r   r@   r   r   r   r   rQ   >  s   rQ   N)%r1   Z	traitletsr   r   r   r   r   r   r   r	   r
   Zwidget_descriptionr   Ztrait_typesr   r   Zvaluewidgetr   Zwidgetr   r   Zwidget_corer   Z
widget_intr   r   r   r%   r,   r.   r7   r8   rA   rB   rE   rJ   rQ   r   r   r   r   <module>   s0   ,	 #&) "