o
    沪g*2                     @  sF  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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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-m.Z. d dl/m0Z0m1Z1 erd dl2m3Z3 d dl4m5Z5 eG dd de
e0 Z6G dd dZ7dS )    )annotations)	dataclass)dedent)TYPE_CHECKINGAnyCallableGenericcastoverload)OptionSequenceconvert_anything_to_list)current_form_id)index_maybe_coerce_enum)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valuesave_for_app_testingto_key)StreamlitAPIException)	Selectbox)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsget_session_stateregister_widget)Tcheck_python_comparable)Sequence)DeltaGeneratorc                   @  s6   e Zd ZU ded< ded< ddd	Z	
ddddZdS )SelectboxSerdezSequence[T]options
int | Noneindexvobjectreturnc                 C  s*   |d u rd S t | jdkrdS t| j|S Nr   )lenr'   r   )selfr*    r0   `/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/elements/widgets/selectbox.py	serialize>   s
   zSelectboxSerde.serialize ui_value	widget_idstrT | Nonec                 C  s6   |d ur|n| j }|d urt| jdkr| j| S d S r-   )r)   r.   r'   )r/   r4   r5   idxr0   r0   r1   deserializeE   s   $zSelectboxSerde.deserializeN)r*   r+   r,   r(   )r3   )r4   r(   r5   r6   r,   r7   )__name__
__module____qualname____annotations__r2   r9   r0   r0   r0   r1   r&   9   s   
 

r&   c                   @  s   e Zd Zededddddfddddd0d d!Zeedddddfddddd1d$d!Zed%dedddddfddddd2d'd!Zdedddddfddddd(d3d+d,Zed4d.d/Z	dS )5SelectboxMixinr   NzChoose an optionFvisible)placeholderdisabledlabel_visibilitylabelr6   r'   OptionSequence[T]r)   intformat_funcCallable[[Any], Any]key
Key | Nonehelp
str | None	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | Noner@   rA   boolrB   r   r,   r"   c
                C     d S Nr0   r/   rC   r'   r)   rF   rH   rJ   rL   rN   rP   r@   rA   rB   r0   r0   r1   	selectboxO      zSelectboxMixin.selectboxNoner7   c
                C  rS   rT   r0   rU   r0   r0   r1   rV   a   rW   rV   r(   c
                C  s*   t  }| j|||||||||	|
|||dS )aO  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 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

        options : Iterable
            Labels for the select options in an ``Iterable``. This can be a
            ``list``, ``set``, or anything supported by ``st.dataframe``. If
            ``options`` is dataframe-like, the first column will be 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 options. It receives
            the raw option as an argument and should output the label to be
            shown for that option. This has no impact on the return value of
            the command.

        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 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 that disables the selectbox 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
        -------
        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

        )rC   r'   r)   rF   rH   rJ   rL   rN   rP   r@   rA   rB   ctx)r   
_selectbox)r/   rC   r'   r)   rF   rH   rJ   rL   rN   rP   r@   rA   rB   rY   r0   r0   r1   rV   s   s"    )r@   rA   rB   rY   rY   ScriptRunContext | Nonec
             
     s  t |}t| j|||dkrd n|d t|| t|}t| td|t| j| fdd|D |||
d}t|t	sH|d urHt
dt|j |d urft|dkrfd|  krat|k sft
d t
dt j}|d urz||v rz|| d u rzd }t }||_||_|d ur||_ fd	d|D |jd d < t| j|_|
|_||_t||j_|d urt||_t||}t|j|||	|j|j |d
d}t!|||}|j"r| |j}|d ur||_d|_#|rt$||  | j%d| |jS )Nr   )default_valuerV   c                      g | ]}t  |qS r0   r6   .0optionrF   r0   r1   
<listcomp>.      z-SelectboxMixin._selectbox.<locals>.<listcomp>)user_keyform_idrC   r'   r)   rJ   r@   z$Selectbox Value has invalid type: %szWSelectbox index must be greater than or equal to 0 and less than the length of options.c                   r]   r0   r^   r_   rb   r0   r1   rc   G  rd   	int_value)on_change_handlerrN   rP   deserializer
serializerrY   
value_typeT)&r   r   dgr   r   r#   r   r   
isinstancerE   r   typer:   r.   r    filtered_stateSelectboxProtoidrC   defaultr'   rf   r@   rA   r   rB   valuer   rJ   r&   r!   r9   r2   r   value_changed	set_valuer   _enqueue)r/   rC   r'   r)   rF   rH   rJ   rL   rN   rP   r@   rA   rB   rY   opt
element_idsession_stateselectbox_protoserdewidget_stateserialized_valuer0   rb   r1   rZ     s   
*


zSelectboxMixin._selectboxr%   c                 C  s
   t d| S )zGet our DeltaGenerator.r%   )r	   )r/   r0   r0   r1   rl   k  s   
zSelectboxMixin.dg)rC   r6   r'   rD   r)   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   r@   r6   rA   rR   rB   r   r,   r"   )rC   r6   r'   rD   r)   rX   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   r@   r6   rA   rR   rB   r   r,   r7   )rC   r6   r'   rD   r)   r(   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   r@   r6   rA   rR   rB   r   r,   r7   )rC   r6   r'   rD   r)   r(   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   r@   r6   rA   rR   rB   r   rY   r[   r,   r7   )r,   r%   )
r:   r;   r<   r
   r6   rV   r   rZ   propertyrl   r0   r0   r0   r1   r>   N   sn     `r>   N)8
__future__r   dataclassesr   textwrapr   typingr   r   r   r   r	   r
   streamlit.dataframe_utilr   r   !streamlit.elements.lib.form_utilsr   -streamlit.elements.lib.options_selector_utilsr   r   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   r   streamlit.errorsr   streamlit.proto.Selectbox_pb2r   rp   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   r   r   r    r!   streamlit.type_utilr"   r#   collections.abcr$   streamlit.delta_generatorr%   r&   r>   r0   r0   r0   r1   <module>   s*     