
    ը	f*                         d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlZddlZddlmZmZmZ  G d d	ej$                        Z G d
 dej$                        Zy)z8
Created on Mon Nov 26 11:57:54 2012

@author: lucadelu
    N)	globalvargcmd)
try_remove)
retRLiPath)	RLIWizard)Button	StaticBoxTextCtrlc                       e Zd Zdej                   ed      ej                  ej                  z  fdZd Z	d Z
d Zd Zy)	ViewFrameNzModify the configuration filec           	      "   || _         t               | _        || _        t        j
                  j                  | j                  |      | _        t        j                  j                  | f|||d| | j                  t        j                  t        j
                  j                  t        j                  d      t        j                               t        j                   | t        j"                        | _        t'        | j$                  t        j"                  t)        dj+                  | j                                    | _        t/        | j$                  t        j"                  t        j0                  d      | _        | j2                  j5                  t        j6                  | j8                         t;        | j                        }| j2                  j=                  d	j                  |j?                                      |jA                          tC        | t        jD                        | _#        tC        | t        jH                        | _%        | jF                  j5                  t        jL                  | jN                         | jJ                  j5                  t        jL                  | jP                         | jS                          	 tU        jV                         | _,        y # tZ        $ r tU        j\                         d
   | _,        Y y w xY w)Nparentidtitle	grass.icor   r   z/View and modify the configuration file '{name}'namer   r   label)K   )r   r   stylesize    )/r   r   rlipathconfileospathjoinpathfilewxFrame__init__SetIconIconr   ICONDIRBITMAP_TYPE_ICOPanelID_ANYpanelr	   _formatconfilesBoxr
   TE_MULTILINEtextCtrlBindEVT_TEXT
OnFileTextopenSetValue	readlinescloser   ID_EXIT	btn_closeID_SAVEbtn_ok
EVT_BUTTONOnCloseOnOk_layoutlocalegetencodingencAttributeErrorgetdefaultlocale)	selfr   confgifacer   r   r   kwargsfs	            //usr/lib/grass83/gui/wxpython/rlisetup/frame.pyr&   zViewFrame.__init__   s    !|T\\48
$Lv"ELVLGGBGGLL!2!2K@"BTBTU	
 XXTbii8
$::yy..4f$,,f.G
 !::"))2??
 	2;;8rwwq{{}56		t

;DRZZ8BMM4<<8		2	4))+DH 	4..03DH	4s   K& &%LLc                    t        j                  dd      }t        j                  t         j                        }t        j                  | j
                  t         j                        }|j                  | j                  dt         j                         t        j                  t         j                        }|j                  | j                  t         j                  d       |j                  | j                  t         j                  d       |j                  |dt         j                  d       |j                  | j                  dt         j                  d       |j                  |d	t         j                  d       |j                  d	       |j                  d	       | j                  j!                  d
       | j                  j#                  |       | j%                  |       | j'                          yzSet the layoutr   )
proportionflag   )rP   border)r   r      )posrP   rR   )rO   rP   rR   r   TN)r$   GridBagSizerBoxSizerVERTICALStaticBoxSizerr0   
HORIZONTALAddr2   EXPANDr=   ALLr;   r-   AddGrowableRowAddGrowableColSetAutoLayoutSetSizerAndFitSetSizerLayoutrG   
panelsizer	mainsizerconfilesSizerbuttonSizers        rL   rA   zViewFrame._layoutC   sH   __Q*
KK,	))$*:*:BMMJ$--ABIIF kk"--0"&&;RVVA> 	}&ryyKdjjQRYYqIkabiiJ!!!$!!!$

  &

!!*-i     c                 $    | j                          yzClose windowNDestroyrG   events     rL   r?   zViewFrame.OnClose\       rh   c                 V   t        j                  | j                  t        d      j	                  | j
                        t        d      t         j                  t         j                  z  t         j                  z        }|j                         t         j                  k(  rit        j                  | j                  | j                  dd      }|j                  | j                   t"        j$                  z          |j'                          |j)                          | j)                          y)	Launches helpzkAre you sure that you want modify r.li configuration file {name}?
