o
    Yh.f                     @  sV  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
 d dlmZ d dlmZmZmZmZ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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/m0Z0 d dl1m2Z2 erd dl3m4Z4 d dl1m2Z2 eG dd dZ5eG dd dZ6G dd dZ7dS )    )annotations)	dataclass)dedent)TYPE_CHECKINGLiteralcastoverload)current_form_id)HeightLayoutConfigWidthWithoutContentvalidate_heightvalidate_width)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valueto_key)StreamlitAPIException)TextArea)	TextInput)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsget_session_stateregister_widget)validate_icon_or_emoji)SupportsStr)DeltaGeneratorc                   @  *   e Zd ZU ded< dddZddd	Zd
S )TextInputSerde
str | Nonevalueui_valuereturnc                 C     |d ur|S | j S Nr'   selfr(    r/   h/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/streamlit/elements/widgets/text_widgets.pydeserialize@      zTextInputSerde.deserializevc                 C     |S r+   r/   r.   r3   r/   r/   r0   	serializeC      zTextInputSerde.serializeNr(   r&   r)   r&   r3   r&   r)   r&   __name__
__module____qualname____annotations__r1   r6   r/   r/   r/   r0   r%   <      
 
r%   c                   @  r$   )TextAreaSerder&   r'   r(   r)   c                 C  r*   r+   r,   r-   r/   r/   r0   r1   K   r2   zTextAreaSerde.deserializer3   c                 C  r4   r+   r/   r5   r/   r/   r0   r6   N   r7   zTextAreaSerde.serializeNr8   r9   r:   r/   r/   r/   r0   r@   G   r?   r@   c                   @  s  e Zd Ze									d=ddddddd>d#d$Ze									d?ddddddd@d&d$Zed'									d=dddddddAd)d$Z									d=ddddddd*dBd-d.Ze								dCddddd/dDd2d3Ze								dEddddd/dFd4d3Zed5								dCddddd/dGd6d3Z								dCdddddd7dHd8d9Ze	dId;d<Z
dS )JTextWidgetsMixin NdefaultFvisiblestretch)placeholderdisabledlabel_visibilityiconwidthlabelstrr'   	max_chars
int | Nonekey
Key | NonetypeLiteral['default', 'password']helpr&   autocomplete	on_changeWidgetCallback | NoneargsWidgetArgs | NonekwargsWidgetKwargs | NonerF   rG   boolrH   r   rI   rJ   r   r)   c                C     d S r+   r/   r.   rK   r'   rM   rO   rQ   rS   rT   rU   rW   rY   rF   rG   rH   rI   rJ   r/   r/   r0   
text_inputS      zTextWidgetsMixin.text_inputSupportsStr | Nonec                C  r\   r+   r/   r]   r/   r/   r0   r^   i   r_   r^   str | SupportsStr | Nonec                C  sr   t  }| jdi d|d|d|d|d|d|d|d|d	|	d
|
d|d|d|d|d|d|S )u#  Display a single-line text input widget.

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

        value : object or None
            The text value of this widget when it first renders. This will be
            cast to str internally. If ``None``, will initialize empty and
            return ``None`` until the user provides input. Defaults to empty string.

        max_chars : int or None
            Max number of characters allowed in text input.

        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 : "default" or "password"
            The type of the text input. This can be either "default" (for
            a regular text input), or "password" (for a text input that
            masks the user's typed value). Defaults to "default".

        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``.

        autocomplete : str
            An optional value that will be passed to the <input> element's
            autocomplete property. If unspecified, this value will be set to
            "new-password" for "password" inputs, and the empty string for
            "default" inputs. For more details, see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete

        on_change : callable
            An optional callback invoked when this text input's value changes.

        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.

        placeholder : str or None
            An optional string displayed when the text input is empty. If None,
            no text is displayed.

        disabled : bool
            An optional boolean that disables the text input if set to
            ``True``. The default is ``False``.

        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 aligned with other widgets.

        icon : str, None
            An optional emoji or icon to display within the input field to the
            left of the value. 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.

        width : "stretch" or int
            The width of the text input widget. This can be one of the
            following:

            - ``"stretch"`` (default): The width of the widget matches the
              width of the parent container.
            - An integer specifying the width in pixels: The widget has a
              fixed width. If the specified width is greater than the width of
              the parent container, the width of the widget matches the width
              of the parent container.

        Returns
        -------
        str or None
            The current value of the text input widget or ``None`` if no value has been
            provided by the user.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> title = st.text_input("Movie title", "Life of Brian")
        >>> st.write("The current movie title is", title)

        .. output::
           https://doc-text-input.streamlit.app/
           height: 260px

        rK   r'   rM   rO   rQ   rS   rT   rU   rW   rY   rF   rG   rH   rI   rJ   ctxNr/   )r   _text_input)r.   rK   r'   rM   rO   rQ   rS   rT   rU   rW   rY   rF   rG   rH   rI   rJ   rb   r/   r/   r0   r^      sF    
	
)rF   rG   rH   rI   rJ   rb   rb   ScriptRunContext | Nonec                C  s  t |}t| j|||dkrd n|d t|| |d ur t|nd }td|| j||||||t|||d}t j}|d urI||v rI|| d u rId }t }||_	||_
|d urY||_t| j|_||_t||j_|d urqt||_|d urx||_|d urt||_|d urt||_|dkrtj|_n|dkrtj|_ntd| d|d u r|dkrd	nd}||_t|}t|j	||	|
|j|j |d
d}|j!r|jd ur|j|_d|_"t#| t$|d}| jj%d||d |jS )NrB   default_valuer^   )user_keydgrK   r'   rM   rQ   rS   rT   rF   rI   rJ   rC   password'zK' is not a valid text_input type. Valid types are 'default' and 'password'.znew-passwordstring_valueon_change_handlerrW   rY   deserializer
serializerrb   
value_typeT)rJ   layout_config)&r   r   rh   r   rL   r   r   filtered_stateTextInputProtoidrK   rC   r	   form_idrG   r   rH   r'   r   rS   rM   rF   r!   rI   DEFAULTrQ   PASSWORDr   rT   r%   r    r1   r6   value_changed	set_valuer   r   _enqueue)r.   rK   r'   rM   rO   rQ   rS   rT   rU   rW   rY   rF   rG   rH   rI   rJ   rb   
element_idsession_statetext_input_protoserdewidget_staterr   r/   r/   r0   rc   '  s   








