
    ^h<                     J   S r SSKrSSKJr  SSKJrJrJrJrJ	r	J
r
  SSKJr  SSKJrJr  SSKJrJr  SS	KJr  SS
KJr  SSKJr  SS0r\" \5       " S S\5      5       r\" \5       " S S\\5      5       r\" \5       " S S\\5      5       r\" \5       " S S\\5      5       rg)z7Implement common widgets layouts as reusable components    N)defaultdict)InstanceBoolUnicodeCUnicodeCaselessStrEnumTuple)Integer)	HasTraits
TraitError)observevalidate   )Widget)GridBox)	doc_subststyle_paramsa  

    grid_gap : str
        CSS attribute used to set the gap between the grid cells

    justify_content : str, in ['flex-start', 'flex-end', 'center', 'space-between', 'space-around']
        CSS attribute used to align widgets vertically

    align_items : str, in ['top', 'bottom', 'center', 'flex-start', 'flex-end', 'baseline', 'stretch']
        CSS attribute used to align widgets horizontally

    width : str
    height : str
        width and heightc                      ^  \ rS rSrSr\" SSSS9r\" / SQSSS9r\" / S	QSS
S9r	\" SSSS9r
\" SSSS9rU 4S jrS rS rS rSrU =r$ )LayoutProperties"   a'  Mixin class for layout templates

This class handles mainly style attributes (height, grid_gap etc.)

Parameters
----------

{style_params}


Note
----

This class is only meant to be used in inheritance as mixin with other
classes. It will not work, unless `self.layout` attribute is defined.

