
    hMh<                        d Z ddlZddlmZ ddlmZmZmZmZm	Z	m
Z
 ddlmZ ddl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iZ ee           G d de                      Z ee           G d dee                      Z ee           G d dee                      Z ee           G d dee                      ZdS )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                        e Zd ZdZ eddd          Z eg ddd          Z eg ddd	          Z eddd
          Z	 eddd
          Z
 fdZd Zd Zd Z xZS )LayoutPropertiesaK  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                      j        di | t          t                    | _        ddd| j        d<   |                                  |                                  d S )Nr   r   )r   r   align_items )super__init__r   dict_property_rewrite_copy_layout_props_set_observersselfkwargs	__class__s     c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/ipywidgets/widgets/widget_templates.pyr#   zLayoutProperties.__init__O   sv    ""6"""!,T!2!28D;E1G 1G}-!!!    c                     |d         |d         }}| j         |                             ||          }t          | j        ||           dS )z=delegate the trait types to their counterparts in self.layoutnewnameN)r%   getsetattrlayout)r)   changevaluer0   s       r,   _delegate_to_layoutz$LayoutProperties._delegate_to_layoutW   sJ    UmVF^t&t,00>>T5)))))r-   c                 n    t                                           }|                     | j        |           dS )z<set observers on all layout properties defined in this classN)r   class_trait_namesr   r6   )r)   _propss     r,   r'   zLayoutProperties._set_observers]   s0    !3355T-v66666r-   c                     t                                           }|D ]K}t          | |          }|r7| j        |                             ||          }t          | j        ||           Ld S N)r   r8   getattrr%   r1   r2   r3   )r)   r9   propr5   s       r,   r&   z#LayoutProperties._copy_layout_propsb   su    !3355 	2 	2DD$''E 2.t488FFT5111		2 	2r-   )__name__
__module____qualname____doc__r   grid_gapr   justify_contentr    widthheightr#   r6   r'   r&   __classcell__r+   s   @r,   r   r   "   s1        & w*, , ,H &o	* 	* 	*1	3 3 3O
 "/	  	  	  >	@ @ @K
 G') ) )E W') ) )F    * * *7 7 7
2 2 2 2 2 2 2r-   r   c            
           e Zd ZdZ eed          Z eed          Z eed          Z eed          Z	 eed          Z
 e e             e             e            g d          Z e e             e             e            g d          Z ed          Z fdZed             Zd	 Zd
 Z edddddddd          d             Z xZS )	AppLayouta"   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2frrK   default_value)rK   3frrK   c                 b     t                      j        di | |                                  d S Nr!   r"   r#   _update_layoutr(   s     r,   r#   zAppLayout.__init__   8    ""6"""r-   c                     t          j        d|           r| S t          j        d|           r| dz   S t          d                    |                     )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_csszAppLayout._size_to_css   s\    8*D11 	K8M4(( 	$; ##)6$<<1 1 	1r-   c                 F    t          t          | j        |                    S r;   )listmapr\   )r)   	size_lists     r,   _convert_sizeszAppLayout._convert_sizes   s    C)955666r-   c                 (   g dg dg dg}|                      | j                  }|                      | j                  }| j        | j        | j        | j        | j        d}d |                                D             }|sd S |                                D ]\  }}||j	        _
        | j        rt          |          dk    r6t          |                                          d         }|||g|||g|||gg}n| j        |D ]}|d= |d= | j        |d         d         |d         d<   | j        |d         d         |d         d	<   | j        | j        | j        d
