
    Xh|                         d Z ddlmZmZmZ ddlmZ ddlmZm	Z	m
Z
mZ  G d de	      Ze G d d	e             Zd
 Ze G d de             Zd Zy)z]Link and DirectionalLink classes.

Propagate changes between widgets on the javascript side.
   )Widgetregisterwidget_serialization)
CoreWidget    )UnicodeTupleInstance
TraitErrorc                   0     e Zd ZdZdZ fdZ fdZ xZS )WidgetTraitTuplez<Traitlet for validating a single (Widget, 'trait_name') pairzA (Widget, 'trait_name') pairc                     t        |   t        t              t	               fi | d|vr|j                  dd      sd| _        y y y )Ndefault_value
allow_noneF )super__init__r
   r   r   getdefault_args)selfkwargs	__class__s     R/var/www/html/myenv/lib/python3.12/site-packages/ipywidgets/widgets/widget_link.pyr   zWidgetTraitTuple.__init__   sF    &)79??&(L%1P
 !#D 2Q(    c                 .   t         |   ||      }|\  }}|j                         j                  |      }dj	                  |j
                  j                  |      }|t        d|z        |j                  j                  d      st        d|z        |S )Nz{}.{}zNo such trait: %ssyncz%s cannot be synced)	r   validate_elementstraitsr   formatr   __name__	TypeErrormetadata)r   objvaluewidget
trait_nametrait
trait_reprr   s          r   r   z"WidgetTraitTuple.validate_elements   s    )#u5"
##J/^^F$4$4$=$=zJ
 =/*<==##F+1J>??r   )r    
__module____qualname____doc__	info_textr   r   __classcell__r   s   @r   r   r      s    F/I# r   r   c                        e Zd ZdZ ed      j                  d      Z  ed      j
                  dddieZ	  ed      j
                  dddieZ
 fd	Zd
 Z xZS )LinkzLink Widget

    source: a (Widget, 'trait_name') tuple for the source trait
    target: a (Widget, 'trait_name') tuple that should be updated
    	LinkModelTr   z&The target (widget, 'trait_name') pair)helpr   z&The source (widget, 'trait_name') pairc                 8    ||d<   ||d<   t        |   di | y )Nsourcetargetr   )r   r   )r   r5   r6   r   r   s       r   r   zLink.__init__7   s'    !x!x"6"r   c                 $    | j                          y )N)close)r   s    r   unlinkzLink.unlink=   s    

r   r   )r    r)   r*   r+   r   tag_model_namer   r   r6   r5   r   r9   r-   r.   s   @r   r0   r0   +   sr     +&***5KP#KLPPsVZs^rsFP#KLPPsVZs^rsF#r   r0   c                     t        | |      S )a  Link two widget attributes on the frontend so they remain in sync.

    The link is created in the front-end and does not rely on a roundtrip
    to the backend.

    Parameters
    ----------
    source : a (Widget, 'trait_name') tuple for the first trait
    target : a (Widget, 'trait_name') tuple for the second trait

    Examples
    --------

    >>> c = link((widget1, 'value'), (widget2, 'value'))
    )r0   )attr1attr2s     r   jslinkr?   A   s      ur   c                   @    e Zd ZdZ ed      j                  d      Zy)DirectionalLinkzA directional link

    source: a (Widget, 'trait_name') tuple for the source trait
    target: a (Widget, 'trait_name') tuple that should be updated
    when the source trait changes.
    DirectionalLinkModelTr2   N)r    r)   r*   r+   r   r:   r;   r   r   r   rA   rA   T   s"     015545@Kr   rA   c                     t        | |      S )a  Link a source widget attribute with a target widget attribute.

    The link is created in the front-end and does not rely on a roundtrip
    to the backend.

    Parameters
    ----------
    source : a (Widget, 'trait_name') tuple for the source trait
    target : a (Widget, 'trait_name') tuple for the target trait

    Examples
    --------

    >>> c = dlink((src_widget, 'value'), (tgt_widget, 'value'))
    )rA   )r5   r6   s     r   jsdlinkrD   _   s      66**r   N)r+   r%   r   r   r   widget_corer   	traitletsr   r	   r
   r   r   r0   r?   rA   rD   r   r   r   <module>rG      sj   
 ; : # : :u 8 
:  
*& 
Ad A 
A+r   