
    ը	f,'                         d Z ddlmZ ddlmZ ddlmZ ddlmZ  G d de	      Z
 G d d	e	      Z G d
 de	      Z G d de	      Zy)az  
@package lmgr.giface

@brief Layer Manager GRASS interface

Classes:
 - giface::LayerManagerGrassInterface

(C) 2012 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 Anna Kratochvilova <kratochanna gmail.com>
@author Vaclav Petras <wenzeslaus gmail.com>
    )print_function)Signal)Notification)GetLayerNameFromCmdc                   (    e Zd ZdZd Zd Zd Zd Zy)Layerz@implements core::giface::Layer

    .. note::

        Currently implemented without specifying the interface.
        It only provides all attributes of existing layer as used in lmgr.
    c                      || _         || _        y N)_layer_pydata)selflayerpydatas      ,/usr/lib/grass83/gui/wxpython/lmgr/giface.py__init__zLayer.__init__"   s        c                 &    | j                   d   |   S Nr   )r   r   names     r   __getattr__zLayer.__getattr__&   s    ||At$$r   c                 <    | j                   d   j                         S r   )r   keysr   s    r   __dir__zLayer.__dir__)   s    ||A##%%r   c                 v    | j                   | j                   j                  dS | j                   j                  S )N )maplayerr   r   s    r   __str__zLayer.__str__,   s;     %););)C 	
 ##	
r   N)__name__
__module____qualname____doc__r   r   r   r    r   r   r   r      s    %&
r   r   c                   z    e Zd ZdZd Zd Zd Zd Zd ZddZ	ddZ
d	 ZddZd ZddZddZd Zd Zd Zd Zy
)	LayerListz@implements core.giface.Layerc                     || _         y r
   )_tree)r   trees     r   r   zLayerList.__init__7   s	    
r   c                 >    t        | D cg c]  }| c}      S c c}w r
   )lenr   r   s     r   __len__zLayerList.__len__:   s    t,eE,--,s   	c              #   ^  K   | j                   r| j                   j                  | j                   j                        d   }|rh|j                         rWt	        || j                   j                  |             | j                   j                  |      }|r|j                         rUyyyyyw)z'Iterates over the contents of the list.r   N)r(   GetFirstChildrootIsOkr   	GetPyDataGetNextItem)r   items     r   __iter__zLayerList.__iter__=   s     ::::++DJJOO<Q?D499;D$**"6"6t"<==zz--d3 499;$;$ s   B%B-(B-c                 2    | D cg c]  }| c}|   S c c}w )z2Select a layer from the LayerList using the index.r$   )r   indexls      r   __getitem__zLayerList.__getitem__E   s     a '' s   	c                 2    d| D cg c]  }| c}z  S c c}w )z&Return a representation of the object.zLayerList(%r)r$   r,   s     r   __repr__zLayerList.__repr__I   s    T!:E%!:::!:s   	c                     | j                   j                  d|      }g }|D ]8  }t        || j                   j                  |            }|j	                  |       : |S )NTmulticheckedOnly)r(   GetSelectedLayerr   r2   append)r   r?   itemslayersr4   r   s         r   GetSelectedLayerszLayerList.GetSelectedLayersM   s]    

++$K+P 	!D$

 4 4T :;EMM% 	! r   c                     | j                   j                  d|      }|y| j                   j                  |      }t        ||      S )z?Returns selected layer or None when there is no selected layer.Fr=   N)r(   r@   r2   r   )r   r?   r4   datas       r   r@   zLayerList.GetSelectedLayerV   sD    zz**K*P<::''-Dt$$r   c                 L    t        || j                  j                  |            S )z(For compatibility only, will be removed.)r   r(   r2   r,   s     r   GetLayerInfozLayerList.GetLayerInfo_   s    UDJJ00788r   Nc                     | j                   j                  |||||      }t        || j                   j                  |            S )a]  Adds a new layer to the layer list.

        Launches property dialog if needed (raster, vector, etc.)

        :param ltype: layer type (raster, vector, raster_3d, ...)
        :param name: layer name
        :param checked: if True layer is checked
        :param opacity: layer opacity level
        :param cmd: command (given as a list)
        )ltypelnamelcheckedlopacitylcmd)r(   AddLayerr   r2   )r   rJ   r   checkedopacitycmdr8   s          r   rO   zLayerList.AddLayerc   sF     JJtgc   
 Q

