
    &e\+                    \   d dl m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mZmZmZ d dl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)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/ erd dl0m1Z1 e G d de
e)                               Z2 G d d          Z3dS )    )annotations)	dataclass)dedent)TYPE_CHECKINGAnyCallableGenericSequencecast)current_form_id)check_callback_rulescheck_session_state_rules get_label_visibility_proto_valuemaybe_coerce_enum)StreamlitAPIException)	Selectbox)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsregister_widget)compute_widget_id)KeyLabelVisibilityOptionSequenceTcheck_python_comparableensure_indexablemaybe_raise_label_warningsto_key)index_)DeltaGeneratorc                  8    e Zd ZU ded<   ded<   ddZ	 dddZdS )SelectboxSerdezSequence[T]options
int | Noneindexvobjectreturnc                h    |d S t          | j                  dk    rdS t          | j        |          S Nr   )lenr'   r#   )selfr*   s     Dlib/python3.11/site-packages/streamlit/elements/widgets/selectbox.py	serializezSelectboxSerde.serialize;   s8    94t|!!1dlA&&&     ui_value	widget_idstrT | Nonec                j    ||n| j         }|%t          | j                  dk    r| j        |         nd S r.   )r)   r/   r'   )r0   r5   r6   idxs       r1   deserializezSelectboxSerde.deserializeB   s?    
 #.hhDJ$'ODL8I8IA8M8Mt|C  SWWr3   N)r*   r+   r,   r(   )r4   )r5   r(   r6   r7   r,   r8   )__name__
__module____qualname____annotations__r2   r;    r3   r1   r&   r&   6   sg         ' ' ' ' X X X X X X Xr3   r&   c                      e Zd Z ed          dedddddfddddd(d!            Zdedddddfddddd"d)d%Zed*d'            ZdS )+SelectboxMixin	selectboxr   NzChoose an optionFvisible)placeholderdisabledlabel_visibilitylabelr7   r'   OptionSequence[T]r)   r(   format_funcCallable[[Any], Any]key
Key | Nonehelp
str | None	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | NonerE   rF   boolrG   r   r,   r8   c
               b    t                      }|                     |||||||||	|
|||          S )a  Display a select widget.

        Parameters
        ----------
        label : str
            A short label explaining to the user what this select widget 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.
        options : Iterable
            Labels for the select options in an Iterable. For example, this can
            be a list, numpy.ndarray, pandas.Series, pandas.DataFrame, or
            pandas.Index. For pandas.DataFrame, the first column is used.
            Each label will be cast to str internally by default.
        index : int
            The index of the preselected option on first render. If ``None``,
            will initialize empty and return ``None`` until the user selects an option.
            Defaults to 0 (the first option).
        format_func : function
            Function to modify the display of the labels. It receives the option
            as an argument and its output will be cast to str.
        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 selectbox.
        on_change : callable
            An optional callback invoked when this selectbox'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
            A string to display when no options are selected.
            Defaults to 'Choose an option'.
        disabled : bool
            An optional boolean, which disables the selectbox 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
        -------
        any
            The selected option or ``None`` if no option is selected.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> option = st.selectbox(
        ...     'How would you like to be contacted?',
        ...     ('Email', 'Home phone', 'Mobile phone'))
        >>>
        >>> st.write('You selected:', option)

        .. output::
           https://doc-selectbox.streamlit.app/
           height: 320px

        To initialize an empty selectbox, use ``None`` as the index value:

        >>> import streamlit as st
        >>>
        >>> option = st.selectbox(
        ...    "How would you like to be contacted?",
        ...    ("Email", "Home phone", "Mobile phone"),
        ...    index=None,
        ...    placeholder="Select contact method...",
        ... )
        >>>
        >>> st.write('You selected:', option)

        .. output::
           https://doc-selectbox-empty.streamlit.app/
           height: 320px

        )rH   r'   r)   rJ   rL   rN   rP   rR   rT   rE   rF   rG   ctx)r   
