³ò
0ŽGc           @   sË   d  d k  l Z d  d k l 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
 Z
 d d d „  ƒ  YZ d e i f d „  ƒ  YZ d „  Z d	 „  Z d d
 „ Z d „  Z d S(   iÿÿÿÿ(   t   minidom(   t   saxutilsNt   Templatec           B   s#   e  Z d  Z d d „ Z d „  Z RS(   sF        A class that handles the specific aspects of template files.
    c         C   sw  d |  _  d |  _ d |  _ | |  _ | d  j	 oBt i | ƒ } | i d ƒ } t | ƒ oø | d } y) t	 i
 | i d ƒ d i i ƒ |  _  Wn" t t f j
 o d |  _  n Xy) t	 i
 | i d ƒ d i i ƒ |  _ Wn" t t f j
 o d |  _ n Xy) t	 i
 | i d ƒ d i i ƒ |  _ Wqot t f j
 o d |  _ qoXqsd |  _  d |  _ d |  _ n d  S(   Nt    t   templatedatai    t   authort   descriptiont   instructions(   R   R   R   t   filenamet   NoneR    t   parset   getElementsByTagNamet   lenR   t   unescapet
   firstChildt   datat
   IndexErrort   AttributeError(   t   selfR   t   filexmlR   t   desc_xml(    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyt   __init__   s6    				
""&		c         C   s¶   | i  } d | } d | d } | | d ƒ | | d t i t i |  i ƒ ƒ ƒ | | d t i t i |  i ƒ ƒ ƒ | | d t i t i |  i ƒ ƒ ƒ | | d ƒ d  S(   Ns       i   s   <templatedata>
s   <author>%s</author>
s   <description>%s</description>
s    <instructions>%s</instructions>
s   </templatedata>
(   t   writeR   t   escapet   commont   _encode_to_xmlR   R   R   (   R   t   outfilet   tabst   fwritet   t1t   t2(    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyR   8   s    	
			N(   t   __name__t
   __module__t   __doc__R	   R   R   (    (    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyR      s   !t   TemplateListDialogc           B   sP   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c         C   s9   t  i i |  d  d d ƒ g  |  _ |  i ƒ  d  |  _ d  S(   NiÿÿÿÿR   (   t   templates_uiR"   R   R	   t	   templatest   fill_template_listt   selected_template(   R   (    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyR   J   s    	
c         C   s3   |  i  i ƒ  } | d j o |  i | Sn d  Sd  S(   Ni    (   t   template_namest   GetSelectionR$   R	   (   R   t   index(    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyt   get_selectedP   s    c         C   s#   |  i  ƒ  |  _ |  i t i ƒ d  S(   N(   R*   R&   t   EndModalt   wxt   ID_OPEN(   R   t   event(    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyt   on_openW   s    c         C   sS  |  i  ƒ  |  _ |  i d  j	 oé t |  i ƒ } |  i |  i i ƒ  ƒ |  i i t	 i
 | i ƒ ƒ |  i i t	 i
 | i ƒ ƒ |  i i t	 i
 | i ƒ ƒ t i i t i d ƒ } t i i |  i ƒ | j o |  i i ƒ  |  i i ƒ  qE|  i i ƒ  |  i i ƒ  n> |  i d ƒ |  i i d ƒ |  i i d ƒ |  i i d ƒ | i ƒ  d  S(   NR$   R   (   R*   R&   R	   R   t   set_template_nameR'   t   GetStringSelectionR   t   SetValuet   misct   wxstrR   R   t   ost   patht   joinR   t   wxglade_patht   dirnamet
   btn_deletet   Disablet   btn_editt   Enablet   Skip(   R   R.   t   tt   wxglade_templates(    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyt   on_select_template[   s&    	c         C   s'   |  i  i t d ƒ t i | ƒ ƒ d  S(   Ns   wxGlade template:
(   t   template_namet   SetLabelt   _R3   R4   (   R   t   name(    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyR0   r   s    c         C   s#   |  i  ƒ  |  _ |  i t i ƒ d  S(   N(   R*   R&   R+   R,   t   ID_EDIT(   R   R.   (    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyt   on_editu   s    c         C   sÊ   |  i  ƒ  |  _ |  i d  j	 o§ |  i i ƒ  } t i t d ƒ t i	 | ƒ t d ƒ d t i
 t i Bt i Bƒt i
 j oH y t i |  i ƒ Wn t j
 o } | GHn X|  i ƒ  d  |  _ qÆ n d  S(   Ns   Delete template '%s'?s   Are you sure?t   style(   R*   R&   R	   R'   R1   R,   t
   MessageBoxRD   R3   R4   t   YESt   NOt   CENTRER5   t   unlinkt	   ExceptionR%   (   R   R.   RE   t   e(    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyt	   on_deletey   s    $

c         C   s]   t  ƒ  |  _ |  i i ƒ  x= |  i D]2 } |  i i t i i t i i | ƒ ƒ d ƒ q# Wd  S(   Ni    (	   t   load_templatesR$   R'   t   Cleart   AppendR5   R6   t   splitextt   basename(   R   t   n(    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyR%   ‡   s
    
 (
   R   R    R   R*   R/   RA   R0   RG   RP   R%   (    (    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyR"   I   s   							c          C   sˆ   t  i i t i ƒ  d ƒ }  |  t i j o% t i t  i i |  d d ƒ ƒ } n g  } t t i t  i i t i d d ƒ ƒ ƒ t | ƒ S(   s+       Finds all the available templates.
    s   .wxgladeR$   s   *.wgt(	   R5   R6   R7   t   configt   _get_appdatapathR   R8   t   globt   sorted(   t   dt   extra(    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyRQ      s    %c          C   sZ   t  ƒ  }  |  i i ƒ  |  i i ƒ  |  i ƒ  t i j o |  i } n d } |  i	 ƒ  | S(   s3       Returns the filename of a template to load
    N(
   R"   R:   t   HideR<   t	   ShowModalR,   R-   R&   R	   t   Destroy(   t   dlgt   ret(    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyt   select_template   s    	
c         C   s  t  i d d d ƒ } |  d j	 o | i i t i t i i	 t i i
 |  i ƒ d ƒ ƒ ƒ | i i t i |  i ƒ ƒ | i i t i |  i ƒ ƒ | i i t i |  i ƒ ƒ n d } t ƒ  } | i ƒ  t i j oƒ | i i ƒ  i ƒ  } | i i ƒ  | _ | i i ƒ  | _ | i i ƒ  | _ | p- t i t d ƒ t d ƒ t i t i Bƒ qZn | i ƒ  | } | o  t i i t i ƒ  d d ƒ } t i i | ƒ pR y t i | ƒ Wqôt t  f j
 o( } t d ƒ | | f GHd | f SqôXn t i i | | d	 ƒ } n | o] t i i | ƒ oJ t i t d
 ƒ | t d ƒ t i! t i" Bt i# Bƒ t i! j o
 d } n | | f S(   sP       Returns an out file name and template description for saving a template
    iÿÿÿÿR   i    s(   Can't save a template with an empty namet   Errors   .wxgladeR$   s   ERROR creating %s: %ss   .wgtsC   A template called '%s' already exists:
do you want to overwrite it?t   QuestionN($   R#   t   TemplateInfoDialogR	   RB   R2   R3   R4   R5   R6   RU   RT   R   R   R   R   R   R^   R,   t   ID_OKt   GetValuet   stripRI   RD   t   OKt
   ICON_ERRORR_   R7   RW   RX   t   existst   mkdirt   OSErrort   IOErrorRJ   RK   t   ICON_QUESTION(   R   R`   Ra   t   retdataRE   R[   RO   (    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyt   save_template¬   sD    	/ 	"
$
c          C   sM   t  ƒ  }  |  i i ƒ  d  } |  i ƒ  t i j o |  i } n |  i ƒ  | S(   N(	   R"   t   btn_openR]   R	   R^   R#   RF   R&   R_   (   R`   Ra   (    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pyt   manage_templatesÔ   s    	
(    (   t   xml.domR    t   xml.saxR   RW   R#   R   R3   R5   RY   R,   R   R"   RQ   Rb   R	   Rq   Rs   (    (    (    s>   C:\Python25\Lib\site-packages\_spe\plugins\wxGlade\template.pys   <module>	   s   7G		(