瀏覽代碼

wxGUI: fix overlays in d.mon

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@68998 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 8 年之前
父節點
當前提交
90f4d85d6e
共有 3 個文件被更改,包括 46 次插入23 次删除
  1. 2 2
      gui/wxpython/lmgr/frame.py
  2. 1 1
      gui/wxpython/mapdisp/frame.py
  3. 43 20
      gui/wxpython/mapdisp/main.py

+ 2 - 2
gui/wxpython/lmgr/frame.py

@@ -754,9 +754,9 @@ class GMFrame(wx.Frame):
                 self.GetMapDisplay().AddBarscale()
         elif layertype == 'rastleg':
             if len(command) > 1:
-                self.GetMapDisplay().AddLegend(cmd=command, showDialog=False)
+                self.GetMapDisplay().AddLegend(cmd=command)
             else:
-                self.GetMapDisplay().AddLegend(showDialog=True)
+                self.GetMapDisplay().AddLegend()
         elif layertype == 'northarrow':
             if len(command) > 1:
                 self.GetMapDisplay().AddArrow(cmd=command)

+ 1 - 1
gui/wxpython/mapdisp/frame.py

@@ -1228,7 +1228,7 @@ class MapFrame(SingleMapFrame):
 
         self.MapWindow.mouse['use'] = 'pointer'
 
-    def AddLegend(self, cmd=None, showDialog=None):
+    def AddLegend(self, cmd=None):
         """Handler for legend map decoration menu selection."""
 
         if cmd:

+ 43 - 20
gui/wxpython/mapdisp/main.py

@@ -83,6 +83,7 @@ class DMonMap(Map):
         # TODO temporary solution, layer managment by different tools in GRASS
         # should be resovled
         self.ownedLayers = []
+        self.oldOverlays = []
 
         if mapfile:
             self.mapfileCmd = mapfile
@@ -175,28 +176,34 @@ class DMonMap(Map):
                                                  layerType=ltype)[0]
 
                 args = {}
-                if ltype in ('barscale', 'rastleg', 'northarrow'):
-                    classLayer = Overlay
+
+                if ltype in ('barscale', 'rastleg', 'northarrow', 'text'):
+                    # TODO: this is still not optimal
+                    # it is there to prevent adding the same overlay multiple times
+                    if cmd in self.oldOverlays:
+                        continue
                     if ltype == 'rastleg':
-                        args['id'] = 0
+                        self._giface.GetMapDisplay().AddLegend(cmd=cmd)
                     elif ltype == 'barscale':
-                        args['id'] = 1
-                    else:
-                        args['id'] = 2
-                else:
-                    classLayer = MapLayer
-                    args['ltype'] = ltype
-
-                mapLayer = classLayer(
-                    name=name,
-                    cmd=cmd,
-                    Map=None,
-                    hidden=True,
-                    render=False,
-                    mapfile=mapFile,
-                    **args)
-                mapLayer.GetRenderMgr().updateProgress.connect(
-                    self.GetRenderMgr().ReportProgress)
+                        self._giface.GetMapDisplay().AddBarscale(cmd=cmd)
+                    elif ltype == 'northarrow':
+                        self._giface.GetMapDisplay().AddArrow(cmd=cmd)
+                    elif ltype == 'text':
+                        self._giface.GetMapDisplay().AddDtext(cmd=cmd)
+                    self.oldOverlays.append(cmd)
+                    continue
+
+                classLayer = MapLayer
+                args['ltype'] = ltype
+
+                mapLayer = classLayer(name=name,
+                                      cmd=cmd,
+                                      Map=None,
+                                      hidden=True,
+                                      render=False,
+                                      mapfile=mapFile,
+                                      **args)
+                mapLayer.GetRenderMgr().updateProgress.connect(self.GetRenderMgr().ReportProgress)
                 if render_env:
                     mapLayer.GetRenderMgr().UpdateRenderEnv(render_env)
                     render_env = dict()
@@ -316,6 +323,22 @@ class LayerList(object):
     def __init__(self, map, giface):
         self._map = map
         self._giface = giface
+        self._index = 0
+
+    def __len__(self):
+        return len(self._map.GetListOfLayers())
+
+    def __iter__(self):
+        return self
+
+    def next(self):
+        items = self._map.GetListOfLayers()
+        try:
+            result = items[self._index]
+        except IndexError:
+            raise StopIteration
+        self._index += 1
+        return result
 
     def GetSelectedLayers(self, checkedOnly=True):
         # hidden and selected vs checked and selected