You could broke the configuration file...r   WARNINGr   messagecaptionr   wreplace)encodingmodeerrorsN)r$   MessageDialogr   r.   r/   r   YES_NOYES_DEFAULTICON_WARNING	ShowModalID_YEScodecsr6   r#   rD   writetextr    linesepr9   rl   )rG   rn   dlgrK   s       rL   r@   zViewFrame.OnOk`   s    ;;
 f$,,f'iL))bnn,r>

 ==?bii's9A GGDII

*+GGIrh   c                 .    |j                         | _        y)z File input interactively enteredN)	GetStringr   rm   s     rL   r5   zViewFrame.OnFileTextw   s    OO%	rh   )__name__
__module____qualname__r$   r,   r.   DEFAULT_FRAME_STYLERESIZE_BORDERr&   rA   r?   r@   r5    rh   rL   r   r      sE    
 99/0$$r'7'77-4^2.&rh   r   c                       e Zd Zdej                   ed      ej                  ej                  z  fdZd Z	d Z
d Zd Zd Zd	 Zd
 Zd Zy)RLiSetupFrameNzSetup for r.li modulesc                    || _         t               | _        | j                         | _        t        j                  j                  | f|||d| | j                  t        j                  t        j                  j                  t        j                  d      t
        j                               t        j                   | t
        j"                        | _        t'        | j$                  t
        j"                  t)        d            | _        t        j,                  | j$                  t
        j"                  | j                        | _        t1        | t
        j2                        | _        t1        | t
        j6                        | _        t1        | t
        j"                  t)        d            | _        | j:                  j=                  t)        d             t1        | t
        j"                  t)        d	            | _        | j>                  j=                  t)        d
             t1        | t
        j"                  t)        d            | _         | j@                  j=                  t)        d             t1        | t
        j"                  t)        d            | _!        | jB                  j=                  t)        d             | j4                  jE                  t
        jF                  | jH                         | j8                  jE                  t
        jF                  | jJ                         | j:                  jE                  t
        jF                  | jL                         | j>                  jE                  t
        jF                  | jN                         | j@                  jE                  t
        jF                  | jP                         | jB                  jE                  t
        jF                  | jR                         | jU                          | jW                  | jY                                | j[                  | jY                                y )Nr   r   r   z+Available sampling area configuration filesr   )r   r   choicesRemovezRemove a configuration fileCreatezCreate a new configuration fileRenamezRename a configuration filez	View/Editz"View and edit a configuration file).r   r   r   	ListFiles	listfilesr$   r%   r&   r'   r(   r    r!   r"   r   r)   r*   r+   r,   r-   r	   r.   r0   ListBoxlistfileBoxr   ID_CLOSEr;   ID_HELPbtn_help
btn_remove
SetToolTipbtn_new
btn_renamebtn_viewr3   r>   r?   OnHelpOnRemoveOnNewOnRenameOnViewrA   
SetMinSizeGetBestSizeSetClientSize)rG   r   rI   r   r   r   rJ   s          rL   r&   zRLiSetupFrame.__init__}   s    !|) 	$Lv"ELVLGGBGGLL!2!2K@"BTBTU	
 XXTbii8
$::yyAB

 ::::"))T^^

  t<drzz: !H+N""1%B#CDTbiiq{K"C DE !H+N""1%B#CDdryy+O  #G!HIBMM4<<82==$++6R]]DMM:"--4R]]DMM:2==$++6 	((*+4++-.rh   c                 X   t        j                  dd      }t        j                  t         j                        }t        j                  | j
                  t         j                        }|j                  | j                  dt         j                         t        j                  t         j                        }|j                  | j                  t         j                  d       |j                  | j                  t         j                  d       |j                  | j                  t         j                  d       |j                  | j                  t         j                  d       |j                  | j                  t         j                  d       |j                  | j                   t         j                  d       |j                  |dt         j                  d       |j                  | j"                  dt         j                  d       |j                  |d	t         j                  d       |j%                  d	       |j'                  d	       | j"                  j)                  d
       | j"                  j+                  |       | j-                  |       | j/                          yrN   )r$   rU   rV   rW   rX   r0   rY   rZ   r   r[   r   r\   r   r   r   r   r;   r-   r]   r^   r_   r`   ra   rb   rc   s        rL   rA   zRLiSetupFrame._layout   s   __Q*
