o
    沪g-                     @  sn  d dl 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mZmZm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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- d dl.m/Z/m0Z0 e
rd dlmZ d dl1m2Z2 d dl,m3Z3m4Z4m5Z5 eG dd dee/ Z6d#ddZ7d$ddZ8G d d! d!Z9d"S )%    )annotations)Sequence)	dataclassfield)dedent)TYPE_CHECKINGAnyCallableGenericcast)OptionSequence)current_form_id)check_and_convert_to_indices(convert_to_sequence_and_check_comparableget_default_indicesmaybe_coerce_enum_sequence)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)&StreamlitSelectionCountExceedsMaxError)MultiSelect)gather_metrics)ScriptRunContextget_script_run_ctx)register_widget)Tis_iterable)DeltaGenerator)
WidgetArgsWidgetCallbackWidgetKwargsc                   @  s@   e Zd ZU ded< eedZded< dd	d
Z	ddddZdS )MultiSelectSerdezSequence[T]options)default_factory	list[int]default_valuevaluelist[T]returnc                 C  s   t | j|}|d ur|S g S )N)r   r'   )selfr+   indices r0   b/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/elements/widgets/multiselect.py	serializeE   s   zMultiSelectSerde.serialize ui_valuelist[int] | None	widget_idstrc                   s$   |d ur|n j } fdd|D S )Nc                   s   g | ]} j | qS r0   )r'   ).0ir.   r0   r1   
<listcomp>Q   s    z0MultiSelectSerde.deserialize.<locals>.<listcomp>r*   )r.   r4   r6   current_valuer0   r:   r1   deserializeI   s   zMultiSelectSerde.deserializeN)r+   r,   r-   r)   )r3   )r4   r5   r6   r7   r-   r,   )	__name__
__module____qualname____annotations__r   listr*   r2   r>   r0   r0   r0   r1   r&   @   s   
 
r&   defaultSequence[Any] | Any | Noner-   intc                 C  s*   | d u rdS t | sdS tttt | S )Nr      )r!   lenr   r   r   )rD   r0   r0   r1   _get_default_countT   s
   rI   
selectionsmax_selections
int | Nonec                 C  s,   |d u rd S t | }||krt||dd S )N)current_selections_countmax_selections_count)rI   r   )rJ   rK   default_countr0   r0   r1   _check_max_selections\   s   rP   c                   @  sp   e Zd Zeddedddddfdddddd-d"d#Zdedddddfdddddd$d.d(d)Zed/d+d,ZdS )0MultiSelectMixinmultiselectNzChoose an optionFvisible)rK   placeholderdisabledlabel_visibilitylabelr7   r'   OptionSequence[T]rD   
Any | Noneformat_funcCallable[[Any], Any]key
Key | Nonehelp
str | None	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | NonerK   rL   rT   rU   boolrV   r   r-   r,   c
                C  s,   t  }| j|||||||||	|
||||dS )aU  Display a multiselect widget.
        The multiselect widget starts as empty.

        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.

        default: Iterable of V, V, or None
            List of default values. Can also be a single value.

        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 widget'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.

        max_selections: int
            The max selections that can be selected at a time.

        placeholder: str
            A string to display when no options are selected.
            Defaults to "Choose an option."

        disabled: bool
            An optional boolean that disables the multiselect widget 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
        -------
        list
            A list with the selected options

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> options = st.multiselect(
        ...     "What are your favorite colors",
        ...     ["Green", "Yellow", "Red", "Blue"],
        ...     ["Yellow", "Red"],
        ... )
        >>>
        >>> st.write("You selected:", options)

        .. output::
           https://doc-multiselect.streamlit.app/
           height: 420px

        )rW   r'   rD   rZ   r\   r^   r`   rb   rd   rK   rT   rU   rV   ctx)r   _multiselect)r.   rW   r'   rD   rZ   r\   r^   r`   rb   rd   rK   rT   rU   rV   rg   r0   r0   r1   rR   j   s"   zzMultiSelectMixin.multiselect)rK   rT   rU   rV   rg   rE   rg   ScriptRunContext | Nonec
                  s^  t |}d}t| j|||d t|| t|} fdd|D }t||}t| j}t||||||||
|d	}t }||_	||j
d d < ||_||_||_|
pQd|_||_t||j_||jd d < |d urlt||_t||}t|j	|||	|j|j|dd}t|j|
 t|||}|jr||j|jd d < d	|_|rt||  | j|| |jS )
NrR   r<   c                   s   g | ]} |qS r0   r0   )r8   optionrZ   r0   r1   r;     s    z1MultiSelectMixin._multiselect.<locals>.<listcomp>)user_keyform_idrW   r'   rD   r^   rK   rT   r   int_array_value)on_change_handlerrb   rd   deserializer
serializerrg   
value_typeT) r   r   dgr   r   r   r   r   MultiSelectProtoidrD   rm   rU   rW   rK   rT   r   rV   r+   r'   r   r^   r&   r   r>   r2   rP   r   value_changed	set_valuer   _enqueue)r.   rW   r'   rD   rZ   r\   r^   r`   rb   rd   rK   rT   rU   rV   rg   widget_nameindexable_optionsformatted_optionsdefault_valuesrm   
element_idprotoserdewidget_stater0   rk   r1   rh      sx   





zMultiSelectMixin._multiselectr"   c                 C  s
   t d| S )zGet our DeltaGenerator.r"   )r   r:   r0   r0   r1   rs   O  s   
zMultiSelectMixin.dg)rW   r7   r'   rX   rD   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rK   rL   rT   r7   rU   rf   rV   r   r-   r,   )rW   r7   r'   rX   rD   rE   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rK   rL   rT   r7   rU   rf   rV   r   rg   ri   r-   r,   )r-   r"   )	r?   r@   rA   r   r7   rR   rh   propertyrs   r0   r0   r0   r1   rQ   i   s@     YrQ   N)rD   rE   r-   rF   )rJ   rE   rK   rL   ):
__future__r   collections.abcr   dataclassesr   r   textwrapr   typingr   r   r	   r
   r   streamlit.dataframe_utilr   !streamlit.elements.lib.form_utilsr   -streamlit.elements.lib.options_selector_utilsr   r   r   r   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   r   streamlit.errorsr   streamlit.proto.MultiSelect_pb2r   rt   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   streamlit.type_utilr    r!   streamlit.delta_generatorr"   r#   r$   r%   r&   rI   rP   rQ   r0   r0   r0   r1   <module>   s2    

