o
    沪g
P                     @  sb  U d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
mZmZmZ d dlmZ d dlmZ d dlmZmZ d d	lmZmZ d d
lmZmZmZmZmZ d dlmZm Z m!Z!m"Z"m#Z# d dl$m%Z& d dl'm(Z( d dl)m*Z*m+Z+ d dl,m-Z-m.Z.m/Z/m0Z0m1Z1 erd dl2m3Z3 ee4e5f Z6de7d< e
de4dZ8e
de5dZ9eG dd dZ:G dd dZ;dS )    )annotationsN)	dataclass)dedent)TYPE_CHECKINGLiteralTypeVarUnioncastoverload)	TypeAlias)current_form_id)JSNumberJSNumberBoundsException)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valueto_key)!StreamlitInvalidNumberFormatErrorStreamlitJSNumberBoundsErrorStreamlitMixedNumericTypesErrorStreamlitValueAboveMaxErrorStreamlitValueBelowMinError)NumberInput)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsget_session_stateregister_widget)DeltaGeneratorr   Number	IntOrNoneFloatOrNonec                   @  s6   e Zd ZU ded< ded< dddZ		ddddZdS )NumberInputSerdeNumber | Nonevalueint	data_typevreturnc                 C  s   |S N )selfr-   r0   r0   c/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/elements/widgets/number_input.py	serializeE   s   zNumberInputSerde.serialize ui_value	widget_idstrc                 C  s2   |d ur|n| j }|d ur| jtjkrt|}|S r/   )r*   r,   NumberInputProtoINTr+   )r1   r5   r6   valr0   r0   r2   deserializeH   s   zNumberInputSerde.deserializeN)r-   r)   r.   r)   )r4   )r5   r)   r6   r7   r.   r)   )__name__
__module____qualname____annotations__r3   r;   r0   r0   r0   r2   r(   @   s   
 
r(   c                   @  sB  e Zd Ze				d9ddddd:d!d"Ze	d;dddddddddddd#d<d$d"Ze		d=ddddddddddd%
d>d&d"Ze			d?dddddddddd'	d@d(d"Ze					dAdddddBd,d"Zed-										dAdddddCd0d"Z										dAddddd1dDd4d5ZedEd7d8ZdS )FNumberInputMixinNminFvisible)placeholderdisabledlabel_visibilitylabelr7   	min_valuer+   	max_value
int | Noner*   IntOrNone | Literal['min']stepformat
str | Nonekey
Key | Nonehelp	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | NonerC   rD   boolrE   r   r.   int | IntOrNonec                C     d S r/   r0   r1   rF   rG   rH   r*   rK   rL   rN   rP   rQ   rS   rU   rC   rD   rE   r0   r0   r2   number_input\      
zNumberInputMixin.number_input)r*   rK   rL   rN   rP   rQ   rS   rU   rC   rD   rE   c                C  rY   r/   r0   rZ   r0   r0   r2   r[   l      )
rK   rL   rN   rP   rQ   rS   rU   rC   rD   rE   c                C  rY   r/   r0   rZ   r0   r0   r2   r[   {   r]   )	rL   rN   rP   rQ   rS   rU   rC   rD   rE   c       
         C  rY   r/   r0   rZ   r0   r0   r2   r[      r]   float | NoneFloatOrNone | Literal['min']float | FloatOrNonec                C  rY   r/   r0   rZ   r0   r0   r2   r[      r\   r[   r)   Number | Literal['min'] | Nonec                C  s.   t  }| j|||||||||	|
