
    ը	f                         d Z ddlmZ ddlZddlmZ ddlZddlZddlm	Z
 ddlmZ ddlmZ ddlmZmZmZ ddlmZ dd	lmZ  G d
 dej0                        Zy)a  
@package lmgr.pyshell

@brief wxGUI Interactive Python Shell for Layer Manager

Classes:
 - pyshell::PyShellWindow

.. todo::
    Run pyshell and evaluate code in a separate instance of python &
    design the widget communicate back and forth with it

(C) 2011 by the GRASS Development Team

This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.

@author Martin Landa <landa.martin gmail.com>
    )print_functionN)redirect_stdout)Shell)VERSION)ButtonClearButtonIsDark)SetDarkMode)CheckWxVersionc                   P    e Zd ZdZej
                  dfdZd Zd Zd	dZ	d Z
d Zy)
PyShellWindowzPython Shell WindowNc           	      ,   || _         || _        t        j                  j                  | f||d| t        d      t        z  dz   t        d      dz  z   dz   t        d      dz  z   dz   | _        t        | t        j                  | j                  t        | j                  | j                  d	
      }t        j                  dk(  rt        g d      rd|d<   t!        di || _        t%               rt'        | j"                         | j(                  t        _        t-        |       | _        | j.                  j1                  t        j2                  | j4                         | j.                  j7                  t        d             || _        |rxt;        | t        j                  t        d            | _        | j<                  j1                  t        j2                  |       | j<                  j7                  t        d             | j?                          y )N)parentidz,Welcome to wxGUI Interactive Python Shell %sz

z5Type %s for more GRASS scripting related information.z
"help(gs)"
z2Type %s to add raster or vector to the layer tree.z"AddLayer('map_name')")gsAddLayerhelp)r   r   	introTextlocalsdarwin)   r      F
useStockIdDelete all text from the shellzSimple &editor)r   labelz Open a simple Python code editor ) r   gifacewxPanel__init___r   introdictID_ANYgrassr   Helpsysplatformr   PyShellshellr	   r
   _displayhookdisplayhookr   btnClearBind
EVT_BUTTONOnClear
SetToolTipsimpleEditorHandlerr   btnSimpleEditor_layout)selfr   r   r   r3   kwargs	shellargss          -/usr/lib/grass83/gui/wxpython/lmgr/pyshell.pyr!   zPyShellWindow.__init__)   s    
$?v"?? <=GGH<WX  DE()	)  	
 yyjjT]]DIIN	
	 <<8#y(A&+Il#)y)
8

#++#D)2==$,,7  #C!DE#6 #)$299AFVDW#XD   %%bmm5HI  ++A.P,QR    c                     t        |       y )N)print)r6   values     r9   r,   zPyShellWindow._displayhookV   s	    er:   c                 H   t        j                  t         j                        }|j                  | j                  dt         j
                         t        j                  t         j                        }| j                  rO|j                  | j                  dt         j
                  t         j                  z  t         j                  z  d       |j                          |j                  | j                  dt         j
                  d       |j                  |dt         j                  t         j
                  z  d       |j                  |        |j                  |        | j!                  |       | j                          | j#                  d       | j%                          y )N   )
proportionflagr      )r@   rA   borderT)r   BoxSizerVERTICALAddr+   EXPAND
HORIZONTALr3   r4   LEFTRIGHTAddStretchSpacerr.   ALLFitSetSizeHintsSetSizerSetAutoLayoutLayout)r6   sizerbtnSizers      r9   r5   zPyShellWindow._layoutY   s   BKK(		$**	;;;r}}-##LL$$YY(2883	   	!!#T]]qryyK		(qrvv		/A!	L		$4 e
4 r:   c                 x   d}|dk(  s|dk7  r t        j                  |d      d   }|rd}d}|s*|dk(  s|dk7  r t        j                  |d      d   }|rd}d}|st        d	      |z  S | j                  j	                         j                  ||d
d|z  g       |dk(  rt        d      |z  S t        d      |z  S )zAdd selected map to the layer tree

        :param name: name of raster/vector map to be added
        :param type: map type ('raster', 'vector', 'auto' for autodetection)
        Nrastervectorcell)elementfullnamezd.rastzd.vectz#Raster or vector map <%s> not foundTzmap=%s)ltypelnamelcheckedlcmdzRaster map <%s> addedzVector map <%s> added)r&   	find_filer"   r   GetLayerTreer   )r6   namerZ   fnamer]   s        r9   r   zPyShellWindow.AddLayers   s     H 1OOD&9*EE %8+u/@OOD(;JGE :;tDD  "++ut4EAQ:R 	, 	
 H,-55()E11r:   c                     t        t        j                               5 }t        |       ddd       |j	                         S # 1 sw Y   j	                         S xY w)zOverride help() function

        :param obj object/str: generate the help of the given object

        return str: help str of the given object
        N)r   ioStringIOr   getvalue)r6   objfs      r9   r'   zPyShellWindow.Help   sC     R[[]+ 	qI	zz|	zz|s   AAc                     | j                   j                          | j                   j                  | j                         | j                   j	                          y)r   N)r+   clear	showIntror#   prompt)r6   events     r9   r1   zPyShellWindow.OnClear   s8    



TZZ(

r:   )auto)__name__
__module____qualname____doc__r   r%   r!   r,   r5   r   r'   r1   r   r:   r9   r   r   &   s0     "$+Z42@	r:   r   )rq   
__future__r   rc   
contextlibr   r(   r   wx.py.shellr   r*   wx.py.versionr   grass.scriptscriptr&   gui_core.wrapr   r   r	   gui_core.pystcr
   core.globalvarr   r    r   r   r:   r9   <module>r{      sB   ( & 	 & 
 	 ( !  5 5 & )|BHH |r:   