U
    ARdm                     @   s   d dl mZmZmZmZ d dlmZ d dlmZ e	ee	df e	ee	 dddZ
ee	 ed d	d
dZG dd dZG dd deZG dd deZdS )    )AnyListOptionalTuple)util)get_script_run_ctx.)root_containerparent_pathindexreturnc                 C   s   | g}| | || |S N)extendappend)r   r	   r
   
delta_path r   4/tmp/pip-unpacked-wheel-b9et7o5g/streamlit/cursor.pymake_delta_path   s    

r   RunningCursor)r   r   c                 C   sJ   | dkrdS t  }|dkrdS | |jkr2|j|  S t| d}||j| < |S )zReturn the top-level RunningCursor for the given container.
    This is the cursor that is used when user code calls something like
    `st.foo` (which uses the main container) or `st.sidebar.foo` (which uses
    the sidebar container).
    N)r   )r   Zcursorsr   )r   ctxcursorr   r   r   get_container_cursor   s    



r   c                   @   s   e Zd ZdZedddZeedddZee	edf ddd	Z
eedd
dZeee dddZeedddZddddZeedddZdS )CursorzA pointer to a delta location in the app.

    When adding an element to the app, you should always call
    get_locked_cursor() on that element's respective Cursor.
    r   c                 C   s
   t | S r   )r   repr_selfr   r   r   __repr__=   s    zCursor.__repr__c                 C   s
   t  dS )zwThe top-level container this cursor lives within - either
        RootContainer.MAIN or RootContainer.SIDEBAR.
        NNotImplementedErrorr   r   r   r   r   @   s    zCursor.root_container.c                 C   s
   t  dS )z0The cursor's parent's path within its container.Nr   r   r   r   r   r	   G   s    zCursor.parent_pathc                 C   s
   t  dS )z/The index of the Delta within its parent block.Nr   r   r   r   r   r
   L   s    zCursor.indexc                 C   s   t | j| j| jS )zrThe complete path of the delta pointed to by this cursor - its
        container, parent path, and index.
        )r   r   r	   r
   r   r   r   r   r   Q   s    zCursor.delta_pathc                 C   s
   t  d S r   r   r   r   r   r   	is_lockedX   s    zCursor.is_lockedLockedCursorc                 K   s
   t  d S r   r   r   propsr   r   r   get_locked_cursor\   s    zCursor.get_locked_cursorc                 C   s
   t  dS )zOther data in this cursor. This is a temporary measure that will go
        away when we implement improved return values for elements.

        This is only implemented in LockedCursor.
        Nr   r   r   r   r   r"   _   s    zCursor.propsN)__name__
__module____qualname____doc__strr   propertyintr   r   r	   r
   r   r   boolr   r#   r   r"   r   r   r   r   r   6   s   r   c                   @   s   e Zd Zdeeedf dddZeedddZeeedf dd	d
ZeedddZ	ee
dddZddddZdS )r   r   .)r   r	   c                 C   s   || _ || _d| _dS )a  A moving pointer to a delta location in the app.

        RunningCursors auto-increment to the next available location when you
        call get_locked_cursor() on them.

        Parameters
        ----------
        root_container: int
            The root container this cursor lives in.
        parent_path: tuple of ints
          The full path of this cursor, consisting of the IDs of all ancestors.
          The 0th item is the topmost ancestor.

        r   N)_root_container_parent_path_index)r   r   r	   r   r   r   __init__j   s    zRunningCursor.__init__r   c                 C   s   | j S r   r,   r   r   r   r   r   }   s    zRunningCursor.root_containerc                 C   s   | j S r   r-   r   r   r   r   r	      s    zRunningCursor.parent_pathc                 C   s   | j S r   r.   r   r   r   r   r
      s    zRunningCursor.indexc                 C   s   dS )NFr   r   r   r   r   r      s    zRunningCursor.is_lockedr    c                 K   s.   t f | j| j| jd|}|  jd7  _|S )Nr   r	   r
      )r    r,   r-   r.   )r   r"   Zlocked_cursorr   r   r   r#      s    zRunningCursor.get_locked_cursorN)r   )r$   r%   r&   r*   r   r/   r)   r   r	   r
   r+   r   r#   r   r   r   r   r   i   s   c                   @   s   e Zd Zdeeedf edddZeeddd	Zeeedf dd
dZeedddZ	ee
dddZd dddZeedddZdS )r    r   r   .r3   c                 K   s   || _ || _|| _|| _dS )a  A locked pointer to a location in the app.

        LockedCursors always point to the same location, even when you call
        get_locked_cursor() on them.

        Parameters
        ----------
        root_container: int
            The root container this cursor lives in.
        parent_path: tuple of ints
          The full path of this cursor, consisting of the IDs of all ancestors. The
          0th item is the topmost ancestor.
        index: int
        **props: any
          Anything else you want to store in this cursor. This is a temporary
          measure that will go away when we implement improved return values
          for elements.

        N)r,   r.   r-   _props)r   r   r	   r
   r"   r   r   r   r/      s    zLockedCursor.__init__r   c                 C   s   | j S r   r0   r   r   r   r   r      s    zLockedCursor.root_containerc                 C   s   | j S r   r1   r   r   r   r   r	      s    zLockedCursor.parent_pathc                 C   s   | j S r   r2   r   r   r   r   r
      s    zLockedCursor.indexc                 C   s   dS )NTr   r   r   r   r   r      s    zLockedCursor.is_lockedc                 K   s
   || _ | S r   r5   r!   r   r   r   r#      s    zLockedCursor.get_locked_cursorc                 C   s   | j S r   r6   r   r   r   r   r"      s    zLockedCursor.propsN)r   r   )r$   r%   r&   r*   r   r/   r)   r   r	   r
   r+   r   r#   r   r"   r   r   r   r   r       s$     
r    N)typingr   r   r   r   Z	streamlitr   Zstreamlit.runtime.scriptrunnerr   r*   r   r   r   r   r    r   r   r   r   <module>   s    
 
31