[GRASS-SVN] r33317 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Sep 7 13:26:52 EDT 2008


Author: martinl
Date: 2008-09-07 13:26:52 -0400 (Sun, 07 Sep 2008)
New Revision: 33317

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
Log:
wxGUI: text layer bug fixes (trac #301 and #302)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2008-09-07 15:23:36 UTC (rev 33316)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py	2008-09-07 17:26:52 UTC (rev 33317)
@@ -451,13 +451,18 @@
         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 @@
 
     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"""

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-09-07 15:23:36 UTC (rev 33316)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-09-07 17:26:52 UTC (rev 33317)
@@ -416,42 +416,41 @@
                 # 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 @@
         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,51 +3809,44 @@
         """
         Handler for text decoration menu selection.
         """
+        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
 
-        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]
-
         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
+            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.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)
+            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)
 
-        self.MapWindow.UpdateMap(render=False, renderVector=False)
-
     def GetOptData(self, dcmd, type, params, propwin):
         """
         Callback method for decoration overlay command generated by



More information about the grass-commit mailing list