
    &e3              	          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
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/m0Z0m1Z1 erd dl2m3Z3 edee         ddde
e	e4                  fd            Z5edee         deee         ef         de	e4         fd            Z5dee         deee         edf         de
e	e4                  fdZ5deee         edf         de4fdZ6de4de4fdZ7e G d dee+                               Z8 G d d          Z9dS )    )	dataclass)dedent)
TYPE_CHECKINGAnyCallableGenericListOptionalSequenceUnioncastoverload)current_form_id)check_callback_rulescheck_session_state_rules get_label_visibility_proto_valuemaybe_coerce_enum_sequence)StreamlitAPIException)MultiSelect)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsregister_widget)compute_widget_id)
KeyLabelVisibilityOptionSequenceTcheck_python_comparableensure_indexableis_iterableis_typemaybe_raise_label_warningsto_key)DeltaGeneratoroptdefault_valuesNreturnc                     d S N r)   r*   s     Flib/python3.11/site-packages/streamlit/elements/widgets/multiselect.py_check_and_convert_to_indicesr1   A   	     C    c                     d S r-   r.   r/   s     r0   r1   r1   H   r2   r3   c                 X    |d vrdS t          |t                    sgt          |d          st          |d          r.t          t          t          t
                   |                    }n|r| v r|g}nt          |          }|D ]}| vrt          d           fd|D             S )zIPerform validation checks and return indices based on the default values.Nznumpy.ndarrayzpandas.core.series.Seriesz5Every Multiselect default value must exist in optionsc                 :    g | ]}                     |          S r.   )index).0valuer)   s     r0   
<listcomp>z1_check_and_convert_to_indices.<locals>.<listcomp>i   s%    999CIIe999r3   )
isinstancelistr%   r   r   r   r   )r)   r*   r9   s   `  r0   r1   r1   O   s     $c//tnd++ 2 >?33 	2w78
 8
 	2 "$x}n"E"EFFNN 	2>S#8#8,-NN!.11N  'G   
 :999.9999r3   defaultc                     | dS t          |           sdS t          t          t          t                   |                     S )Nr      )r$   lenr   r   r   )r=   s    r0   _get_default_countrA   l   s=    qw qtHSM7++,,,r3   current_selectionsmax_selectionsc                 N    | dk    rdnd}|dk    rdnd}d|  d| d| d| d| dS )	Nr?   optionoptionsz
Multiselect has  z) selected but `max_selections`
is set to z. This happened because you either gave too many options to `default`
or you manipulated the widget's state through `st.session_state`. Note that
the latter can happen before the line indicated in the traceback.
Please select at most z.
r.   )rB   rC   curr_selections_nounmax_selections_nouns       r0   _get_over_max_options_messagerJ   t   s~    '9Q'>'>88I&4&9&9((y# &:  
 & 
 )<   r3   c                       e Zd ZU ee         ed<   ee         ed<   dee         dee         fdZ	 dde	ee                  de
dee         fd	Zd
S )MultiSelectSerderF   default_valuer9   r+   c                 ,    t          | j        |          S r-   )r1   rF   )selfr9   s     r0   	serializezMultiSelectSerde.serialize   s    ,T\5AAAr3    ui_value	widget_idc                 6     ||n j         } fd|D             S )Nc                 *    g | ]}j         |         S r.   )rF   )r8   irO   s     r0   r:   z0MultiSelectSerde.deserialize.<locals>.<listcomp>   s    777AQ777r3   )rM   )rO   rR   rS   current_values   `   r0   deserializezMultiSelectSerde.deserialize   s5     !,HH$2D 	 87777777r3   N)rQ   )__name__
__module____qualname__r   r!   __annotations__r	   intrP   r
   strrX   r.   r3   r0   rL   rL      s         a[9BtAw B49 B B B B 8 849%8 8 
a	8 8 8 8 8 8r3   rL   c            !           e Zd Z ed          dedddddfddddddedee         d	ee         d
e	egef         dee
         dee         dee         dee         dee         dee         dedededee         fd            Zdedddddfdddddddedee         d	eee         edf         d
e	egef         dee
         dee         dee         dee         dee         dee         dedededee         dee         fdZedd            ZdS )MultiSelectMixinmultiselectNzChoose an optionFvisible)rC   placeholderdisabledlabel_visibilitylabelrF   r=   format_funckeyhelp	on_changeargskwargsrC   rc   rd   re   r+   c
                d    t                      }|                     |||||||||	|
