Browse Source

wxGUI: read/write history file with encoding 'utf-8' (see https://trac.osgeo.org/grass/ticket/1293)
(merge https://trac.osgeo.org/grass/changeset/45548 from devbr6)


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

Martin Landa 14 years ago
parent
commit
40edcc2ac0
2 changed files with 17 additions and 10 deletions
  1. 10 6
      gui/wxpython/gui_modules/goutput.py
  2. 7 4
      gui/wxpython/gui_modules/prompt.py

+ 10 - 6
gui/wxpython/gui_modules/goutput.py

@@ -24,6 +24,7 @@ import textwrap
 import time
 import threading
 import Queue
+import codecs
 
 import wx
 import wx.stc
@@ -412,7 +413,7 @@ class GMConsole(wx.SplitterWindow):
 
     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 @@ class GMConsole(wx.SplitterWindow):
         # 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 @@ class GMStc(wx.stc.StyledTextCtrl):
                 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

+ 7 - 4
gui/wxpython/gui_modules/prompt.py

@@ -24,6 +24,7 @@ import sys
 import shlex
 import copy
 import difflib
+import codecs
 
 import wx
 import wx.stc
@@ -505,10 +506,11 @@ class GPrompt(object):
         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 @@ class GPromptSTC(GPrompt, wx.stc.StyledTextCtrl):
                 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: