o
    ,&]i                     @  s   U 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
 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 erYd dlmZ d 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	TypeAliascast)Self)DeltaGenerator)compute_and_register_element_id)StreamlitAPIException)Block)
ForwardMsg)enqueue_messageget_script_run_ctx)register_widget)TracebackType)Cursor)WidgetCallback)smalllargemediumr   DialogWidthwidthreturn'BlockProto.Dialog.DialogWidth.ValueTypec                 C  s.   | dkr	t jjj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   r   )
BlockProtoDialogr   LARGEMEDIUMSMALL)r    r   [/var/www/html/IGF-ODF-V3/venv/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_opened8   s   
r'   c                      sp   e Zd Zeddddd/ddZd0 fddZd1ddZd2dd Zd2d!d"Zd3 fd$d%Z	d4 fd-d.Z
  ZS )5r   Tr   ignore)dismissibler   
on_dismissparentr   titlestrr)   r#   r   r   r*   +Literal['ignore', 'rerun'] | WidgetCallbackr   c             
   C  s   |dvrt |std| dt }||j_||j_t||j_|dk}d }|rXt }t	dd d| |||t |s<t
|ndd}||j_t|t |rL|nd d	d
 dd
 |dd | jjra| jjjng }	td| j|td}
|	|
_||
_|
S )N)r(   rerunzYou have passed zI to `on_dismiss`. But only 'ignore', 'rerun', or a callable is supported.r(   dialogFcallback)user_keykey_as_main_identitydgr,   r)   r   r*   c                 S     | S Nr   xr   r   r    <lambda>       z Dialog._create.<locals>.<lambda>c                 S  r5   r6   r   r7   r   r   r    r9      r:   trigger_value)on_change_handlerdeserializer
serializerctx
value_typer   )block_protodg_type)callabler
   r   r0   r,   r)   r!   r   r   r	   r-   idr   
_active_dg_cursor
delta_pathr   _blockr   _delta_path_current_proto)r+   r,   r)   r   r*   rA   is_dismiss_activated
element_idr?   rG   r0   r   r   r    _createR   sJ   


zDialog._createroot_container
int | NonecursorCursor | NoneDeltaGenerator | None
block_type
str | Noner$   c                   s"   t  |||| d | _d | _d S r6   )super__init__rJ   rI   )selfrN   rP   r+   rS   	__class__r   r    rV      s   
zDialog.__init__r"   c                 C  sn   | j du s
| jdu rt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. This should never happen.)rJ   rI   RuntimeErrorr'   r   metadatarG   delta	add_blockCopyFromr0   is_openr   )rW   r"   msgr   r   r    _update   s   
zDialog._updatec                 C     |  d d S )NTra   rW   r   r   r    open      zDialog.openc                 C  rb   )NFrc   rd   r   r   r    close   rf   zDialog.closer   c                   s   t    | S r6   )rU   	__enter__rd   rX   r   r    rh      s   
zDialog.__enter__exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | NoneLiteral[False]c                   s   t  |||S r6   )rU   __exit__)rW   ri   rk   rm   rX   r   r    rp      s   zDialog.__exit__)r+   r   r,   r-   r)   r#   r   r   r*   r.   r   r   )
rN   rO   rP   rQ   r+   rR   rS   rT   r   r$   r"   r#   r   r$   )r   r$   )r   r   )ri   rj   rk   rl   rm   rn   r   ro   )__name__
__module____qualname__staticmethodrM   rV   ra   re   rg   rh   rp   __classcell__r   r   rX   r    r   Q   s    ?


r   N)r   r   r   r   rq   )#
__future__r   typingr   r   r   r   typing_extensionsr   streamlit.delta_generatorr   streamlit.elements.lib.utilsr	   streamlit.errorsr
   streamlit.proto.Block_pb2r   r   streamlit.proto.ForwardMsg_pb2r   7streamlit.runtime.scriptrunner_utils.script_run_contextr   r   streamlit.runtime.stater   typesr   streamlit.cursorr   r   r   __annotations__r!   r'   r   r   r   r   r    <module>   s$   