||||          S )aD  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 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.
        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 selectbox 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 multiselect.
        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 multiselect.
        on_change : callable
            An optional callback invoked when this multiselect'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, which disables the multiselect widget if set
            to True. The default is False. This argument can only be supplied
            by keyword.
        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
        -------
        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

        )rf   rF   r=   rg   rh   ri   rj   rk   rl   rC   rc   rd   re   ctx)r   _multiselect)rO   rf   rF   r=   rg   rh   ri   rj   rk   rl   rC   rc   rd   re   rn   s                  r0   ra   zMultiSelectMixin.multiselect   sW    Z !""  #)#- ! 
 
 	
r3   )rC   rc   rd   re   rn   rn   c
                V   t          |          }t          | j        |           t          ||           t	          |          }t          |           t          ||           t          ||          }t          d||fd|D             ||||
|t          | j                  |r|j
        nd           }|g n|}t                      }||_        ||_        ||j        d d <   fd|D             |j        d d <   t          | j                  |_        |
pd|_        ||_        ||_        t)          |          |j        _        |t/          |          |_        t3          ||          }t5          d|||||	|j        |j        |	  	        }t;          |j                  }|
r#||
k    rt=          t?          ||
                    tA          |||          }|j!        r+|                    |j                  |j        d d <   d|_"        | j        #                    d|           |j        S )	N)rM   rh   ra   c                 @    g | ]}t           |                    S r.   r^   r8   rE   rg   s     r0   r:   z1MultiSelectMixin._multiselect.<locals>.<listcomp>3  s+    @@@&SV,,--@@@r3   )
user_keyrf   rF   r=   rh   ri   rC   rc   form_idpagec                 @    g | ]}t           |                    S r.   rr   rs   s     r0   r:   z1MultiSelectMixin._multiselect.<locals>.<listcomp>C  s+    'S'S'SVKK,?,?(@(@'S'S'Sr3   r   )rt   on_change_handlerrk   rl   deserializer
serializerrn   T)$r'   r   dgr   r#   r"   r&   r1   r   r   page_script_hashMultiSelectProtoidrf   r=   rF   ru   rC   rc   rd   r   re   r9   r   ri   rL   r   rX   rP   rA   r   rJ   r   value_changed	set_value_enqueue)rO   rf   rF   r=   rg   rh   ri   rj   rk   rl   rC   rc   rd   re   rn   r)   indicesr~   rM   multiselect_protoserdewidget_statedefault_counts       `                  r0   ro   zMultiSelectMixin._multiselect  s   $ SkkTWi000!SAAAAw''$$$"5*:;;;/W==@@@@C@@@)##DG,,),6%%$
 
 
 *122g,..!"''4!!!!$'S'S'S'Ss'S'S'S!!!!$$3DG$<$<!+9+>Q((3%%-"3S4
 4
*0 %+D\\" m44&'*

 

 

 +<+=>> 	mn<<'-m^LL   2,MM% 	/).9K)L)L#AAA&*.'(9:::!!r3   r(   c                 "    t          d|           S )zGet our DeltaGenerator.r(   )r   )rO   s    r0   r{   zMultiSelectMixin.dgj  s     $d+++r3   )r+   r(   )rY   rZ   r[   r   r^   r    r!   r
   r   r   r   r   r   r   r]   boolr   r	   ra   r   r   r   ro   propertyr{   r.   r3   r0   r`   r`      s       ^M""
 "&,/!".2%))-|
 )--,5|
 |
 |
|
  "|
 #	|

 seSj)|
 c]|
 sm|
 N+|
 z"|
 &|
 !|
 |
 |
 *|
  
a!|
 |
 |
 #"|
D 48,/!".2%))-U" )--,5*.!U" U" U"U"  "U" x}c4/0	U"
 seSj)U" c]U" smU" N+U" z"U" &U" !U" U" U" *U"  &'!U"" 
a#U" U" U" U"n , , , X, , ,r3   r`   ):dataclassesr   textwrapr   typingr   r   r   r   r	   r
   r   r   r   r   streamlit.elements.formr   streamlit.elements.utilsr   r   r   r   streamlit.errorsr   streamlit.proto.MultiSelect_pb2r   r}   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%   r&   r'   streamlit.delta_generatorr(   r]   r1   rA   rJ   rL   r`   r.   r3   r0   <module>r      s   " ! ! ! ! !                              4 3 3 3 3 3            3 2 2 2 2 2 K K K K K K 9 9 9 9 9 9 O O O O O O O O            = < < < < <                         9888888 
	#(,d3i   
 
	#(-hsmS.@(A	#Y   
:	#:(-hsmS$.F(G:d3i: : : ::-hsmS$&> ? -C - - - -	c 	3 	 	 	 	 8 8 8 8 8wqz 8 8 8$Z, Z, Z, Z, Z, Z, Z, Z, Z, Z,r3   