,,Q/00r   c                 N    | j                   j                  |j                         y)zRemove layer from layer listN)r(   Deleter   r,   s     r   DeleteLayerzLayerList.DeleteLayers   s    

%,,'r   c                 t    d| j                   _        | j                   j                  |j                  |       y)zCheck or uncheck layerT)rP   N)r(   
forceCheck	CheckItemr   )r   r   rP   s      r   
CheckLayerzLayerList.CheckLayerw   s)     $



U\\7;r   c                 P    | j                   j                  |j                  |       y)zSelect or unselect layerN)r(   
SelectItemr   )r   r   selects      r   SelectLayerzLayerList.SelectLayer|   s    

ellF3r   c                 ,   d|v r<|d   |j                   d   d<   t        |d   d      \  }}|r||j                   d   d<   d|v r|d   |j                   d   d<   d|v r$|j                   d   d	   j                  |d          | j                  j	                  |j
                         | j                  j                  |j
                         | j                  j                  |j
                  | j                  j                  |j
                               y
)z"Change layer (cmd, ltype, opacity)rR   r   T)fullyQualifiedlabelrJ   typerQ   r   N)	r   r   
SetOpacityr(   ChangeLayerr   SetItemIconSetItemText_getLayerName)r   r   kwargs	layerNamefounds        r   rc   zLayerList.ChangeLayer   s    F?&,UmEMM!U#26%=QUVIu,5a )f'-gEMM!V$MM!Z(33F94EF

u||,

u||,

u||TZZ-E-Eell-STr   c                 L    | j                   j                  |j                        S )z1Returns True if layer is checked, False otherwise)r(   IsItemCheckedr   r,   s     r   IsLayerCheckedzLayerList.IsLayerChecked   s    zz''55r   c                     | j                   j                  d|      }|g S g }|D ]8  }t        || j                   j                  |            }|j	                  |       : |S )Nr   keyvalue)r(   FindItemByDatar   r2   rA   )r   r   rB   rC   r4   r   s         r   GetLayersByNamezLayerList.GetLayersByName   sg    

))fD)A=IF %dDJJ$8$8$>?e$% Mr   c                     |dk(  rt        d       | j                  j                  ||      }|yt        || j                  j	                  |            S )zReturns layer with specified.

        Returns only one layer.
        Avoid using this method, it might be removed in the future.
        r   zQgiface.GetLayerByData(): Do not with use key='name', use GetLayersByName instead.rn   N)printr(   rq   r   r2   )r   ro   rp   r4   s       r   GetLayerByDatazLayerList.GetLayerByData   sW     &=0 zz((S(><tzz33D9::r   )TF)NNg      ?N)r    r!   r"   r#   r   r-   r5   r9   r;   rD   r@   rH   rO   rU   rY   r]   rc   rl   rr   ru   r$   r   r   r&   r&   4   sV    '.4(;%91 (<
4U 6	;r   r&   c                       e Zd ZdZd Zd ZddZdej                  fdZ	dej                  fdZd Zd	 Zdd
Zd Zd Zd Zd Zd Zd Zd Zy)LayerManagerGrassInterfacez(@implements core::giface::GrassInterfacec                     || _         t        d      | _        t        d      | _        t        d      | _        t        d      | _        t        d      | _        y)zConstructor is specific to the current implementation.

        Uses Layer Manager object including its private attributes.
        (It encapsulates existing Layer Manager so access to private members
        is intention.)
        z%LayerManagerGrassInterface.mapCreatedz/LayerManagerGrassInterface.currentMapsetChangedz)LayerManagerGrassInterface.grassdbChangedz$LayerManagerGrassInterface.updateMapz+LayerManagerGrassInterface.workspaceChangedN)lmgrr   
