[GRASS-SVN] r54881 - in grass/trunk/gui/wxpython: core lmgr mapdisp nviz

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 3 12:05:54 PST 2013


Author: wenzeslaus
Date: 2013-02-03 12:05:54 -0800 (Sun, 03 Feb 2013)
New Revision: 54881

Modified:
   grass/trunk/gui/wxpython/core/giface.py
   grass/trunk/gui/wxpython/lmgr/giface.py
   grass/trunk/gui/wxpython/mapdisp/frame.py
   grass/trunk/gui/wxpython/mapdisp/main.py
   grass/trunk/gui/wxpython/mapdisp/mapwindow.py
   grass/trunk/gui/wxpython/nviz/mapwindow.py
Log:
wxGUI/mapdisp: querying uses giface to ask for layers (layer representation not finished), querying in d.mon works

Modified: grass/trunk/gui/wxpython/core/giface.py
===================================================================
--- grass/trunk/gui/wxpython/core/giface.py	2013-02-03 19:54:55 UTC (rev 54880)
+++ grass/trunk/gui/wxpython/core/giface.py	2013-02-03 20:05:54 UTC (rev 54881)
@@ -88,9 +88,9 @@
         function(text)
         os.environ["GRASS_MESSAGE_FORMAT"] = orig
 
-    def GetLayerTree(self):
+    def GetLayerList(self):
         return None
-
+        
     def GetMapDisplay(self):
         """!Get current map display.
         """

Modified: grass/trunk/gui/wxpython/lmgr/giface.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/giface.py	2013-02-03 19:54:55 UTC (rev 54880)
+++ grass/trunk/gui/wxpython/lmgr/giface.py	2013-02-03 20:05:54 UTC (rev 54881)
@@ -15,6 +15,35 @@
 @author Vaclav Petras <wenzeslaus gmail.com>
 """
 
+
+class Layer(object):
+    def __init__(self, pydata):
+        self._pydata = pydata
+
+    def __getattr__(self, name):
+        return self._pydata[0][name]
+
+
+class LayerList(object):
+    def __init__(self, tree):
+        self._tree = tree
+
+#    def __iter__(self):
+#        for in :
+#            yield 
+
+    def GetSelectedLayers(self, checkedOnly = True):
+        items = self._tree.GetSelectedLayer(multi = True, checkedOnly = True)
+        layers = []
+        for item in items:
+            layer = Layer(self._tree.GetPyData(item))
+            layers.append(layer)
+        return layers
+
+    def GetLayerInfo(self, layer):
+        return Layer(self._tree.GetPyData(layer))
+
+
 class LayerManagerGrassInterface:
     def __init__(self, lmgr):
         self.lmgr = lmgr
@@ -41,8 +70,11 @@
         self.lmgr._gconsole.WriteError(line = line)
 
     def GetLayerTree(self):
-        return self.lmgr.GetLayerTree()
+        return LayerList(self.lmgr.GetLayerTree())
 
+    def GetLayerList(self):
+        return LayerList(self.lmgr.GetLayerTree())
+
     def GetMapDisplay(self):
         """!Get current map display.
 

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2013-02-03 19:54:55 UTC (rev 54880)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2013-02-03 20:05:54 UTC (rev 54881)
@@ -638,7 +638,7 @@
             if pgnum > -1:
                 self.layerbook.DeletePage(pgnum)
 
-    def Query(self, x, y, layers):
+    def Query(self, x, y):
         """!Query selected layers. 
 
         Calls QueryMap in case of raster or more vectors,
@@ -647,9 +647,10 @@
         @param x,y coordinates
         @param layers selected tree item layers
         """
+        layers = self._giface.GetLayerList().GetSelectedLayers(checkedOnly = True)
         filteredLayers = []
         for layer in layers:
-            ltype = self.tree.GetLayerInfo(layer, key = 'maplayer').GetType()
+            ltype = layer.maplayer.GetType()
             if ltype in ('raster', 'rgb', 'his',
                          'vector', 'thememap', 'themechart'):
                 filteredLayers.append(layer)
@@ -662,8 +663,13 @@
         layers = filteredLayers
         # set query snap distance for v.what at map unit equivalent of 10 pixels
         qdist = 10.0 * ((self.Map.region['e'] - self.Map.region['w']) / self.Map.width)
-        east, north = self.MapWindow.Pixel2Cell((x, y))
 
+        # TODO: replace returning None by exception or so
+        try:
+            east, north = self.MapWindow.Pixel2Cell((x, y))
+        except TypeError:
+            return
+
         posWindow = self.ClientToScreen((x + self.MapWindow.dialogOffset,
                                          y + self.MapWindow.dialogOffset))
 
@@ -671,7 +677,7 @@
         nVectors = 0
         isDbConnection = False
         for l in layers:
-            maplayer = self.tree.GetLayerInfo(l, key = 'maplayer')
+            maplayer = l.maplayer
             if maplayer.GetType() == 'raster':
                 isRaster = True
                 break