KK,	))$*:*:BMMJ$**qryyI kk"--0266!<bffQ?BFF1=bffQ?BFF1=RVVA> 	}&ryyK 	djjQRYYqIkabiiJ!!!$!!!$

  &

!!*-i rh   c                    g }t        j                  | j                        D ][  }t         j                  j	                  t         j                  j                  | j                  |            sK|j                  |       ] t        |      S )z-Check the configuration files inside the path)r    listdirr   r!   isfiler"   appendsorted)rG   r   ls      rL   r   zRLiSetupFrame.ListFiles   se     	 DLL) 	$Aww~~bggll4<<;<  #	$ i  rh   c                 $    | j                          yrj   rk   rm   s     rL   r?   zRLiSetupFrame.OnClose   ro   rh   c                 4    t        j                  d| d       y)rq   zg.manualzwxGUI.rlisetup)r   entryN)r   
RunCommandrm   s     rL   r   zRLiSetupFrame.OnHelp   s    
47GHrh   c                    	 | j                   | j                  j                         d      }t        j                  | j                  t        d      |z  t        d      t        j                  t        j                  z  t        j                  z        }|j                         t        j                  k(  r~| j                  j                  | j                  j                         d          t!        t"        j$                  j'                  | j(                  |             | j+                         | _         |j-                          y# t        $ r# t	        j
                  | t        d             Y yw xY w)7Remove configuration file from path and update the listr   'You have to select a configuration filer   rt   Nz0Do you want remove r.li configuration file <%s>?z#Remove new r.li configuration file?rs   )r   r   GetSelections
IndexErrorr   GMessager.   r$   r{   r   r|   r}   ICON_QUESTIONr   r   Deleter   r    r!   r"   r   r   rl   )rG   rn   r   r   s       rL   r   zRLiSetupFrame.OnRemove   s   	nnT%5%5%C%C%Ea%HIG ;;KLwV;<))bnn,r/?/??	
 ==?bii'##D$4$4$B$B$DQ$GHrww||DLL':;!^^-DN#  	MMQ'P%Q 		s   *E )E0/E0c                     t        |        | j                         | _        | j                  j	                          | j                  j                  | j                         y)r   N)r   r   r   r   ClearSetrm   s     rL   r   zRLiSetupFrame.OnNew   sA    $) T^^,rh   c                    	 | j                   | j                  j                         d      }t        j                  | j                  t        d      |z  t        d            }|j                         t        j                  k(  r|j                         }| j                  t        j                  |}t        j                   t        j"                  j%                  | j                  |      |       | j'                         | _         | j                  j)                          | j                  j+                  | j                          yy# t        $ r# t	        j
                  | t        d             Y yw xY w)z%Rename an existing configuration filer   r   r   NzXSet the new name for %s "                                            "configuration filezRename configuration file)r   rt   ru   )r   r   r   r   r   r   r.   r$   TextEntryDialogr   r   ID_OKGetValuer   r    seprenamer!   r"   r   r   r   )rG   rn   r   r   resnewnames         rL   r   zRLiSetupFrame.OnRename  s#   	nnT%5%5%C%C%Ea%HIG   ;;@ 	
 12
 ==?bhh&,,.C"&,,<GIIbggll4<<97C!^^-DN""$  0 '  	MMQ'P%Q 		s   *E )E43E4c                     	 | j                   | j                  j                         d      }t        | |      }|j                          y# t        $ r# t	        j
                  | t        d             Y yw xY w)z"Show and edit a configuration filer   r   r   N)rH   )	r   r   r   r   r   r   r.   r   Show)rG   rn   r   frames       rL   r   zRLiSetupFrame.OnView!  sm    	nnT%5%5%C%C%Ea%HIG $W-

  	MMQ'P%Q 		s   *A
 
)A65A6)r   r   r   r$   r,   r.   r   r   r&   rA   r   r?   r   r   r   r   r   r   rh   rL   r   r   |   s[     99()$$r'7'776/r@	!I.-14
rh   r   )__doc__r$   r    corer   r   grass.script.utilsr   rlisetup.functionsr   rlisetup.wizardr   rB   r   gui_core.wrapr   r	   r
   r%   r   r   r   rh   rL   <module>r      sO    
 	   ) ) %   5 5f& f&RoBHH orh   