³ò
ÒóDc           @   s5   d  Z  d d k Z d d k Z d d d „  ƒ  YZ d S(   t   
iÿÿÿÿNt   Widgetc           B   sÂ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d „ Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z RS(   sŠ  Template object - base for all widgets.
    
    <pre>Widget(**params)</pre>
    
    <p>A number of optional params may be passed to the Widget initializer.</p>
    
    <dl>
    <dt>decorate<dd>defaults to True.  If true, will call <tt>theme.decorate(self)</tt> to allow the theme a chance to decorate the widget.
    <dt>style<dd>a dict of style parameters.
    <dt>x, y, width, height<dd>position and size parameters, passed along to style
    <dt>align, valign<dd>alignment parameters, passed along to style
    <dt>font, color, background<dd>other common parameters that are passed along to style
    <dt>cls<dd>class name as used by Theme
    <dt>name<dd>name of widget as used by Form.  If set, will call <tt>form.add(self,name)</tt> to add the widget to the most recently created Form.
    <dt>focusable<dd>True if this widget can receive focus via Tab, etc.  Defaults to True.
    <dt>disabled<dd>True of this widget is disabled.  Defaults to False.
    <dt>value<dd>initial value
    </dl>
    
    <strong>Example - Creating your own Widget</strong>
    <p>This example shows which methods are template methods.</p>
    <code>
    class Draw(gui.Widget):
        def paint(self,s):
            #paint the pygame.Surface
            return
        
        def update(self,s):
            #update the pygame.Surface and return the update rects
            return [pygame.Rect(0,0,self.rect.w,self.rect.h)]
            
        def event(self,e):
            #handle the pygame.Event
            return
            
        def resize(self,width=None,height=None):
            #return the width and height of this widget
            return 256,256
    </code>
    c      	   K   s1  h  |  _  | i d t ƒ | i d h  ƒ | i d t ƒ | i d t ƒ | d |  _ | d |  _ t i | i d d ƒ | i d d ƒ | i d d ƒ | i d	 d ƒ ƒ |  _	 | d } x- d D]% } | | j o | | | | <q¿ q¿ Wt
 i |  | ƒ |  _
 d |  _ d | j o | d |  _ n d | j oi d d  k } | d |  _ t | i d ƒ o9 | i i d  j o& | i i i |  ƒ | i i |  _ qšn d | j o | d |  _ n d |  _ | d t j o[ d d  k } t | i d ƒ p d GH| i ƒ  | i _ n | i i i i |  | d ƒ n d  S(   Nt   decoratet   stylet	   focusablet   disabledt   xi    t   yt   widtht   heightt   alignt   valignt   colort   fontt
   backgroundt   defaultt   clst   nameiÿÿÿÿt   formt   valuet    t   apps   gui.widget: creating an App(	   s   aligns   valignR   R   s   widths   heights   colors   fonts
   background(   t   connectst
   setdefaultt   Truet   FalseR   R   t   pygamet   Rectt   gett   rectR   t   StyleR   R   R   t   hasattrt   Formt   Nonet   addR   t   pclsR   t   Appt   themeR   (   t   selft   paramst   st   attR   R   (    (    s   ../pgu/gui/widget.pyt   __init__1   s:    	K
 #	&	c         C   sH   t  |  d d ƒ d j o+ |  i i |  j o |  i i |  ƒ qD n d S(   sF   Focus this Widget.
        
        <pre>Widget.focus()</pre>
        t	   containerN(   t   getattrR!   R+   t   myfocust   focus(   R&   (    (    s   ../pgu/gui/widget.pyR.   W   s    c         C   s1   t  |  d d ƒ d j o |  i i |  ƒ n d S(   sD   Blur this Widget.
        
        <pre>Widget.blur()</pre>
        R+   N(   R,   R!   R+   t   blur(   R&   (    (    s   ../pgu/gui/widget.pyR/   _   s    c         C   s1   t  |  d d ƒ d j o |  i i |  ƒ n d S(   sV   Open this Widget as a modal dialog.
        
        <pre>Widget.open()</pre>
        R+   N(   R,   R!   R+   t   open(   R&   (    (    s   ../pgu/gui/widget.pyR0   e   s    c         C   s1   t  |  d d ƒ d j o |  i i |  ƒ n d S(   s`   Close this Widget (if it is a modal dialog.)
        
        <pre>Widget.close()</pre>
        R+   N(   R,   R!   R+   t   close(   R&   (    (    s   ../pgu/gui/widget.pyR1   k   s    c         C   s   |  i  i |  i  i f S(   s£  Template method - return the size and width of this widget.

        <p>Responsible for also resizing all sub-widgets.</p>
                
        <pre>Widget.resize(width,height): return width,height</pre>
        
        <dl>
        <dt>width<dd>suggested width
        <dt>height<dd>suggested height
        </dl>
        
        <p>If not overridden, will return self.style.width, self.style.height</p>
        (   R   R   R	   (   R&   R   R	   (    (    s   ../pgu/gui/widget.pyt   resizeq   s    c         C   sƒ   t  |  d ƒ p d Sn t  |  d ƒ p d Sn d d k } t  | i d ƒ o0 | i i i o d Sn | i i i ƒ  d Sn d S(   sÄ   Change the size of this widget.
        
        <p>Calling this method will cause a resize on all the widgets,
        including this one.</p>
        
        <pre>Widget.chsize()</pre>
        t   _paintedNR+   iÿÿÿÿR   (   R   R   R$   t   _chsizet   chsize(   R&   R   (    (    s   ../pgu/gui/widget.pyR5   €   s    	c         C   s   d S(   s  Template method - update the surface
        
        <pre>Widget.update(s): return list of pygame.Rect(s)</pre>
        
        <dl>
        <dt>s<dd>pygame.Surface to update
        </dl>
        
        <p>return - a list of the updated areas as pygame.Rect(s).</p>
        N(    (   R&   R(   (    (    s   ../pgu/gui/widget.pyt   updateœ   s    c         C   s   d S(   s¥   Template method - paint the surface
        
        <pre>Widget.paint(s)</pre>
        
        <dl>
        <dt>s<dd>pygame.Surface to paint
        </dl>
        N(    (   R&   R(   (    (    s   ../pgu/gui/widget.pyt   paint©   s    	c         C   s1   t  |  d d ƒ d j o |  i i |  ƒ n d S(   sW   Request a repaint of this Widget.
        
        <pre>Widget.repaint()</pre>
        R+   N(   R,   R!   R+   t   repaint(   R&   (    (    s   ../pgu/gui/widget.pyR8   ´   s    c         C   s.   t  |  d d ƒ d j o |  i i ƒ  n d S(   sZ   Request a repaint of all Widgets.
        
        <pre>Widget.repaintall()</pre>
        R+   N(   R,   R!   R+   t
   repaintall(   R&   (    (    s   ../pgu/gui/widget.pyR9   º   s    c         C   s1   t  |  d d ƒ d j o |  i i |  ƒ n d S(   sX   Request a reupdate of this Widget
        
        <pre>Widget.reupdate()</pre>
        R+   N(   R,   R!   R+   t   reupdate(   R&   (    (    s   ../pgu/gui/widget.pyR:   À   s    c         C   s1   t  |  d d ƒ d j o |  i i |  ƒ n d S(   s®   Pass focus to next Widget.
        
        <p>Widget order determined by the order they were added to their container.</p>
        
        <pre>Widget.next()</pre>
        R+   N(   R,   R!   R+   t   next(   R&   (    (    s   ../pgu/gui/widget.pyR;   Æ   s    c         C   s1   t  |  d d ƒ d j o |  i i |  ƒ n d S(   s¶   Pass focus to previous Widget.
        
        <p>Widget order determined by the order they were added to their container.</p>
        
        <pre>Widget.previous()</pre>
        R+   N(   R,   R!   R+   t   previous(   R&   (    (    s   ../pgu/gui/widget.pyR<   Î   s    c         C   sâ   |  i  i |  i  i } } | |  i i 7} | |  i i 7} t |  d d ƒ } xr | oj | | i  i 7} | | i  i 7} t | d ƒ o$ | | i i 7} | | i i 7} n t | d d ƒ } qN Wt i | | |  i  i	 |  i  i
 ƒ S(   s…   Get the absolute rect of this widget on the App screen
        
        <pre>Widget.get_abs_rect(): return pygame.Rect</pre>
        R+   t   _rect_contentN(   R   R   R   R=   R,   R!   R   R   R   t   wt   h(   R&   R   R   t   c(    (    s   ../pgu/gui/widget.pyt   get_abs_rectØ   s    
c         G   s#   h  | d <| d <|  i  | <d S(   sC  Connect a event code to a callback function.
        
        <p>There may only be one callback per event code.</p>
        
        <pre>Object.connect(code,fnc,value)</pre>
        
        <dl>
        <dt>code<dd>event type [[gui-const]]
        <dt>fnc<dd>callback function
        <dt>*values<dd>values to pass to callback.  Please note that callbacks may also have "magicaly" parameters.  Such as:
            <dl>
            <dt>_event<dd>receive the event
            <dt>_code<dd>receive the event code
            <dt>_widget<dd>receive the sending widget
            </dl>
        </dl>
        
        <strong>Example</strong>
        <code>
        def onclick(value):
            print 'click',value
        
        w = Button("PGU!")
        w.connect(gui.CLICK,onclick,'PGU Button Clicked')
        </code>
        t   fnct   valuesN(   R   (   R&   t   codeRB   RC   (    (    s   ../pgu/gui/widget.pyt   connectê   s    c         C   s!  | |  i  j o|  i  | } | d } t | d ƒ } | i i } t | i i ƒ |  } t | d ƒ o | i d ƒ n g  } h  | d <| d <|  d <}	 x^ | D]V }
 |
 |	 i ƒ  j o | i |	 |
 ƒ q¨ t	 | ƒ o | i | i d ƒ ƒ q¨ Pq¨ W| i
 | ƒ | | Œ  n d S(	   sÄ   Send a code, event callback trigger.
        
        <pre>Object.send(code,event=None)</pre>
        
        <dl>
        <dt>code<dd>event code
        <dt>event<dd>event
        </dl>
        RB   RC   t   im_classi    t   _eventt   _codet   _widgetN(   R   t   listt	   func_codet   co_argcountt   co_varnamesR   t   popt   keyst   appendt   lent   extend(   R&   RD   t   eventt   conRB   RC   t   nargst   namest   argst   magicR   (    (    s   ../pgu/gui/widget.pyt   send  s$    

!! c         C   s2   |  i  o d  Sn |  i | i | ƒ |  i | ƒ S(   N(   R   RY   t   typeRS   (   R&   t   e(    (    s   ../pgu/gui/widget.pyRG   )  s    c         C   s   d S(   s˜  Template method - called when an event is passed to this object.
        
        <p>Please note that if you use an event, returning the value True
        will stop parent containers from also using the event.  (For example, if
        your widget handles TABs or arrow keys, and you don't want those to 
        also alter the focus.)</p>
        
        <dl>
        <dt>e<dd>event
        </dl>
        N(    (   R&   R[   (    (    s   ../pgu/gui/widget.pyRS   2  s    N(   t   __name__t
   __module__t   __doc__R*   R.   R/   R0   R1   R!   R2   R5   R6   R7   R8   R9   R:   R;   R<   RA   RE   RY   RG   RS   (    (    (    s   ../pgu/gui/widget.pyR      s(   (	&												
		!		(    (   R^   R   R   R   (    (    (    s   ../pgu/gui/widget.pys   <module>   s   