[GRASS-SVN] r45549 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Mar 4 11:05:06 EST 2011


Author: martinl
Date: 2011-03-04 08:05:06 -0800 (Fri, 04 Mar 2011)
New Revision: 45549

Modified:
   grass/trunk/gui/wxpython/gui_modules/goutput.py
   grass/trunk/gui/wxpython/gui_modules/prompt.py
Log:
wxGUI: read/write history file with encoding 'utf-8' (see #1293)
(merge r45548 from devbr6)


Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py	2011-03-04 16:02:06 UTC (rev 45548)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py	2011-03-04 16:05:06 UTC (rev 45549)
@@ -24,6 +24,7 @@
 import time
 import threading
 import Queue
+import codecs
 
 import wx
 import wx.stc
@@ -412,7 +413,7 @@
 
     def WriteError(self, line):
         """!Write message in error style"""
-        self.WriteLog(line, style=self.cmd_output.StyleError, switchPage = True)
+        self.WriteLog(line, style = self.cmd_output.StyleError, switchPage = True)
 
     def RunCmd(self, command, compReg = True, switchPage = False,
                onDone = None):
@@ -435,10 +436,13 @@
         # update history file
         env = grass.gisenv()
         try:
-            fileHistory = open(os.path.join(env['GISDBASE'], env['LOCATION_NAME'], env['MAPSET'],
-                                            '.bash_history'), 'a')
+            fileHistory = codecs.open(os.path.join(env['GISDBASE'],
+                                                   env['LOCATION_NAME'],
+                                                   env['MAPSET'],
+                                                   '.bash_history'),
+                                      encoding = 'utf-8', mode = 'a')
         except IOError, e:
-            self.WriteError(str(e))
+            self.WriteError(e)
             fileHistory = None
         
         if fileHistory:
@@ -1068,8 +1072,8 @@
                 elif os.environ.has_key('GRASS_DB_ENCODING'):
                     txt = unicode(txt, os.environ['GRASS_DB_ENCODING'])
                 else:
-                    txt = _('Unable to encode text. Please set encoding in GUI preferences.') + '\n'
-                    
+                    txt = utils.EncodeString(txt)
+                
                 self.AddText(txt)
         
         # reset output window to read only

Modified: grass/trunk/gui/wxpython/gui_modules/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/prompt.py	2011-03-04 16:02:06 UTC (rev 45548)
+++ grass/trunk/gui/wxpython/gui_modules/prompt.py	2011-03-04 16:05:06 UTC (rev 45549)
@@ -24,6 +24,7 @@
 import shlex
 import copy
 import difflib
+import codecs
 
 import wx
 import wx.stc
@@ -505,10 +506,11 @@
         hist = list()
         env = grass.gisenv()
         try:
-            fileHistory = open(os.path.join(env['GISDBASE'],
-                                            env['LOCATION_NAME'],
-                                            env['MAPSET'],
-                                            '.bash_history'), 'r')
+            fileHistory = codecs.open(os.path.join(env['GISDBASE'],
+                                                   env['LOCATION_NAME'],
+                                                   env['MAPSET'],
+                                                   '.bash_history'),
+                                      encoding = 'utf-8', mode = 'r')
         except IOError:
             return hist
         
@@ -1059,6 +1061,7 @@
                 cmd = utils.split(str(line))
             except UnicodeError:
                 cmd = utils.split(utils.EncodeString((line)))
+            cmd = map(utils.DecodeString, cmd)
             
             #  send the command list to the processor 
             if cmd[0] in ('r.mapcalc', 'r3.mapcalc') and len(cmd) == 1:



More information about the grass-commit mailing list