Browse Source

wxGUI/g.gui.psmap: add checking map frame exists if you add labels (#1048)

* wxGUI/g.gui.psmap: add checking map frame exists if you add labels

* wxGUI/g.gui.psmap: fix loading Vector labels dialog list
Tomas Zigo 4 years ago
parent
commit
03029a7493
3 changed files with 34 additions and 21 deletions
  1. 2 2
      gui/wxpython/psmap/dialogs.py
  2. 26 16
      gui/wxpython/psmap/frame.py
  3. 6 3
      gui/wxpython/psmap/instructions.py

+ 2 - 2
gui/wxpython/psmap/dialogs.py

@@ -6451,7 +6451,7 @@ class PointDialog(PsmapDialog):
             style=fs.FS_RIGHT)
         self.rotCtrl.SetFormat("%f")
         self.rotCtrl.SetDigits(1)
-        
+
         self.rotCtrl.SetToolTip(
             _("Counterclockwise rotation in degrees"))
         self.rotCtrl.SetValue(float(self.pointDict['rotate']))
@@ -6880,7 +6880,7 @@ class LabelsDialog(PsmapDialog):
         self.select = Select(
             parent=panel,
             multiple=True,
-            type='labels',
+            type='label',
             fullyQualified=False)
         self.select.SetValue(','.join(self.labelsDict['labels']))
         self.select.SetFocus()

+ 26 - 16
gui/wxpython/psmap/frame.py

@@ -240,6 +240,24 @@ class PsMapFrame(wx.Frame):
         self.SetSizer(mainSizer)
         mainSizer.Fit(self)
 
+    def _checkMapFrameExists(self, type_id):
+        """Check if map frame exists
+
+        :param int type_id: type id (raster, vector,...)
+
+        :return bool: False if map frame doesn't exists
+        """
+        if self.instruction.FindInstructionByType('map'):
+            mapId = self.instruction.FindInstructionByType('map').id
+        else:
+            mapId = None
+
+        if not type_id:
+            if not mapId:
+                GMessage(message=_("Please, create map frame first."))
+                return False
+        return True
+
     def InstructionFile(self):
         """Creates mapping instructions"""
 
@@ -653,15 +671,9 @@ class PsMapFrame(wx.Frame):
             id = self.instruction.FindInstructionByType('raster').id
         else:
             id = None
-        if self.instruction.FindInstructionByType('map'):
-            mapId = self.instruction.FindInstructionByType('map').id
-        else:
-            mapId = None
 
-        if not id:
-            if not mapId:
-                GMessage(message=_("Please, create map frame first."))
-                return
+        if not self._checkMapFrameExists(type_id=id):
+            return
 
 ##        dlg = RasterDialog(self, id = id, settings = self.instruction)
 # dlg.ShowModal()
@@ -679,14 +691,9 @@ class PsMapFrame(wx.Frame):
             id = self.instruction.FindInstructionByType('vector').id
         else:
             id = None
-        if self.instruction.FindInstructionByType('map'):
-            mapId = self.instruction.FindInstructionByType('map').id
-        else:
-            mapId = None
-        if not id:
-            if not mapId:
-                GMessage(message=_("Please, create map frame first."))
-                return
+
+        if not self._checkMapFrameExists(type_id=id):
+            return
 
 ##        dlg = MainVectorDialog(self, id = id, settings = self.instruction)
 # dlg.ShowModal()
@@ -865,6 +872,9 @@ class PsMapFrame(wx.Frame):
         else:
             id = None
 
+        if not self._checkMapFrameExists(type_id=id):
+            return
+
         if 'labels' not in self.openDialogs:
             dlg = LabelsDialog(self, id=id, settings=self.instruction)
             self.openDialogs['labels'] = dlg

+ 6 - 3
gui/wxpython/psmap/instructions.py

@@ -97,12 +97,13 @@ class Instruction:
         for each in self.instruction:
             if each.id == id:
                 if each.type == 'map':
-                    # must remove raster, vector layers too
+                    # must remove raster, vector layers, labels too
                     vektor = self.FindInstructionByType('vector', list=True)
                     vProperties = self.FindInstructionByType(
                         'vProperties', list=True)
                     raster = self.FindInstructionByType('raster', list=True)
-                    for item in vektor + vProperties + raster:
+                    labels = self.FindInstructionByType('labels', list=True)
+                    for item in vektor + vProperties + raster + labels:
                         if item in self.instruction:
                             self.instruction.remove(item)
 
@@ -120,7 +121,9 @@ class Instruction:
             self.instruction.append(instruction)
         # add to drawable objects
         if instruction.type not in (
-                'page', 'raster', 'vector', 'vProperties', 'initMap'):
+                'page', 'raster', 'vector', 'vProperties', 'initMap',
+                'labels',
+        ):
             if instruction.type == 'map':
                 self.objectsToDraw.insert(0, instruction.id)
             else: