Explorar el Código

wx.psmap: enable to write accented characters (supported by Latin1)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@48221 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová hace 13 años
padre
commit
10fb90ad78
Se han modificado 1 ficheros con 29 adiciones y 10 borrados
  1. 29 10
      gui/wxpython/gui_modules/psmap_dialogs.py

+ 29 - 10
gui/wxpython/gui_modules/psmap_dialogs.py

@@ -903,21 +903,40 @@ class Text(InstructionObject):
     def __str__(self):
         text = self.instruction['text'].replace('\n','\\n')
         instr = "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)
+        try:
+            instr += " %s\n" % text.encode('latin_1')
+        except UnicodeEncodeError, err:
+            try:
+                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 ''
+        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)
-        instr += string.Template("    border $border\n").substitute(self.instruction)
+            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)
-        instr += string.Template("    background $background\n").substitute(self.instruction)
+            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)
+            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)
+            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)
+            instr += (string.Template("    xoffset $xoffset\n    yoffset $yoffset\n").
+                                                            substitute(self.instruction).encode('latin_1'))
         instr += "    end"
         return instr