³ņ
0Gc           @   sČ  d  Z  d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k l Z d d k	 Z	 d Z
 e i e Z d g Z e a h  Z h  Z e a g  a e a e a e a e a e a d   Z d   Z d d	 f a d
 f  d     YZ d f  d     YZ  e a! d   Z" e a# e a$ e	 i% d  Z& d   Z' e e d  Z( d   Z) d   Z* d   Z+ d   Z, d   Z- d   Z. d   Z/ e a0 d   Z1 d   Z2 d   Z3 d   Z4 d   Z5 d   Z6 d   Z7 e d   Z8 d!   Z9 d"   Z: d#   Z; d$   Z< d%   Z= d&   Z> d' f  d(     YZ? d) f  d*     YZ@ d+ eA f d,     YZB d- eA f d.     YZC h  e? d/ <eB d0 <eC d1 <ZD h  ZE h  ZF h  aG d2   ZH e d3  ZI d4 f  d5     YZJ d6   ZK d S(7   s  How the code is generated: every time the end of an object is reached during
the parsing of the xml tree, either the function 'add_object' or the function
'add_class' is called: the latter when the object is a toplevel one, the former
when it is not. In the last case, 'add_object' calls the appropriate ``writer''
function for the specific object, found in the 'obj_builders' dict. Such
function accepts one argument, the CodeObject representing the object for
which the code has to be written, and returns 3 lists of strings, representing
the lines to add to the '__init__', '__set_properties' and '__do_layout'
methods of the parent object.
i’’’’N(   t   XmlParsingErrort   pythont   pyc         C   sM   t  oB |  d  d j o d |  d SqI |  d  d j o d |  SqI n |  S(   Ni   t   wxs   wx.i   t   EVT_(   t   use_new_namespace(   t
   class_name(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   cnQ   s    c         C   sV   t  oA d i g  } t |   i d  D] } | t |  q' ~  Sn t |   Sd  S(   Nt   |(   R   t   joint   strt   splitR   (   t   flagst   _[1]t   f(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   cn_fY   s    Ai   i   t
   ClassLinesc           B   s   e  Z d  Z d   Z RS(   s;       Stores the lines of python code for a custom class
    c         C   sU   g  |  _  g  |  _ g  |  _ g  |  _ g  |  _ h  |  _ t |  _ g  |  _ g  |  _	 d  S(   N(
   t   initt   parents_initt   sizers_initt   propst   layoutt   dependenciest   Falset   donet   event_handlerst
   extra_code(   t   self(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   __init__h   s    								(   t   __name__t
   __module__t   __doc__R   (    (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR   d   s   t   SourceFileContentc           B   sD   e  Z d  Z d d d d  Z d   Z d   Z d   Z d   Z RS(   s¢       Keeps info about an existing file that has to be updated, to replace only
    the lines inside a wxGlade block, an to keep the rest of the file as it was
    c         C   sr   | |  _  | |  _ | |  _ g  |  _ | d  j o h  |  _ n h  |  _ h  |  _ |  i d  j o |  i   n d  S(   N(   t   namet   contentt   classest   new_classest   Nonet   spacesR   t   build_untouched_content(   R   R!   R"   R#   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR      s    						c         C   s  d } t } t i d  } t i d  } t i d  } t i d  } t } t } d }	 t |  i  }
 g  } xX|
 D]P} d } | p} | i d  } | i d  } | d j o | } d } q| d j o | } d } qt | d f | d f  \ } } n | o | d j o t } | }	 n | o7 | i	 |	  } | | j  o | d j o
 t } qin | i
 |  } | oy | oq | d j	 od | d j o | i d t  t } n | i d	  } |  i |  } d	 |  i | <| i |  qv | p¦| i
 |  } | o¹ | d j	 o¬ | i d	  } | i d
  } | i d  } | d j o
 | } n |  i |  } | |  i | <t } | d j o | i d t | f  q¢| i d t | | f  qĘ| i
 |  } | oQ | d j	 oD | i d	  } |  i | i d
   } d	 |  i i | h   | <n | d j	 o+ |  i |  o | i d t | f  n | i |  |  i |  o | i d t  qĘqv | i
 |  d j	 o
 t } qv qv W| p | i d t  n |
 i   d i |  |  _ d S(   sÉ           Builds a string with the contents of the file that must be left as is,
        and replaces the wxGlade blocks with tags that in turn will be replaced
        by the new wxGlade blocks
        s2   ^\s*class\s+([a-zA-Z_]\w*)\s*(\([\s\w.,]*\))?:\s*$s;   ^(\s*)#\s*begin\s+wxGlade:\s*([A-Za-z_]+\w*)??[.]?(\w+)\s*$s   ^\s*#\s*end\s+wxGlade\s*$sO   ^\s+def\s+([A-Za-z_]+\w*)\s*\(.*\):\s*#\s*wxGlade:\s*(\w+)\.<event_handler>\s*$i’’’’s   """s   '''s   <%swxGlade insert new_classes>i   i   i   s   <%swxGlade replace %s>s   <%swxGlade replace %s %s>s   <%swxGlade event_handlers %s>s   <%swxGlade extra_modules>
t    N(   R%   R   t   ret   compilet   openR!   t   findt   mint   Truet   rfindt   matcht   appendt   noncet   groupt   add_packageR#   R&   R   t
   setdefaultt   is_end_of_classt   is_import_linet   closeR	   R"   (   R   R   t   new_classes_insertedt
   class_declt   block_startt	   block_endt   event_handlert   inside_blockt   inside_triple_quotet   triple_quote_strt   tmp_int	   out_linest   linet   quote_indext   triple_dquote_indext   triple_squote_indext   tmp_quote_strt	   end_indext   resultR&   t   which_classt   which_blockt   which_handler(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR'      s     

	
	
				
c         C   s)   t  o | i d  Sn | i d  Sd  S(   Ns	   import wxs   from wxPython.wx import *(   R   t
   startswith(   R   RC   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR7   	  s    c         C   s   | i    i d  S(   Ns   # end of class (   t   stripRM   (   R   RC   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR6     s    c         C   s   t  p | Sn |  i } t d  j	 o | i t d  } n t i i |  i t i d  } | i	 d  o | d } n | o | d | Sn | Sd  S(   NR(   t   .i   (
   t   multiple_filesR!   t   out_dirR%   t   replacet   ost   patht   dirnamet   sepRM   (   R   R   R!   t   pkg(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR4     s    	!N(	   R   R   R   R%   R   R'   R7   R6   R4   (    (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR    }   s   	w		c         C   s   d |  S(   Ns       (    (   t   number(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   tabs$  s    s   \\[natbv"]?c         C   s/   |  i  d  d j o d Sn |  i  d  Sd  S(   Ni    s   \s   \\(   R3   (   R0   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   _do_replace1  s    c         C   sĻ   |  p d Sn |  i  d d  }  | o t i t |   }  n |  i  d d  }  y; t |  d  t o | o d |  d Sn d |  d SWn= t j
 o1 t o | o d	 |  d SqĖ d
 |  d Sn Xd S(   s       returns a quoted version of 's', suitable to insert in a python source file
    as a string object. Takes care also of gettext support
    s   ""t   "s   \"s   \s   \\t   asciis   _("s   ")s   _(u"s   u"N(   RR   t   _quote_str_patternt   subRZ   t   unicodet   _use_gettextt   UnicodeDecodeError(   t   st	   translatet   escape_chars(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt	   quote_str5  s    c   	      C   s/  |  d } |  d } d d k  } d d k } y t |  d  a Wn t t f j
 o t a n Xy t |  d  a Wn t t f j
 o t a n Xd t | i     i	 d d	  | i
 d d  f a y t |  d  a Wn t t f j
 o n XyB t g  } |  d i d  d  D] } | t |  q~  a WnB t t f j
 o0 t i d j	 o t i i i a qd a n Xy |  d } Wn t t f j
 o d } n Xh  a h  a d t i | i   t i   f t o d p d g a t i i p! d t i t i   f t d <n g  a | o t i d d | i    n | a  t  p” t o# t! i" i# |  o t$ |  a% q+d a% t& i'   a( | a) t( i* d  x t D] } t( i* |  q²Wt( i* d t  t( i* d t  t( i* d  n0 d a% t! i" i+ |  p t, d   n | a- d S(    sW      Writer initialization function.
    - app_attrs: dict of attributes of the application. The following two
                 are always present:
           path: output path for the generated code (a file if multi_files is
                 False, a dir otherwise)
         option: if True, generate a separate file for each custom class
    RT   t   optioni’’’’Nt   use_gettextt	   overwrites   %s%sRO   R(   i
   i   i   R   t   for_versioni   i   t   encodings#   # generated by wxGlade %s on %s%s

s
   import wx
s   from wxPython.wx import *
s   # generated by wxGlade %s%s

i    s   # -*- coding: %s -*-
s   #!/usr/bin/env python
s   <%swxGlade extra_modules>
s    
<%swxGlade replace extracode>

s   
s@   'path' must be a directory when generating multiple output filesi@B i (   i   i   (.   t   timet   randomt   intR`   t   KeyErrort
   ValueErrorR   t
   _overwriteR
   RR   t	   randrangeR2   R   t   tupleR   Ri   t   commont   app_treeR%   t   appR#   t   _current_extra_modulest   versiont   asctimet   generated_fromt   header_linest   configt   preferencest   write_timestampt   _current_extra_codet   insertt   lowerRP   RS   RT   t   isfileR    t   previous_sourcet	   cStringIOt   StringIOt   output_filet   output_file_namet   writet   isdirR    RQ   (	   t	   app_attrst   out_patht   multi_filesRk   Rl   R   t   tt	   _encodingRC   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt
   initializeG  sd    	


8	 c          C   s  t  d j	 od t }  t  i o d i t  i  } n d } t  i i |  |  t  _ d t }  d i t i    } t  i i |  |  t  _ d t }  d i d g t	 d g  } t  i i |  |  t  _ t
 i d t t  i  } xY | D]Q }  t  i i |  d	 t d
   } d | | f } t  i i |  d |  t  _ qė Wt
 i d t t  i  } x& | D] }  t  i i |  d  t  _ q`Wt i t  i t  i d  nń t pé d i t i    } t i   i d t |  } d t }  d i d g t	 d g  } | i |  |  } t i   y2 t i t | d  t o t i t d  n Wn9 t j
 o } t t |    n t j
 o n Xb n d S(   sR       Writer ``finalization'' function: flushes buffers, closes open files, ...
    s   <%swxGlade insert new_classes>R(   s   <%swxGlade extra_modules>
s   <%swxGlade replace extracode>s   
s   # begin wxGlade: extracodes   # end wxGlade
s,   (<%swxGlade replace ([a-zA-Z_]\w*) +[.\w]+>)i   i   sG   %s# content of this block not found: did you rename this class?
%spass
i    s   <%swxGlade event_handlers \w+>t   codegeniķ  N(   R   R%   R2   R$   R	   R"   RR   Rv   t   keysR~   R)   t   findallR&   t   getRY   Rs   t	   save_fileR!   RP   R   t   getvalueR8   R   t
   _app_addedRS   t   chmodt   IOErrorR    R
   t   OSError(   t   tagt   codet   tagst   indentt   commentt   emR"   t   e(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   finalize„  s^    



	  

c         C   s9   y t  |  i d  SWn t t f j
 o t Sn Xd S(   sä       Returns True if 'obj' should be added as an attribute of its parent's
    class, False if it should be created as a local variable of __do_layout.
    To do so, tests for the presence of the special property 'attribute'
    t	   attributeN(   Rm   t
   propertiesRn   Ro   R.   (   t   obj(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   test_attributeē  s    c         C   s¤  y t  |  i } Wn' t j
 o t   } t  |  i <n Xy t | i } WnX t j
 oL | i i d d | i | i f d g  t	 i
 d d | i | i  nūXy | i |  \ } } } Wn | GH  n X| i oŚ| i o) | i o | i   | i i |  n | i i |  t | d t  } t | d  oL | i |  } xĮ | D]. \ }	 }
 } | i i |	 | |
  | f  qZWn d | i j ow t |  \ } }	 |	 d j o d	 | i }	 n xD | i d i   D]+ \ }
 } | i i |	 | |
  | f  qäWn | i p t | d
 | i i d
 d   } | oh t i d d |  } | i i |  t o
 t  } n t! d j	 } | o t	 i
 d d | i  q±qµqłnA | i d j o  | i i# d | i$ d   n | i% i |  | i& i |  | i' i |  t oJ | i o@ | i | i j o- d | i t( | i  f } d | i) | <n x3 t t i | i  d g   D] } d | i) | <qWd S(   sI       adds the code to build 'sub_obj' to the class body of 'top_obj'.
    s   
