
    g6                        d dl mZ d dlZd dlmZ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 d dlmZ d dlmZ d d	lmZmZ erd d
lmZ d dlmZmZmZ dddZ G d d      Zy)    )annotationsN)TYPE_CHECKINGLiteralcast)FormDatacurrent_form_id
is_in_form)check_cache_replay_rulescheck_session_state_rules)StreamlitAPIException)	Block_pb2)gather_metrics)ScriptRunContextget_script_run_ctx)DeltaGenerator)
WidgetArgsWidgetCallbackWidgetKwargsc                    | t        j                  d|  d      }nt        j                  d      }|j                  d      S )Nz;
            There are multiple identical forms with `key='z'`.

            To fix this, please make sure that the `key` argument is unique for
            each `st.form` you create.
            a  
            There are multiple identical forms with the same generated key.

            When a form is created, it's assigned an internal key based on
            its structure. Multiple forms with an identical structure will
            result in the same internal key, which causes this error.

            To fix this error, please pass a unique `key` argument to
            `st.form`.
            
)textwrapdedentstrip)user_keymessages     L/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/form.py_build_duplicate_form_messager   "   sQ    //;;C* E
 //	
 ==    c                     e Zd Z ed      	 dddd	 	 	 	 	 	 	 	 	 dd       Z ed      	 	 	 	 	 dddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
       Z	 	 	 	 	 ddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZedd       Zy)	FormMixinformFT)enter_to_submitborderc                  t        | j                        rt        d      t                t	        d|d       |}t               }|@||j                  v}|r|j                  j                  |       nt        t        |            t        j                         }||j                  _        ||j                  _        ||j                  _        ||j                  _        | j                  j!                  |      }	t#        |      |	_        |	S )aT  Create a form that batches elements together with a "Submit" button.

        A form is a container that visually groups other elements and
        widgets together, and contains a Submit button. When the form's
        Submit button is pressed, all widget values inside the form will be
        sent to Streamlit in a batch.

        To add elements to a form object, you can use ``with`` notation
        (preferred) or just call methods directly on the form. See
        examples below.

        Forms have a few constraints:

        - Every form must contain a ``st.form_submit_button``.
        - ``st.button`` and ``st.download_button`` cannot be added to a form.
        - Forms can appear anywhere in your app (sidebar, columns, etc),
          but they cannot be embedded inside other forms.
        - Within a form, the only widget that can have a callback function is
          ``st.form_submit_button``.

        Parameters
        ----------
        key : str
            A string that identifies the form. Each form must have its own
            key. (This key is not displayed to the user in the interface.)
        clear_on_submit : bool
            If True, all widgets inside the form will be reset to their default
            values after the user presses the Submit button. Defaults to False.
            (Note that Custom Components are unaffected by this flag, and
            will not be reset to their defaults on form submission.)
        enter_to_submit : bool
            Whether to submit the form when a user presses Enter while
            interacting with a widget inside the form.

            If this is ``True`` (default), pressing Enter while interacting
            with a form widget is equivalent to clicking the first
            ``st.form_submit_button`` in the form.

            If this is ``False``, the user must click an
            ``st.form_submit_button`` to submit the form.

            If the first ``st.form_submit_button`` in the form is disabled,
            the form will override submission behavior with
            ``enter_to_submit=False``.

        border : bool
            Whether to show a border around the form. Defaults to True.

            .. note::
                Not showing a border can be confusing to viewers since interacting with a
                widget in the form will do nothing. You should only remove the border if
                there's another border (e.g. because of an expander) or the form is small
                (e.g. just a text input and a submit button).

        Examples
        --------
        Inserting elements using ``with`` notation:

        >>> import streamlit as st
        >>>
        >>> with st.form("my_form"):
        ...     st.write("Inside the form")
        ...     slider_val = st.slider("Form slider")
        ...     checkbox_val = st.checkbox("Form checkbox")
        ...
        ...     # Every form must have a submit button.
        ...     submitted = st.form_submit_button("Submit")
        ...     if submitted:
        ...         st.write("slider", slider_val, "checkbox", checkbox_val)
        >>> st.write("Outside the form")

        .. output::
           https://doc-form1.streamlit.app/
           height: 425px

        Inserting elements out of order:

        >>> import streamlit as st
        >>>
        >>> form = st.form("my_form")
        >>> form.slider("Inside the form")
        >>> st.slider("Outside the form")
        >>>
        >>> # Now add a submit button to the form:
        >>> form.form_submit_button("Submit")

        .. output::
           https://doc-form2.streamlit.app/
           height: 375px

        z&Forms cannot be nested in other forms.NF)default_valuekeywrites_allowed)r	   dgr   r
   r   r   form_ids_this_runaddr   r   Blockr!   form_idclear_on_submitr"   r#   _blockr   
_form_data)
selfr&   r-   r"   r#   r,   ctxnew_form_idblock_protoblock_dgs
             r   r!   zFormMixin.form>   s    H dgg'(PQQ "!#eT  "?!)>)>>K%%))'2+,I#,NOOoo'#* +:(+:("(77>>+. 'w/r   form_submit_buttonN	secondary)typeicondisableduse_container_widthc               r    t               }
