Quellcode durchsuchen

wxGUI: text layer bug fixes (trac https://trac.osgeo.org/grass/ticket/301 and https://trac.osgeo.org/grass/ticket/302)
(merge from devbr6, https://trac.osgeo.org/grass/changeset/33317)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33318 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa vor 16 Jahren
Ursprung
Commit
4932e3f618
2 geänderte Dateien mit 60 neuen und 57 gelöschten Zeilen
  1. 12 4
      gui/wxpython/gui_modules/gdialogs.py
  2. 48 53
      gui/wxpython/gui_modules/mapdisp.py

+ 12 - 4
gui/wxpython/gui_modules/gdialogs.py

@@ -451,13 +451,18 @@ class TextLayerDialog(wx.Dialog):
         self.ovlId = ovlId
         self.parent = parent
 
-        if self.ovlId in self.parent.MapWindow.textdict:
-            self.currText, self.currFont, self.currClr, self.currRot = self.parent.MapWindow.textdict[drawid]
+        if self.ovlId in self.parent.MapWindow.textdict.keys():
+            self.currText = self.parent.MapWindow.textdict[self.ovlId]['text']
+            self.currFont = self.parent.MapWindow.textdict[self.ovlId]['font']
+            self.currClr  = self.parent.MapWindow.textdict[self.ovlId]['color']
+            self.currRot  = self.parent.MapWindow.textdict[self.ovlId]['rotation']
+            self.currCoords = self.parent.MapWindow.textdict[self.ovlId]['coords']
         else:
             self.currClr = wx.BLACK
             self.currText = ''
             self.currFont = self.GetFont()
             self.currRot = 0.0
+            self.currCoords = [10, 10, 10, 10]
 
         sizer = wx.BoxSizer(wx.VERTICAL)
         box = wx.GridBagSizer(vgap=5, hgap=5)
@@ -566,8 +571,11 @@ class TextLayerDialog(wx.Dialog):
 
     def GetValues(self):
         """Get text properties"""
-        return (self.currText, self.currFont,
-                self.currClr, self.currRot)
+        return { 'text' : self.currText,
+                 'font' : self.currFont,
+                 'color' : self.currClr,
+                 'rotation' : self.currRot,
+                 'coords' : self.currCoords }
 
 class LoadMapLayersDialog(wx.Dialog):
     """Load selected map layers (raster, vector) into layer tree"""

+ 48 - 53
gui/wxpython/gui_modules/mapdisp.py

@@ -416,42 +416,41 @@ class BufferedWindow(MapWindow, wx.Window):
                 # self.ovlcoords[drawid] = coords
 
         elif pdctype == 'text': # draw text on top of map
-            text = img[0]
-            rotation = float(img[3])
-            w, h = self.GetFullTextExtent(img[0])[0:2]
-            pdc.SetFont(img[1])
-            pdc.SetTextForeground(img[2])
-            coords, w, h = self.TextBounds(img, coords)
+            rotation = float(img['rotation'])
+            w, h = self.GetFullTextExtent(img['text'])[0:2]
+            pdc.SetFont(img['font'])
+            pdc.SetTextForeground(img['color'])
+            coords, w, h = self.TextBounds(img)
             if rotation == 0:
-                pdc.DrawText(img[0], coords[0], coords[1])
+                pdc.DrawText(img['text'], coords[0], coords[1])
             else:
-                pdc.DrawRotatedText(img[0], coords[0], coords[1], rotation)
+                pdc.DrawRotatedText(img['text'], coords[0], coords[1], rotation)
             pdc.SetIdBounds(drawid, (coords[0], coords[1], w, h))
-            # self.ovlcoords[drawid] = coords
-
+            
         pdc.EndDrawing()
         self.Refresh()
 
         return drawid
 
-    def TextBounds(self, textinfo, coords):
+    def TextBounds(self, textinfo):
         """
         Return text boundary data
 
         @param textinfo text metadata (text, font, color, rotation)
         @param coords reference point
         """
-        rotation = float(textinfo[3])
-
+        rotation = float(textinfo['rotation'])
+        coords = textinfo['coords']
+        
         Debug.msg (4, "BufferedWindow.TextBounds(): text=%s, rotation=%f" % \
-                   (textinfo[0], rotation))
+                   (textinfo['text'], rotation))
 
         self.Update()
         self.Refresh()
 
-        self.SetFont(textinfo[1])
+        self.SetFont(textinfo['font'])
 
-        w, h = self.GetTextExtent(textinfo[0])
+        w, h = self.GetTextExtent(textinfo['text'])
 
         if rotation == 0:
             coords[2], coords[3] = coords[0] + w, coords[1] + h
@@ -864,7 +863,10 @@ class BufferedWindow(MapWindow, wx.Window):
         self.Update()
         self.RefreshRect(r, False)
         self.lastpos = (event.GetX(), event.GetY())
-
+        
+        if id > 100: # text
+            self.textdict[id]['coords'] = r2
+        
     def MouseDraw(self, pdc=None, begin=None, end=None):
         """
         Mouse box or line from 'begin' to 'end'
@@ -3807,50 +3809,43 @@ class MapFrame(wx.Frame):
         """
         Handler for text decoration menu selection.
         """
-
-        id = 2 # index for overlay layer in render
-
-        # default values
-        text = ''
-        font = self.GetFont()
-        color = wx.BLACK
-        coords = [10, 10, 10, 10]
-        rotation = 0.0
-
-        # if self.MapWindow.currtxtid == None: # text doesn't already exist
-        #    id = wx.NewId() + 100
-        # else: # text already exists
-        #    id = self.MapWindow.currtxtid
-            # textcoords = self.ovlcoords[id]
+        if self.MapWindow.dragid > -1:
+            id = self.MapWindow.dragid
+        else:
+            # index for overlay layer in render
+            if len(self.MapWindow.textdict.keys()) > 0:
+                id = self.MapWindow.textdict.keys()[-1] + 1
+            else:
+                id = 101
 
         dlg = gdialogs.TextLayerDialog(parent=self, ovlId=id, title=_('Add text layer'),
                                        size=(400, 200))
 
-        dlg.CenterOnScreen()
+        dlg.CenterOnParent()
 
         # If OK button pressed in decoration control dialog
         if dlg.ShowModal() == wx.ID_OK:
-            text = dlg.GetValues()[0]
-            coords, w, h = self.MapWindow.TextBounds(dlg.GetValues(),
-                                                     coords)
-        # delete object if it has no text
-        if text == '':
-            try:
-                self.MapWindow.pdc.ClearId(id)
-                self.MapWindow.pdc.RemoveId(id)
-                del self.MapWindow.textdict[id]
-                # del self.ovlcoords[id]
-            except:
-                pass
-            return
-
-        self.MapWindow.pdc.ClearId(id)
-        self.MapWindow.pdc.SetId(id)
-        self.MapWindow.textdict[id] = (text, font, color, rotation)
-        self.MapWindow.Draw(self.MapWindow.pdc, img=self.MapWindow.textdict[id],
-                            drawid=id, pdctype='text', coords=coords)
+            text = dlg.GetValues()['text']
+            coords, w, h = self.MapWindow.TextBounds(dlg.GetValues())
+        
+            # delete object if it has no text
+            if text == '':
+                try:
+                    self.MapWindow.pdc.ClearId(id)
+                    self.MapWindow.pdc.RemoveId(id)
+                    del self.MapWindow.textdict[id]
+                except:
+                    pass
+                return
 
-        self.MapWindow.UpdateMap(render=False, renderVector=False)
+            self.MapWindow.pdc.ClearId(id)
+            self.MapWindow.pdc.SetId(id)
+            self.MapWindow.textdict[id] = dlg.GetValues()
+            
+            self.MapWindow.Draw(self.MapWindow.pdcDec, img=self.MapWindow.textdict[id],
+                                drawid=id, pdctype='text', coords=coords)
+            
+            self.MapWindow.UpdateMap(render=False, renderVector=False)
 
     def GetOptData(self, dcmd, type, params, propwin):
         """