o
    Yh=                     @  s  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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 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l0m1Z1m2Z2m3Z3m4Z4 d dl5m6Z6 erd dl7m8Z8 d dl9m:Z: d dlm;Z; d dl<m=Z= edZ>d"ddZ?eG dd de
e> Z@G dd  d ZAd!S )#    )annotations)	dataclass)dedent)TYPE_CHECKINGAnyCallableGenericTypeVarcastoverload)	TypeGuard)OptionSequenceconvert_anything_to_list)current_form_id)LayoutConfigvalidate_width)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)check_python_comparable)Sequence)DeltaGenerator)WidthWithoutContent)RegisterWidgetResultTvalueT | Sequence[T]returnTypeGuard[Sequence[T]]c                 C  s   t | ttfS N)
isinstancelisttuple)r,    r4   i/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/streamlit/elements/widgets/select_slider.py_is_range_valueI   s   r6   c                   @  sD   e Zd ZU ded< ded< ded< dd
dZ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 r0   )_as_index_list)selfr<   r4   r4   r5   	serializeS   s   
zSelectSliderSerde.serializeui_valuelist[int] | NoneT | tuple[T, T]c                   s8   |s j }tdt fdd|D } jr|S |d S )Ntuple[T, T]c                 3  s    | ]
} j t| V  qd S r0   )r8   int).0xr?   r4   r5   	<genexpr>^   s    z0SelectSliderSerde.deserialize.<locals>.<genexpr>r   )r,   r
   r3   r;   )r?   rA   return_valuer4   rH   r5   deserializeV   s   zSelectSliderSerde.deserializer   c                   sD   t |r fdd|D }|\}}||kr||g}|S t j|gS )Nc                   s   g | ]}t  j|qS r4   )r   r8   rF   valrH   r4   r5   
<listcomp>f       z4SelectSliderSerde._as_index_list.<locals>.<listcomp>)r6   r   r8   )r?   r<   slider_valuestartendr4   rH   r5   r>   d   s   z SelectSliderSerde._as_index_listN)r<   r=   r.   r9   )rA   rB   r.   rC   r<   r   r.   r9   )__name__
__module____qualname____annotations__r@   rK   r>   r4   r4   r4   r5   r7   M   s   
 

r7   c                   @  s   e Z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ed&d"dedddddfddddd3d)d!Zd"dedddddddddfd4d,d-Zed5d/d0Z	dS )6SelectSliderMixinNFvisiblestretch)disabledlabel_visibilitywidthlabelstrr8   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 | Noner[   r:   r\   r   r]   r)   r.   rD   c
                C     d S r0   r4   r?   r^   r8   r,   rb   rd   rf   rh   rj   rl   r[   r\   r]   r4   r4   r5   select_slidero      zSelectSliderMixin.select_sliderr4   T | Noner+   c
                C  rn   r0   r4   ro   r4   r4   r5   rp      rq   rp   T | Sequence[T] | NonerC   c
                C  s*   t  }| j|||||||||	|
|||dS )a[  
        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 : 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.

        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 aligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        width : "stretch" or int
            The width of the slider 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
        -------
        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

        )r^   r8   r,   rb   rd   rf   rh   rj   rl   r[   r\   ctxr]   )r!   _select_slider)r?   r^   r8   r,   rb   rd   rf   rh   rj   rl   r[   r\   r]   rt   r4   r4   r5   rp      s"    #rt   ScriptRunContext | Nonec              
     s  t |}t| j||d t|| t|t tdkr$tddfdd	}|}td
|| 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 |d}t!|t"}t#|j
|||	|j$|j%|dd}t&|jt'rt(t)d||}nt*||}|j+r|%|j|jd d < d|_,|rt-||  | jj.d||d |jS )N)default_valuer   z,The `options` argument needs to be non-emptyr<   r   r.   r9   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 r4   )r   rL   )optr4   r5   rN   h  s    zKSelectSliderMixin._select_slider.<locals>.as_index_list.<locals>.<listcomp>r   )r6   r   
ValueError)r<   rP   rQ   rR   )rx   r,   r4   r5   as_index_listf  s   
z7SelectSliderMixin._select_slider.<locals>.as_index_listrp   c                      g | ]}t  |qS r4   r_   rF   optionrb   r4   r5   rN   ~  rO   z4SelectSliderMixin._select_slider.<locals>.<listcomp>)user_keydgr^   r8   r,   rf   r]   z%s   c                   r{   r4   r|   r}   r   r4   r5   rN     rO   )r]   double_array_value)on_change_handlerrj   rl   deserializer
serializerrt   
value_typez!RegisterWidgetResult[tuple[T, T]]Tslider)layout_configrS   )/r   r   r   r   r   r&   lenr   r   SliderProtoidTypeSELECT_SLIDERtyper^   formatdefaultminmaxstepINT	data_typer8   r   form_idr[   r   r\   r,   r   rf   r   r   r7   r6   r%   rK   r@   r1   r3   r   r
   r   value_changed	set_valuer   _enqueue)r?   r^   r8   r,   rb   rd   rf   rh   rj   rl   r[   r\   rt   r]   rz   rP   
element_idslider_protor   serdewidget_stater4   )rb   rx   r,   r5   ru   F  s   




z SelectSliderMixin._select_sliderr(   c                 C  s
   t d| S )zGet our DeltaGenerator.r(   )r
   rH   r4   r4   r5   r     s   
zSelectSliderMixin.dg)r^   r_   r8   r`   r,   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   r[   r:   r\   r   r]   r)   r.   rD   )r^   r_   r8   r`   r,   rr   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   r[   r:   r\   r   r]   r)   r.   r+   )r^   r_   r8   r`   r,   rs   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   r[   r:   r\   r   r]   r)   r.   rC   )r^   r_   r8   r`   r,   rs   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   r[   r:   r\   r   rt   rv   r]   r)   r.   rC   )r.   r(   )
rT   rU   rV   r   r_   rp   r   ru   propertyr   r4   r4   r4   r5   rX   n   sr     6qrX   N)r,   r-   r.   r/   )B
__future__r   dataclassesr   textwrapr   typingr   r   r   r   r	   r
   r   typing_extensionsr   streamlit.dataframe_utilr   r   !streamlit.elements.lib.form_utilsr   #streamlit.elements.lib.layout_utilsr   r   -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.type_utilr&   collections.abcr'   streamlit.delta_generatorr(   r)   streamlit.runtime.state.commonr*   r+   r6   r7   rX   r4   r4   r4   r5   <module>   s6   $
 
 