
    g                        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rd d	lmZ d d
lmZ ed   Zded<   	 	 	 	 ddZddZ G d de
      Zy)    )annotations)TYPE_CHECKINGLiteralcast)Self	TypeAlias)DeltaGenerator)StreamlitAPIException)Block)
ForwardMsg)enqueue_messageget_script_run_ctx)TracebackType)Cursor)smalllarger   DialogWidthc                    | 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)widths    R/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/lib/dialog.py_process_dialog_width_inputr   &   s<       ,,222((...    c                `    t               }| r"|r|j                  rt        d      d|_        yyy)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
   )should_openscript_run_ctxs     r   !_assert_first_dialog_to_be_openedr!   3   s@     ()N ~++' e  ,0( &{r   c                       e Zd Zeddd	 	 	 	 	 	 	 	 	 dd       Z	 	 	 	 	 	 	 	 d fdZddZddZddZd fd	Z		 	 	 	 	 	 	 	 d fd
Z
 xZS )r   Tr   )dismissibler   c               h   t               }||j                  _        ||j                  _        t	        |      |j                  _        | j                  j                  r | j                  j                  j                  ng }t        t        | j                  |t                    }||_        ||_        |S )N)block_protodg_type)r   dialogtitler#   r   r   
_active_dg_cursor
delta_pathr   r   _block_delta_path_current_proto)parentr(   r#   r   r%   r+   r'   s          r   _createzDialog._createL   s     !l#( )4&#>u#E  5;4E4E4M4MF%%00SU 	 ffmmVmTU' +r   c                F    t         |   ||||       d | _        d | _        y N)super__init__r.   r-   )selfroot_containercursorr/   
block_type	__class__s        r   r4   zDialog.__init__e   s*     	D 26-1r   c                   | j                   J d       | j                  J d       t        |       t               }| j                  |j                  j
                  dd |j                  j                  j                  | j                          ||j                  j                  j                  _
        |j                  j                  | _         t        |       y)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   )r5   r   msgs      r   _updatezDialog._updater   s     "".S0SS.+P-PP+)+6l%)%5%5"		$$T%8%89-8		""*!ii11r   c                &    | j                  d       y )NTrA   r5   s    r   openzDialog.open   s    Tr   c                &    | j                  d       y )NFrC   rD   s    r   closezDialog.close   s    Ur   c                $    t         |           | S r2   )r3   	__enter__)r5   r9   s    r   rI   zDialog.__enter__   s     	r   c                &    t         |   |||      S r2   )r3   __exit__)r5   exc_typeexc_valexc_tbr9   s       r   rK   zDialog.__exit__   s     w'6::r   )
r/   r	   r(   strr#   boolr   r   returnr   )r6   z
int | Noner7   zCursor | Noner/   zDeltaGenerator | Noner8   z
str | None)r   rP   )rQ   None)rQ   r   )rL   ztype[BaseException] | NonerM   zBaseException | NonerN   zTracebackType | NonerQ   zLiteral[False])__name__
__module____qualname__staticmethodr0   r4   rA   rE   rG   rI   rK   __classcell__)r9   s   @r   r   r   K   s    
 !$ 	
  
 02"2 2 &	2
 2;,; &; %	;
 
; ;r   r   N)r   r   rQ   z'BlockProto.Dialog.DialogWidth.ValueType)r   rP   rQ   rR   )
__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   <module>rd      sg    # / / - 4 2 9 5
 #' !12Y 2
/
/,
/00H;^ H;r   