|||||dS )a  Display a numeric input widget.

        .. note::
            Integer values exceeding +/- ``(1<<53) - 1`` cannot be accurately
            stored or returned by the widget due to serialization contstraints
            between the Python server and JavaScript client. You must handle
            such numbers as floats, leading to a loss in precision.

        Parameters
        ----------
        label : str
            A short label explaining to the user what this input is for.
            The label can optionally contain GitHub-flavored Markdown of the
            following types: Bold, Italics, Strikethroughs, Inline Code, Links,
            and Images. Images display like icons, with a max height equal to
            the font height.

            Unsupported Markdown elements are unwrapped so only their children
            (text contents) render. Display unsupported elements as literal
            characters by backslash-escaping them. E.g.,
            ``"1\. Not an ordered list"``.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives.

            For accessibility reasons, you should never set an empty label, but
            you can hide it with ``label_visibility`` if needed. In the future,
            we may disallow empty labels by raising an exception.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        min_value : int, float, or None
            The minimum permitted value.
            If None, there will be no minimum.

        max_value : int, float, or None
            The maximum permitted value.
            If None, there will be no maximum.

        value : int, float, "min" or None
            The value of this widget when it first renders. If ``None``, will initialize
            empty and return ``None`` until the user provides input.
            If "min" (default), will initialize with min_value, or 0.0 if
            min_value is None.

        step : int, float, or None
            The stepping interval.
            Defaults to 1 if the value is an int, 0.01 otherwise.
            If the value is not specified, the format parameter will be used.

        format : str or None
            A printf-style format string controlling how the interface should
            display numbers. The output must be purely numeric. This does not
            impact the return value of the widget. Formatting is handled by
            `sprintf.js <https://github.com/alexei/sprintf.js>`_.

            For example, ``format="%0.1f"`` adjusts the displayed decimal
            precision to only show one digit after the decimal.

        key : str or int
            An optional string or integer to use as the unique key for the widget.
            If this is omitted, a key will be generated for the widget
            based on its content. No two widgets may have the same key.

        help : str or None
            A tooltip that gets displayed next to the widget label. Streamlit
            only displays the tooltip when ``label_visibility="visible"``. If
            this is ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        on_change : callable
            An optional callback invoked when this number_input's value changes.

        args : tuple
            An optional tuple of args to pass to the callback.

        kwargs : dict
            An optional dict of kwargs to pass to the callback.

        placeholder : str or None
            An optional string displayed when the number input is empty.
            If None, no placeholder is displayed.

        disabled : bool
            An optional boolean that disables the number input if set to
            ``True``. The default is ``False``.

        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. The default is ``"visible"``. If this
            is ``"hidden"``, Streamlit displays an empty spacer instead of the
            label, which can help keep the widget alligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        Returns
        -------
        int or float or None
            The current value of the numeric input widget or ``None`` if the widget
            is empty. The return type will match the data type of the value parameter.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> number = st.number_input("Insert a number")
        >>> st.write("The current number is ", number)

        .. output::
           https://doc-number-input.streamlit.app/
           height: 260px

        To initialize an empty number input, use ``None`` as the value:

        >>> import streamlit as st
        >>>
        >>> number = st.number_input(
        ...     "Insert a number", value=None, placeholder="Type a number..."
        ... )
        >>> st.write("The current number is ", number)

        .. output::
           https://doc-number-input-empty.streamlit.app/
           height: 260px

        )rF   rG   rH   r*   rK   rL   rN   rP   rQ   rS   rU   rC   rD   rE   ctx)r   _number_input)r1   rF   rG   rH   r*   rK   rL   rN   rP   rQ   rS   rU   rC   rD   rE   rb   r0   r0   r2   r[      s&    )rC   rD   rE   rb   rb   ScriptRunContext | Nonec                C  sV  t |}t| j||	|dkr|nd d t|| td|t| j||||||||d u r,d nt|d}||||g}tdd |D }tdd |D }|sV|sVt||||dt	 j
}|d urj||v rj|| d u rjd }|dkr|d uru|}n|r||r|d	}n|rd
}nd	}t|tj}t|t}|d u r|r|sd}nd}|d u r|rdnd}|dv r|rd
d l}|d| d n|d dkr|rd
d l}|d| d |d u r|rdnd}zt|d  W n ttfy   t|w |o|}|d ur|d ur||krt||d|d ur|d ur||k rt||dzf|rU|d ur-tt|d |d ur:tt|d |d urGtt|d |d urTtt|d n,|d ur`t|d |d urkt|d |d urvt|d |d urt|d W n ty } ztt|d }~ww |rtjntj}t }||_||_ ||_!|d ur||_"|d urt||_#t| j|_$||_%t&||j'_(|d urt)||_*|d ur||_+d|_,|d ur||_-d|_.|d ur||_/|d ur||_0t1||}t2|j|	|
||j3|j4|dd}|j5r!|j(d ur|j(|_(d|_6| j7d| |j(S ) NrA   )default_valuer[   )
user_keyform_idrF   rG   rH   r*   rK   rL   rP   rC   c                 s  s&    | ]}t |tjtd tfV  qd S r/   )
isinstancenumbersIntegraltyper7   .0ar0   r0   r2   	<genexpr>~  s
    
z1NumberInputMixin._number_input.<locals>.<genexpr>c                 s  s$    | ]}t |ttd tfV  qd S r/   )rh   floatrk   r7   rl   r0   r0   r2   ro     s    
)r*   rG   rH   rK   g        r   T%dz%0.2f)rq   z%uz%iz<Warning: NumberInput value below has type float, but format z displays as integer.fz[Warning: NumberInput value below has type int so is displayed as int despite format string .   g{Gz?   )r*   rG   )r*   rH   z`min_value`z`max_value`z`step`z`value`double_value)on_change_handlerrS   rU   deserializer
serializerrb   
value_type)8r   r   dgr   r   r   r7   allr   r"   filtered_staterh   ri   rj   rp   	streamlitwarning	TypeError
ValueErrorr   r   r   r   validate_int_boundsr+   validate_float_boundsr   r   r8   r9   FLOATidr,   rF   defaultrC   rg   rD   r   rE   r*   r   rP   rA   has_minmaxhas_maxrK   rL   r(   r#   r;   r3   value_changed	set_value_enqueue)r1   rF   rG   rH   r*   rK   rL   rN   rP   rQ   rS   rU   rC   rD   rE   rb   
element_idnumber_input_argsall_int_argsall_float_argssession_state	int_valuefloat_valuestall_intser,   number_input_protoserdewidget_stater0   r0   r2   rc   P  s  



















zNumberInputMixin._number_inputr$   c                 C  s
   t d| S )zGet our DeltaGenerator.r$   )r	   )r1   r0   r0   r2   r|     s   
zNumberInputMixin.dg)	NrA   NNNNNNN)rF   r7   rG   r+   rH   rI   r*   rJ   rK   rI   rL   rM   rN   rO   rP   rM   rQ   rR   rS   rT   rU   rV   rC   rM   rD   rW   rE   r   r.   rX   r/   )rF   r7   rG   rI   rH   r+   r*   rJ   rK   rI   rL   rM   rN   rO   rP   rM   rQ   rR   rS   rT   rU   rV   rC   rM   rD   rW   rE   r   r.   rX   )NN)rF   r7   rG   rI   rH   rI   r*   r+   rK   rI   rL   rM   rN   rO   rP   rM   rQ   rR   rS   rT   rU   rV   rC   rM   rD   rW   rE   r   r.   r+   )NNrA   )rF   r7   rG   rI   rH   rI   r*   rJ   rK   r+   rL   rM   rN   rO   rP   rM   rQ   rR   rS   rT   rU   rV   rC   rM   rD   rW   rE   r   r.   rX   )
NNrA   NNNNNNN)rF   r7   rG   r^   rH   r^   r*   r_   rK   r^   rL   rM   rN   rO   rP   rM   rQ   rR   rS   rT   rU   rV   rC   rM   rD   rW   rE   r   r.   r`   )rF   r7   rG   r)   rH   r)   r*   ra   rK   r)   rL   rM   rN   rO   rP   rM   rQ   rR   rS   rT   rU   rV   rC   rM   rD   rW   rE   r   r.   r)   ) rF   r7   rG   r)   rH   r)   r*   ra   rK   r)   rL   rM   rN   rO   rP   rM   rQ   rR   rS   rT   rU   rV   rC   rM   rD   rW   rE   r   rb   rd   r.   r)   )r.   r$   )	r<   r=   r>   r
   r[   r   rc   propertyr|   r0   r0   r0   r2   r@   S   s    	 ) Gr@   )<
__future__r   ri   dataclassesr   textwrapr   typingr   r   r   r   r	   r
   typing_extensionsr   !streamlit.elements.lib.form_utilsr    streamlit.elements.lib.js_numberr   r   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   streamlit.errorsr   r   r   r   r   streamlit.proto.NumberInput_pb2r   r8   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   r    r!   r"   r#   streamlit.delta_generatorr$   r+   rp   r%   r?   r&   r'   r(   r@   r0   r0   r0   r2   <module>   s.    