NTzThe grid-gap CSS attribute.)
allow_nonehelp)
flex-startflex-endcenterzspace-betweenzspace-aroundz"The justify-content CSS attribute.)topbottomr   r   r   baselinestretchzThe align-items CSS attribute.zThe width CSS attribute.c                    > [         TU ]  " S0 UD6  [        [        5      U l        SSS.U R                  S'   U R                  5         U R                  5         g )Nr   r   )r   r   align_items )super__init__r   dict_property_rewrite_copy_layout_props_set_observersselfkwargs	__class__s     ]/home/james-whalen/.local/lib/python3.13/site-packages/ipywidgets/widgets/widget_templates.pyr$   LayoutProperties.__init__O   sQ    "6"!,T!28D;E1G}-!    c                 ~    US   US   p2U R                   U   R                  X"5      n[        U R                  X25        g)z=delegate the trait types to their counterparts in self.layoutnewnameN)r&   getsetattrlayout)r*   changevaluer2   s       r-   _delegate_to_layout$LayoutProperties._delegate_to_layoutW   s:    UmVF^t&&t,00>T)r/   c                 d    [         R                  5       nU R                  U R                  U5        g)z<set observers on all layout properties defined in this classN)r   class_trait_namesr   r8   )r*   _propss     r-   r(   LayoutProperties._set_observers]   s$    !335T--v6r/   c                     [         R                  5       nU HK  n[        X5      nU(       d  M  U R                  U   R	                  X35      n[        U R                  X#5        MM     g N)r   r;   getattrr&   r3   r4   r5   )r*   r<   propr7   s       r-   r'   #LayoutProperties._copy_layout_propsb   sR    !335DD'Eu..t488FT1	 r/   )r&   )__name__
__module____qualname____firstlineno____doc__r   grid_gapr   justify_contentr!   widthheightr$   r8   r(   r'   __static_attributes____classcell__r,   s   @r-   r   r   "   s    & *,H &	*1	3O
 "	  >	@K
 ')E ')F*7
2 2r/   r   c            
       ,  ^  \ rS rSrSr\" \SS9r\" \SS9r\" \SS9r	\" \SS9r
\" \SS9r\" \" 5       \" 5       \" 5       / SQS9r\" \" 5       \" 5       \" 5       / SQS9r\" SS9rU 4S jr\S	 5       rS
 rS r\" SSSSSSSS5      S 5       rSrU =r$ )	AppLayoutl   a  Define an application like layout of widgets.

Parameters
----------

header: instance of Widget
left_sidebar: instance of Widget
center: instance of Widget
right_sidebar: instance of Widget
footer: instance of Widget
    widgets to fill the positions in the layout

merge: bool
    flag to say whether the empty positions should be automatically merged

pane_widths: list of numbers/strings
    the fraction of the total layout width each of the central panes should occupy
    (left_sidebar,
    center, right_sidebar)

pane_heights: list of numbers/strings
    the fraction of the width the vertical space that the panes should occupy
     (left_sidebar, center, right_sidebar)

{style_params}

Examples
--------

Tr   )1fr2frrS   default_value)rS   3frrS   c                 F   > [         TU ]  " S0 UD6  U R                  5         g Nr"   r#   r$   _update_layoutr)   s     r-   r$   AppLayout.__init__       "6"r/   c                     [         R                  " SU 5      (       a  U $ [         R                  " SU 5      (       a  U S-   $ [        SR                  U 5      5      e)Nz\d+\.?\d*(px|fr|%)$z
\d+\.?\d*$frzqthe pane sizes must be in one of the following formats: '10px', '10fr', 10 (will be converted to '10fr').Got '{}')rematch	TypeErrorformat)sizes    r-   _size_to_cssAppLayout._size_to_css   sO    88*D11K88M4(($; ##)6$<1 	1r/   c                 @    [        [        U R                  U5      5      $ r?   )listmapre   )r*   	size_lists     r-   _convert_sizesAppLayout._convert_sizes   s    C))9566r/   c                    / SQ/ SQ/ SQ/nU R                  U R                  5      nU R                  U R                  5      nU R                  U R                  U R
                  U R                  U R                  S.nUR                  5        VVs0 s H  u  pVUc  M
  XV_M     nnnU(       d  g UR                  5        H  u  pVXVR                  l
        M     U R                  (       a  [        U5      S:X  a(  [        UR                  5       5      S   nXUU/XUU/XUU//nOU R                  c  U H  nUS	 M     US	 U R
                  c  US   S   US   S'   U R                  c  US   S   US   S'   U R
                  c'  U R                  c  U R                  c  S	/S
//nS/nSS/nU R                  c  US	 US	 U R                  c  US	 US	 SR                  S U 5       5      n	SR                  U5      U R                  l        SR                  U5      U R                  l        XR                  l        ['        UR)                  5       5      U l        g s  snnf )N)headerrn   rn   )left-sidebarr   right-sidebar)footerrq   rq   )rn   rq   ro   rp   r   r   r   rn   rq   rS   
c              3   b   #    U  H%  nS R                  SR                  U5      5      v   M'     g7fz"{}" Nrc   join.0lines     r-   	<genexpr>+AppLayout._update_layout.<locals>.<genexpr>   ,      ,M8K -3MM#((4.,I,I8K   -/rw   )rk   pane_widthspane_heightsrn   rq   left_sidebarright_sidebarr   itemsr5   	grid_areamergelenrh   keysry   grid_template_columnsgrid_template_rowsgrid_template_areastuplevalueschildren)
r*   r   r   r   all_childrenpositionchildr   rowgrid_template_areas_csss
             r-   r[   AppLayout._update_layout   sp   =J=? !% 3 3D4D4D E!001B1BC"&++"&++(,(9(9)-););"&++	/ ,8+=+=+?*+? %H$+? 	 * '~~/OH%-LL"  0 ::8}!03(0H'E(0H'E(0H'E'G#
 ;;&2F  3-a0$$,0CA0Fq0I'*1-%%-1DQ1G1K'*2.%%-**2+,4:z*B'-2G)*/&;;&+A.*1-;;&+B/*2. #')) ,M8K,M #M -0HH5J,K)),2D)E&*A'hoo/0k*s   	IIrq   rn   r   r   r   r   r   r   c                 $    U R                  5         g r?   r[   r*   r6   s     r-   _child_changedAppLayout._child_changed   s     	r/   r   )rC   rD   rE   rF   rG   r   r   rn   rq   r   r   r   r	   r   r   r   r   r   r$   staticmethodre   rk   r[   r   r   rL   rM   rN   s   @r-   rP   rP   l   s    @ f.Ff.FFt4LV5Mf.F 
HJ
&;=KXZ'<>L t$E 1 17D1L Xx>?GN,,r/   rP   c                      ^  \ rS rSrSr\" 5       r\" 5       rSU 4S jjr\	" SS5      S 5       r
S rS rS	 rS
 rSrU =r$ )GridspecLayout   aZ  Define a N by M grid layout

Parameters
----------

n_rows : int
    number of rows in the grid

n_columns : int
    number of columns in the grid

{style_params}

Examples
--------

>>> from ipywidgets import GridspecLayout, Button, Layout
>>> layout = GridspecLayout(n_rows=4, n_columns=2, height='200px')
>>> layout[:3, 0] = Button(layout=Layout(height='auto', width='auto'))
>>> layout[1:, 1] = Button(layout=Layout(height='auto', width='auto'))
>>> layout[-1, 0] = Button(layout=Layout(height='auto', width='auto'))
>>> layout[0, 1] = Button(layout=Layout(height='auto', width='auto'))
>>> layout
c                 *  > [         TU ]  " S0 UD6  Xl        X l        [	        U R                  5       Vs/ s H  nS/U R                  -  PM     snU l        SU R                  4-  U l        SU R                  4-  U l        0 U l        SU l	        g s  snf )N.zrepeat(%d, 1fr)r   r"   )
r#   r$   n_rows	n_columnsrange_grid_template_areas_grid_template_rows_grid_template_columns	_children	_id_count)r*   r   r   r+   ir,   s        r-   r$   GridspecLayout.__init__  s    "6""EJ4;;EW$XEWcUT^^%;EW$X!#4~#E &74>>:K&K# %Ys   Br   r   c                 4    US   S:  a  US   $ [        S5      e)Nr7   r   z-n_rows and n_columns must be positive integer)r   )r*   proposals     r-   _validate_integer GridspecLayout._validate_integer#  s&    Gq G$$HIIr/   c                    [        U[        5      (       a+  UR                  U R                  5      u  p4n[	        X4U5      nOU/n[        U[        5      (       a-  UR                  U R
                  5      u  p4n[	        X4U5      nXg4$ U/nXg4$ )zDconvert a two-dimensional slice to a list of rows and column indices)
isinstancesliceindicesr   r   r   )r*   r   columnstartstopstriderowscolumnss           r-   _get_indices_from_slice&GridspecLayout._get_indices_from_slice)  s     c5!!"%++dkk":Ef-D5Dfe$$"(.."@EE0G } hG}r/   c                    Uu  p4U =R                   S-  sl         SU R                   -  nXRR                  l        U R                  X45      u  pgU HQ  nU HH  nU R                  U   U   nUS:w  a  XR
                  ;   a  U R
                  U	 XPR                  U   U'   MJ     MS     X R
                  U'   U R                  5         g )Nr   z
