瀏覽代碼

wxGUI/mapwin: fix correct horizontal raster legend position after apply new legend setting (#1080)

Tomas Zigo 4 年之前
父節點
當前提交
47579afce3
共有 1 個文件被更改,包括 23 次插入0 次删除
  1. 23 0
      gui/wxpython/mapwin/decorations.py

+ 23 - 0
gui/wxpython/mapwin/decorations.py

@@ -267,8 +267,30 @@ class LegendController(OverlayController):
         self._activateLabel = _("Raster legend properties")
         # default is in the center to avoid trimmed legend on the edge
         self._defaultAt = 'at=5,50,47,50'
+        self._actualAt = self._defaultAt
         self._cmd = ['d.legend', self._defaultAt]
 
+    def SetCmd(self, cmd):
+        """Overriden method
+
+        Required for setting default or actual raster legend position.
+        """
+        hasAt = False
+        for i in cmd:
+            if i.startswith("at="):
+                hasAt = True
+                # reset coordinates, 'at' values will be used, see GetCoords
+                self._coords = None
+                break
+        if not hasAt:
+            if self._actualAt != self._defaultAt:
+                cmd.append(self._actualAt)
+            else:
+                cmd.append(self._defaultAt)
+        self._cmd = cmd
+
+    cmd = property(fset=SetCmd, fget=OverlayController.GetCmd)
+
     def GetPlacement(self, screensize):
         if not hasPIL:
             self._giface.WriteWarning(
@@ -330,6 +352,7 @@ class LegendController(OverlayController):
                 break
 
         self._coords = None
+        self._actualAt = atStr
         self.Show()
 
     def StartResizing(self):