Переглянути джерело

bugfix https://trac.osgeo.org/grass/ticket/995
(merge https://trac.osgeo.org/grass/changeset/41397, https://trac.osgeo.org/grass/changeset/41398) from devbr6


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

Martin Landa 15 роки тому
батько
коміт
870d956d39

+ 15 - 3
gui/wxpython/gis_set.py

@@ -198,8 +198,14 @@ class GRASSStartup(wx.Frame):
                 self.gisdbase = os.getenv("HOME")
             else:
                 self.gisdbase = os.getcwd()
-        self.tgisdbase.SetValue(self.gisdbase)
-
+        try:
+            self.tgisdbase.SetValue(self.gisdbase)
+        except UnicodeDecodeError:
+            wx.MessageBox(parent = self, caption = _("Error"),
+                          message = _("Unable to set GRASS database. "
+                                      "Check your locale settings."),
+                          style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+        
         self.OnSetDatabase(None)
         location = self.GetRCValue("LOCATION_NAME")
         if location == "<UNKNOWN>" or \
@@ -523,7 +529,13 @@ class GRASSStartup(wx.Frame):
 
     def UpdateLocations(self, dbase):
         """!Update list of locations"""
-        self.listOfLocations = utils.GetListOfLocations(dbase)
+        try:
+            self.listOfLocations = utils.GetListOfLocations(dbase)
+        except UnicodeEncodeError:
+            wx.MessageBox(parent = self, caption = _("Error"),
+                          message = _("Unable to set GRASS database. "
+                                      "Check your locale settings."),
+                          style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
         
         self.lblocations.Clear()
         self.lblocations.InsertItems(self.listOfLocations, 0)

+ 12 - 0
gui/wxpython/gui_modules/gcmd.py

@@ -134,6 +134,18 @@ class NvizError(GException):
 
 class Popen(subprocess.Popen):
     """!Subclass subprocess.Popen"""
+    def __init__(self, *args, **kwargs):
+        if subprocess.mswindows:
+            try:
+                kwargs['args'] = map(utils.EncodeString, kwargs['args'])
+            except KeyError:
+                if len(args) > 0:
+                    targs = list(args)
+                    targs[0] = map(utils.EncodeString, args[0])
+                    args = tuple(targs)
+        
+        subprocess.Popen.__init__(self, *args, **kwargs)
+        
     def recv(self, maxsize=None):
         return self._recv('stdout', maxsize)
     

+ 2 - 2
gui/wxpython/gui_modules/location_wizard.py

@@ -1681,8 +1681,8 @@ class SummaryPage(TitledPage):
         projdesc = self.parent.projpage.projdesc
         ellipsedesc = self.parent.ellipsepage.ellipsedesc
         datumdesc = self.parent.datumpage.datumdesc
-        self.ldatabase.SetLabel(str(database))
-        self.llocation.SetLabel(str(location))
+        self.ldatabase.SetLabel(database)
+        self.llocation.SetLabel(location)
         label = ''
         
         if coordsys == 'epsg':

+ 25 - 8
gui/wxpython/gui_modules/utils.py

@@ -17,6 +17,7 @@ import sys
 import platform
 import string
 import glob
+import locale
 
 import globalvar
 grassPath = os.path.join(globalvar.ETCDIR, "python")
@@ -465,7 +466,7 @@ def PathJoin(*args):
         return path[1].upper() + ':\\' + path[3:].replace('/', '\\')
     
     return path
-    
+
 def ReadEpsgCodes(path):
     """!Read EPSG code from the file
 
@@ -551,13 +552,16 @@ def GetListOfLocations(dbase):
     @return list of locations (sorted)
     """
     listOfLocations = list()
-    
-    for location in glob.glob(os.path.join(dbase, "*")):
-        try:
-            if os.path.join(location, "PERMANENT") in glob.glob(os.path.join(location, "*")):
-                listOfLocations.append(os.path.basename(location))
-        except:
-            pass
+
+    try:
+        for location in glob.glob(os.path.join(dbase, "*")):
+            try:
+                if os.path.join(location, "PERMANENT") in glob.glob(os.path.join(location, "*")):
+                    listOfLocations.append(os.path.basename(location))
+            except:
+                pass
+    except UnicodeEncodeError, e:
+        raise e
     
     ListSortLower(listOfLocations)
     
@@ -607,3 +611,16 @@ def GetColorTables():
         return list()
     
     return ret.splitlines()
+
+def EncodeString(string):
+    """!Return encoded string
+
+    @param string string to be encoded
+
+    @return encoded string
+    """
+    enc = locale.getdefaultlocale()[1]
+    if enc:
+        return string.encode(enc)
+    
+    return string