s?   # code for %s (type %s) not generated: no suitable writer foundt   WARNINGs=   code for %s (type %s) not generated: no suitable writer foundR   t
   get_eventst   eventss   -1s   #self.%st	   extracodeR(   s   \\nsq   %s has extra code, but you are not overwriting existing sources: please check that the resulting code is correct!t   wxStaticBoxSizeri   i    s   from %s import %s
t   import_modulesN(*   R#   t   klassRn   R   t   obj_builderst   baseR   t   extendR!   Rs   t   messaget   get_codet
   in_windowst   is_containert   is_toplevelt   reverseR   t   getattrR   t   hasattrR¦   R   R1   R¢   t   generate_code_idt	   iteritemst   previewR   R)   R^   R   RP   R   R   R%   R   t   popR   R   R   t   without_packageR   (   t   top_objt   sub_objR«   t   builderR   R   R   t   mycnt   evtst   idt   eventt   handlert   id_nameR   t   warnt   keyt   dep(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt
   add_objectń  sv    '

 ' '
	
 	
 c         C   s>  | i  } y: g  } | i d  D] } | t |  q  ~ \ }	 }
 Wnq t j
 oe | i o t |  o d | } q} n | i d j o% t d j  o t d  d | } qĒ n Xd |	 |
 f } y t	 |  i
 } Wn' t j
 o t   } t	 |  i
 <n Xd	 | i  | | t |  t |  f } | i i |  d
 S(   sc       writes the code to add the object 'obj' to the sizer 'sizer'
    in the 'toplevel' object.
    t   ,s   self.t
   wxNotebooki   i   t   wxNotebookSizers   (%s)s   (%d, %d)s   %s.Add(%s, %s, %s, %s)
N(   i   i   (   R!   R   Rm   Ro   R±   R¤   R­   Ri   R   R#   R«   Rn   R   R   R   R1   (   t   toplevelt   sizerR£   Rf   t   flagt   bordert   obj_nameR   Rb   t   wt   hR«   t   buffer(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   add_sizeritemB  s    	=
'%c         C   s   |  i  d  d S(   s;       Removes the package name from the given class name
    RO   i’’’’(   R   (   R   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR»   [  s    c   2   0   C   sŪ  t  p
 t } nc t i i t |  i i d t i  d  } t	 p t i i
 |  o
 d } n t |  } h  a t i |  i  o t |  i i o d Sn y5 t |  i } t | d t  } t | d t  } Wn t j
 o
   n X| d j	 o0 | i i |  i  o t } | i |  i } nK t } t d  } t | d g   } | o x | D] }	 d t |	 <q\Wn g  }
 |
 i } t i |  i  p t   t |  i <n |  i p¾ t | d	 |  i i d	 d
   } | oR t  i! d d |  } t |  i i" i |  | p t# i$ d d |  i%  q.n t  o8 | o1 t& i d
 i t |  i i" d d d    qrn t |  d |  i i d d   } |  i p | o | i'   o
 d } n | oŪ | |  i  } | d j	 o= d i g  } | i( d  D] } | | i'   qł~  } n |  i o= |  i | j o- d d k) } |  i d | i* dK dL  } n
 |  i } | d t+ |  | f  | t d  d  n) | d j	 o t# i$ d d |  i%  n | | d t+ |  i   |  i } | i d d  } | o | | d | |   n | d j	 o g  } | i( d  D] } | | i'   q@~ } xh t, |  D]; \ } } | p | | d |  qi| | d |  qiWn | | d | |  i   | } t |  i i- } t |  i i. } | i/   x | D] } | | |  qžWx | D] } | | |  qWt0 | d  o, x) | i1 |   D] } | | |  qUWn | d | d   | | d!  t |  i i2 } t0 | d"  oC x@ | i3 |   D]+ \ } } } | i | | |  | f  qĮWn | o | d  n t4 dM j  p t5 o[ xĄ | D]L \ }  } } |  i6 d$  o |  d d% }  n | | d& | |  | f  q%Wni xe | D]] \ }  } } |  i6 d$  o# | | d' | | |  d f  q| | d( | | |  f  qW| | d)  | d j	 o | o~ d* t7 |  i d+ f }! | i8 i9 |!  d, j  o t# i$ d d- |  i%  n" | i8 i |! d
 i |
   | _8 g  }
 |
 i } n t | d. t:  |   }" |" i; t |  i i<  t= |"  }# | o | d/ t d   n | | d0 t+ |  i   |# p | | d1  n  x |" D] } | | |  qW| | d)  | d j	 o | o~ d* t7 |  i d2 f }! | i8 i9 |!  d, j  o t# i$ d d3 |  i%  n" | i8 i |! d
 i |
   | _8 g  }
 |
 i } n | o | d t d  d4  n t |  i i> }$ t |  i i? }% t0 | d5  o | i@ |   }& n g  }& | | d6 t+ |  i   |$ p |% p |& ok |% i/   x |% D] } | | |  q}	Wx |$ D] } | | |  q	Wx. |& D] } | | |  q»	Wn | | d1  | | d)  | d j	 ow | oo d* t7 |  i d7 f }! | i8 i9 |!  d, j  o t# i$ d d8 |  i%  qw