gdgg}dg}ddg}| j        |d= |d= | j        |d	= |d	= d                    d |D                       }	d                    |          | j	        _        d                    |          | j	        _        |	| j	        _        t'          |                                          | _        d S )N)headerrc   rc   )left-sidebarr   right-sidebar)footerrf   rf   )rc   rf   rd   re   r   c                     i | ]
\  }}|||S r;   r!   .0positionchilds      r,   
<dictcomp>z,AppLayout._update_layout.<locals>.<dictcomp>   .     * * *'%( u(((r-   r   r   rc   rf   rK   
c              3   f   K   | ],}d                      d                    |                    V  -dS z"{}" NrZ   joinri   lines     r,   	<genexpr>z+AppLayout._update_layout.<locals>.<genexpr>   T       ,M ,M04 -3MM#((4..,I,I ,M ,M ,M ,M ,M ,Mr-   rs   )ra   pane_widthspane_heightsrc   rf   left_sidebarright_sidebarr   itemsr3   	grid_areamergelenr^   keysru   grid_template_columnsgrid_template_rowsgrid_template_areastuplevalueschildren)
r)   r   r   r   all_childrenr   rj   rk   rowgrid_template_areas_csss
             r,   rS   zAppLayout._update_layout   s   ===JJJ===? !% 3 3D4D E E!001BCC"&+"&+(,(9)-);"&+	/ /* *+7+=+=+?+?* * *  	F'~~// 	. 	.OHe%-EL"": !	/8}}!!003(0(H'E(0(H'E(0(H'E'G##
 ;&2 # #FF-a0$,0CA0Fq0I'*1-%-1DQ1G1K'*2.%-*2+,4:z*B'-2G)*/&;&+A.*1-;&+B/*2. #')) ,M ,M8K,M ,M ,M #M #M -0HH5J,K,K)),2D)E)E&*A'hoo//00r-   rf   rc   r   r|   r}   r   rz   r{   c                 .    |                                   d S r;   rS   r)   r4   s     r,   _child_changedzAppLayout._child_changed   s     	r-   )r>   r?   r@   rA   r   r   rc   rf   r|   r}   r   r	   r   rz   r{   r   r   r#   staticmethodr\   ra   rS   r   r   rF   rG   s   @r,   rI   rI   l   s        @ Xf...FXf...F8Ft444LHV555MXf...F %

HHJJ

&;&;&;= = =K5XXZZ'<'<'<> > >L Dt$$$E     1 1 \17 7 7D1 D1 D1L WXx>?GN, , , ,    r-   rI   c                        e Zd ZdZ e            Z e            Zd fd	Z edd          d             Z	d Z
d Zd	 Zd
 Z xZS )GridspecLayouta   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
    Nc                       t                      j        di | | _        | _         fdt	           j                  D              _        d j        fz   _        d j        fz   _        i  _        d _	        d S )Nc                 &    g | ]}d gj         z  S ).)	n_columns)ri   ir)   s     r,   
