³ò
˜iìDc           @   s   d  Z  d d d „  ƒ  YZ d S(   s   document layout engine.t   Layoutc           B   s€   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d d	 „ Z d
 „  Z d „  Z d „  Z d „  Z RS(   s}   the document layout engine
    
    .widgets -- elements are kept in this list.  read-only, use add to add items to it. 
    c         C   s   g  |  _  | |  _ d S(   s/   initialize the object with the size of the box.N(   t   _widgetst   rect(   t   selfR   (    (    s   ../pgu/gui/layout.pyt   __init__   s    	c         C   s   |  i  i | ƒ d S(   sÜ  add a document element to the layout.
        
        a document element may be
        - a tuple (w,h) if it is a whitespace element
        - a tuple (0,h) if it is a linebreak element
        - an integer -1,0,1 if it is a command to start a new block of elements that are aligned either left,center, or right.
        - an object with a .rect (for size) -- such as a word element
        - an object with a .rect (for size) and .align -- such as an image element
        N(   R   t   append(   R   t   e(    (    s   ../pgu/gui/layout.pyt   add   s    c         C   s  |  i  ƒ  g  |  _ xÔ |  i D]É } t | ƒ t j o" | d d j o |  i | ƒ q t | ƒ t j o& | d d j o |  i | d ƒ q t | ƒ t j o |  i d | ƒ q t	 | d ƒ o |  i
 | ƒ q |  i | ƒ q W|  i ƒ  t |  i |  i |  i ƒ |  i _ d S(   sÉ   resize the layout
        this method recalculates the position of all document elements
        after they have been added to the document.  .rect.x,y will be updated for all
        objects.
        i    i   t   alignN(   t   initt   widgetsR   t   typet   tuplet   do_spacet   do_brt   intt   do_blockt   hasattrt   do_alignt   do_itemt   linet   maxt   yt   left_bottomt   right_bottomR   t   h(   R   R   (    (    s   ../pgu/gui/layout.pyt   resize   s    
	
 $$
c         C   sŒ   |  i  i |  i  i |  _ |  _ |  i  i |  _ |  i  i |  _ d |  _ d |  _ |  i  i |  _ |  i  i |  _ d |  _ g  |  _ d |  _	 d  S(   Ni    iÿÿÿÿ(
   R   t   xR   t   leftt   rightR   R   R   t   itemsR   (   R   (    (    s   ../pgu/gui/layout.pyR	   1   s    				c         C   s-   |  i  |  i j o |  i i |  _ n |  i S(   N(   R   R   R   R   (   R   (    (    s   ../pgu/gui/layout.pyt   getleft>   s    c         C   s-   |  i  |  i j o |  i i |  _ n |  i S(   N(   R   R   R   R   (   R   (    (    s   ../pgu/gui/layout.pyt   getrightC   s    c         C   s   |  i  ƒ  | |  _ d  S(   N(   R   R   (   R   R   (    (    s   ../pgu/gui/layout.pyR   H   s    
iÿÿÿÿc         C   s   |  i  ƒ  | |  _ d  S(   N(   R   R   (   R   R   (    (    s   ../pgu/gui/layout.pyR   L   s    
c         C   sr  | i  } |  i |  i |  i } } } | i i | i i } } | d j o8 |  i ƒ  |  i i |  i i | d |  _ d |  _	 n³ | d j oE |  i ƒ  t
 |  i |  i |  i ƒ |  _ d |  _ |  i i |  _ na | d j oS |  i ƒ  t
 |  i |  i |  i ƒ |  _ d |  _ |  i i |  i i | |  _ n |  i |  i | i _ | i _ |  i | |  _ |  i |  _ | d j oD t
 |  i | ƒ |  _ |  i |  i |  _ |  i ƒ  |  _ d |  _ n | d j oA |  i |  _ |  i | |  _ | | | | |  _ |  _ |  _ nO | d j oA |  i | |  _ |  i | |  _ | | | |  _ |  _ |  _ n |  i i | ƒ d  S(   Ni    i   iÿÿÿÿi   (   R   R   R   R   R   t   wR   R   t   widtht   fitR   R   R   R   R   R
   R   (   R   R   R   t   oxt   oyt   ohR!   R   (    (    s   ../pgu/gui/layout.pyR   P   sD    	
!
	
	!%!c         C   sl   | \ } } |  i  | |  i ƒ  j o |  i ƒ  n5 |  i i | ƒ t |  i | ƒ |  _ |  i  | 7_  d  S(   N(   R   R    R   R   R   R   R   (   R   R   R!   R   (    (    s   ../pgu/gui/layout.pyR   y   s    c         C   sy   | i  i | i  i } } |  i | |  i ƒ  j o |  i ƒ  n |  i i | ƒ t |  i | ƒ |  _ |  i | 7_ d  S(   N(	   R   R!   R   R   R    R   R   R   R   (   R   R   R!   R   (    (    s   ../pgu/gui/layout.pyR   ‚   s    c         C   sÃ  |  i  ƒ  } |  i ƒ  } |  i } |  i } t |  i ƒ d j o( t |  i d ƒ t j o |  i d =n d } xF |  i D]; } t | ƒ t j o | | d 7} qx | | i i	 7} qx W| d j o
 | } nL | d j o# | | | | d } d |  _
 n | d j o | | } n xo |  i D]d } t | ƒ t j o | | d 7} q#| | | i _ | i _ |  i i | ƒ | | i i	 7} q#Wg  |  _ |  i |  i |  _ |  i  ƒ  |  _ d |  _ d  S(   Ni    iÿÿÿÿi   i   (   R   R    R   R   t   lenR   R   R   R   R!   R#   R   R
   R   R   (   R   t   x1t   x2R   R   R!   R   R   (    (    s   ../pgu/gui/layout.pyR   Š   s4    		0
 %
 %	N(   t   __name__t
   __module__t   __doc__t   NoneR   R   R   R	   R   R    R   R   R   R   R   R   (    (    (    s   ../pgu/gui/layout.pyR       s   							)			N(    (   R,   R    (    (    (    s   ../pgu/gui/layout.pys   <module>   s   