mapCreatedcurrentMapsetChangedgrassdbChanged	updateMapworkspaceChanged)r   rz   s     r   r   z#LayerManagerGrassInterface.__init__   s[     	 !!HI %+=%
! %%PQ   FG !''T Ur   c                 P     | j                   j                  j                  |i | y r
   )rz   	_gconsoleRunCmd)r   argsrg   s      r   r   z!LayerManagerGrassInterface.RunCmd   s!    "		""D3F3r   c                 |    dd|z  g}|r|j                  d       | j                  |dt        j                         y )Nzg.manualzentry=%sz-oF)compRegnotification)rA   r   r   NO_NOTIFICATION)r   entryonlinecmdlists       r   HelpzLayerManagerGrassInterface.Help   s8    zE12NN4 GU9U9UVr   Nc                 T    | j                   j                  j                  |||       y )N)textwrapr   )rz   r   WriteLog)r   r   r   r   s       r   r   z#LayerManagerGrassInterface.WriteLog   s!    		$$$T$Ur   c                 T    | j                   j                  j                  |||       y )N)r   pidr   )rz   r   WriteCmdLog)r   r   r   r   s       r   r   z&LayerManagerGrassInterface.WriteCmdLog   s!    		''Ts'Vr   c                 P    | j                   j                  j                  |       y N)r   )rz   r   WriteWarningr   r   s     r   r   z'LayerManagerGrassInterface.WriteWarning   s    		((d(3r   c                 P    | j                   j                  j                  |       y r   )rz   r   
WriteErrorr   s     r   r   z%LayerManagerGrassInterface.WriteError   s    		&&D&1r   c                 N    | j                   j                  j                  |      S )N)err)rz   r   GetLog)r   r   s     r   r   z!LayerManagerGrassInterface.GetLog   s     yy""))c)22r   c                 6    | j                   j                         S r
   )rz   GetLayerTreer   s    r   r   z'LayerManagerGrassInterface.GetLayerTree   s    yy%%''r   c                 H    t        | j                  j                               S r
   )r&   rz   r   r   s    r   GetLayerListz'LayerManagerGrassInterface.GetLayerList   s    //122r   c                 :    | j                   j                  d      S NTonlyCurrentrz   GetMapDisplayr   s    r   r   z(LayerManagerGrassInterface.GetMapDisplay   s    yy&&4&88r   c                 :    | j                   j                  d      S )NFr   r   r   s    r   GetAllMapDisplaysz,LayerManagerGrassInterface.GetAllMapDisplays   s    yy&&5&99r   c                     | j                   j                  d      r*| j                   j                  d      j                         S y r   )rz   r   GetMapWindowr   s    r   r   z'LayerManagerGrassInterface.GetMapWindow   s;    99""t"499**t*<IIKKr   c                 J    | j                   j                  j                         S r
   )rz   goutputGetProgressBarr   s    r   GetProgressz&LayerManagerGrassInterface.GetProgress  s    yy  //11r   c                 j    | j                   j                  j                         j                  |       y r
   )rz   r   	GetPromptUpdateCmdHistory)r   rR   s     r   r   z+LayerManagerGrassInterface.UpdateCmdHistory  s#    		##%66s;r   rv   )r    r!   r"   r#   r   r   r   r   	HIGHLIGHTr   MAKE_VISIBLEr   r   r   r   r   r   r   r   r   r   r   r$   r   r   rx   rx      so    2#VJ4W #'\5K5K V %)|7P7P W423(39:2<r   rx   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)'LayerManagerGrassInterfaceForMapDisplayzProvides reference only to the given layer list (according to tree),
    not to the current.

    @implements core::giface::GrassInterface
    c                 @    || _         || _        t        d      | _        y)z
        :param giface: original grass interface
        :param tree: tree which will be used instead of the tree from giface
        z1LayerManagerGrassInterfaceForMapDisplay.updateMapN)_gifacer)   r   r~   )r   gifacer)   s      r   r   z0LayerManagerGrassInterfaceForMapDisplay.__init__  s!    
 	   STr   c                     | j                   S r
   )r)   r   s    r   r   z4LayerManagerGrassInterfaceForMapDisplay.GetLayerTree  s    yyr   c                 ,    t        | j                        S r
   )r&   r)   r   s    r   r   z4LayerManagerGrassInterfaceForMapDisplay.GetLayerList  s    ##r   c                 R    | j                   j                         j                         S r
   )r)   r   r   r   s    r   r   z4LayerManagerGrassInterfaceForMapDisplay.GetMapWindow"  s    yy&&(5577r   c                 .    t        | j                  |      S r
   )getattrr   r   s     r   r   z3LayerManagerGrassInterfaceForMapDisplay.__getattr__%  s    t||T**r   N)	r    r!   r"   r#   r   r   r   r   r   r$   r   r   r   r   
  s!    	U$8+r   r   N)r#   
__future__r   grass.pydispatch.signalr   core.gifacer   
core.utilsr   objectr   r&   rx   r   r$   r   r   <module>r      sN   " & * $ *
F 
6z; z;zV< V<r+f +r   