<listcomp>z+GridspecLayout.__init__.<locals>.<listcomp>  s"    $X$X$XcUT^%;$X$X$Xr-   zrepeat(%d, 1fr)r   r!   )
r"   r#   n_rowsr   range_grid_template_areas_grid_template_rows_grid_template_columns	_children	_id_count)r)   r   r   r*   r+   s   `   r,   r#   zGridspecLayout.__init__  s    ""6""""$X$X$X$XU4;EWEW$X$X$X!#4~#E &74>:K&K#r-   r   r   c                 H    |d         dk    r|d         S t          d          )Nr5   r   z-n_rows and n_columns must be positive integer)r   )r)   proposals     r,   _validate_integerz GridspecLayout._validate_integer#  s,    Gq  G$$HIIIr-   c                 *   t          |t                    r0|                    | j                  \  }}}t	          |||          }n|g}t          |t                    r0|                    | j                  \  }}}t	          |||          }n|g}||fS )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_slicez&GridspecLayout._get_indices_from_slice)  s     c5!! 	"%++dk":":E4f--DD5Dfe$$ 	"(.."@"@E4E400GGhGW}r-   c                 R   |\  }}| xj         dz  c_         d| j         z  }||j        _        |                     ||          \  }}|D ]A}|D ]<}| j        |         |         }|dk    r|| j        v r| j        |= || j        |         |<   =B|| j        |<   |                                  d S )Nr   z
widget%03dr   )r   r3   r   r   r   r   rS   )	r)   keyr5   r   r   obj_idr   r   current_values	            r,   __setitem__zGridspecLayout.__setitem__:  s    V!.!'44S&AAg 	@ 	@C! @ @ $ 9# >v F C''MT^,K,K}59?)#.v66	@ "'vr-   c                      | j         | \  }}d }|D ]3}|D ].}| j        |         |         }|p|}||k    rt          d          /4| j        |         S )NzTThe slice spans several widgets, but only a single widget can be retrieved at a time)r   r   rY   r   )r)   r   r   r   r   r   r   
new_obj_ids           r,   __getitem__zGridspecLayout.__getitem__L  s    44c:g 	1 	1C! 1 1!6s;FC
-:Z''# %0 1 1 1 (1 ~f%%r-   c                     d                     d | j        D                       }| j        | j        _        | j        | j        _        || j        _        t          | j	        
                                          | _        d S )Nrp   c              3   f   K   | ],}d                      d                    |                    V  -dS rr   rt   rv   s     r,   rx   z0GridspecLayout._update_layout.<locals>.<genexpr>]  sT       ,S ,S04 -3MM#((4..,I,I ,S ,S ,S ,S ,S ,Sr-   )ru   r   r   r3   r   r   r   r   r   r   r   r   )r)   r   s     r,   rS   zGridspecLayout._update_layout[  s    "&)) ,S ,S8<8Q,S ,S ,S #S #S -1,G))-)A&*A'dn335566r-   )NN)r>   r?   r@   rA   r
   r   r   r#   r   r   r   r   r   rS   rF   rG   s   @r,   r   r      s         2 WYYF		I	 	 	 	 	 	 Xh$$J J %$J
  "  $& & &7 7 7 7 7 7 7r-   r   c                        e Zd ZdZ eed          Z eed          Z eed          Z eed          Z	 e
d          Z fdZd Z eddd	d
d          d             Z xZS )TwoByTwoLayouta   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"))

    TrJ   rM   c                 b     t                      j        di | |                                  d S rQ   rR   r(   s     r,   r#   zTwoByTwoLayout.__init__  rT   r-   c                    ddgddgg}| j         | j        | j        | j        d}d |                                D             }|sd S |                                D ]\  }}||j        _        | j        rt          |          dk    r0t          |
                                          d         }||g||gg}nd	d
g}t          |          D ]\  }}|                    d|z             |                    d|z             }
}	|dz   dz  }|	1|
/|d         |         |d         |<   |d         |         |d         |<   p|	|d         |         |d         |<   |
|d         |         |d         |<   d                    d |D                       }d| j        _        d| j        _        || j        _        t#          |                                          | _        d S )Ntop-left	top-rightbottom-leftbottom-right)r   r   r   r   c                     i | ]
\  }}|||S r;   r!   rh   s      r,   rl   z1TwoByTwoLayout._update_layout.<locals>.<dictcomp>  rm   r-   r   r   leftrightztop-zbottom-   rp   c              3   f   K   | ],}d                      d                    |                    V  -dS rr   rt   rv   s     r,   rx   z0TwoByTwoLayout._update_layout.<locals>.<genexpr>  ry   r-   z1fr 1fr)top_left	top_rightbottom_leftbottom_rightr~   r3   r   r   r   r^   r   	enumerater1   ru   r   r   r   r   r   r   )r)   r   r   r   rj   rk   r   r   r   r   r   i_neighbourr   s                r,   rS   zTwoByTwoLayout._update_layout  sL    !+K8 -~>@ &*]&*n(,(8)-):< <
* *+7+=+=+?+?* * *  	F'~~// 	. 	.OHe%-EL"": 	N8}}!!003(0(';(0(';'=## "7+!*7!3!3 N NIAv"*,,v"?"?iZ`N`AaAaC#$q5A+K{v~4G4J;4W+A.q14G4J;4W+A.q114G4J14M+A.q114G4J14M+A.q1"&)) ,M ,M8K,M ,M ,M #M #M -6))2&*A'hoo//00r-   r   r   r   r   r   c                 .    |                                   d S r;   r   r   s     r,   r   zTwoByTwoLayout._child_changed  s    r-   )r>   r?   r@   rA   r   r   r   r   r   r   r   r   r#   rS   r   r   rF   rG   s   @r,   r   r   f  s         8 x4000HD111I(6d333K8Ft444L Dt$$$E    21 21 21h WZ^WMM  NM    r-   r   )rA   rW   collectionsr   	traitletsr   r   r   r   r   r	   r
   r   r   r   r   widgetr   
widget_boxr   docutilsr   _doc_snippetsr   rI   r   r   r!   r-   r,   <module>r      s   = = 				 # # # # # # O O O O O O O O O O O O O O O O       + + + + + + + + ' ' ' ' ' ' ' '                    " =G2 G2 G2 G2 G2y G2 G2 G2R =J J J J J) J J JZ =h7 h7 h7 h7 h7W. h7 h7 h7V =_ _ _ _ _W. _ _ _ _ _r-   