L iTEddlmZddlZddlmZmZmZddlmZm Z m Z ddl m Z m Z mZmZmZmZddlmZmZddlmZmZddlmZdd lmZdd lmZdd lmZm Z erdd l!m"Z"dd l#m$Z$m%Z%m&Z&dddZ'GddZ(y)) annotationsN) TYPE_CHECKINGLiteralcast)FormDatacurrent_form_id is_in_form)HeightWidthget_height_configget_width_configvalidate_heightvalidate_width)check_cache_replay_rulescheck_session_state_rules)Keyto_key)StreamlitAPIException) Block_pb2)gather_metrics)ScriptRunContextget_script_run_ctx)DeltaGenerator) WidgetArgsWidgetCallback WidgetKwargsc|tjd|d}ntjd}|jdS)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`.  )textwrapdedentstrip)user_keymessages ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/elements/form.py_build_duplicate_form_messager%+sQ//;;C*E   //    == c  eZdZed dddddd ddZed dd d d dd dd  dd Z dd d d dd dd  ddZeddZy ) FormMixinformFTstretchcontent)enter_to_submitborderwidthheightct|jr tdtt d|d|}t }|@||j v} | r|j j|ntt|tj} || j_ || j_ || j_|| j_t!|d| j"j%t'|t)|d| j*j%t-||jj/| } t1|| _| S)aRCreate 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). width : "stretch", "content", or int The width of the form container. This can be one of the following: - ``"stretch"`` (default): The width of the container matches the width of the parent container. - ``"content"``: The width of the container matches the width of its content, but doesn't exceed the width of the parent container. - An integer specifying the width in pixels: The container has a fixed width. If the specified width is greater than the width of the parent container, the width of the container matches the width of the parent container. height : "content", "stretch", or int The height of the form container. This can be one of the following: - ``"content"`` (default): The height of the container matches the height of its content. - ``"stretch"``: The height of the container matches the height of its content or the height of the parent container, whichever is larger. If the container is not in a parent container, the height of the container matches the height of its content. - An integer specifying the height in pixels: The container has a fixed height. If the content is larger than the specified height, scrolling is enabled. .. note:: Use scrolling containers sparingly. If you use scrolling containers, avoid heights that exceed 500 pixels. Otherwise, the scroll surface of the container might cover the majority of the screen on mobile devices, which makes it hard to scroll the rest of the app. 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_valuekeywrites_allowedT) allow_content)r dgrrrrform_ids_this_runaddr%rBlockr)form_idclear_on_submitr,r-r width_configCopyFromr r height_configr _blockr _form_data) selfr2r:r,r-r.r/r9ctx new_form_id block_protoblock_dgs r$r)zFormMixin.formGs-L dgg '(PQ Q "!#eT " ?!)>)>>K%%))'2+,I#,NOOoo' #*  +: (+: ("( uD1  ))*:5*ABd3!!**+>+.'w/r&form_submit_buttonN secondary)r2typeicondisableduse_container_widthr.c t} | | rdnd} |dvrtd|d|j|||||||| | | | S)u(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 `_. 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 : 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. 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. 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 subtlety. 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 `_ 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. .. deprecated:: ``use_container_width`` is deprecated and will be removed in a future release. For ``use_container_width=True``, use ``width="stretch"``. For ``use_container_width=False``, use ``width="content"``. width : "content", "stretch", or int The width of the button. This can be one of the following: - ``"content"`` (default): The width of the button matches the width of its content, but doesn't exceed the width of the parent container. - ``"stretch"``: The width of the button matches the width of the parent container. - An integer specifying the width in pixels: The button has a fixed width. If the specified width is greater than the width of the parent container, the width of the button matches the width of the parent container. Returns ------- bool True if the button was clicked. r*r+)primaryrFtertiaryztThe type argument to st.form_submit_button must be "primary", "secondary", or "tertiary". The argument passed was "z".) labelhelpon_clickargskwargsrGrHrIrAr.r2)rr_form_submit_button) r@rNrOrPrQrRr2rGrHrIrJr.rAs r$rEzFormMixin.form_submit_buttonsV!"  *!4I)E ; ;',,065  ''(  r&)r2rGrHrIrAr.ct|j} t|xsd| d|} |jj|| |d|||||| | |  S)NzFormSubmitter:-T) rNr2rOis_form_submitterrPrQrRrGrHrIrAr.)rr5r_button)r@rNrOrPrQrRr2rGrHrIrAr.r9submit_button_keys r$rSzFormMixin._form_submit_buttonsl"$''*"3KM^G9AeW+Mww!"  r&ctd|S)zGet our DeltaGenerator.r)r)r@s r$r5z FormMixin.dgs$d++r&)F)r2strr:boolr,r[r-r[r.r r/r returnr)SubmitNNNN)rNrZrO str | NonerPWidgetCallback | NonerQWidgetArgs | NonerRWidgetKwargs | Noner2 Key | NonerG+Literal['primary', 'secondary', 'tertiary']rHr^rIr[rJz bool | Noner.r r\r[)rNrZrOr^rPr_rQr`rRrar2rbrGrcrHr^rIr[rAzScriptRunContext | Noner.r r\r[)r\r) __name__ __module__ __qualname__rr)rErSpropertyr5r&r$r(r(FsF!&d !% "d dd  d  ddd ddL()*."&&* b rusV#//SS52%9O8PP6p,p,r&