
    &ePD                    J   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 d dlZd dlmZ d dl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 d dlmZmZ d dl m!Z!m"Z"m#Z#m$Z$ d dl%m&Z& d dl'm(Z(m)Z)m*Z*m+Z+ e	e,e-f         Z.e G d d                      Z/ G d d          Z0dS )    )annotationsN)	dataclass)dedent)LiteralUnioncastoverload)current_form_id)check_callback_rulescheck_session_state_rules get_label_visibility_proto_value)StreamlitAPIException)JSNumberJSNumberBoundsException)NumberInput)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsregister_widget)compute_widget_id)KeyLabelVisibilitymaybe_raise_label_warningsto_keyc                  8    e Zd ZU ded<   ded<   ddZ	 dddZdS )NumberInputSerdeNumber | Nonevalueint	data_typevreturnc                    |S N )selfr$   s     Glib/python3.11/site-packages/streamlit/elements/widgets/number_input.py	serializezNumberInputSerde.serialize3   s         ui_value	widget_idstrc                h    ||n| j         }|$| j        t          j        k    rt	          |          }|S r'   )r!   r#   NumberInputProtoINTr"   )r)   r.   r/   vals       r*   deserializezNumberInputSerde.deserialize6   s9     *2)=XX4:?t~1A1EEEc((C
r,   N)r$   r    r%   r    )r-   )r.   r    r/   r0   r%   r    )__name__
__module____qualname____annotations__r+   r5   r(   r,   r*   r   r   .   s]         NNN    9;      r,   r   c                  
   e Zd Ze	 	 	 	 	 	 	 	 	 	 d,ddddd-d             Ze	 	 	 	 	 	 	 	 	 	 d.ddddd/d"            Z ed#          	 	 	 	 	 	 	 	 	 	 d,ddddd0d%            Z	 	 	 	 	 	 	 	 	 	 d,ddddd&d1d)Zed2d+            ZdS )3NumberInputMixinNminFvisible)placeholderdisabledlabel_visibilitylabelr0   	min_valuer    	max_valuer!   Number | Literal['min']stepformat
str | Nonekey
Key | Nonehelp	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | Noner>   r?   boolr@   r   r%   Numberc                   d S r'   r(   r)   rA   rB   rC   r!   rE   rF   rH   rJ   rK   rM   rO   r>   r?   r@   s                  r*   number_inputzNumberInputMixin.number_inputB   	    & 	r,   Nonec                   d S r'   r(   rT   s                  r*   rU   zNumberInputMixin.number_inputW   rV   r,   rU   Number | Literal['min'] | Nonec               f    t                      }|                     |||||||||	|
|||||          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 Markdown and supports the following
            elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.

            This also supports:

            * Emoji shortcodes, such as ``:+1:``  and ``:sunglasses:``.
              For a list of all supported codes,
              see https://share.streamlit.io/streamlit/emoji-shortcodes.

            * LaTeX expressions, by wrapping them in "$" or "$$" (the "$$"
              must be on their own lines). Supported LaTeX functions are listed
              at https://katex.org/docs/supported.html.

            * Colored text, using the syntax ``:color[text to be colored]``,
              where ``color`` needs to be replaced with any of the following
              supported colors: blue, green, orange, red, violet, gray/grey, rainbow.

            Unsupported 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``.

            For accessibility reasons, you should never set an empty label (label="")
            but hide it with label_visibility if needed. In the future, we may disallow
            empty labels by raising an exception.
        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. Output must be purely numeric. This does not impact
            the return value. Valid formatters: %d %e %f %g %i %u
        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. Multiple widgets of the same type may
            not share the same key.
        help : str
            An optional tooltip that gets displayed next to the input.
        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, which disables the number input if set to
            True. The default is False.
        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. If "hidden", the label doesn't show but there
            is still empty space for it above the widget (equivalent to label="").
            If "collapsed", both the label and the space are removed. Default is
            "visible".

        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

        )rA   rB   rC   r!   rE   rF   rH   rJ   rK   rM   rO   r>   r?   r@   ctx)r   _number_input)r)   rA   rB   rC   r!   rE   rF   rH   rJ   rK   rM   rO   r>   r?   r@   r[   s                   r*   rU   zNumberInputMixin.number_inputl   sZ    @ !""!!#- " 
 
 	
r,   )r>   r?   r@   r[   r[   ScriptRunContext | Nonec               D	   t          |          }t          | j        |	           t          |dk    r|nd |           t	          ||           t          d||||||||||d nt          |          t          | j                  |r|j        nd           }||||g}t          d |D                       }t          d |D                       }|sf|sdt          dt          |          j         dt          |          j         d	t          |          j         d
t          |          j         d	          |dk    r||}n|r|rd}n|rd}nd}t          |t          j                  }t          |t                     }|	|r|sd}nd}||rdnd}|dv r |rdd l}|                    d| d           n+|d         dk    r|rdd l}|                    d| d           ||rdnd}	 t!          |dz             n'# t&          t(          f$ r t          d|z            w xY w|o|}||||k    rt          d| d|           ||||k     rt          d| d|           	 |r]|t+          j        |d           |t+          j        |d            |t+          j        |d!           |t+          j        |d"           n\|t+          j        |d           |t+          j        |d            |t+          j        |d!           |t+          j        |d"           n.# t0          $ r!}t          t          |                    d }~ww xY w|rt2          j        nt2          j        }t3                      }||_        ||_        ||_        |||_        |t          |          |_         t          | j                  |_!        ||_"        tG          |          |j$        _%        |tM          |          |_'        |||_(        d|_)        |||_*        d|_+        |||_,        |||_-        t]          ||          }t_          d|||	|
||j0        |j1        |#	  	        }|j2        r|j%        |j%        |_%        d|_3        | j        4                    d|           |j%        S )$Nr<   )default_valuerH   rU   )user_keyrA   rB   rC   r!   rE   rF   rH   rJ   r>   form_idpagec              3  t   K   | ]3}t          |t          j        t          d           t          f          V  4d S r'   )
isinstancenumbersIntegraltyper0   .0as     r*   	<genexpr>z1NumberInputMixin._number_input.<locals>.<genexpr>,  sP       
 
 q7+T$ZZ=>>
 
 
 
 
 