@@ -705,8 +711,8 @@
         vcmd = ['v.what', '--v']
         
         for layer in layers:
-            ltype = self.tree.GetLayerInfo(layer, key = 'maplayer').GetType()
-            dcmd = self.tree.GetLayerInfo(layer, key = 'cmd')
+            ltype = layer.maplayer.GetType()
+            dcmd = layer.cmd
             name, found = GetLayerNameFromCmd(dcmd)
             
             if not found:
@@ -784,9 +790,9 @@
         Attribute data of selected vector object are displayed in GUI dialog.
         Data can be modified (On Submit)
         """
-        mapName = self.tree.GetLayerInfo(layer, key = 'maplayer').name
+        mapName = layer.maplayer.name
         
-        if self.tree.GetLayerInfo(layer, key = 'maplayer').GetMapset() != \
+        if layer.maplayer.GetMapset() != \
                 grass.gisenv()['MAPSET']:
             mode = 'display'
         else:
@@ -832,7 +838,7 @@
                     qlayer = self.AddTmpVectorMapLayer(mapName, cats, useId = False)
                 
                 # set opacity based on queried layer
-                opacity = self.tree.GetLayerInfo(layer, key = 'maplayer').GetOpacity(float = True)
+                opacity = layer.maplayer.GetOpacity(float = True)
                 qlayer.SetOpacity(opacity)
                 
                 self.MapWindow.UpdateMap(render = False, renderVector = False)

Modified: grass/trunk/gui/wxpython/mapdisp/main.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/main.py	2013-02-03 19:54:55 UTC (rev 54880)
+++ grass/trunk/gui/wxpython/mapdisp/main.py	2013-02-03 20:05:54 UTC (rev 54881)
@@ -226,6 +226,54 @@
         """
         return self._renderCmdFile(force, windres)
 
+
+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 __iter__(self):
+#        for in :
+#            yield
+
+    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 DMonGrassInterface(StandaloneGrassInterface):
+    def __init__(self, mapframe):
+        StandaloneGrassInterface.__init__(self)
+        self._mapframe = mapframe
+
+    def GetLayerList(self):
+        return LayerList(self._mapframe.GetMap())
+
+
 class DMonFrame(MapFrame):
     def OnZoomToMap(self, event):
         layers = self.MapWindow.GetMap().GetListOfLayers()
@@ -244,9 +292,11 @@
 
         # actual use of StandaloneGrassInterface not yet tested
         # needed for adding functionality in future
+        giface = DMonGrassInterface(None)
         self.mapFrm = DMonFrame(parent = None, id = wx.ID_ANY, Map = self.Map,
-                                giface = StandaloneGrassInterface(),
-                                size = monSize)
+                                giface = giface, size = monSize)
+        # FIXME: hack to solve dependency
+        giface._mapframe = self.mapFrm
         # self.SetTopWindow(Map)
         self.mapFrm.GetMapWindow().SetAlwaysRenderEnabled(True)
         self.mapFrm.Show()

Modified: grass/trunk/gui/wxpython/mapdisp/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-02-03 19:54:55 UTC (rev 54880)
+++ grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-02-03 20:05:54 UTC (rev 54881)
@@ -1175,15 +1175,7 @@
             self.frame.StatusbarUpdate()
             
         elif self.mouse["use"] == "query":
-            # querying
-            if self.frame.IsStandalone():
-                GMessage(parent = self.frame,
-                         message = _("Querying is not implemented in standalone mode of Map Display"))
-                return
-
-            layers = self.tree.GetSelectedLayer(multi = True, checkedOnly = True)
-
-            self.frame.Query(self.mouse['begin'][0],self.mouse['begin'][1], layers)
+            self.frame.Query(self.mouse['begin'][0],self.mouse['begin'][1])
         
         elif self.mouse["use"] in ["measure", "profile"]:
             # measure or profile

Modified: grass/trunk/gui/wxpython/nviz/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/nviz/mapwindow.py	2013-02-03 19:54:55 UTC (rev 54880)
+++ grass/trunk/gui/wxpython/nviz/mapwindow.py	2013-02-03 20:05:54 UTC (rev 54881)
@@ -769,10 +769,8 @@
                          message = _("Querying is not implemented in standalone mode of Map Display"))
                 return
 
-            layers = self.tree.GetSelectedLayer(multi = True, checkedOnly = True)
+            self.frame.Query(self.mouse['begin'][0],self.mouse['begin'][1])
 
-            self.frame.Query(self.mouse['begin'][0],self.mouse['begin'][1], layers)
-
         elif self.mouse["use"] in ('arrow', 'scalebar'):
             self.lmgr.nviz.FindWindowById(
                     self.lmgr.nviz.win['decoration'][self.mouse["use"]]['place']).SetValue(False)



More information about the grass-commit mailing list