zTextWidgetsMixin._text_input)rF   rG   rH   rJ   heightHeight | Nonec
                C  r\   r+   r/   r.   rK   r'   r   rM   rO   rS   rU   rW   rY   rF   rG   rH   rJ   r/   r/   r0   	text_area     zTextWidgetsMixin.text_areac
                C  r\   r+   r/   r   r/   r/   r0   r     r   r   c
                C  s,   t  }| j|||||||||	|
||||dS )a  Display a multi-line text input widget.

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

        value : object or None
            The text value of this widget when it first renders. This will be
            cast to str internally. If ``None``, will initialize empty and
            return ``None`` until the user provides input. Defaults to empty string.

        height : "content", "stretch", int, or None
            The height of the text area widget. This can be one of the
            following:

            - ``None`` (default): The height of the widget fits three lines.
            - ``"content"``: The height of the widget matches the
              height of its content.
            - ``"stretch"``: The height of the widget matches the height of
              its content or the height of the parent container, whichever is
              larger. If the widget is not in a parent container, the height
              of the widget matches the height of its content.
            - An integer specifying the height in pixels: The widget has a
              fixed height. If the content is larger than the specified
              height, scrolling is enabled.

            The widget's height can't be smaller than the height of two lines.
            When ``label_visibility="collapsed"``, the minimum height is 68
            pixels. Otherwise, the minimum height is 98 pixels.

        max_chars : int or None
            Maximum number of characters allowed in text area.

        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 text_area's value changes.

        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.

        placeholder : str or None
            An optional string displayed when the text area is empty. If None,
            no text is displayed.

        disabled : bool
            An optional boolean that disables the text area if set to ``True``.
            The default is ``False``.

        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 aligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        width : "stretch" or int
            The width of the text area widget. This can be one of the
            following:

            - ``"stretch"`` (default): The width of the widget matches the
              width of the parent container.
            - An integer specifying the width in pixels: The widget has a
              fixed width. If the specified width is greater than the width of
              the parent container, the width of the widget matches the width
              of the parent container.

        Returns
        -------
        str or None
            The current value of the text area widget or ``None`` if no value has been
            provided by the user.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> txt = st.text_area(
        ...     "Text to analyze",
        ...     "It was the best of times, it was the worst of times, it was the age of "
        ...     "wisdom, it was the age of foolishness, it was the epoch of belief, it "
        ...     "was the epoch of incredulity, it was the season of Light, it was the "
        ...     "season of Darkness, it was the spring of hope, it was the winter of "
        ...     "despair, (...)",
        ... )
        >>>
        >>> st.write(f"You wrote {len(txt)} characters.")

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

        )rK   r'   r   rM   rO   rS   rU   rW   rY   rF   rG   rH   rJ   rb   )r   
