o
    h                     @  s   U d dl 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 d dlmZmZ erGd d	lmZ d d
lmZ ed Zded< dddZdddZG dd de
ZdS )    )annotations)TYPE_CHECKINGLiteralcast)Self	TypeAlias)DeltaGenerator)StreamlitAPIException)Block)
ForwardMsg)enqueue_messageget_script_run_ctx)TracebackType)Cursor)smalllarger   DialogWidthwidthreturn'BlockProto.Dialog.DialogWidth.ValueTypec                 C  s   | dkr	t jjjS t jjjS )zMaps the user-provided literal to a value of the DialogWidth proto enum.

    Returns the mapped enum field for "small" by default and otherwise the mapped type.
    r   )
BlockProtoDialogr   LARGESMALL)r    r   Q/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/elements/lib/dialog.py_process_dialog_width_input&   s   

r   should_openboolNonec                 C  s.   t  }| r|r|jrtdd|_dS dS dS )a  Check whether a dialog has already been opened in the same script run.

    Only one dialog is supposed to be opened. The check is implemented in a way
    that for a script run, the open function can only be called once.
    One dialog at a time is a product decision and not a technical one.

    Raises
    ------
    StreamlitAPIException
        Raised when a dialog has already been opened in the current script run.
    zOnly one dialog is allowed to be opened at the same time. Please make sure to not call a dialog-decorated function more than once in a script run.TN)r   has_dialog_openedr	   )r   script_run_ctxr   r   r   !_assert_first_dialog_to_be_opened3   s   
r"   c                      sn   e Zd Zedddd,ddZd- fddZd.ddZd/ddZd/ddZd0 fd!d"Z	d1 fd*d+Z
  ZS )2r   Tr   )dismissibler   parentr   titlestrr#   r   r   r   r   c                C  s\   t  }||j_||j_t||j_| jjr| jjjng }t	d| j
|td}||_||_|S )Nr   )block_protodg_type)r   dialogr%   r#   r   r   
_active_dg_cursor
delta_pathr   _blockr   _delta_path_current_proto)r$   r%   r#   r   r'   r,   r)   r   r   r   _createL   s   zDialog._createroot_container
int | NonecursorCursor | NoneDeltaGenerator | None
block_type
str | Nonec                   s"   t  |||| d | _d | _d S N)super__init__r/   r.   )selfr1   r3   r$   r6   	__class__r   r   r:   e   s   
zDialog.__init__r   c                 C  sv   | j dus	J d| jdusJ dt| t }| j|jjdd< |jj| j  ||jjj	_
|jj| _ t| dS )zISend an updated proto message to indicate the open-status for the dialog.Nz!Dialog not correctly initialized!)r/   r.   r"   r   metadatar,   delta	add_blockCopyFromr)   is_openr   )r;   r   msgr   r   r   _updater   s   
zDialog._updater   c                 C     |  d d S )NTrD   r;   r   r   r   open      zDialog.openc                 C  rE   )NFrF   rG   r   r   r   close   rI   zDialog.closer   c                   s   t    | S r8   )r9   	__enter__rG   r<   r   r   rK      s   
zDialog.__enter__exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | NoneLiteral[False]c                   s   t  |||S r8   )r9   __exit__)r;   rL   rN   rP   r<   r   r   rS      s   zDialog.__exit__)
r$   r   r%   r&   r#   r   r   r   r   r   )r1   r2   r3   r4   r$   r5   r6   r7   )r   r   )r   r   )r   r   )rL   rM   rN   rO   rP   rQ   r   rR   )__name__
__module____qualname__staticmethodr0   r:   rD   rH   rJ   rK   rS   __classcell__r   r   r<   r   r   K   s    


r   N)r   r   r   r   )r   r   r   r   )
__future__r   typingr   r   r   typing_extensionsr   r   streamlit.delta_generatorr   streamlit.errorsr	   streamlit.proto.Block_pb2r
   r   streamlit.proto.ForwardMsg_pb2r   7streamlit.runtime.scriptrunner_utils.script_run_contextr   r   typesr   streamlit.cursorr   r   __annotations__r   r"   r   r   r   r   r   <module>   s   

