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 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cast)Self	TypeAlias)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   Z/var/www/html/mmpi2/mmpi_env/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 }|rWt }t	dd | |||t |s;t
|ndd}||j_t|t |rK|nd dd	 d
d	 |dd | jjr`| 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(   dialogcallback)user_keydgr,   r)   r   r*   c                 S     | S Nr   xr   r   r    <lambda>~       z Dialog._create.<locals>.<lambda>c                 S  r4   r5   r   r6   r   r   r    r8      r9   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*   r@   is_dismiss_activated
element_idr>   rF   r0   r   r   r    _createR   sH   

	zDialog._createroot_container
int | NonecursorCursor | NoneDeltaGenerator | None
block_type
str | Noner$   c                   s"   t  |||| d | _d | _d S r5   )super__init__rI   rH   )selfrM   rO   r+   rR   	__class__r   r    rU      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.)rI   rH   RuntimeErrorr'   r   metadatarF   delta	add_blockCopyFromr0   is_openr   )rV   r"   msgr   r   r    _update   s   
zDialog._updatec                 C     |  d d S )NTr`   rV   r   r   r    open      zDialog.openc                 C  ra   )NFrb   rc   r   r   r    close   re   zDialog.closer   c                   s   t    | S r5   )rT   	__enter__rc   rW   r   r    rg      s   
zDialog.__enter__exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | NoneLiteral[False]c                   s   t  |||S r5   )rT   __exit__)rV   rh   rj   rl   rW   r   r    ro      s   zDialog.__exit__)r+   r   r,   r-   r)   r#   r   r   r*   r.   r   r   )
rM   rN   rO   rP   r+   rQ   rR   rS   r   r$   r"   r#   r   r$   )r   r$   )r   r   )rh   ri   rj   rk   rl   rm   r   rn   )__name__
__module____qualname__staticmethodrL   rU   r`   rd   rf   rg   ro   __classcell__r   r   rW   r    r   Q   s    >


r   N)r   r   r   r   rp   )#
__future__r   typingr   r   r   typing_extensionsr   r   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$   

