L i[RddlmZddlmZddlmZddlmZmZm Z m Z m Z m Z m Z ddlmZmZddlmZddlmZmZmZddlmZmZmZmZdd lmZmZdd lm Z m!Z!m"Z"m#Z#m$Z$m%Z%dd l&m'Z'dd l(m)Z*dd l+m,Z,ddl-m.Z.m/Z/ddl0m1Z1ddl2m3Z3erddlm4Z4mZddlmZddl5m6Z6ddl0m7Z7m8Z8m9Z9e dZ:Gdde e:Z;ddZ< ddZ=GddZ>y)) annotations)Sequence)dedent) TYPE_CHECKINGAnyGenericLiteralTypeVarcastoverload)OptionSequenceconvert_anything_to_list)current_form_id) LayoutConfigWidthWithoutContentvalidate_width)(convert_to_sequence_and_check_comparablecreate_mappingsget_default_indicesmaybe_coerce_enum_sequence)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valuesave_for_app_testingto_key)&StreamlitSelectionCountExceedsMaxError) MultiSelect)gather_metrics)ScriptRunContextget_script_run_ctx)register_widget) is_iterable)Callabler)r )DeltaGenerator) WidgetArgsWidgetCallback WidgetKwargsTcfeZdZUded<ded<ded<ded<d d  dd Zdd Zdd Zy )MultiSelectSerde Sequence[T]options list[str]formatted_optionsdict[str, int] formatted_option_to_option_indexz list[int]default_options_indicesN)r4cD||_||_||_|xsg|_y)aInitialize the MultiSelectSerde. We do not store an option_to_formatted_option mapping because the generic options might not be hashable, which would raise a RuntimeError. So we do two lookups: option -> index -> formatted_option[index]. Parameters ---------- options : Sequence[T] The sequence of selectable options. formatted_options : list[str] The string representations of each option. The formatted_options correspond to the options sequence by index. formatted_option_to_option_index : dict[str, int] A mapping from formatted option strings to their corresponding indices in the options sequence. default_option_index : int or None, optional The index of the default option to use when no selection is made. If None, no default option is selected. N)r/r1r3r4)selfr/r1r3r4s l/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/elements/widgets/multiselect.py__init__zMultiSelectSerde.__init__Us(< !20P-'>'D"$ct|}g}|D]<} |jj|}|j|j|>|S#t $r|jt d|YgwxYw)Nstr)rr/indexappendr1 ValueErrorr )r6valueconverted_valuevaluesv option_indexs r7 serializezMultiSelectSerde.serializexs|259  .A .#||11!4  d44\BC .  . d5!n- .s9A$A87A8c(|'|jDcgc]}|j|c}Sg}|D]<} |jj|}|j |j|>|Scc}w#t $r|j |YbwxYwN)r4r/r1r<r=r>)r6ui_valueirArBrCs r7 deserializezMultiSelectSerde.deserializes  -1-I-IJDLLOJ J " !A !#55;;A>  dll<89 !  K ! a  !sA/9A44BB) r/r.r1r0r3r2r4zlist[int] | NonereturnNone)r?list[T | str] | list[T]rJr0)rGzlist[str] | NonerJrL)__name__ __module__ __qualname____annotations__r8rDrIr9r7r-r-Ose   &44&&59 !E!E% !E +9 !E "2 !E !EF  r9r-cJ|yt|syttd|S)Nrz Sequence[Any])r%lenr )defaults r7_get_default_countrVs' w  tOW- ..r9cD|yt|}||kDr t||y)N)current_selections_countmax_selections_count)rVr) selectionsmax_selections default_counts r7_check_max_selectionsr]s6&z2M~%4%2  &r9c VeZdZededddddfddddddd ddZededddddfddddddd ddZededddddfddddddd dd Zed dedddddfddddddd dd Zdedddddfdddddddd  dd ZeddZ y)MultiSelectMixinNFvisiblestretch)r[ placeholderdisabledlabel_visibilityaccept_new_optionswidthc yrFrQr6labelr/rU format_funckeyhelp on_changeargskwargsr[rbrcrdrerfs r7 multiselectzMultiSelectMixin.multiselects&r9Tc yrFrQrhs r7rpzMultiSelectMixin.multiselects&r9c yrFrQrhs r7rpzMultiSelectMixin.multiselects&#&r9rpc f| dk(rd} t}|j||||||||| | | | | |||S)aDisplay 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 : list or tuple An optional list or 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 or None A string to display when no options are selected. If this is ``None`` (default), the widget displays placeholder text based on the widget's configuration: - "Choose options" is displayed when options are available and ``accept_new_options=False``. - "Choose or add options" is displayed when options are available and ``accept_new_options=True``. - "Add options" is displayed when no options are available and ``accept_new_options=True``. - "No options to select" is displayed when no options are available and ``accept_new_options=False``. The widget is also disabled in this case. 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 aligned with other widgets. If this is ``"collapsed"``, Streamlit displays no label or spacer. accept_new_options : bool Whether the user can add selections that aren't included in ``options``. If this is ``False`` (default), the user can only select from the items in ``options``. If this is ``True``, the user can enter new items that don't exist in ``options``. When a user enters and selects a new item, it is included in the widget's returned list as a string. The new item is not added to the widget's drop-down menu. Streamlit will use a case-insensitive match from ``options`` before adding a new item, and a new item can't be added if a case-insensitive match is already selected. The ``max_selections`` argument is still enforced. width : "stretch" or int The width of the multiselect widget. This can be one of the following: - ``"stretch"`` (default): The width of the widget matches the width of the parent container. - An integer specifying the width in pixels: The widget has a fixed width. If the specified width is greater than the width of the parent container, the width of the widget matches the width of the parent container. Returns ------- list A list of the selected options. The list contains copies of the selected options, not the originals. Examples -------- **Example 1: Use a basic multiselect widget** You can declare one or more initial selections with the ``default`` parameter. >>> import streamlit as st >>> >>> options = st.multiselect( ... "What are your favorite colors?", ... ["Green", "Yellow", "Red", "Blue"], ... default=["Yellow", "Red"], ... ) >>> >>> st.write("You selected:", options) .. output:: https://doc-multiselect.streamlit.app/ height: 350px **Example 2: Let users to add new options** To allow users to enter and select new options that aren't included in the ``options`` list, use the ``accept_new_options`` parameter. To prevent users from adding an unbounded number of new options, use the ``max_selections`` parameter. >>> import streamlit as st >>> >>> options = st.multiselect( ... "What are your favorite cat names?", ... ["Jellybeans", "Fish Biscuit", "Madam President"], ... max_selections=5, ... accept_new_options=True, ... ) >>> >>> st.write("You selected:", options) .. output:: https://doc-multiselect-accept-new-options.streamlit.app/ height: 350px  )rir/rUrjrkrlrmrnror[rbrcrdrerfctx)r# _multiselect)r6rir/rUrjrkrlrmrnror[rbrcrdrerfrvs r7rpzMultiSelectMixin.multiselectsb@ " K "  #)#-1!!  r9)r[rbrcrdrerfrvc &t|}d}t|j|||t|| t |}t ||\}}t ||}| dk(rd} t|j}t||hd|j||||| | || }t}||_ ||jdd||_ | |_ ||_| xsd|_| xsd|_t#| |j$_||j(dd|t+||_||_t1||||}t3|j||| |j4|j6|d }t9|j&| t;|||}|j<r/|j7|j&|j>ddd |_ tC|tE| }|r tG||||jjI||| |j&S)Nrp) default_valuertru>r/rjr[re) user_keykey_as_main_identitydgrir/rUrlr[rbrerfr)r1r3r4string_array_value)on_change_handlerrnro deserializer serializerrv value_typeT)rf) layout_config)%rrr|rrrrrrMultiSelectProtoidrUform_idrcrir[rbrrdr?r/rrlrer-r$rIrDr]r value_changed raw_values set_valuerrr_enqueue)r6rir/rUrjrkrlrmrnror[rbrcrdrerfrv widget_nameindexable_optionsr1r3default_valuesr element_idprotoserde widget_staters r7rwzMultiSelectMixin._multiselects*(Sk#  GG  !  #5*:;DWM>M {? ;;-->H " K!$''*4  " ww%")#1+ 0!") a ! -2'-2'G ( $- a  EJ#5  /-M$2  ' HH'**+   l00.A1 '#4   % %"'//,2D2D"EE  Q "EOu$51  j+ > e=I!!!r9ctd|S)zGet our DeltaGenerator.r')r )r6s r7r|zMultiSelectMixin.dg;s$d++r9) rir;r/OptionSequence[T]rU Any | NonerjCallable[[Any], str]rk Key | Nonerl str | NonermWidgetCallback | NonernWidgetArgs | NoneroWidgetKwargs | Noner[ int | NonerbrrcboolrdrrezLiteral[False]rfrrJzlist[T]) rir;r/rrUrrjrrkrrlrrmrrnrrorr[rrbrrcrrdrrez Literal[True]rfrrJz list[T | str]) rir;r/rrUrrjrrkrrlrrmrrnrrorr[rrbrrcrrdrrerrfrrJlist[T] | list[T | str]) rir;r/rrUrrjrrkrrlrrmrrnrrorr[rrbrrcrrdrrezLiteral[False, True] | boolrfrrJr)"rir;r/rrUrrjrrkrrlrrmrrnrrorr[rrbrrcrrdrrerrfrrvzScriptRunContext | NonerJr)rJr') rMrNrOr r;rpr!rwpropertyr|rQr9r7r_r_s #,/+/"&&*&*"&,5-2%.##  *   ) $# * +!"##$ %( #,/+/"&&*&*"&,5,0%.##  *   ) $# * *!"##$ %( #,/+/"&&*&&*"&,5#(%.#&&#& & * &  &&)& &$&#& &&*& !!&"##&$ !%&&(M" #,/+/"&&*T &*"&,5:?%.#T T #T  T * T  T T )T  T $T #T  T T *T 8!T "##T $ !%T #T t#,/+/"&&*z"&*"&,5#(%.'+%z"z"#z" z" * z"  z"z")z" z"$z"#z" z"z"*z" !!z""##z"$%%z"& !'z"x,,r9r_N)rUSequence[Any] | Any | NonerJint)rZrr[rrJrK)? __future__rcollections.abcrtextwraprtypingrrrr r r r streamlit.dataframe_utilr r!streamlit.elements.lib.form_utilsr#streamlit.elements.lib.layout_utilsrrr-streamlit.elements.lib.options_selector_utilsrrrrstreamlit.elements.lib.policiesrrstreamlit.elements.lib.utilsrrrrrrstreamlit.errorsrstreamlit.proto.MultiSelect_pb2r rstreamlit.runtime.metrics_utilr!streamlit.runtime.scriptrunnerr"r#streamlit.runtime.stater$streamlit.type_utilr%r&streamlit.delta_generatorr'r(r)r*r+r-rVr]r_rQr9r7rs#$N=  L9O3278  CLAwqzAH/  *