r,   c              3  j   K   | ].}t          |t          t          d           t          f          V  /d S r'   )rd   floatrg   r0   rh   s     r*   rk   z1NumberInputMixin._number_input.<locals>.<genexpr>1  sJ       
 
89Jq5$t**c233
 
 
 
 
 
r,   z>All numerical arguments must be of the same type.
`value` has z type.
`min_value` has z type.
`max_value` has z type.
`step` has z type.g        r   T%dz%0.2f)rn   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?   zAFormat string for st.number_input contains invalid characters: %szThe default `value` z2 must be greater than or equal to the `min_value` z/ must be less than or equal to the `max_value` z`min_value`z`max_value`z`step`z`value`)r`   on_change_handlerrM   rO   deserializer
serializerr[   )5r   r   dgr   r   r   r0   r
   page_script_hashallr   rg   r6   rd   re   rf   rm   	streamlitwarning	TypeError
ValueErrorr   validate_int_boundsvalidate_float_boundsr   r2   r3   FLOATidr#   rA   defaultr>   ra   r?   r   r@   r!   r   rJ   r<   has_minmaxhas_maxrE   rF   r   r   r5   r+   value_changed	set_value_enqueue)r)   rA   rB   rC   r!   rE   rF   rH   rJ   rK   rM   rO   r>   r?   r@   r[   r   number_input_argsint_args
float_args	int_valuefloat_valuestall_intser#   number_input_protoserdewidget_states                                r*   r\   zNumberInputMixin._number_input   s   & SkkTWi000!#(E>>%%t	
 	
 	
 	
 	#5*:;;; + 3[9I9I#DG,,),6%%$
 
 
" '	5$? 
 
&
 
 
 
 

  
 
=N
 
 
 
 

  	
 	'<!%e!5< <%))__%=< < &*)__%=< < !%T

 3	< < <   E>>$! j  ug&677	 ..= #
 # 		 #>&3TTGF '''K'""""JJ=%= = =    BZ39""""JJE;AE E E  
 <!+11tD	&1*:& 	 	 	'S  	 ) U%69u;L;L'kukk`ikk    U%69u;L;L'huhh]fhh  	0 E(0!=   (0!=   #0x@@@$0	BBB(29mLLL(29mLLL#24BBB$25)DDD& 	0 	0 	0'A///	0 -5P$((:J:P	-// "'0$#( ).&"-0-=-=*%4TW%=%="&.#4T5
 5
+1 &,Tll# %.")-& %.")-&&*#(.% 	22&'*

 

 

 % 	0!-+7+="(+/();<<<!!s%   )G< <$H &B;L" "
M,MM*'streamlit.delta_generator.DeltaGenerator'c                "    t          d|           S )zGet our DeltaGenerator.z(streamlit.delta_generator.DeltaGenerator)r   )r)   s    r*   rw   zNumberInputMixin.dg  s     >EEEr,   )
NNr<   NNNNNNN)rA   r0   rB   r    rC   r    r!   rD   rE   r    rF   rG   rH   rI   rJ   rG   rK   rL   rM   rN   rO   rP   r>   rG   r?   rQ   r@   r   r%   rR   )
NNNNNNNNNN)rA   r0   rB   r    rC   r    r!   rW   rE   r    rF   rG   rH   rI   rJ   rG   rK   rL   rM   rN   rO   rP   r>   rG   r?   rQ   r@   r   r%   r    )rA   r0   rB   r    rC   r    r!   rY   rE   r    rF   rG   rH   rI   rJ   rG   rK   rL   rM   rN   rO   rP   r>   rG   r?   rQ   r@   r   r%   r    ) rA   r0   rB   r    rC   r    r!   rY   rE   r    rF   rG   rH   rI   rJ   rG   rK   rL   rM   rN   rO   rP   r>   rG   r?   rQ   r@   r   r[   r]   r%   r    )r%   r   )	r6   r7   r8   r	   rU   r   r\   propertyrw   r(   r,   r*   r;   r;   A   s        $(#')."!+/"&&* #',5!     X(  $(#'"!+/"&&* #',5!     X( ^N## $(#'05"!+/"&&*P
 #',5!P
 P
 P
 P
 P
 $#P
j $(#'05"!+/"&&*N" #',5'+#N" N" N" N" N" N"` F F F XF F Fr,   r;   )1
__future__r   re   dataclassesr   textwrapr   typingr   r   r   r	   rz   streamlit.elements.formr
   streamlit.elements.utilsr   r   r   streamlit.errorsr   streamlit.js_numberr   r   streamlit.proto.NumberInput_pb2r   r2   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   r   r   r   streamlit.runtime.state.commonr   streamlit.type_utilr   r   r   r   r"   rm   rR   r   r;   r(   r,   r*   <module>r      s   # " " " " "  ! ! ! ! ! !       1 1 1 1 1 1 1 1 1 1 1 1     3 3 3 3 3 3         
 3 2 2 2 2 2 A A A A A A A A K K K K K K 9 9 9 9 9 9 O O O O O O O O            = < < < < < X X X X X X X X X X X X	sEz	        $QF QF QF QF QF QF QF QF QF QFr,   