o
    沪g;                     @  sh  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 d dlmZ d dl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-m.Z.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5 erd dl6m7Z7 d dl8m9Z9 dddZ:eG dd de
e4 Z;G dd dZ<dS )     )annotations)	dataclass)dedent)TYPE_CHECKINGAnyCallableGenericcastoverload)	TypeGuard)OptionSequenceconvert_anything_to_list)current_form_id)index_maybe_coerce_enum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)StreamlitAPIException)Slider)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsregister_widget)RegisterWidgetResult)Tcheck_python_comparable)Sequence)DeltaGeneratorvalueT | Sequence[T]returnTypeGuard[Sequence[T]]c                 C  s   t | ttfS N)
isinstancelisttuple)r(    r0   d/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/elements/widgets/select_slider.py_is_range_valueF   s   r2   c                   @  sH   e Zd ZU ded< ded< ded< dd
dZ	ddddZdddZdS )SelectSliderSerdezSequence[T]options	list[int]r(   boolis_range_valuevobjectr*   c                 C  s
   |  |S r,   )_as_index_list)selfr8   r0   r0   r1   	serializeP   s   
zSelectSliderSerde.serialize ui_valuelist[int] | None	widget_idstrT | tuple[T, T]c                   s@   |s j }ttttf t fdd|D } jr|S |d S )Nc                 3  s    | ]
} j t| V  qd S r,   )r4   int).0xr;   r0   r1   	<genexpr>_   s    z0SelectSliderSerde.deserialize.<locals>.<genexpr>r   )r(   r	   r/   r$   r7   )r;   r>   r@   return_valuer0   rF   r1   deserializeS   s   
zSelectSliderSerde.deserializec                   sD   t |r fdd|D }|\}}||kr||g}|S t j|gS )Nc                   s   g | ]}t  j|qS r0   )r   r4   rD   valrF   r0   r1   
<listcomp>g       z4SelectSliderSerde._as_index_list.<locals>.<listcomp>)r2   r   r4   )r;   r8   slider_valuestartendr0   rF   r1   r:   e   s   z SelectSliderSerde._as_index_listNr8   r9   r*   r5   )r=   )r>   r?   r@   rA   r*   rB   )__name__
__module____qualname____annotations__r<   rI   r:   r0   r0   r0   r1   r3   J   s   
 
r3   c                   @  s   e Zd Zeedddddfdddd.ddZeddedddddfdddd/d"dZed#ddedddddfdddd0d&dZddeddddddddfd1d)d*Zed2d,d-Z	dS )3SelectSliderMixinNFvisible)disabledlabel_visibilitylabelrA   r4   OptionSequence[T]r(   tuple[T, T] | list[T]format_funcCallable[[Any], Any]key
Key | Nonehelp
str | None	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | NonerX   r6   rY   r   r*   tuple[T, T]c
                C     d S r,   r0   r;   rZ   r4   r(   r]   r_   ra   rc   re   rg   rX   rY   r0   r0   r1   select_sliderq      zSelectSliderMixin.select_sliderr0   T | Noner$   c
                C  rj   r,   r0   rk   r0   r0   r1   rl      rm   rl   T | Sequence[T] | NonerB   c
                C  s(   t  }| j|||||||||	|
||dS )aI  
        Display a slider widget to select items from a list.

        This also allows you to render a range slider by passing a two-element
        tuple or list as the ``value``.

        The difference between ``st.select_slider`` and ``st.slider`` is that
        ``select_slider`` accepts any datatype and takes an iterable set of
        options, while ``st.slider`` only accepts numerical or date/time data and
        takes a range as input.

        Parameters
        ----------
        label : str
            A short label explaining to the user what this slider 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.

        value : a supported type or a tuple/list of supported types or None
            The value of the slider when it first renders. If a tuple/list
            of two values is passed here, then a range slider with those lower
            and upper bounds is rendered. For example, if set to `(1, 10)` the
            slider will have a selectable range between 1 and 10.
            Defaults to first option.

        format_func : function
            Function to modify the display of the labels from the options.
            argument. 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. 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 select_slider'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.

        disabled : bool
            An optional boolean that disables the select slider 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 value or tuple of any value
            The current value of the slider widget. The return type will match
            the data type of the value parameter.

        Examples
        --------
        >>> import streamlit as st
        >>>
        >>> color = st.select_slider(
        ...     "Select a color of the rainbow",
        ...     options=[
        ...         "red",
        ...         "orange",
        ...         "yellow",
        ...         "green",
        ...         "blue",
        ...         "indigo",
        ...         "violet",
        ...     ],
        ... )
        >>> st.write("My favorite color is", color)

        And here's an example of a range select slider:

        >>> import streamlit as st
        >>>
        >>> start_color, end_color = st.select_slider(
        ...     "Select a range of color wavelength",
        ...     options=[
        ...         "red",
        ...         "orange",
        ...         "yellow",
        ...         "green",
        ...         "blue",
        ...         "indigo",
        ...         "violet",
        ...     ],
        ...     value=("red", "blue"),
        ... )
        >>> st.write("You selected wavelengths between", start_color, "and", end_color)

        .. output::
           https://doc-select-slider.streamlit.app/
           height: 450px

        )rZ   r4   r(   r]   r_   ra   rc   re   rg   rX   rY   ctx)r   _select_slider)r;   rZ   r4   r(   r]   r_   ra   rc   re   rg   rX   rY   rp   r0   r0   r1   rl      s     rp   ScriptRunContext | Nonec              
     s  t |}t| j||d t|| t|t tdkr$tddfdd	}|}td