_selectbox)r0   rH   r'   r)   rJ   rL   rN   rP   rR   rT   rE   rF   rG   rX   s                 r1   rC   zSelectboxMixin.selectboxL   sR    r !""##-  
 
 	
r3   )rE   rF   rG   rX   rX   ScriptRunContext | Nonec
                  t          |          }t          | j        |           t          |dk    rd n||           t	          ||           t          |          }t          |           t          d||fd|D             ||||
t          | j                  |r|j	        nd 
  
        }t          |t                    s&|$t          dt          |          j        z            |>t          |          dk    r+d|cxk    rt          |          k     sn t          d          t!                      }||_        ||_        |||_        fd|D             |j        d d <   t          | j                  |_        |
|_        ||_        t1          |          |j        _        |t7          |          |_        t;          ||          }t=          d|||||	|j        |j         |		  	        }tC          |||          }|j"        r*|                     |j                  }|||_        d
|_#        | j        $                    d|           |j        S )Nr   )default_valuerL   rC   c                @    g | ]}t           |                    S r@   r7   .0optionrJ   s     r1   
<listcomp>z-SelectboxMixin._selectbox.<locals>.<listcomp>   s+    @@@&SV,,--@@@r3   )	user_keyrH   r'   r)   rL   rN   rE   form_idpagez$Selectbox Value has invalid type: %sz7Selectbox index must be between 0 and length of optionsc                @    g | ]}t           |                    S r@   r^   r_   s     r1   rb   z-SelectboxMixin._selectbox.<locals>.<listcomp>  s+    %Q%Q%Q6c++f*=*=&>&>%Q%Q%Qr3   )rc   on_change_handlerrR   rT   deserializer
serializerrX   T)%r"   r   dgr   r!   r    r   r   r   page_script_hash
isinstanceintr   typer<   r/   SelectboxProtoidrH   defaultr'   rd   rE   rF   r   rG   valuer   rN   r&   r   r;   r2   r   value_changed	set_value_enqueue)r0   rH   r'   r)   rJ   rL   rN   rP   rR   rT   rE   rF   rG   rX   optrp   selectbox_protoserdewidget_stateserialized_values       `               r1   rY   zSelectboxMixin._selectbox   s   " SkkTWi000!

SVWWWW"5*:;;;w''$$$@@@@C@@@##DG,,),6%%$
 
 
 %%% 	%*;'6e9MM   SAa56K6K6K6K3s886K6K6K6K'I   )** %&+O#%Q%Q%Q%QS%Q%Q%Q""1$'":":&1##+ 1Q2
 2
(. #)$<<O sE**&'*

 

 

 )wDD% 	-$|/ABB+(8%(,O%o666!!r3   'DeltaGenerator'c                "    t          d|           S )zGet our DeltaGenerator.r$   )r   )r0   s    r1   rj   zSelectboxMixin.dg/  s     $d+++r3   )rH   r7   r'   rI   r)   r(   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rE   r7   rF   rV   rG   r   r,   r8   )rH   r7   r'   rI   r)   r(   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rE   r7   rF   rV   rG   r   rX   rZ   r,   r8   )r,   r{   )	r<   r=   r>   r   r7   rC   rY   propertyrj   r@   r3   r1   rB   rB   K   s        ^K  
 ,/+/"&&*G
 .,5G
 G
 G
 G
 G
 ! G
Z ,/+/"&&*W" .,5'+W" W" W" W" W" W"r , , , X, , ,r3   rB   N)4
__future__r   dataclassesr   textwrapr   typingr   r   r   r	   r
   r   streamlit.elements.formr   streamlit.elements.utilsr   r   r   r   streamlit.errorsr   streamlit.proto.Selectbox_pb2r   ro   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   r    r!   r"   streamlit.utilr#   streamlit.delta_generatorr$   r&   rB   r@   r3   r1   <module>r      sk   # " " " " " ! ! ! ! ! !       H H H H H H H H H H H H H H H H 3 3 3 3 3 3            3 2 2 2 2 2 E E E E E E 9 9 9 9 9 9 O O O O O O O O            = < < < < <	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 " ! ! ! ! ! 9888888 X X X X XWQZ X X X(g, g, g, g, g, g, g, g, g, g,r3   