| i8 i |! d
 i |
   | _8 n | d j	 o| o| i2 i |  i h   }' g  }( x | D]z \ }) } } | |' j o^ |( i t d  d9 | t+ |  i  f  |( i | d: |  |( i | d;  d |' | <q±
q±
Wd< t7 |  i f }! | i8 i9 |!  d, j  o t# i$ d d= |  i%  n" | i8 i |! d
 i |(   | _8 ~( n h  }' x} | D]u \ }) } } | |' j oY | d t d  d9 | t+ |  i  f  | | d> |  | | d?  d |' | <q«q«Wt t |  i _ | d@ t+ |  i   t  o9 | d j	 o, | o | iA i d
 i |
   n d Sn t  oĀ| d j	 omdA t7 }! | i8 i |! d
  | _8 dB t7 }! d
 i t iB    }* | i8 i |! |*  | _8 t |  i iC iB   }+ dC g |+ d) g }, dD t7 }! | i8 i |! d
 i |,   | _8 d
 i t |  i i" d d d   } | o t# i$ d dE |  i%  n dF | } dG t7 }! | i8 i |! |  | _8 y t# iD | | i8 dH  Wn& tE dI t | i% |  i f   n Xd Sn t i i t |  i i d t i  d  } tF iG   }- |- iH } x tI D] }. | |.  qTW| dJ  x" t |  i iC D] }/ | |/  qW| d)  | d  d
 i t |  i i" d d d   } dF | } | |  | d  x |
 D] }. | |.  qöWy t# iD | |- iJ   dH  Wn d d kK }0 |0 iL   n X|- iM   n x" t |  i iC D] }1 d t |1 <qfWt |  i i" o( t& i; t |  i i" d d d   n tN iH } x |
 D] }. | |.  qĆWd S(N   s/       Generates the code for a custom class.
    RO   s   .pyNR   R   i   t   extra_modulesi   RØ   R(   s   \\ns   
R„   sq   %s has extra code, but you are not overwriting existing sources: please check that the resulting code is correct!i’’’’t   custom_bases   , RÉ   s   _%di
   i   i	   s   class %s(%s):
s#   def __init__(self, *args, **kwds):
sz   %s has custom base classes, but you are not overwriting existing sources: please check that the resulting code is correct!s   # begin wxGlade: %s.__init__
t   styles   kwds["style"] = %s
s!   %s.__init__(self, *args, **kwds)
s   %s.__init__(self)
t   get_init_codes   self.__set_properties()
s   self.__do_layout()
R¦   i   t   #s   .GetId()s   %s(self, %s, self.%s)
s   self.Bind(%s, self.%s, %s)
s   self.Bind(%s, self.%s, id=%s)
s   # end wxGlade
s   <%swxGlade replace %s %s>R   i    sD   wxGlade __init__ block not found for %s, __init__ code NOT generatedt   get_properties_codes   
%sdef __set_properties(self):
s%   # begin wxGlade: %s.__set_properties
s   pass
t   __set_propertiessT   wxGlade __set_properties block not found for %s, __set_properties code NOT generateds   def __do_layout(self):
t   get_layout_codes    # begin wxGlade: %s.__do_layout
t   __do_layoutsJ   wxGlade __do_layout block not found for %s, __do_layout code NOT generateds3   def %s(self, event): # wxGlade: %s.<event_handler>
s+   print "Event handler `%s' not implemented"
s   event.Skip()

s   <%swxGlade event_handlers %s>sP   wxGlade event_handlers block not found for %s, event_handlers code NOT generateds,   print "Event handler `%s' not implemented!"
s   event.Skip()
s   
# end of class %s


s   <%swxGlade insert new_classes>s   <%swxGlade extra_modules>
s   # begin wxGlade: dependencies
s    <%swxGlade replace dependencies>s   %s (or one of its chilren) has extra code classes, but you are not overwriting existing sources: please check that the resulting code is correct!s,   # begin wxGlade: extracode
%s
# end wxGlade
s   <%swxGlade replace extracode>R   s    py_codegen.add_class: %s, %s, %ss   
# begin wxGlade: dependencies
i įõi Ź;(   i   i   (O   RP   R   RS   RT   R	   RQ   R«   RR   RV   Rp   t   existsR%   R    Rv   R#   t   has_keyR   R¬   R­   Rµ   R   R   Rn   R   R&   R.   RY   R1   R   R¹   R¢   R   R)   R^   R   Rs   RÆ   R!   R~   RN   R   Rl   Rq   R»   t	   enumerateR   R   R“   R¶   RŲ   R   R¦   Ri   R   RM   R2   R"   R,   t   generate_common_propertiesR®   R   t   lenR   R   RÜ   R$   R   R   R   R   R   R   R   Rz   R   t	   tracebackt	   print_excR8   R   (2   t   code_objt   prev_srct   filenameR¾   Ræ   t   mycn_ft   is_newt   indentationt   modst   mRÓ   R   R   RÖ   R­   R   t   bRl   R«   t   propR×   t   _[2]t   basest   it   tabt
   init_linesR   t   lR   RĮ   RĀ   RĆ   t   win_idR   t   obj_pt
   write_bodyt   layout_linest   sizers_init_linest   extra_layout_linest   already_theret   bufR!   R   RÕ   t   depst   outRC   t   moduleRć   RĒ   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt	   add_classb  sų   
%$# 	
	)	
=!			#0 	
    $ 	 		
	!		 
!#	
   
% 	! 		$




!&
	 
 

&

  (	 c         C   sÆ  t  a |  i d  } | p
 d } n t p
 t } nN t i i t | d  } t i i	 |  p
 d } n t o
 d } n d } | d j	 o d Sn |  i d  } |  i d  } | p d Sn g  } | i } | o> t d  }	 | d	 | t d
  f  | t d  d  n` t d  }	 | d  t o$ | |	 d  | |	 d |  n | |	 d | t d  f  | |	 t d  d  | |	 d | | f  | o | |	 d |  | |	 d |  | |	 d  | d |  | d  t d  }	 t o$ | |	 d  | |	 d |  n | |	 d | | f  n+ | |	 d | | f  | |	 d |  | |	 d |  t o÷ t i i t | d  } t i   }
 |
 i } | d  x t D] } | |  qĻW| d | | f  x | D] } | |  qžWy t i | |
 i   d  Wn d d k } | i   n Xy t i | d  Wn t j
 o n X|
 i   n% t i } x | D] } | |  qWd S(   s{       Generates the code for a wxApp instance.
    If the file to write into already exists, this function does nothing.
    R!   Ru   s   .pyi   Nt   classt
   top_windowi   s   class %s(%s):
t   wxApps   def OnInit(self):
s   if __name__ == "__main__":
s   import gettext
sC   gettext.install("%s") # replace with the appropriate catalog name

s   %s = %s(0)
t   wxPySimpleAppt   wxInitAllImageHandlerss   ()
s   %s = %s(None, -1, "")
s   self.SetTopWindow(%s)
s
   %s.Show()
s
   return 1

s   # end of class %s

s   %s.SetTopWindow(%s)
s   %s.MainLoop()
s   #!/usr/bin/env python
s   from %s import %s

R   i’’’’iķ  (   R.   R   R   RP   R   RS   RT   R	   RQ   RŽ   R%   Rp   R1   RY   R   R`   R   R   R   Rz   Rs   R   R   Rć   Rä   R   R   R8   R   (   R   t   top_win_classR!   Rę   Rē   R«   t   top_wint   linesR1   Rņ   Rž   R   RC   Rć   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   add_appÄ  s~    	
	
		
  	 c         C   s9   |  i  o d Sn$ t |   o d |  i Sn |  i Sd  S(   NR   s   self.%s(   R³   R¤   R!   (   R£   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   _get_code_name  s    c         C   s³   t  |   } |  i i d d  i   } | d d j } t d j  p |  i d j o
 d } n d } | o0 | d	 | d
 t d  d | | d  f Sn | d	 | d | Sd S(   sJ       returns the code fragment that sets the size of the given object.
    t   sizeR(   i’’’’t   di   i   t   SetSizet
   SetMinSizeRO   t   (t	   wxDLG_SZEs   (%s, (%s)))
s   ((%s))
N(   i   i   (   R
  R¢   R   RN   Ri   t   parentR%   R   (   R£   R!   R  t   use_dialog_unitst   method(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   generate_code_size  s    
c      	   C   s>   d t  |  d d !d  t  |  d d !d  t  |  d d  f S(   Ns
   %d, %d, %di   i   i   i   (   Rm   (   Rb   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   _string_to_colour1  s    c         C   sz   t  |   } y% t d  d t |  i d  } Wn: t t f j
 o( t d  d t |  i d  } n X| d | S(   s[       returns the code fragment that sets the foreground colour of
    the given object.
    t   wxColours   (%s)t
   foregroundt   wxSystemSettings_GetColours   .SetForegroundColour(%s)
(   R
  R   R  R¢   t
   IndexErrorRo   (   R£   R   t   color(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   generate_code_foreground5  s    c         C   sz   t  |   } y% t d  d t |  i d  } Wn: t t f j
 o( t d  d t |  i d  } n X| d | S(   s[       returns the code fragment that sets the background colour of
    the given object.
    R  s   (%s)t
   backgroundR  s   .SetBackgroundColour(%s)
(   R
  R   R  R¢   R  Ro   (   R£   R   R  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   generate_code_backgroundD  s    c   	      C   s£   |  i  d } | d } t | d  } | d } t | d  } t | d  } d | d i d	 d
  } t |   } | d t d  d | | | | | | f S(   sJ       returns the code fragment that sets the font of the given object.
    t   fontR  t   familyt
   underlinedR×   t   weights   "%s"t   faceR[   s   \"s	   .SetFont(t   wxFonts   (%s, %s, %s, %s, %s, %s))
(   R¢   R   RR   R
  (	   R£   R  R  R  R   R×   R!  R"  R   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   generate_code_fontS  s    

c         C   s!  |  o |  i  o d Sn | d j o |  i i d  } n | d j o d Sn | i d  } t |  d j o | d  \ } } n d | d f S| p d | f Sn | i   d j o t d	  } n | i   } | i   } d
 | j o d | | f | f Sn d | | | f | f S(   sł       returns a 2-tuple of strings representing the LOC that sets the id of the
    given object: the first line is the declaration of the variable, and is
    empty if the object's id is a constant, and the second line is the value
    of the id
    R(   s   -1RĮ   t   =i   i   i    t   ?s	   wxNewId()RO   s   %s = %s
s   global %s; %s = %s
(   R(   s   -1N(   R(   s   -1(   R¹   R%   R¢   R   R   Rā   RN   R   (   R£   RĮ   t   tokensR!   t   val(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR·   c  s    '%c         C   s%   t  |   } | d t |  i d  S(   sM       returns the code fragment that sets the tooltip of the given object.
    s   .SetToolTipString(%s)
t   tooltip(   R
  Re   R¢   (   R£   R   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   generate_code_tooltip}  s    c         C   sJ   t  |   } y t |  i d  } Wn t } n X| o | d Sn d  S(   Nt   disableds   .Enable(False)
(   R
  Rm   R¢   R   (   R£   R   R+  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   generate_code_disabled  s
    c         C   sJ   t  |   } y t |  i d  } Wn t } n X| o | d Sn d  S(   Nt   focuseds   .SetFocus()
(   R
  Rm   R¢   R   (   R£   R   R-  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   generate_code_focused  s
    c         C   sJ   t  |   } y t |  i d  } Wn t } n X| o | d Sn d  S(   Nt   hiddens   .Hide()
(   R
  Rm   R¢   R   (   R£   R   R/  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   generate_code_hidden  s
    c         C   sY   t  |   } |  i d } g  } x3 t |  D]% } | i | d | | | f  q, W| S(   Nt   extrapropertiess   .Set%s(%s)
(   R
  R¢   t   sortedR1   (   R£   R   Rī   t   retR!   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   generate_code_extraproperties  s     #c         C   s  |  i  } g  } | i d d  i   o | i t |    n | i d  o | i t |    n | i d  o | i t |    n | i d  o | i t |    n | i d  o | i t |    n | i d  o | i t	 |    n | i d  o | i t
 |    n | i d	  o | i t |    n | i d
  o" |  i o | i t |    n | S(   s¶       generates the code for various properties common to all widgets (background
    and foreground colors, font, ...)
    Returns a list of strings containing the generated code
    R  R(   R  R  R  R)  R+  R-  R/  R1  (   R¢   R   RN   R1   R  R  R  R$  R*  R,  R.  R0  R¹   R®   R4  (   t   widgetRī   Rž   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRį   §  s    	0'''''''t   FontPropertyHandlerc           B   s¹   e  Z d  Z h  d d <d d <d d <d d <d	 d
 <d d <d d <Z h  d d <d d <d d <Z h  d d <d d <d d <Z d   Z d   Z d   Z d   Z	 RS(   s   Handler for font propertiest	   wxDEFAULTt   defaultt   wxDECORATIVEt
   decorativet   wxROMANt   romant   wxSWISSt   swisst   wxSCRIPTt   scriptt   wxMODERNt   modernt
   wxTELETYPEt   teletypet   wxNORMALt   normalt   wxSLANTt   slantt   wxITALICt   italict   wxLIGHTt   lightt   wxBOLDt   boldc         C   s   h  |  i  d <|  i d <|  i d <|  _ h  d d <d d <d d <d d <d d <d d <|  _ d  |  _ g  |  _ d  S(	   NR  R×   R!  t   0R  R   R(   R"  (   t   font_familiest   font_stylest   font_weightst   dictst   attrsR%   t   currentt	   curr_data(   R   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR   Ė  s    (	c         C   s@   g  |  _  | d j o | |  i j o | |  _ n
 d  |  _ d  S(   NR  (   RV  RT  RU  R%   (   R   R!   RT  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt
   start_elemÓ  s    	c         C   s   | d j o |  i  | i d <t Snu |  i d  j	 od |  i i |  i  } | o" | i d i |  i  d  } n d i |  i  } | |  i  |  i <n d  S(   NR  R(   RO  (	   RT  R¢   R.   RU  R%   RS  R   R	   RV  (   R   R!   Rå   t   decodeR(  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   end_elemŁ  s    )c         C   s   |  i  i |  d  S(   N(   RV  R1   (   R   t   data(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt	   char_datać  s    (
   R   R   R   RP  RQ  RR  R   RW  RY  R[  (    (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR6  Ą  s   				
t   DummyPropertyHandlerc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s2   Empty handler for properties that do not need codec         C   s   d  S(   N(    (   R   R!   RT  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRW  ė  s    c         C   s   t  S(   N(   R.   (   R   R!   Rå   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRY  ģ  s    c         C   s   d  S(   N(    (   R   RZ  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR[  ķ  s    (   R   R   R   RW  RY  R[  (    (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR\  é  s   		t   EventsPropertyHandlerc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   h  |  _  d  |  _ g  |  _ d  S(   N(   t   handlersR%   t
   event_namet   curr_handler(   R   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR   ó  s    		c         C   s"   | d j o | d |  _  n d  S(   NRĆ   RĀ   (   R_  (   R   R!   RT  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRW  ų  s    c         C   s   | d j oJ |  i  o* |  i o  d i |  i  |  i |  i  <n d  |  _  g  |  _ n& | d j o |  i | i d <t Sn d  S(   NRĆ   R(   R§   (   R_  R`  R	   R^  R%   R¢   R.   (   R   R!   Rå   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRY  ü  s     	c         C   s+   | i    } | o |  i i |  n d  S(   N(   RN   R`  R1   (   R   RZ  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR[    s    (   R   R   R   RW  RY  R[  (    (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR]  ņ  s   			
t   ExtraPropertiesPropertyHandlerc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s   h  |  _  d  |  _ g  |  _ d  S(   N(   R   R%   t	   prop_namet	   curr_prop(   R   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR     s    		c         C   s\   | d j oK | d } | o- | d i    o | d i   | d } n | |  _ n d  S(   Nt   propertyR!   i    i   (   t   islowert   upperRb  (   R   R!   RT  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRW    s
    
c         C   s   | d j oJ |  i  o* |  i o  d i |  i  |  i |  i  <n d  |  _  g  |  _ n& | d j o |  i | i d <t Sn d  S(   NRd  R(   R1  (   Rb  Rc  R	   R   R%   R¢   R.   (   R   R!   Rå   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRY    s     	c         C   s+   | i    } | o |  i i |  n d  S(   N(   RN   Rc  R1   (   R   RZ  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR[  %  s    (   R   R   R   RW  RY  R[  (    (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRa    s   			
R  R§   R1  c         C   sP   y t  | |  } Wn% t j
 o t i |  d   } n X| o |   Sn d  S(   N(   t   _property_writersRn   t   _global_property_writersR   R%   (   t   property_namet   widget_namet   cls(    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   get_property_handler@  s    %c         C   sZ   | d j o | t |  <n< y | t | |  <Wn& t j
 o h  | |  <t | <n Xd S(   są       sets a function to parse a portion of XML to get the value of the property
    property_name. If widget_name is not None, the function is called only if
    the property in inside a widget whose class is widget_name
    N(   R%   Rh  Rg  Rn   (   Ri  RĆ   Rj  (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   add_property_handlerF  s    t   WidgetHandlerc           B   s8   e  Z d  Z g  Z d   Z d   Z d   Z d   Z RS(   sM       Interface the various code generators for the widgets must implement
    c         C   s   g  g  g  f S(   sŃ           Handler for normal widgets (non-toplevel): returns 3 lists of strings,
        init, properties and layout, that contain the code for the
        corresponding methods of the class to generate
        (    (   R   R£   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyR°   [  s    c         C   s   g  S(   s           Handler for the code of the set_properties method of toplevel objects.
        Returns a list of strings containing the code to generate
        (    (   R   R£   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRŚ   c  s    c         C   s   g  S(   s2          Handler for the code of the constructor of toplevel objects.  Returns a
        list of strings containing the code to generate.  Usually the default
        implementation is ok (i.e. there are no extra lines to add). The
        generated lines are appended at the end of the constructor
        (    (   R   R£   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRŲ   j  s    c         C   s   g  S(   sõ           Handler for the code of the do_layout method of toplevel objects.
        Returns a list of strings containing the code to generate.
        Usually the default implementation is ok (i.e. there are no
        extra lines to add)
        (    (   R   R£   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRÜ   s  s    (   R   R   R   RŖ   R°   RŚ   RŲ   RÜ   (    (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyRn  S  s   				c         C   s   | t  |  <d  S(   N(   R¬   (   Rj  RĆ   (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pyt   add_widget_handler  s    (L   R   t   sysRS   t   os.pathRs   R{   R   t	   xml_parseR    R)   t   languaget   modulesR   t   writert   default_extensionsR%   R#   R¬   t   obj_propertiesR2   Rz   R   RP   R   R   RQ   R.   R   R   R   Ri   R   R    R   RY   Rp   R`   R*   R]   RZ   Re   R   R    R¤   RČ   RŌ   R»   R   R   R	  R
  R  R  R  R  R$  R·   R*  R,  R.  R0  R4  Rį   R6  R\  t   objectR]  Ra  Rh  Rg  t   _widget_extra_modulesRv   Rl  Rm  Rn  Ro  (    (    (    sH   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\codegen\py_codegen.pys   <module>   s   $			¤			^	B	
	Q			’ a	T														)	 		,