widget%03dr   )r   r5   r   r   r   r   r[   )	r*   keyr7   r   r   obj_idr   r   current_values	            r-   __setitem__GridspecLayout.__setitem__:  s    !.!'44SAC! $ 9 9# >v F C'M^^,K}59?))#.v6	 "  "'vr/   c                     U R                   " U6 u  p#S nU H9  nU H0  nU R                  U   U   nU=(       d    UnXG:w  d  M'  [        S5      e   M;     U R                  U   $ )NzTThe slice spans several widgets, but only a single widget can be retrieved at a time)r   r   rb   r   )r*   r   r   r   r   r   r   
new_obj_ids           r-   __getitem__GridspecLayout.__getitem__L  su    44c:C!!66s;FC
-:'# %0 1 1	 "  ~~f%%r/   c                 $   SR                  S U R                   5       5      nU R                  U R                  l        U R
                  U R                  l        XR                  l        [        U R                  R                  5       5      U l        g )Nrt   c              3   b   #    U  H%  nS R                  SR                  U5      5      v   M'     g7frv   rx   rz   s     r-   r}   0GridspecLayout._update_layout.<locals>.<genexpr>]  s,      ,S8Q -3MM#((4.,I,I8Qr   )ry   r   r   r5   r   r   r   r   r   r   r   r   )r*   r   s     r-   r[   GridspecLayout._update_layout[  sp    "&)) ,S8<8Q8Q,S #S -1,G,G))-)A)A&*A'dnn3356r/   )r   r   r   r   r   r   r   r   )NN)rC   rD   rE   rF   rG   r
   r   r   r$   r   r   r   r   r   r[   rL   rM   rN   s   @r-   r   r      sS    2 YF	I	 h$J %J
"$&7 7r/   r   c                      ^  \ rS rSrSr\" \SS9r\" \SS9r\" \SS9r	\" \SS9r
\" SS9rU 4S jrS r\" SS	S
SS5      S 5       rSrU =r$ )TwoByTwoLayoutif  a  Define a layout with 2x2 regular grid.