|dvrt        d| d      | j                  |||||||||	|

      S )uL  Display a form submit button.

        When this button is clicked, all widget values inside the form will be
        sent from the user's browser to your Streamlit server in a batch.

        Every form must have at least one ``st.form_submit_button``. An
        ``st.form_submit_button`` cannot exist outside of a form.

        For more information about forms, check out our `docs
        <https://docs.streamlit.io/develop/concepts/architecture/forms>`_.

        Parameters
        ----------
        label : str
            A short label explaining to the user what this button is for. This
            defaults to ``"Submit"``. 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.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown
        help : str or None
            A tooltip that gets displayed when the button is hovered over. 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_click : callable
            An optional callback invoked when this button is clicked.
        args : tuple
            An optional tuple of args to pass to the callback.
        kwargs : dict
            An optional dict of kwargs to pass to the callback.
        type : "primary", "secondary", or "tertiary"
            An optional string that specifies the button type. This can be one
            of the following:

            - ``"primary"``: The button's background is the app's primary color
              for additional emphasis.
            - ``"secondary"`` (default): The button's background coordinates
              with the app's background color for normal emphasis.
            - ``"tertiary"``: The button is plain text without a border or
              background for subtly.

        icon : str or None
            An optional emoji or icon to display next to the button label. If ``icon``
            is ``None`` (default), no icon is displayed. If ``icon`` is a
            string, the following options are valid:

            - A single-character emoji. For example, you can set ``icon="🚨"``
              or ``icon="🔥"``. Emoji short codes are not supported.

            - An icon from the Material Symbols library (rounded style) in the
              format ``":material/icon_name:"`` where "icon_name" is the name
              of the icon in snake case.

              For example, ``icon=":material/thumb_up:"`` will display the
              Thumb Up icon. Find additional icons in the `Material Symbols               <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Rounded>`_
              font library.
        disabled : bool
            Whether to disable the button. If this is ``False`` (default), the
            user can interact with the button. If this is ``True``, the button
            is grayed-out and can't be clicked.

            If the first ``st.form_submit_button`` in the form is disabled,
            the form will override submission behavior with
            ``enter_to_submit=False``.

        use_container_width : bool
            Whether to expand the button's width to fill its parent container.
            If ``use_container_width`` is ``False`` (default), Streamlit sizes
            the button to fit its contents. If ``use_container_width`` is
            ``True``, the width of the button matches its parent container.

            In both cases, if the contents of the button are wider than the
            parent container, the contents will line wrap.

        Returns
        -------
        bool
            True if the button was clicked.
        )primaryr6   tertiaryztThe type argument to st.form_submit_button must be "primary", "secondary", or "tertiary". 
The argument passed was "z".)
labelhelpon_clickargskwargsr7   r8   r9   r:   r1   )r   r   _form_submit_button)r0   r>   r?   r@   rA   rB   r7   r8   r9   r:   r1   s              r   r5   zFormMixin.form_submit_button   sn    V !" ;;',,065 
 '' 3 ( 
 	
r   )r7   r8   r9   r:   r1   c                   t        | j                        }d| d| }| j                  j                  |||d|||||||	|
      S )NzFormSubmitter:-T)r>   r&   r?   is_form_submitterr@   rA   rB   r7   r8   r9   r:   r1   )r   r(   _button)r0   r>   r?   r@   rA   rB   r7   r8   r9   r:   r1   r,   submit_button_keys                r   rC   zFormMixin._form_submit_button@  sc     "$''*,WIQug>ww!" 3  
 	
r   c                    t        d|       S )zGet our DeltaGenerator.r   )r   )r0   s    r   r(   zFormMixin.dg_  s     $d++r   )F)
r&   strr-   boolr"   rK   r#   rK   returnr   )SubmitNNNN)r>   rJ   r?   
str | Noner@   WidgetCallback | NonerA   WidgetArgs | NonerB   WidgetKwargs | Noner7   +Literal['primary', 'secondary', 'tertiary']r8   rN   r9   rK   r:   rK   rL   rK   )r>   rJ   r?   rN   r@   rO   rA   rP   rB   rQ   r7   rR   r8   rN   r9   rK   r:   rK   r1   zScriptRunContext | NonerL   rK   )rL   r   )	__name__
__module____qualname__r   r!   r5   rC   propertyr(    r   r   r    r    =   s   F !&~
 !%~~ ~
 ~ ~ 
~ ~@ () *."&&*~
 =H$)~
~
 ~
 (	~

  ~
 $~
 :~
 ~
 ~
 "~
 
~
 *~
D *."&&*
 =H$)'+

 
 (	

  
 $
 :
 
 
 "
 %
 

> , ,r   r    )N)r   rN   rL   rJ   )
__future__r   r   typingr   r   r   !streamlit.elements.lib.form_utilsr   r   r	   streamlit.elements.lib.policiesr
   r   streamlit.errorsr   streamlit.protor   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.delta_generatorr   streamlit.runtime.stater   r   r   r   r    rW   r   r   <module>rb      sI    #  / / S S 3 % 9 O8PP6e, e,r   