ó
0¾I]c           @   s^  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 i d d 6Z e e ƒ d e f d „  ƒ  Yƒ Z e e ƒ d e e f d „  ƒ  Yƒ Z e e ƒ d e e f d „  ƒ  Yƒ Z e e ƒ d e e f d „  ƒ  Yƒ Z d S(   s7   Implement common widgets layouts as reusable componentsiÿÿÿÿN(   t   defaultdict(   t   Instancet   Boolt   Unicodet   CUnicodet   CaselessStrEnumt   Tuple(   t   Integer(   t	   HasTraitst
   TraitError(   t   observet   validatei   (   t   Widget(   t   GridBox(   t	   doc_substsÍ  

    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 heightt   style_paramst   LayoutPropertiesc           B   sÎ   e  Z d  Z e d d e d d ƒZ e d d d d d g d e d d	 ƒZ e d
 d d d d d d g d e d d ƒZ	 e d d e d d ƒZ
 e d d e d d ƒZ d „  Z d „  Z d „  Z d „  Z RS(   sK  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.

    t
   allow_nonet   helps   The grid-gap CSS attribute.s
   flex-starts   flex-endt   centers   space-betweens   space-arounds"   The justify-content CSS attribute.t   topt   bottomt   baselinet   stretchs   The align-items CSS attribute.s   The width CSS attribute.c         K   sX   t  t |  ƒ j |   t t ƒ |  _ i d d 6d d 6|  j d <|  j ƒ  |  j ƒ  d  S(   Ns
   flex-startR   s   flex-endR   t   align_items(   t   superR   t   __init__R    t   dictt   _property_rewritet   _copy_layout_propst   _set_observers(   t   selft   kwargs(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR   O   s    

c         C   sE   | d | d } } |  j  | j | | ƒ } t |  j | | ƒ d S(   s=   delegate the trait types to their counterparts in self.layoutt   newt   nameN(   R   t   gett   setattrt   layout(   R   t   changet   valueR"   (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyt   _delegate_to_layoutW   s    c         C   s#   t  j ƒ  } |  j |  j | ƒ d S(   s<   set observers on all layout properties defined in this classN(   R   t   class_trait_namesR
   R(   (   R   t   _props(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR   ]   s    c         C   se   t  j ƒ  } xR | D]J } t |  | ƒ } | r |  j | j | | ƒ } t |  j | | ƒ q q Wd  S(   N(   R   R)   t   getattrR   R#   R$   R%   (   R   R*   t   propR'   (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR   b   s    N(   t   __name__t
   __module__t   __doc__R   t   Nonet   Truet   grid_gapR   t   justify_contentR   t   widtht   heightR   R(   R   R   (    (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR   "   s6   									t	   AppLayoutc        	   B   s  e  Z d  Z e e d e ƒZ e e d e ƒZ e e d e ƒZ e e d e ƒZ	 e e d e ƒZ
 e e ƒ  e ƒ  e ƒ  d d d d g ƒZ e e ƒ  e ƒ  e ƒ  d d d d g ƒZ e d e ƒ Z d „  Z e d „  ƒ Z d „  Z d	 „  Z e d
 d d d d d d d ƒ d „  ƒ Z RS(   s"   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
    --------

    R   t   default_valuet   1frt   2frt   3frc         K   s$   t  t |  ƒ j |   |  j ƒ  d  S(   N(   R   R6   R   t   _update_layout(   R   R    (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR   œ   s    c         C   sI   t  j d |  ƒ r |  St  j d |  ƒ r0 |  d St d j |  ƒ ƒ ‚ d  S(   Ns   \d+\.?\d*(px|fr|%)$s
   \d+\.?\d*$t   frsq   the pane sizes must be in one of the following formats: '10px', '10fr', 10 (will be converted to '10fr').Got '{}'(   t   ret   matcht	   TypeErrort   format(   t   size(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyt   _size_to_css    s    	c         C   s   t  t |  j | ƒ ƒ S(   N(   t   listt   mapRB   (   R   t	   size_list(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyt   _convert_sizes«   s    c   
      C   s°  d d d g d d d g d d d g g } |  j  |  j ƒ } |  j  |  j ƒ } i |  j d 6|  j d 6|  j d 6|  j d 6|  j d 6} d „  | j ƒ  Dƒ } | s¦ d  Sx& | j ƒ  D] \ } } | | j	 _
 q³ W|  j rHt | ƒ d k r-t | j ƒ  ƒ d } | | | g | | | g | | | g g } qH|  j d  k r^x | D] } | d =qCW| d =n  |  j d  k r†| d d | d d <n  |  j d  k r®| d d	 | d d
 <n  |  j d  k r|  j d  k r|  j d  k rd g d g g } d g } d d g } n  |  j d  k r%| d =| d =n  |  j d  k rH| d
 =| d
 =qHn  d j d „  | Dƒ ƒ }	 d j | ƒ |  j	 _ d j | ƒ |  j	 _ |	 |  j	 _ t | j ƒ  ƒ |  _ d  S(   Nt   headers   left-sidebarR   s   right-sidebart   footerc         S   s+   i  |  ]! \ } } | d  k	 r | | “ q S(   N(   R0   (   t   .0t   positiont   child(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pys
   <dictcomp>½   s   		i   i    iþÿÿÿiÿÿÿÿR8   s   
c         s   s'   |  ] } d  j  d j | ƒ ƒ Vq d S(   s   "{}"t    N(   R@   t   join(   RI   t   line(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pys	   <genexpr>ë   s   RL   (   RF   t   pane_widthst   pane_heightsRG   RH   t   left_sidebart   right_sidebarR   t   itemsR%   t	   grid_areat   merget   lenRC   t   keysR0   RM   t   grid_template_columnst   grid_template_rowst   grid_template_areast   tuplet   valuest   children(
   R   RZ   RX   RY   t   all_childrenR]   RJ   RK   t   rowt   grid_template_areas_css(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR;   ®   s`    


	
	
RH   RG   R   RQ   RR   RU   RO   RP   c         C   s   |  j  ƒ  d  S(   N(   R;   (   R   R&   (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyt   _child_changedô   s    (   R-   R.   R/   R   R   R1   RG   RH   RQ   RR   R   R   R   RO   RP   R   RU   R   t   staticmethodRB   RF   R;   R
   Ra   (    (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR6   l   s"   			Ft   GridspecLayoutc           B   sk   e  Z d  Z e ƒ  Z e ƒ  Z d	 d	 d „ Z e d d ƒ d „  ƒ Z	 d „  Z
 d „  Z d „  Z d „  Z RS(
   sŸ   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         K   s“   t  t |  ƒ j |   | |  _ | |  _ g  t |  j ƒ D] } d g |  j ^ q8 |  _ d |  j f |  _ d |  j f |  _ i  |  _	 d |  _
 d  S(   Nt   .s   repeat(%d, 1fr)i    (   R   Rc   R   t   n_rowst	   n_columnst   ranget   _grid_template_areast   _grid_template_rowst   _grid_template_columnst	   _childrent	   _id_count(   R   Re   Rf   R    t   i(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR     s    		/	Re   Rf   c         C   s(   | d d k r | d St  d ƒ ‚ d  S(   NR'   i    s-   n_rows and n_columns must be positive integer(   R	   (   R   t   proposal(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyt   _validate_integer#  s    c         C   sš   t  | t ƒ r? | j |  j ƒ \ } } } t | | | ƒ } n	 | g } t  | t ƒ r‡ | j |  j ƒ \ } } } t | | | ƒ } n	 | g } | | f S(   sD   convert a two-dimensional slice to a list of rows and column indices(   t
   isinstancet   slicet   indicesRe   Rg   Rf   (   R   R_   t   columnt   startt   stopt   stridet   rowst   columns(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyt   _get_indices_from_slice)  s    		c   	      C   sÓ   | \ } } |  j  d 7_  d |  j  } | | j _ |  j | | ƒ \ } } xi | D]a } xX | D]P } |  j | | } | d k rŸ | |  j k rŸ |  j | =n  | |  j | | <q` WqS W| |  j | <|  j ƒ  d  S(   Ni   s
   widget%03dRd   (   Rl   R%   RT   Ry   Rh   Rk   R;   (	   R   t   keyR'   R_   Rs   t   obj_idRw   Rx   t   current_value(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyt   __setitem__:  s    c         C   s€   |  j  | Œ  \ } } d  } xW | D]O } xF | D]> } |  j | | } | pO | } | | k r/ t d ƒ ‚ q/ q/ Wq" W|  j | S(   NsT   The slice spans several widgets, but only a single widget can be retrieved at a time(   Ry   R0   Rh   R?   Rk   (   R   Rz   Rw   Rx   R{   R_   Rs   t
   new_obj_id(    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyt   __getitem__L  s    c         C   sb   d j  d „  |  j Dƒ ƒ } |  j |  j _ |  j |  j _ | |  j _ t |  j	 j
 ƒ  ƒ |  _ d  S(   Ns   
c         s   s'   |  ] } d  j  d j | ƒ ƒ Vq d S(   s   "{}"RL   N(   R@   RM   (   RI   RN   (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pys	   <genexpr>]  s   (   RM   Rh   Rj   R%   RX   Ri   RY   RZ   R[   Rk   R\   R]   (   R   R`   (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR;   [  s    N(   R-   R.   R/   R   Re   Rf   R0   R   R   Ro   Ry   R}   R   R;   (    (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyRc   ú   s   					t   TwoByTwoLayoutc           B   s˜   e  Z d  Z e e d e ƒZ e e d e ƒZ e e d e ƒZ e e d e ƒZ	 e
 d e ƒ Z d „  Z d „  Z e d d d d d	 ƒ d
 „  ƒ Z RS(   sã   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"))

    R   R7   c         K   s$   t  t |  ƒ j |   |  j ƒ  d  S(   N(   R   R€   R   R;   (   R   R    (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR   Œ  s    c         C   s#  d d g d d g g } i |  j  d 6|  j d 6|  j d 6|  j d 6} d „  | j ƒ  Dƒ } | sf d  Sx& | j ƒ  D] \ } } | | j _ qs W|  j rÍt | ƒ d k rÛ t	 | j
 ƒ  ƒ d } | | g | | g g } qÍd d	 g } xã t | ƒ D]Ò \ } } | j d
 | ƒ | j d | ƒ }	 }
 | d d } |	 d  k r||
 d  k r|| d | | d | <| d | | d | <qô |	 d  k r¡| d | | d | <qô |
 d  k rô | d | | d | <qô qô Wn  d j d „  | Dƒ ƒ } d |  j _ d |  j _ | |  j _ t | j ƒ  ƒ |  _ d  S(   Ns   top-lefts	   top-rights   bottom-lefts   bottom-rightc         S   s+   i  |  ]! \ } } | d  k	 r | | “ q S(   N(   R0   (   RI   RJ   RK   (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pys
   <dictcomp>›  s   		i   i    t   leftt   rights   top-s   bottom-i   s   
c         s   s'   |  ] } d  j  d j | ƒ ƒ Vq d S(   s   "{}"RL   N(   R@   RM   (   RI   RN   (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pys	   <genexpr>»  s   s   1fr 1fr(   t   top_leftt	   top_rightt   bottom_leftt   bottom_rightRS   R%   RT   RU   RV   RC   RW   t	   enumerateR#   R0   RM   RX   RY   RZ   R[   R\   R]   (   R   RZ   R^   R]   RJ   RK   Rx   Rm   Rs   R   R   t   i_neighbourR`   (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR;     sD    	

		' Rƒ   R…   R„   R†   RU   c         C   s   |  j  ƒ  d  S(   N(   R;   (   R   R&   (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyRa   Ä  s    (   R-   R.   R/   R   R   R1   Rƒ   R„   R…   R†   R   RU   R   R;   R
   Ra   (    (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyR€   f  s   		4(   R/   R=   t   collectionsR    t	   traitletsR   R   R   R   R   R   R   R   R	   R
   R   t   widgetR   t
   widget_boxR   t   docutilsR   t   _doc_snippetsR   R6   Rc   R€   (    (    (    sB   lib/python2.7/site-packages/ipywidgets/widgets/widget_templates.pyt   <module>   s&   .
Ik