[GRASS-SVN] r49667 - grass/trunk/gui/wxpython/psmap

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Dec 12 02:33:33 EST 2011


Author: annakrat
Date: 2011-12-11 23:33:33 -0800 (Sun, 11 Dec 2011)
New Revision: 49667

Modified:
   grass/trunk/gui/wxpython/psmap/dialogs.py
Log:
wxGUI: wx.psmap - fix reading and writing configuration file with non ascii characters

Modified: grass/trunk/gui/wxpython/psmap/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/dialogs.py	2011-12-12 07:02:52 UTC (rev 49666)
+++ grass/trunk/gui/wxpython/psmap/dialogs.py	2011-12-12 07:33:33 UTC (rev 49667)
@@ -951,11 +951,30 @@
         
     def __str__(self):
         text = self.instruction['text'].replace('\n','\\n')
-        instr = "text %s %s" % (self.instruction['east'], self.instruction['north'])
+        instr = u"text %s %s" % (self.instruction['east'], self.instruction['north'])
+        instr += " %s\n" % text
+        instr += (string.Template("    font $font\n    fontsize $fontsize\n    color $color\n").
+                                                                   substitute(self.instruction))
+        instr += string.Template("    hcolor $hcolor\n").substitute(self.instruction)
+        if self.instruction['hcolor'] != 'none':
+            instr += string.Template("    hwidth $hwidth\n").substitute(self.instruction)
+        instr += string.Template("    border $border\n").substitute(self.instruction)
+        if self.instruction['border'] != 'none':
+            instr += string.Template("    width $width\n").substitute(self.instruction)
+        instr += string.Template("    background $background\n").substitute(self.instruction)
+        if self.instruction["ref"] != '0':
+            instr += string.Template("    ref $ref\n").substitute(self.instruction)
+        if self.instruction["rotate"]:
+            instr += string.Template("    rotate $rotate\n").substitute(self.instruction)
+        if float(self.instruction["xoffset"]) or float(self.instruction["yoffset"]):
+            instr += (string.Template("    xoffset $xoffset\n    yoffset $yoffset\n").
+                                                            substitute(self.instruction))
+        instr += "    end"
         try:
-            instr += " %s\n" % text.encode('latin_1')
+            instr = instr.encode('latin1')
         except UnicodeEncodeError, err:
             try:
+                print err
                 pos = str(err).split('position')[1].split(':')[0].strip()
             except IndexError:
                 pos = ''
@@ -969,24 +988,7 @@
                             "which is required by module ps.map.")
             GMessage(message = message)
             return ''
-        instr += (string.Template("    font $font\n    fontsize $fontsize\n    color $color\n").
-                                                                   substitute(self.instruction).
-                                                                   encode('latin_1'))
-        instr += string.Template("    hcolor $hcolor\n").substitute(self.instruction).encode('latin_1')
-        if self.instruction['hcolor'] != 'none':
-            instr += string.Template("    hwidth $hwidth\n").substitute(self.instruction).encode('latin_1')
-        instr += string.Template("    border $border\n").substitute(self.instruction).encode('latin_1')
-        if self.instruction['border'] != 'none':
-            instr += string.Template("    width $width\n").substitute(self.instruction).encode('latin_1')
-        instr += string.Template("    background $background\n").substitute(self.instruction).encode('latin_1')
-        if self.instruction["ref"] != '0':
-            instr += string.Template("    ref $ref\n").substitute(self.instruction).encode('latin_1')
-        if self.instruction["rotate"]:
-            instr += string.Template("    rotate $rotate\n").substitute(self.instruction).encode('latin_1')
-        if float(self.instruction["xoffset"]) or float(self.instruction["yoffset"]):
-            instr += (string.Template("    xoffset $xoffset\n    yoffset $yoffset\n").
-                                                            substitute(self.instruction).encode('latin_1'))
-        instr += "    end"
+        
         return instr
     
     def Read(self, instruction, text, **kwargs):
@@ -1005,7 +1007,7 @@
                         instr['XY'] = False
                         instr['east'], instr['north'] = float(e), float(n)
                         
-                    instr['text'] = line.split(None, 3)[3]
+                    instr['text'] = line.split(None, 3)[3].decode('latin_1')
                 
                 elif sub == 'font':
                     instr['font'] = line.split(None, 1)[1]
@@ -1681,6 +1683,24 @@
         vInstruction += string.Template("    label $label\n    lpos $lpos\n").substitute(dic)
         
         vInstruction += "    end"
+        try:
+            vInstruction = vInstruction.encode('Latin_1')
+        except UnicodeEncodeError, err:
+            try:
+                print err
+                pos = str(err).split('position')[1].split(':')[0].strip()
+            except IndexError:
+                pos = ''
+            if pos:
+                message = _("Characters on position %s are not supported "
+                            "by ISO-8859-1 (Latin 1) encoding "
+                            "which is required by module ps.map.") % pos
+            else:
+                message = _("Not all characters are supported "
+                            "by ISO-8859-1 (Latin 1) encoding "
+                            "which is required by module ps.map.")
+            GMessage(message = message)
+            return ''
         return vInstruction
     
     def Read(self, instruction, text, **kwargs):
@@ -1773,7 +1793,7 @@
             if line.startswith('lpos'):
                 instr['lpos'] = int(line.split()[1])
             elif line.startswith('label'):
-                instr['label'] = line.split(None, 1)[1]
+                instr['label'] = line.split(None, 1)[1].decode('latin_1')
             elif line.startswith('layer'):
                 instr['layer'] = line.split()[1]
             elif line.startswith('masked'):



More information about the grass-commit mailing list