[GRASS-SVN] r57432 - in grass/trunk/gui/wxpython: core lmgr mapdisp vnet

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 7 15:33:27 PDT 2013


Author: wenzeslaus
Date: 2013-08-07 15:33:26 -0700 (Wed, 07 Aug 2013)
New Revision: 57432

Modified:
   grass/trunk/gui/wxpython/core/giface.py
   grass/trunk/gui/wxpython/lmgr/giface.py
   grass/trunk/gui/wxpython/mapdisp/main.py
   grass/trunk/gui/wxpython/mapdisp/test_mapdisp.py
   grass/trunk/gui/wxpython/vnet/dialogs.py
   grass/trunk/gui/wxpython/vnet/vnet_core.py
Log:
wxGUI/vnet: using giface instead of tree (fixes broken vnet, one usage of tree remains)

Modified: grass/trunk/gui/wxpython/core/giface.py
===================================================================
--- grass/trunk/gui/wxpython/core/giface.py	2013-08-07 21:08:10 UTC (rev 57431)
+++ grass/trunk/gui/wxpython/core/giface.py	2013-08-07 22:33:26 UTC (rev 57432)
@@ -49,7 +49,29 @@
         """
         raise NotImplementedError()
 
+    def GetSelectedLayer(self, checkedOnly=False):
+        """!Returns selected layer or None when there is no selected layer.
 
+        @note Parameter checkedOnly is here False by default. This might change
+        if we find the right way of handling unchecked layers.
+        """
+        raise NotImplementedError()
+
+    def AddLayer(self, ltype, name=None, checked=None,
+                 opacity=1.0, cmd=None):
+        """!Adds a new layer to the layer list.
+
+        Launches property dialog if needed (raster, vector, etc.)
+
+        @param ltype layer type (raster, vector, 3d-raster, ...)
+        @param name layer name
+        @param checked if True layer is checked
+        @param opacity layer opacity level
+        @param cmd command (given as a list)
+        """
+        raise NotImplementedError()
+
+
 class GrassInterface:
     """!GrassInterface provides the functionality which should be available
     to every GUI component.
@@ -208,7 +230,7 @@
         os.environ["GRASS_MESSAGE_FORMAT"] = orig
 
     def GetLayerList(self):
-        return None
+        raise NotImplementedError()
 
     def GetMapDisplay(self):
         """!Get current map display.
@@ -221,7 +243,9 @@
         return []
 
     def GetMapWindow(self):
-        return None
+        raise NotImplementedError()
 
     def GetProgress(self):
+        # TODO: implement some progress with same inface as gui one
+        # (probably using g.message or similarly to Write... functions)
         raise NotImplementedError()

Modified: grass/trunk/gui/wxpython/lmgr/giface.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/giface.py	2013-08-07 21:08:10 UTC (rev 57431)
+++ grass/trunk/gui/wxpython/lmgr/giface.py	2013-08-07 22:33:26 UTC (rev 57432)
@@ -64,11 +64,37 @@
             layers.append(layer)
         return layers
 
+    # TODO: it is not clear if default of checkedOnly should be False or True
+    def GetSelectedLayer(self, checkedOnly=False):
+        """!Returns selected layer or None when there is no selected layer."""
+        item = self._tree.GetSelectedLayer(multi=False,
+                                           checkedOnly=checkedOnly)
+        if item is None:
+            return None
+        else:
+            data = self._tree.GetPyData(item)
+            return Layer(data)
+
     def GetLayerInfo(self, layer):
         """!For compatibility only, will be removed."""
         return Layer(self._tree.GetPyData(layer))
 
+    def AddLayer(self, ltype, name=None, checked=None,
+                 opacity=1.0, cmd=None):
+        """!Adds a new layer to the layer list.
 