_text_area)r.   rK   r'   r   rM   rO   rS   rU   rW   rY   rF   rG   rH   rJ   rb   r/   r/   r0   r     s$    )rF   rG   rH   rJ   rb   c
                C  s  t |}t| j|||dkrd n|d t|| |d ur t|nd }td|| j|||||t|
|d
}t j}|d urG||v rG|| d u rGd }t }||_	||_
|d urW||_t| j|_||_t||j_|d urot||_|d urv||_|
d urt|
|_t|}t|j	|||	|j|j|dd}|jr|jd ur|j|_d|_t| |d urt|dd n|d	krd
nd}t||d}| jjd||d |jS )NrB   re   r   )	rg   rh   rK   r'   r   rM   rS   rF   rJ   rk   rl   T)allow_content	collapsedz   ^   )rJ   r   rq   ) r   r   rh   r   rL   r   r   rs   TextAreaProtoru   rK   rC   r	   rv   rG   r   rH   r'   r   rS   rM   rF   r@   r    r1   r6   ry   rz   r   r   r   r{   )r.   rK   r'   r   rM   rO   rS   rU   rW   rY   rF   rG   rH   rJ   rb   r|   r}   text_area_protor   r   rr   r/   r/   r0   r   d  s|   



zTextWidgetsMixin._text_arear#   c                 C  s
   t d| S )zGet our DeltaGenerator.r#   )r   )r.   r/   r/   r0   rh     s   
zTextWidgetsMixin.dg)	rB   NNrC   NNNNN) rK   rL   r'   rL   rM   rN   rO   rP   rQ   rR   rS   r&   rT   r&   rU   rV   rW   rX   rY   rZ   rF   r&   rG   r[   rH   r   rI   r&   rJ   r   r)   rL   )	NNNrC   NNNNN) rK   rL   r'   r`   rM   rN   rO   rP   rQ   rR   rS   r&   rT   r&   rU   rV   rW   rX   rY   rZ   rF   r&   rG   r[   rH   r   rI   r&   rJ   r   r)   r&   ) rK   rL   r'   ra   rM   rN   rO   rP   rQ   rR   rS   r&   rT   r&   rU   rV   rW   rX   rY   rZ   rF   r&   rG   r[   rH   r   rI   r&   rJ   r   r)   r&   )"rK   rL   r'   r`   rM   rN   rO   rP   rQ   rL   rS   r&   rT   r&   rU   rV   rW   rX   rY   rZ   rF   r&   rG   r[   rH   r   rI   r&   rJ   r   rb   rd   r)   r&   )rB   NNNNNNN)rK   rL   r'   rL   r   r   rM   rN   rO   rP   rS   r&   rU   rV   rW   rX   rY   rZ   rF   r&   rG   r[   rH   r   rJ   r   r)   rL   )NNNNNNNN)rK   rL   r'   r`   r   r   rM   rN   rO   rP   rS   r&   rU   rV   rW   rX   rY   rZ   rF   r&   rG   r[   rH   r   rJ   r   r)   r&   )rK   rL   r'   ra   r   r   rM   rN   rO   rP   rS   r&   rU   rV   rW   rX   rY   rZ   rF   r&   rG   r[   rH   r   rJ   r   r)   r&   )rK   rL   r'   r`   r   r   rM   rN   rO   rP   rS   r&   rU   rV   rW   rX   rY   rZ   rF   r&   rG   r[   rH   r   rJ   r   rb   rd   r)   r&   )r)   r#   )r;   r<   r=   r   r^   r   rc   r   r   propertyrh   r/   r/   r/   r0   rA   R   s
    +r &crA   N)8
__future__r   dataclassesr   textwrapr   typingr   r   r   r   !streamlit.elements.lib.form_utilsr	   #streamlit.elements.lib.layout_utilsr
   r   r   r   r   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   streamlit.errorsr   streamlit.proto.TextArea_pb2r   r   streamlit.proto.TextInput_pb2r   rt   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater   r   r   r   r    streamlit.string_utilr!   streamlit.type_utilr"   streamlit.delta_generatorr#   r%   r@   rA   r/   r/   r/   r0   <module>   s0   

