U
    ARd=                     @   s   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
 d dlmZ d dlmZ er`d dlmZ eeeeeef  f ZG dd dZd	S )
    )TYPE_CHECKINGListOptionalSequenceUnioncast)deprecate_func_name)StreamlitAPIException)Block)gather_metrics)DeltaGeneratorc                   @   s   e Zd ZedddddZedddeee ed d	d
dZ	ede
e e
d dddZeddeeddddZeddddZeeddZeeddZee	ddZdS )LayoutsMixin	containerr   )returnc                 C   s
   | j  S )a  Insert a multi-element container.

        Inserts an invisible container into your app that can be used to hold
        multiple elements. This allows you to, for example, insert multiple
        elements into your app out of order.

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

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

        >>> import streamlit as st
        >>>
        >>> with st.container():
        ...    st.write("This is inside the container")
        ...
        ...    # You can call any Streamlit command, including custom components:
        ...    st.bar_chart(np.random.randn(50, 3))
        ...
        >>> st.write("This is outside the container")

        .. output ::
            https://doc-container1.streamlitapp.com/
            height: 520px

        Inserting elements out of order:

        >>> import streamlit as st
        >>>
        >>> container = st.container()
        >>> container.write("This is inside the container")
        >>> st.write("This is outside the container")
        >>>
        >>> # Now insert some more in the container
        >>> container.write("This is inside too")

        .. output ::
            https://doc-container2.streamlitapp.com/
            height: 480px
        )dg_blockself r   >/tmp/pip-unpacked-wheel-b9et7o5g/streamlit/elements/layouts.pyr      s    -zLayoutsMixin.containercolumnssmall)gap)specr   r   c                   s   |}t d}t|trd| }t|dks<tdd |D r@|dd }||ttdfd	d
 t }|j_| j	
|t| fdd|D S )a;  Insert containers laid out as side-by-side columns.

        Inserts a number of multi-element containers laid out side-by-side and
        returns a list of container objects.

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

        Columns can only be placed inside other columns up to one level of nesting.

        .. warning::
            Columns cannot be placed inside other columns in the sidebar. This is only possible in the main area of the app.

        Parameters
        ----------
        spec : int or list of numbers
            If an int
                Specifies the number of columns to insert, and all columns
                have equal width.

            If a list of numbers
                Creates a column for each number, and each
                column's width is proportional to the number provided. Numbers can
                be ints or floats, but they must be positive.

                For example, `st.columns([3, 1, 2])` creates 3 columns where
                the first column is 3 times the width of the second, and the last
                column is 2 times that width.
        gap : string ("small", "medium", or "large")
            An optional string, which indicates the size of the gap between each column.
            The default is a small gap between columns. This argument can only be supplied by
            keyword.

        Returns
        -------
        list of containers
            A list of container objects.

        Examples
        --------
        You can use `with` notation to insert any element into a column:

        >>> import streamlit as st
        >>>
        >>> col1, col2, col3 = st.columns(3)
        >>>
        >>> with col1:
        ...    st.header("A cat")
        ...    st.image("https://static.streamlit.io/examples/cat.jpg")
        ...
        >>> with col2:
        ...    st.header("A dog")
        ...    st.image("https://static.streamlit.io/examples/dog.jpg")
        ...
        >>> with col3:
        ...    st.header("An owl")
        ...    st.image("https://static.streamlit.io/examples/owl.jpg")

        .. output ::
            https://doc-columns1.streamlitapp.com/
            height: 620px

        Or you can just call methods directly in the returned objects:

        >>> import streamlit as st
        >>> import numpy as np
        >>>
        >>> col1, col2 = st.columns([3, 1])
        >>> data = np.random.randn(10, 1)
        >>>
        >>> col1.subheader("A wide column with a chart")
        >>> col1.line_chart(data)
        >>>
        >>> col2.subheader("A narrow column with the data")
        >>> col2.write(data)

        .. output ::
            https://doc-columns2.streamlitapp.com/
            height: 550px

        zThe input argument to st.columns must be either a positive integer or a list of positive numeric weights. See [documentation](https://docs.streamlit.io/library/api-reference/layout/st.columns) for more information.)   r   c                 s   s   | ]}|d kV  qdS )r   Nr   ).0weightr   r   r   	<genexpr>   s     z'LayoutsMixin.columns.<locals>.<genexpr>c                 S   s>   t | tkr*|  }dddg}||kr*|S td|  dd S )Nr   ZmediumZlargez_The gap argument to st.columns must be "small", "medium", or "large". 
The argument passed was .)typestrlowerr	   )r   gap_sizeZvalid_sizesr   r   r   
column_gap   s    

z(LayoutsMixin.columns.<locals>.column_gap)normalized_weightr   c                    s    t  }| |j_ |j_d|_|S NT)
BlockProtocolumnr   r   allow_empty)r$   Z	col_proto)r"   r   r   column_proto   s
    z*LayoutsMixin.columns.<locals>.column_protoc                    s   g | ]}  | qS r   r   )r   w)r)   rowtotal_weightr   r   
<listcomp>   s     z(LayoutsMixin.columns.<locals>.<listcomp>)r	   
isinstanceintlenanyfloatr&   Z
horizontalr   r   r   sum)r   r   r   weightsZweights_exceptionr#   block_protor   )r)   r"   r,   r-   r   r   M   s     V
zLayoutsMixin.columnstabs)r7   r   c                    sj   |st dtdd |D r&t dttdddt }|j  | j| t fdd|D S )	u  Insert containers separated into tabs.

        Inserts a number of multi-element containers as tabs.
        Tabs are a navigational element that allows users to easily
        move between groups of related content.

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

        .. warning::
            All the content of every tab is always sent to and rendered on the frontend.
            Conditional rendering is currently not supported.

        Parameters
        ----------
        tabs : list of strings
            Creates a tab for each string in the list. The first tab is selected by default.
            The string is used as the name of the tab and can optionally contain Markdown,
            supporting 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``.

        Returns
        -------
        list of containers
            A list of container objects.

        Examples
        --------
        You can use `with` notation to insert any element into a tab:

        >>> import streamlit as st
        >>>
        >>> tab1, tab2, tab3 = st.tabs(["Cat", "Dog", "Owl"])
        >>>
        >>> with tab1:
        ...    st.header("A cat")
        ...    st.image("https://static.streamlit.io/examples/cat.jpg", width=200)
        ...
        >>> with tab2:
        ...    st.header("A dog")
        ...    st.image("https://static.streamlit.io/examples/dog.jpg", width=200)
        ...
        >>> with tab3:
        ...    st.header("An owl")
        ...    st.image("https://static.streamlit.io/examples/owl.jpg", width=200)

        .. output ::
            https://doc-tabs1.streamlitapp.com/
            height: 620px

        Or you can just call methods directly in the returned objects:

        >>> import streamlit as st
        >>> import numpy as np
        >>>
        >>> tab1, tab2 = st.tabs(["📈 Chart", "🗃 Data"])
        >>> data = np.random.randn(10, 1)
        >>>
        >>> tab1.subheader("A tab with a chart")
        >>> tab1.line_chart(data)
        >>>
        >>> tab2.subheader("A tab with the data")
        >>> tab2.write(data)


        .. output ::
            https://doc-tabs2.streamlitapp.com/
            height: 700px

        zBThe input argument to st.tabs must contain at least one tab label.c                 s   s   | ]}t |td kV  qdS )FN)r/   r    )r   tabr   r   r   r   0  s     z$LayoutsMixin.tabs.<locals>.<genexpr>zBThe tabs input list to st.tabs is only allowed to contain strings.)labelr   c                 S   s   t  }| |j_d|_|S r%   )r&   r8   r9   r(   )r9   	tab_protor   r   r   r:   5  s    z$LayoutsMixin.tabs.<locals>.tab_protoc                 3   s   | ]}  |V  qd S )Nr*   )r   Z	tab_labeltab_containerr:   r   r   r   >  s     )	r	   r2   r    r&   r<   ZSetInParentr   r   tuple)r   r7   r6   r   r;   r   r7      s    [
zLayoutsMixin.tabsexpanderF)r9   expandedr   c                 C   sJ   |dkrt dt }||_||_t }d|_|j| | jj	|dS )a~  Insert a multi-element container that can be expanded/collapsed.

        Inserts a container into your app that can be used to hold multiple elements
        and can be expanded or collapsed by the user. When collapsed, all that is
        visible is the provided label.

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

        .. warning::
            Currently, you may not put expanders inside another expander.

        Parameters
        ----------
        label : str
            A string to use as the header for the expander. 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``.
        expanded : bool
            If True, initializes the expander in "expanded" state. Defaults to
            False (collapsed).

        Examples
        --------
        You can use `with` notation to insert any element into an expander

        >>> import streamlit as st
        >>>
        >>> st.bar_chart({"data": [1, 5, 2, 6, 2, 1]})
        >>>
        >>> with st.expander("See explanation"):
        ...     st.write(\"\"\"
        ...         The chart above shows some numbers I picked for you.
        ...         I rolled actual dice for these, so they're *guaranteed* to
        ...         be random.
        ...     \"\"\")
        ...     st.image("https://static.streamlit.io/examples/dice.jpg")

        .. output ::
            https://doc-expander.streamlitapp.com/
            height: 750px

        Or you can just call methods directly in the returned objects:

        >>> import streamlit as st
        >>>
        >>> st.bar_chart({"data": [1, 5, 2, 6, 2, 1]})
        >>>
        >>> expander = st.expander("See explanation")
        >>> expander.write(\"\"\"
        ...     The chart above shows some numbers I picked for you.
        ...     I rolled actual dice for these, so they're *guaranteed* to
        ...     be random.
        ... \"\"\")
        >>> expander.image("https://static.streamlit.io/examples/dice.jpg")

        .. output ::
            https://doc-expander.streamlitapp.com/
            height: 750px

        Nz#A label is required for an expanderT)r6   )
r	   r&   Z
Expandabler?   r9   r(   Z
expandableZCopyFromr   r   )r   r9   r?   Zexpandable_protor6   r   r   r   r>   @  s    RzLayoutsMixin.expanderc                 C   s
   t d| S )zGet our DeltaGenerator.r   )r   r   r   r   r   r     s    zLayoutsMixin.dgbeta_containerz
2021-11-02beta_expanderbeta_columnsN)F)__name__
__module____qualname__r   r   SpecTyper   r    r   r   r   r7   boolr>   propertyr   r   r@   rA   rB   r   r   r   r   r      s&   /  o^r   N)typingr   r   r   r   r   r   Zstreamlit.deprecation_utilr   Zstreamlit.errorsr	   Zstreamlit.proto.Block_pb2r
   r&   Zstreamlit.runtime.metrics_utilr   Zstreamlit.delta_generatorr   r0   r3   rF   r   r   r   r   r   <module>   s    