+        Launches property dialog if needed (raster, vector, etc.)
+
+        @param ltype layer type (raster, vector, 3d-raster, ...)
+        @param name layer name
+        @param checked if True layer is checked
+        @param opacity layer opacity level
+        @param cmd command (given as a list)
+        """
+        self._tree.AddLayer(ltype=ltype, lname=name, lchecked=checked,
+                            lopacity=opacity, lcmd=cmd)
+
+
 class LayerManagerGrassInterface(object):
     """!@implements GrassInterface"""
     def __init__(self, lmgr):

Modified: grass/trunk/gui/wxpython/mapdisp/main.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/main.py	2013-08-07 21:08:10 UTC (rev 57431)
+++ grass/trunk/gui/wxpython/mapdisp/main.py	2013-08-07 22:33:26 UTC (rev 57432)
@@ -248,8 +248,9 @@
 
 
 class LayerList(object):
-    def __init__(self, map):
+    def __init__(self, map, giface):
         self._map = map
+        self._giface = giface
 
 #    def __iter__(self):
 #        for in :
@@ -264,7 +265,36 @@
             layers.append(layer)
         return layers
 
+    def GetSelectedLayer(self, checkedOnly=False):
+        """!Returns selected layer or None when there is no selected layer."""
+        layers = self.GetSelectedLayers()
+        if len(layers) > 0:
+            return layers[0]
+        else:
+            return None
 
+    def AddLayer(self, ltype, name=None, checked=None,
+                 opacity=1.0, cmd=None):
+        """!Adds a new layer to the layer list.
+
+        Launches property dialog if needed (raster, vector, etc.)
+
+        @param ltype layer type (raster, vector, 3d-raster, ...)
+        @param name layer name
+        @param checked if True layer is checked
+        @param opacity layer opacity level
+        @param cmd command (given as a list)
+        """
+        self._map.AddLayer(ltype="vector", command=cmd,
+                           name=name, active=True,
+                           opacity=opacity, render=True,
+                           pos=-1)
+        # TODO: this should be solved by signal
+        # (which should be introduced everywhere,
+        # alternative is some observer list)
+        self._giface.updateMap.emit(render=True, renderVector=True)
+
+
 class DMonGrassInterface(StandaloneGrassInterface):
     """!@implements GrassInterface"""
     def __init__(self, mapframe):
@@ -272,9 +302,12 @@
         self._mapframe = mapframe
 
     def GetLayerList(self):
-        return LayerList(self._mapframe.GetMap())
+        return LayerList(self._mapframe.GetMap(), giface=self)
 
+    def GetMapWindow(self):
+        return self._mapframe.GetMapWindow()
 
+
 class DMonFrame(MapFrame):
     def OnZoomToMap(self, event):
         layers = self.MapWindow.GetMap().GetListOfLayers()

Modified: grass/trunk/gui/wxpython/mapdisp/test_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/test_mapdisp.py	2013-08-07 21:08:10 UTC (rev 57431)
+++ grass/trunk/gui/wxpython/mapdisp/test_mapdisp.py	2013-08-07 22:33:26 UTC (rev 57432)
@@ -61,7 +61,6 @@
     if WXGUIBASE not in sys.path:
         sys.path.append(WXGUIBASE)
 
-import core.utils as utils
 from core.utils import _
 from core.settings import UserSettings
 from core.globalvar import CheckWxVersion
@@ -70,43 +69,9 @@
 from mapwin.buffered import BufferedMapWindow
 from core.render import Map
 from rlisetup.sampling_frame import RLiSetupMapPanel
+from mapdisp.main import LayerList
 
 
-# TODO: same classes as in dmon
-class Layer(object):
-    def __init__(self, maplayer):
-        self._maplayer = maplayer
-
-    def __getattr__(self, name):
-        if name == 'cmd':
-            return utils.CmdTupleToList(self._maplayer.GetCmd())
-        elif hasattr(self._maplayer, name):
-            return getattr(self._maplayer, name)
-        elif name == 'maplayer':
-            return self._maplayer
-        elif name == 'type':
-            return self._maplayer.GetType()
-            #elif name == 'ctrl':
-        elif name == 'label':
-            return self._maplayer.GetName()
-            #elif name == 'maplayer' : None,
-            #elif name == 'propwin':
-
-
-class LayerList(object):
-    def __init__(self, map_):
-        self._map = map_
-
-    def GetSelectedLayers(self, checkedOnly=True):
-        # hidden and selected vs checked and selected
-        items = self._map.GetListOfLayers()
-        layers = []
-        for item in items:
-            layer = Layer(item)
-            layers.append(layer)
-        return layers
-
-
 class MapdispGrassInterface(StandaloneGrassInterface):
     """!@implements GrassInterface"""
     def __init__(self, map_):
@@ -115,7 +80,7 @@
         self.mapWindow = None
 
     def GetLayerList(self):
-        return LayerList(self._map)
+        return LayerList(self._map, giface=self)
 
     def GetMapWindow(self):
         return self.mapWindow

Modified: grass/trunk/gui/wxpython/vnet/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/vnet/dialogs.py	2013-08-07 21:08:10 UTC (rev 57431)
+++ grass/trunk/gui/wxpython/vnet/dialogs.py	2013-08-07 22:33:26 UTC (rev 57432)
@@ -444,13 +444,12 @@
     def _createInputDbMgrPage(self):
         """!Tab with attribute tables of analysis input layers"""
         self.inpDbMgrData['dbMgr'] = DbMgrBase()
- 
-        selMapName = None       
+
+        selMapName = None
         # if selected vector map is in layer tree then set it
-        if self.mapWin.tree and self.mapWin.tree.layer_selected:
-            selMapData = self.mapWin.tree.GetPyData(self.mapWin.tree.layer_selected)[0]
-            if selMapData['type'] == 'vector': # wrap somehow in LayerTree
-                selMapName = selMapData['maplayer'].name
+        layer = self.giface.GetLayerList().GetSelectedLayer()
+        if layer is not None and layer.type == 'vector':
+            selMapName = layer.maplayer.name
 
         self.inpDbMgrData['browse'] = self.inpDbMgrData['dbMgr'].CreateDbMgrPage(parent = self.notebook,
                                                                                  pageName = 'browse')
@@ -591,21 +590,13 @@
         cmd = ['d.vect', 
                'map=' + vectorMap]
 
-        if self.mapWin.tree and \
-           self.mapWin.tree.FindItemByData(key = 'name', value = vectorMap) is None: 
-            self.mapWin.tree.AddLayer(ltype = "vector", 
-                                      lcmd = cmd,
-                                      lname =vectorMap,
-                                      lchecked = True)
-        #d.mon case
-        else:
-            self.renderLayer = self.mapWin.Map.AddLayer(ltype = "vector", command = cmd,
-                                                        name = vectorMap, active = True,
-                                                        opacity = 1.0,    render = True,       
-                                                        pos = -1)         
+        if True:
+            self.giface.GetLayerList().AddLayer(ltype="vector",
+                                                cmd=cmd,
+                                                name=vectorMap,
+                                                checked=True)
+        # d.mon case is not need giface implementation should solve it for us
 
-            self.giface.updateMap.emit(render=True, renderVector=True)
-
     def UseTurns(self):
         if self.useTurns.IsChecked():
             self.inputData["tlayer"].GetParent().Show()

Modified: grass/trunk/gui/wxpython/vnet/vnet_core.py
===================================================================
--- grass/trunk/gui/wxpython/vnet/vnet_core.py	2013-08-07 21:08:10 UTC (rev 57431)
+++ grass/trunk/gui/wxpython/vnet/vnet_core.py	2013-08-07 22:33:26 UTC (rev 57432)
@@ -349,20 +349,29 @@
                     overwrite = True,
                     vect = [self.results["vect_map"].GetVectMapName(), mapName])
 
+        # TODO: this is a workaround: usage of parent
+        # use giface/LayerList instead (needs to be extended first, please do,
+        # don't forget on abstract giface in core/giface.py and dmon's giface)
+        tree = None
+        try:
+            # map display (MapFrame) should still have tree
+            tree = self.mapWin.parent.tree
+        except:
+            pass
 
-        if not self.mapWin.tree:
+        if tree is None:
             return
 
-        if  self.mapWin.tree.FindItemByData(key = 'name', value = mapName) is None: 
-
-            cmd, cmd_colors = self.vnet_data.GetLayerStyle()#TODO get rid of insert
+        if tree.FindItemByData(key='name', value=mapName) is None:
+            # TODO: get rid of insert
+            cmd, cmd_colors = self.vnet_data.GetLayerStyle()
             cmd.insert(0, 'd.vect')
             cmd.append('map=%s' % mapName)
 
-            self.mapWin.tree.AddLayer(ltype = "vector", 
-                                      lname = mapName,
-                                      lcmd = cmd,
-                                      lchecked = True)
+            tree.AddLayer(ltype = "vector",
+                          lname = mapName,
+                          lcmd = cmd,
+                          lchecked = True)
             if cmd_colors:
                 layerStyleVnetColors = utils.CmdToTuple(cmd_colors)
 



More information about the grass-commit mailing list