Parameters
----------

top_left: instance of Widget
top_right: instance of Widget
bottom_left: instance of Widget
bottom_right: instance of Widget
    widgets to fill the positions in the layout

merge: bool
    flag to say whether the empty positions should be automatically merged

{style_params}

Examples
--------

>>> from ipywidgets import TwoByTwoLayout, Button
>>> TwoByTwoLayout(top_left=Button(description="Top left"),
...                top_right=Button(description="Top right"),
...                bottom_left=Button(description="Bottom left"),
...                bottom_right=Button(description="Bottom right"))

TrR   rU   c                 F   > [         TU ]  " S0 UD6  U R                  5         g rY   rZ   r)   s     r-   r$   TwoByTwoLayout.__init__  r]   r/   c                    SS/SS//nU R                   U R                  U R                  U R                  S.nUR	                  5        VVs0 s H  u  p4Uc  M
  X4_M     nnnU(       d  g UR	                  5        H  u  p4X4R
                  l        M     U R                  (       a  [        U5      S:X  a#  [        UR                  5       5      S   nX3/X3//nOSS	/n[        U5       H~  u  pxUR                  S
U-   5      UR                  SU-   5      pUS-   S-  nU	c!  U
c  US   U   US   U'   US   U   US   U'   MX  U	c  US   U   US   U'   Mk  U
b  Mp  US   U   US   U'   M     SR                  S U 5       5      nSU R
                  l        SU R
                  l        XR
                  l        [#        UR%                  5       5      U l        g s  snnf )Ntop-left	top-rightbottom-leftbottom-right)r   r   r   r   r   r   leftrightztop-zbottom-   rt   c              3   b   #    U  H%  nS R                  SR                  U5      5      v   M'     g7frv   rx   rz   s     r-   r}   0TwoByTwoLayout._update_layout.<locals>.<genexpr>  r   r   z1fr 1fr)top_left	top_rightbottom_leftbottom_rightr   r5   r   r   r   rh   r   	enumerater3   ry   r   r   r   r   r   r   )r*   r   r   r   r   r   r   r   r   r   r   i_neighbourr   s                r-   r[   TwoByTwoLayout._update_layout  s    !+K8 -~>@ &*]]&*nn(,(8(8)-):):< ,8+=+=+?*+? %H$+? 	 * '~~/OH%-LL"  0 ::8}!03(0';(0';'=# "7+!*7!3IA"*,,v"?iZ`N`Aa#$q5A+K{v~4G4J;4W+A.q14G4J;4W+A.q14G4J14M+A.q14G4J14M+A.q1 "4 #')) ,M8K,M #M -6))2&*A'hoo/0O*s   	GGr   r   r   r   r   c                 $    U R                  5         g r?   r   r   s     r-   r   TwoByTwoLayout._child_changed  s    r/   r   )rC   rD   rE   rF   rG   r   r   r   r   r   r   r   r   r$   r[   r   r   rL   rM   rN   s   @r-   r   r   f  ss    8 40HD1I6d3KFt4L t$E21h Z^WM Nr/   r   )rG   r`   collectionsr   	traitletsr   r   r   r   r   r	   r
   r   r   r   r   widgetr   
widget_boxr   docutilsr   _doc_snippetsr   rP   r   r   r"   r/   r-   <module>r      s    = 	 # O O  + '     " =G2y G2 G2R =J) J JZ =h7W. h7 h7V =_W. _ _r/   