
    ge                         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dS )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          |           j        t          t                    t                      fi | d S N)superr   __init__r
   r   r   )selfkwargs	__class__s     >lib/python3.11/site-packages/ipywidgets/widgets/widget_link.pyr   zWidgetTraitTuple.__init__   s=    .%%.x/?/?UUfUUUUU    c                 T   t          t          |                               ||          }|\  }}|                                                    |          }|j        j        d|}|t          d|z            |j                            d          st          d|z            |S )N.zNo such trait: %ssyncz%s cannot be synced)	r   r   validate_elementstraitsgetr   __name__	TypeErrormetadata)r   objvaluewidget
trait_nametrait
trait_reprr   s          r   r   z"WidgetTraitTuple.validate_elements   s    &--??UKK"
##J// & 0 9 9 9::F
 =/*<===##F++ 	@1J>???r   )r   
__module____qualname____doc__	info_textr   r   __classcell__r   s   @r   r   r      sa        FF/IV V V V V        r   r   c                        e Zd ZdZ ed                              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                 \    ||d<   ||d<    t          t          |           j        di | d S )Nsourcetarget )r   r-   r   )r   r2   r3   r   r   s       r   r   zLink.__init__1   s@    !x!x"dD",,V,,,,,r   c                 .    |                                   d S r   )close)r   s    r   unlinkzLink.unlink7   s    

r   r4   )r   r&   r'   r(   r   tag_model_namer   r   r3   r2   r   r7   r*   r+   s   @r   r-   r-   %   s          '+&&***55KP#KLLLPssVZs^rssFP#KLLLPssVZs^rssF- - - - -      r   r-   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'))
    )r-   )attr1attr2s     r   jslinkr=   ;   s      ur   c                   P    e Zd ZdZ ed                              d          ZdS )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.
    DirectionalLinkModelTr/   N)r   r&   r'   r(   r   r8   r9   r4   r   r   r?   r?   N   s;          '0115545@@KKKr   r?   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'))
    )r?   )r2   r3   s     r   jsdlinkrB   Y   s      66***r   N)r(   r"   r   r   r   widget_corer   	traitletsr   r	   r
   r   r   r-   r=   r?   rB   r4   r   r   <module>rE      s+   
 ; : : : : : : : : : # # # # # # : : : : : : : : : : : :    u   , 
    :   
*  & 
A A A A Ad A A 
A+ + + + +r   