Browse Source

Improve the interaction with Layer and LayerList objects

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@55420 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 12 years ago
parent
commit
041b3c4c6d
1 changed files with 19 additions and 4 deletions
  1. 19 4
      gui/wxpython/lmgr/giface.py

+ 19 - 4
gui/wxpython/lmgr/giface.py

@@ -17,6 +17,7 @@ This program is free software under the GNU General Public License
 
 
 from grass.pydispatch.signal import Signal
 from grass.pydispatch.signal import Signal
 
 
+
 class Layer(object):
 class Layer(object):
     """!@implements core::giface::Layer
     """!@implements core::giface::Layer
 
 
@@ -29,16 +30,30 @@ class Layer(object):
     def __getattr__(self, name):
     def __getattr__(self, name):
         return self._pydata[0][name]
         return self._pydata[0][name]
 
 
+    def __dir__(self):
+        return self._pydata[0].keys()
+
+    def __repr__(self):
+        return self.maplayer.name
+
 
 
 class LayerList(object):
 class LayerList(object):
     """!@implements core.giface.Layer"""
     """!@implements core.giface.Layer"""
     def __init__(self, tree):
     def __init__(self, tree):
         self._tree = tree
         self._tree = tree
 
 
-#    def __iter__(self):
-#    """!Iterates over the contents of the list."""
-#        for in :
-#            yield
+    def __iter__(self):
+        """!Iterates over the contents of the list."""
+        for item in self._tree.GetSelectedLayer(multi=True):
+            yield Layer(self._tree.GetPyData(item))
+
+    def __getitem__(self, index):
+        """!Select a layer from the LayerList using the index."""
+        return [l for l in self][index]
+
+    def __repr__(self):
+        """!Return a representation of the object."""
+        return "LayerList(%r)" % [layer for layer in self]
 
 
     def GetSelectedLayers(self, checkedOnly=True):
     def GetSelectedLayers(self, checkedOnly=True):
         items = self._tree.GetSelectedLayer(multi=True,
         items = self._tree.GetSelectedLayer(multi=True,