
VEc           @   se   d  Z  d d k Z d d k Td d k Z d d k Td e i f d     YZ d e f d     YZ d S(   t   
iN(   t   *t   Appc           B   s   e  Z d  Z d d  Z d   Z d d d  Z d   Z d   Z d   Z	 d   Z
 d d d  Z d d	  Z d d
  Z d   Z d   Z d d  Z RS(   s,  The top-level widget for an application.
    
    <pre>App(theme=None)</pre>
    
    <dl>
    <dt>theme<dd>an instance of a Theme, optional as it will use the default Theme class.
    </dl>
    
    <strong>Basic Example</strong>
    <code>
    app = gui.App()
    app.run(widget=widget,screen=screen)
    </code>
    
    <strong>Integrated Example</strong>
    <code>
    app = gui.App()
    gui.init(widget=widget)
    while 1:
        for e in pygame.event.get():
            app.event(e)
        app.update(screen)
    </code>
        
    
    
    c         K   s   |  t  _ | d  j o d d k l } |   } n | |  _ d | d <t i i |  |  t |  _	 d  |  _
 t |  _ t |  _ d  |  _ d  |  _ g  |  _ d  S(   Ni(   t   Themet   appt   decorate(   R   R   t   Nonet   themeR   t	   containert	   Containert   __init__t   Falset   _quitt   widgett   _chsizet   _repaintt   screent   events(   t   selfR   t   paramsR   (    (    s   ../pgu/gui/app.pyR
   %   s    		
						c         C   s  |  i  } |  i } d } | o& | |  _  | i   | i   } } nt i i   o5 t i i   } | |  _  | i   | i   } } n |  i i d j o` |  i i	 d j oM t i i
 |  i i |  i i	 f t  } | |  _  | i   | i   } } nS d } | i   \ } } \ | i _ | i _ t i i
 | | f t  } | |  _  | | |  i _ |  i _	 | | |  i _ |  i _ d \ |  i _ |  i _ d \ | i _ | i _ | i | |  \ | i _ | i _ x/ |  i D]$ } | i   \ | i _ | i _ qWt |  _ d  S(   Ni    i   (   i    i    (   i    i    (   R   R   t	   get_widtht
   get_heightt   pygamet   displayt   get_surfacet   stylet   widtht   heightt   set_modet	   SWSURFACEt   resizet   rectt   wt   ht   xt   yt   windowsR   R   (   R   R   R    t   wsizeR   R   (    (    s   ../pgu/gui/app.pyR   8   s6    				&'	(	$
 "c         C   s   |  t  _ | o | |  _ n | o | |  _ n |  i   |  i } g  |  _ |  i i |  |  | _ |  i |  t	 i
 i d d  t |  _ t |  _ |  i t  d S(   s   Initialize the application.
        
        <pre>App.init(widget=None,screen=None)</pre>
        
        <dl>
        <dt>widget<dd>main widget
        <dt>screen<dd>pygame.Surface to render to
        </dl>
        i  i   N(   R   R   R   R   R   t   widgetst   appendR   t   focusR   t   keyt
   set_repeatt   TrueR   R   R   t   sendt   INIT(   R   R   R   R    (    (    s   ../pgu/gui/app.pyt   initg   s    	
					c         C   s   |  t  _ |  i | i |  t i i |  |  | i t j ok | i d j oW t	 i i
 t h  | i d <| i d < } |  i | i |  t i i |  |  q n d S(   s   Pass an event to the main widget.
        
        <pre>App.event(e)</pre>
        
        <dl>
        <dt>e<dd>event
        </dl>
        i   i   t   buttont   posN(   i   i   (   R   R   R,   t   typeR   R	   t   eventt   MOUSEBUTTONUPR/   R   t   Eventt   CLICKR0   (   R   t   et   sub(    (    s   ../pgu/gui/app.pyR2      s    		c         C   sz   |  t  _ |  i } xB t i i   D]1 } | i t j o |  i p |  i |  q" q" W|  i	 |  } t i
 i	 |  d  S(   N(   R   R   R   R   R2   t   getR1   t   QUITt   mywindowt   updateR   (   R   t   sR6   t   us(    (    s   ../pgu/gui/app.pyt   loop   s    		 c         C   se   | |  _  |  i o |  i   t |  _ n t |  d  o |  i i |  n t i i |  |  d  S(   Nt
   background(	   R   R   R   R   t   hasattrR?   t   paintR   R	   (   R   R   (    (    s   ../pgu/gui/app.pyRA      s    	

c         C   s   | |  _  |  i o |  i   t |  _ n |  i o? |  i |  t |  _ t i d d | i   | i	    g Sn t
 i i |  |  } | Sd S(   sd   Update the screen.
        
        <dl>
        <dt>screen<dd>pygame surface
        </dl>
        i    N(   R   R   R   R   R   RA   R   t   RectR   R   R   R	   R;   (   R   R   R=   (    (    s   ../pgu/gui/app.pyR;      s    	


	)c         C   s@   |  i  | |  x) |  i p |  i   t i i d  q Wd S(   s  Run an application.
        
        <p>Automatically calls <tt>App.init</tt> and then forever loops <tt>App.event</tt> and <tt>App.update</tt></p>
        
        <dl>
        <dt>widget<dd>main widget
        <dt>screen<dd>pygame.Surface to render to
        </dl>
        i
   N(   R.   R   R>   R   t   timet   wait(   R   R   R   (    (    s   ../pgu/gui/app.pyt   run   s    

c         C   s   d  S(   N(    (   R   R    (    (    s   ../pgu/gui/app.pyt   reupdate   s    c         C   s   t  |  _ d  S(   N(   R+   R   (   R   R    (    (    s   ../pgu/gui/app.pyt   repaint   s    c         C   s   t  |  _ d  S(   N(   R+   R   (   R   (    (    s   ../pgu/gui/app.pyt
   repaintall   s    c         C   s   t  |  _ t  |  _ d  S(   N(   R+   R   R   (   R   (    (    s   ../pgu/gui/app.pyt   chsize   s    	c         C   s   t  |  _ d  S(   N(   R+   R   (   R   t   value(    (    s   ../pgu/gui/app.pyt   quit   s    N(   t   __name__t
   __module__t   __doc__R   R
   R   R.   R2   R>   RA   R;   RE   RF   RG   RH   RI   RK   (    (    (    s   ../pgu/gui/app.pyR   	   s   	/ 		
					t   Desktopc           B   s   e  Z d  Z d   Z RS(   sX   Create an App using the <tt>desktop</tt> theme class.
    
    <pre>Desktop()</pre>
    c         K   s$   | i  d d  t i |  |  d  S(   Nt   clst   desktop(   t
   setdefaultR   R
   (   R   R   (    (    s   ../pgu/gui/app.pyR
      s    (   RL   RM   RN   R
   (    (    (    s   ../pgu/gui/app.pyRO      s   (   RN   R   t   pygame.localsR   t   constR	   R   RO   (    (    (    s   ../pgu/gui/app.pys   <module>   s   

