o
    ,&]i#                     @  s  d dl mZ d dl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 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 d dl m!Z!m"Z" ervd dl#m$Z$ d dl%m&Z& G dd deZ'G dd deZ(dS )    )annotationsN)TYPE_CHECKINGAny)BaseCustomComponent)is_dataframe_like)get_dg_singleton_instance)current_form_id)check_cache_replay_rules)compute_and_register_element_id)StreamlitAPIException)
ArrowTable)
SpecialArg)Element)gather_metrics)get_script_run_ctx)register_widget)is_bytes_liketo_bytes)DeltaGenerator)WidgetCallbackc                   @  s   e Zd ZdZdS )MarshallComponentExceptionzCClass for exceptions generated during custom component marshalling.N)__name__
__module____qualname____doc__ r   r   f/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/streamlit/components/v1/custom_component.pyr   (   s    r   c                   @  sh   e Zd ZdZddddddddZedddddddddZdddZej	Z	dddZ
d ddZdS )!CustomComponentzA Custom Component declaration.Ndefaultkey	on_change	tab_indexargsr   r   r    
str | Noner!   WidgetCallback | Noner"   
int | Nonekwargsreturnc                O  s   | j |||||d|S )zAn alias for create_instance.r   )create_instance)selfr   r    r!   r"   r#   r'   r   r   r   __call__1   s   
zCustomComponent.__call__r)   c             
     s  t |dkrtd|d  ddur&ttr"tts"dks&tdzddl}ddlm  W n t	y=   tdw t
  t|d	}i }	g | D ]5\}
}t|rit }|
|_t||_| qPt|rt }|
|_ |jj| | qP||	|
< qPzt|	W n ty } ztd
|d}~ww d fdd}t j}t }|||}|d|j |S )a  Create a new instance of the component.

        Parameters
        ----------
        *args
            Must be empty; all args must be named. (This parameter exists to
            enforce correct use of the function.)
        default: any or None
            The default return value for the component. This is returned when
            the component's frontend hasn't yet specified a value with
            `setComponentValue`.
        key: str or None
            If not None, this is the user key we use to generate the
            component's "widget ID".
        on_change: WidgetCallback or None
            An optional callback invoked when the widget's value changes. No arguments are passed to it.
        tab_index : int, optional
            Specifies the tab order of the iframe containing the component.
            Possible values are:
            - ``None`` (default): Browser default behavior.
            - ``-1``: Removes the iframe from the natural tab order, but it can still be focused programmatically.
            - ``0`` or positive integer: Includes the iframe in the natural tab order.
        **kwargs
            Keyword args to pass to the component.

        Returns
        -------
        any or None
            The component's widget value.

        r   z
Argument 'z' needs a labelNz6tab_index must be None, -1, or a non-negative integer.)component_arrowzTo use Custom Components in Streamlit, you need to install
PyArrow. To do so locally:

`pip install pyarrow`

And if you're using Streamlit Cloud, add "pyarrow" to your requirements.txt.)r   r    z(Could not convert component args to JSONdgr   elementr   r(   r   c              
     s   j |j_t| |j_jd urj|j_d ur|j_|j_|jj	 t
dddh| j jd}||j_ddd	}t|jj|d
d t dd}|j}|d u r[}|S t|tre |}|S )Ncomponent_instancenameurl)user_keykey_as_main_identityr.   r1   r2   	json_argsspecial_argsui_valuer   r(   c                 S     | S Nr   )r7   r   r   r   deserialize_component   s   zZCustomComponent.create_instance.<locals>.marshall_component.<locals>.deserialize_componentc                 S  r8   r9   r   )xr   r   r   <lambda>   s    zMCustomComponent.create_instance.<locals>.marshall_component.<locals>.<lambda>
json_value)deserializer
serializerctxon_change_handler
value_type)r7   r   r(   r   )r1   r0   component_namer   form_idr2   r"   r5   r6   extendr
   idr   r   value
isinstanceArrowTableProtoarrow_proto_to_dataframe)r.   r/   computed_idr:   component_statewidget_valuer-   r   r    r!   r*   serialized_json_argsr6   r"   r   r   marshall_component   sF   





z;CustomComponent.create_instance.<locals>.marshall_componentr0   )r.   r   r/   r   r(   r   )lenr   rH   intboolr   pyarrowstreamlit.components.v1r-   ImportErrorr	   dictitemsr   r   r    r   bytesappendr   marshallarrow_dataframedatajsondumps	Exceptionr   main_dgr   _enqueuer0   )r*   r   r    r!   r"   r#   r'   rT   all_argsr5   arg_namearg_val	bytes_argdataframe_argexrP   r.   r/   return_valuer   rN   r   r)   D   sb   )


0
zCustomComponent.create_instanceotherobjectrS   c                 C  s:   t |to| j|jko| j|jko| j|jko| j|jkS )zEquality operator.)rH   r   r1   pathr2   module_namer*   rj   r   r   r   __eq__   s   




zCustomComponent.__eq__c                 C  s
   | |k S )zInequality operator.r   rn   r   r   r   __ne__   s   
zCustomComponent.__ne__strc                 C  s(   d| j  d| jd ur| j S | j S )N'z': )r1   rl   r2   )r*   r   r   r   __str__   s   (zCustomComponent.__str__)r#   r   r   r   r    r$   r!   r%   r"   r&   r'   r   r(   r   )rj   rk   r(   rS   )r(   rq   )r   r   r   r   r+   r   r)   ro   r   __hash__rp   rs   r   r   r   r   r   .   s$     


r   ))
__future__r   r^   typingr   r   0streamlit.components.types.base_custom_componentr   streamlit.dataframe_utilr   $streamlit.delta_generator_singletonsr   !streamlit.elements.lib.form_utilsr   streamlit.elements.lib.policiesr	   streamlit.elements.lib.utilsr
   streamlit.errorsr   streamlit.proto.Components_pb2r   rI   r   streamlit.proto.Element_pb2r   streamlit.runtime.metrics_utilr   7streamlit.runtime.scriptrunner_utils.script_run_contextr   streamlit.runtime.stater   streamlit.type_utilr   r   streamlit.delta_generatorr   streamlit.runtime.state.commonr   r   r   r   r   r   r   <module>   s,   