|t	| j| fddD ||d}t
 }||_t
jj|_||_d|_||jd d < d|_td |_d|_t
j|_ fddD |jd d < t	| j|_|
|_t||j_|d urt||_t|t }t!|j|||	|j"|j#|dd}t$|jt%rt&t't(t%t)t)f  ||}nt*||}|j+r|#|j|jd d < d|_,|rt-||  | j.d| |jS )N)default_valuer   z,The `options` argument needs to be non-emptyr8   r9   r*   r5   c                   sh   t | r fdd| D }|\}}||kr||g}|S zt | gW S  ty3   d ur. dg Y S w )Nc                   s   g | ]}t  |qS r0   )r   rJ   )optr0   r1   rL   f  s    zKSelectSliderMixin._select_slider.<locals>.as_index_list.<locals>.<listcomp>r   )r2   r   
ValueError)r8   rN   rO   rP   )rt   r(   r0   r1   as_index_listd  s   
z7SelectSliderMixin._select_slider.<locals>.as_index_listrl   c                      g | ]}t  |qS r0   rA   rD   optionr]   r0   r1   rL   }  rM   z4SelectSliderMixin._select_slider.<locals>.<listcomp>)user_keyform_idrZ   r4   r(   ra   z%s   c                   rw   r0   rx   ry   r{   r0   r1   rL     rM   double_array_value)on_change_handlerre   rg   deserializer
serializerrp   
value_typeTsliderrQ   )/r   r   dgr   r   r%   lenr   r   r   SliderProtoidTypeSELECT_SLIDERtyperZ   formatdefaultminmaxstepINT	data_typer4   r}   rX   r   rY   r(   r   ra   r3   r2   r"   rI   r<   r-   r/   r   r	   r#   r$   r   value_changed	set_valuer   _enqueue)r;   rZ   r4   r(   r]   r_   ra   rc   re   rg   rX   rY   rp   rv   rN   
element_idslider_protoserdewidget_stater0   )r]   rt   r(   r1   rq   E  s   




z SelectSliderMixin._select_sliderr'   c                 C  s
   t d| S )zGet our DeltaGenerator.r'   )r	   rF   r0   r0   r1   r     s   
zSelectSliderMixin.dg)rZ   rA   r4   r[   r(   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   rX   r6   rY   r   r*   ri   )rZ   rA   r4   r[   r(   rn   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   rX   r6   rY   r   r*   r$   )rZ   rA   r4   r[   r(   ro   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   rX   r6   rY   r   r*   rB   )rZ   rA   r4   r[   r(   ro   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   rh   rX   r6   rY   r   rp   rr   r*   rB   )r*   r'   )
rR   rS   rT   r
   rA   rl   r   rq   propertyr   r0   r0   r0   r1   rV   p   sj     )mrV   N)r(   r)   r*   r+   )=
__future__r   dataclassesr   textwrapr   typingr   r   r   r   r	   r
   typing_extensionsr   streamlit.dataframe_utilr   r   !streamlit.elements.lib.form_utilsr   -streamlit.elements.lib.options_selector_utilsr   r   r   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   r   streamlit.errorsr   streamlit.proto.Slider_pb2r   r   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   r    r!   r"   streamlit.runtime.state.commonr#   streamlit.type_utilr$   r%   collections.abcr&   streamlit.delta_generatorr'   r2   r3   rV   r0   r0   r0   r1   <module>   s0    	 
%