U
    ARdM                     @   s   d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZmZ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mZmZmZ erd dl m!Z! eG dd dZ"G dd dZ#dS )    )	dataclass)dedent)TYPE_CHECKINGOptionalcast)current_form_id)check_callback_rulescheck_session_state_rules get_label_visibility_proto_value)Checkbox)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsregister_widget)KeyLabelVisibilitymaybe_raise_label_warningsto_key)DeltaGeneratorc                   @   s>   e Zd ZU eed< eedddZd
ee eedddZd	S )CheckboxSerdevalue)vreturnc                 C   s   t |S N)bool)selfr    r   ?/tmp/pip-unpacked-wheel-b9et7o5g/streamlit/elements/checkbox.py	serialize,   s    zCheckboxSerde.serialize )ui_value	widget_idr   c                 C   s   t |d k	r|n| jS r   )r   r   )r   r#   r$   r   r   r    deserialize/   s    zCheckboxSerde.deserializeN)r"   )	__name__
__module____qualname__r   __annotations__r!   r   strr%   r   r   r   r    r   (   s   
r   c                   @   s   e Zd Zedddddeeee ee ee ee	 ee
 eeed
ddZddddd	eeee ee ee ee	 ee
 eeee ed
ddZeddddZdS )CheckboxMixincheckboxFNZvisible)disabledlabel_visibility)
labelr   keyhelp	on_changeargskwargsr-   r.   r   c                C   s$   t  }
| j|||||||||	|
d
S )a  Display a checkbox widget.

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

            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``.
        value : bool
            Preselect the checkbox when it first renders. This will be
            cast to bool internally.
        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 checkbox.
        on_change : callable
            An optional callback invoked when this checkbox'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 checkbox if set to True.
            The default is False. This argument can only be supplied by keyword.
        label_visibility : "visible" or "hidden" or "collapsed"
            The visibility of the label. If "hidden", the label doesn't show but there
            is still empty space for it (equivalent to label="").
            If "collapsed", both the label and the space are removed. Default is
            "visible". This argument can only be supplied by keyword.

        Returns
        -------
        bool
            Whether or not the checkbox is checked.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> agree = st.checkbox('I agree')
        >>>
        >>> if agree:
        ...     st.write('Great!')

        .. output::
           https://doc-checkbox.streamlitapp.com/
           height: 220px

        )
r/   r   r0   r1   r2   r3   r4   r-   r.   ctx)r   	_checkbox)r   r/   r   r0   r1   r2   r3   r4   r-   r.   r5   r   r   r    r,   4   s    TzCheckboxMixin.checkbox)r-   r.   r5   )r/   r   r0   r1   r2   r3   r4   r-   r.   r5   r   c                C   s   t |}t| j| t|dkr"d n||d t||	 t }||_t||_t	| j|_
|d k	rjt||_t|}td||||||j|j|
d	}||_t|	|j_|jr|j|_d|_| jd| |jS )NF)default_valuer0   r,   )Zuser_keyZon_change_handlerr3   r4   Zdeserializer
serializerr5   T)r   r   dgr	   r   CheckboxProtor/   r   defaultr   Zform_idr   r1   r   r   r%   r!   r-   r
   r.   r   value_changed	set_valueZ_enqueue)r   r/   r   r0   r1   r2   r3   r4   r-   r.   r5   Zcheckbox_protoZserdeZcheckbox_stater   r   r    r6      sD     


zCheckboxMixin._checkboxr   )r   c                 C   s
   t d| S )zGet our DeltaGenerator.r   )r   )r   r   r   r    r9      s    zCheckboxMixin.dg)FNNNNN)FNNNNN)r&   r'   r(   r   r*   r   r   r   r   r   r   r   r,   r   r6   propertyr9   r   r   r   r    r+   3   s^         
d      
9r+   N)$Zdataclassesr   textwrapr   typingr   r   r   Zstreamlit.elements.formr   Zstreamlit.elements.utilsr   r	   r
   Zstreamlit.proto.Checkbox_pb2r   r:   Zstreamlit.runtime.metrics_utilr   Zstreamlit.runtime.scriptrunnerr   r   Zstreamlit.runtime.stater   r   r   r   Zstreamlit.type_utilr   r   r   r   Zstreamlit.delta_generatorr   r   r+   r   r   r   r    <module>   s   
