
    &e/                    \   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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- d dl.m/Z/ erd dl0m1Z1 e G d de
e)                               Z2 G d d          Z3dS )    )annotations)	dataclass)dedent)TYPE_CHECKINGAnyCallableGenericSequencecast)current_form_id)check_callback_rulescheck_session_state_rules get_label_visibility_proto_valuemaybe_coerce_enum)StreamlitAPIException)Radio)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsregister_widget)compute_widget_id)KeyLabelVisibilityOptionSequenceTcheck_python_comparableensure_indexablemaybe_raise_label_warningsto_key)index_)DeltaGeneratorc                  8    e Zd ZU ded<   ded<   ddZ	 dddZdS )
RadioSerdezSequence[T]options
int | Noneindexvobjectreturnc                h    |d S t          | j                  dk    rdnt          | j        |          S Nr   )lenr'   r#   )selfr*   s     @lib/python3.11/site-packages/streamlit/elements/widgets/radio.py	serializezRadioSerde.serialize<   s6    94%%**qqt|Q0G0GG     ui_value	widget_idstrT | Nonec                    ||n| j         }|2t          | j                  dk    r| j        |         | j        |         nd S r.   )r)   r/   r'   )r0   r5   r6   idxs       r1   deserializezRadioSerde.deserializeB   sV    
 #.hhDJ DL!!A%%S!- L 	
r3   N)r*   r+   r,   r(   )r4   )r5   r(   r6   r7   r,   r8   )__name__
__module____qualname____annotations__r2   r;    r3   r1   r&   r&   7   sd         H H H H 
 
 
 
 
 
 
r3   r&   c                      e Zd Z ed          dedddddfdddddd)d"            Zdedddddfddddd#d*d&Zed+d(            ZdS ),
RadioMixinradior   NFvisible)disabled
horizontalcaptionslabel_visibilitylabelr7   r'   OptionSequence[T]r)   r(   format_funcCallable[[Any], Any]key
Key | Nonehelp
str | None	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | NonerE   boolrF   rG   Sequence[str] | NonerH   r   r,   r8   c
               d    t                      }|                     |||||||||	|
||||          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 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.

            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. Multiple widgets of the same type may
            not share the same key.
        help : str
            An optional tooltip that gets displayed next to the radio.
        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, which 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. 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
        -------
        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

        )rI   r'   r)   rK   rM   rO   rQ   rS   rU   rE   rF   rG   rH   ctx)r   _radio)r0   rI   r'   r)   rK   rM   rO   rQ   rS   rU   rE   rF   rG   rH   rZ   s                  r1   rC   zRadioMixin.radioS   sU    H !""{{#!-  
 
 	
r3   )rE   rF   rH   rG   rZ   ScriptRunContext | Nonec
                  t          |          }t          | j        |           t          |dk    rd n||           t	          ||           t          |          }t          |           t          d||fd|D             |||||t          | j                  |r|j	        nd           }t          |t                    s&|$t          dt          |          j        z            |>t          |          dk    r+d|cxk    rt          |          k     sn t          d          dd}t!                      }||_        ||_        |||_        fd|D             |j        d d <   t          | j                  |_        ||_        |
|_        t1          |          |j        _        |t7          ||          |j        d d <   |t;          |          |_        t?          ||          }tA          d|||||	|j!        |j"        |	  	        }tG          |||          }|j$        r1|j        #|"                    |j                  }|||_        d|_%        | j        &                    d|           |j        S )Nr   )default_valuerM   rC   c                @    g | ]}t           |                    S r@   r7   .0optionrK   s     r1   
<listcomp>z%RadioMixin._radio.<locals>.<listcomp>  s+    @@@&SV,,--@@@r3   )
user_keyrI   r'   r)   rM   rO   rF   rG   form_idpagez Radio Value has invalid type: %sz3Radio index must be between 0 and length of optionscaptionrP   r,   r7   c                    | dS t          | t                    r| S t          dt          |           j                   )Nr4   z-Radio captions must be strings. Passed type: )
isinstancer7   r   typer<   )rh   s    r1   handle_captionsz*RadioMixin._radio.<locals>.handle_captions  sI    rGS)) +\DMMDZ\\  r3   c                @    g | ]}t           |                    S r@   r`   ra   s     r1   rd   z%RadioMixin._radio.<locals>.<listcomp>)  s+    !M!M!Mv#kk&&9&9":":!M!M!Mr3   )re   on_change_handlerrS   rU   deserializer
serializerrZ   T)rh   rP   r,   r7   )'r"   r   dgr   r!   r    r   r   r   page_script_hashrj   intr   rk   r<   r/   
RadioProtoidrI   defaultr'   rf   rF   rE   r   rH   valuemaprG   r   rO   r&   r   r;   r2   r   value_changed	set_value_enqueue)r0   rI   r'   r)   rK   rM   rO   rQ   rS   rU   rE   rF   rH   rG   rZ   optru   rl   radio_protoserdewidget_stateserialized_values       `                 r1   r[   zRadioMixin._radio   s   $ SkkTWi000!

SVWWWW"5*:;;;w''$$$@@@@C@@@!#DG,,),6%%$
 
 
 %%% 	%*;'2T%[[5II   SAa56K6K6K6K3s886K6K6K6K'E  	 	 	 	 !ll!"'K!M!M!M!M!M!M!MAAA-dg66!+'-M.
 .
$* &)/8&D&DK #%d||K3&&&'*

 

 

 )wDD% 	)!-#(??<3E#F#F #/(8K%$(K!+...!!r3   'DeltaGenerator'c                "    t          d|           S )zGet our DeltaGenerator.r$   )r   )r0   s    r1   rq   zRadioMixin.dgP  s     $d+++r3   )rI   r7   r'   rJ   r)   r(   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rE   rW   rF   rW   rG   rX   rH   r   r,   r8   )rI   r7   r'   rJ   r)   r(   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rE   rW   rF   rW   rH   r   rG   rX   rZ   r\   r,   r8   )r,   r   )	r<   r=   r>   r   r7   rC   r[   propertyrq   r@   r3   r1   rB   rB   R   s        ^G
 ,/+/"&&*S
  )-,5S
 S
 S
 S
 S
 S
r ,/+/"&&*e"  ,5)-e" e" e" e" e" e"N , , , X, , ,r3   rB   N)4
__future__r   dataclassesr   textwrapr   typingr   r   r   r	   r
   r   streamlit.elements.formr   streamlit.elements.utilsr   r   r   r   streamlit.errorsr   streamlit.proto.Radio_pb2r   rt   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"   streamlit.utilr#   streamlit.delta_generatorr$   r&   rB   r@   r3   r1   <module>r      sc   # " " " " " ! ! ! ! ! !       H H H H H H H H H H H H H H H H 3 3 3 3 3 3            3 2 2 2 2 2 9 9 9 9 9 9 9 9 9 9 9 9 O O O O O O O O            = < < < < <	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 " ! ! ! ! ! 9888888 
 
 
 
 
 
 
 
4A, A, A, A, A, A, A, A, A, A,r3   