o
    沪g6                     @  sF  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mZ d dlmZ d dl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,m-Z-m.Z. d dl/m0Z0m1Z1 erd dl2m3Z3 d dl4m5Z5 eG dd de
e0 Z6G dd dZ7dS )    )annotations)	dataclass)dedent)TYPE_CHECKINGAnyCallableGenericcastoverload)OptionSequenceconvert_anything_to_list)current_form_id)index_maybe_coerce_enum)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)Radio)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsget_session_stateregister_widget)Tcheck_python_comparable)Sequence)DeltaGeneratorc                   @  s6   e Zd ZU ded< ded< ddd	Z	
ddddZdS )
RadioSerdezSequence[T]options
int | Noneindexvobjectreturnc                 C  s*   |d u rd S t | jdkrdS t| j|S Nr   )lenr'   r   )selfr*    r0   \/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/elements/widgets/radio.py	serialize?   s   zRadioSerde.serialize ui_value	widget_idstrT | Nonec                 C  sD   |d ur|n| j }|d ur t| jdkr | j| d ur | j| S d S r-   )r)   r.   r'   )r/   r4   r5   idxr0   r0   r1   deserializeE   s   zRadioSerde.deserializeN)r*   r+   r,   r(   )r3   )r4   r(   r5   r6   r,   r7   )__name__
__module____qualname____annotations__r2   r9   r0   r0   r0   r1   r&   :   s   
 
	r&   c                   @  s   e Zd Zededddddfdddddd1d!d"Zeedddddfdddddd2d%d"Zed&dedddddfdddddd3d(d"Zdedddddfddddd)d4d,d-Zed5d/d0Z	dS )6
RadioMixinr   NFvisible)disabled
horizontalcaptionslabel_visibilitylabelr6   r'   OptionSequence[T]r)   intformat_funcCallable[[Any], Any]key
Key | Nonehelp
str | None	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | Noner@   boolrA   rB   Sequence[str] | NonerC   r   r,   r"   c
                C     d S Nr0   r/   rD   r'   r)   rG   rI   rK   rM   rO   rQ   r@   rA   rB   rC   r0   r0   r1   radioV      zRadioMixin.radioNoner7   c
                C  rU   rV   r0   rW   r0   r0   r1   rX   i   rY   rX   r(   c
                C  s,   t  }| j|||||||||	|
||||dS )a  Display a radio button widget.

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

            Labels can include markdown as described in the ``label`` parameter
            and will be cast to str internally by default.

        index : int or None
            The index of the preselected option on first render. If ``None``,
            will initialize empty and return ``None`` until the user selects an option.
            Defaults to 0 (the first option).

        format_func : function
            Function to modify the display of radio 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 radio.

        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 radio'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 radio button if set to
            ``True``. The default is ``False``.

        horizontal : bool
            An optional boolean, which orients the radio group horizontally.
            The default is false (vertical buttons).

        captions : iterable of str or None
            A list of captions to show below each radio button. If None (default),
            no captions are shown.

        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
            The selected option or ``None`` if no option is selected.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> genre = st.radio(
        ...     "What's your favorite movie genre",
        ...     [":rainbow[Comedy]", "***Drama***", "Documentary :movie_camera:"],
        ...     captions=[
        ...         "Laugh out loud.",
        ...         "Get the popcorn.",
        ...         "Never stop learning.",
        ...     ],
        ... )
        >>>
        >>> if genre == ":rainbow[Comedy]":
        ...     st.write("You selected comedy.")
        ... else:
        ...     st.write("You didn't select comedy.")

        .. output::
           https://doc-radio.streamlit.app/
           height: 300px

        To initialize an empty radio widget, use ``None`` as the index value:

        >>> import streamlit as st
        >>>
        >>> genre = st.radio(
        ...     "What's your favorite movie genre",
        ...     [":rainbow[Comedy]", "***Drama***", "Documentary :movie_camera:"],
        ...     index=None,
        ... )
        >>>
        >>> st.write("You selected:", genre)

        .. output::
           https://doc-radio-empty.streamlit.app/
           height: 300px

        )rD   r'   r)   rG   rI   rK   rM   rO   rQ   r@   rA   rB   rC   ctx)r   _radio)r/   rD   r'   r)   rG   rI   rK   rM   rO   rQ   r@   rA   rB   rC   r[   r0   r0   r1   rX   |   s$    )r@   rA   rC   rB   r[   ScriptRunContext | Nonec
                  s  t |}t| j|||dkrd n|d t|| t|}t| td|t| j| fdd|D ||||d	}t|t	sI|d urIt
dt|j |d urgt|dkrgd|  krbt|k sgt
d t
dddd}t j}|d ur||v r|| d u rd }t }||_||_|d ur||_ fdd|D |jd d < t| j|_||_|
|_t||j_|d urt|||jd d < |d urt||_t||}t |j|||	|j!|j"|dd}t#|||}|j$r|jd ur|"|j}|d ur||_d|_%|rt&||  | j'd| |jS )Nr   )default_valuerX   c                      g | ]}t  |qS r0   r6   .0optionrG   r0   r1   
<listcomp>H      z%RadioMixin._radio.<locals>.<listcomp>)user_keyform_idrD   r'   r)   rK   rA   rB   z Radio Value has invalid type: %sz3Radio index must be between 0 and length of optionscaptionrL   r,   r6   c                 S  s.   | d u rdS t | tr| S tdt| j )Nr3   z-Radio captions must be strings. Passed type: )
isinstancer6   r   typer:   )ri   r0   r0   r1   handle_captionsY  s   
z*RadioMixin._radio.<locals>.handle_captionsc                   r_   r0   r`   ra   rd   r0   r1   re   l  rf   	int_value)on_change_handlerrO   rQ   deserializer
serializerr[   
value_typeT)ri   rL   r,   r6   )(r   r   dgr   r   r#   r   r   rj   rF   r   rk   r:   r.   r    filtered_state
RadioProtoidrD   defaultr'   rh   rA   r@   r   rC   valuemaprB   r   rK   r&   r!   r9   r2   r   value_changed	set_valuer   _enqueue)r/   rD   r'   r)   rG   rI   rK   rM   rO   rQ   r@   rA   rC   rB   r[   opt
element_idrl   session_stateradio_protoserdewidget_stateserialized_valuer0   rd   r1   r\   $  s   
*





zRadioMixin._radior%   c                 C  s
   t d| S )zGet our DeltaGenerator.r%   )r	   )r/   r0   r0   r1   rr     s   
zRadioMixin.dg)rD   r6   r'   rE   r)   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   r@   rS   rA   rS   rB   rT   rC   r   r,   r"   )rD   r6   r'   rE   r)   rZ   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   r@   rS   rA   rS   rB   rT   rC   r   r,   r7   )rD   r6   r'   rE   r)   r(   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   r@   rS   rA   rS   rB   rT   rC   r   r,   r7   )rD   r6   r'   rE   r)   r(   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   r@   rS   rA   rS   rC   r   rB   rT   r[   r]   r,   r7   )r,   r%   )
r:   r;   r<   r
   r6   rX   r   r\   propertyrr   r0   r0   r0   r1   r>   U   st     ,pr>   N)8
__future__r   dataclassesr   textwrapr   typingr   r   r   r   r	   r
   streamlit.dataframe_utilr   r   !streamlit.elements.lib.form_utilsr   -streamlit.elements.lib.options_selector_utilsr   r   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   r   streamlit.errorsr   streamlit.proto.Radio_pb2r   rt   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   r   r   r    r!   streamlit.type_utilr"   r#   collections.abcr$   streamlit.delta_generatorr%   r&   r>   r0   r0   r0   r1   <module>   s*     