[Nvda-dev] commit r1959 - in trunk: . source source/gui

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Nvda-dev] commit r1959 - in trunk: . source source/gui

NVDA Subversion
Author: jteh
Date: Thu Apr 24 06:26:18 2008
New Revision: 1959

Log:
Explicitly specify UTF-8 when opening the NVDA log file for writing. Also, logViewer now uses UTF-8 when reading and saving the log. This fixes unicode errors in the log viewer.

Modified:
   trunk/   (props changed)
   trunk/source/gui/logViewer.py
   trunk/source/nvda.pyw

Modified: trunk/source/gui/logViewer.py
==============================================================================
--- trunk/source/gui/logViewer.py (original)
+++ trunk/source/gui/logViewer.py Thu Apr 24 06:26:18 2008
@@ -1,6 +1,7 @@
 """Provides functionality to view the NVDA log.
 """
 
+import codecs
 import wx
 import globalVars
 import gui
@@ -39,7 +40,7 @@
  pos = self.outputCtrl.GetInsertionPoint()
  # Populate the output control with the contents of the log file.
  try:
- self.outputCtrl.SetValue(file(globalVars.appArgs.logFileName, "r").read())
+ self.outputCtrl.SetValue(codecs.open(globalVars.appArgs.logFileName, "r", encoding="UTF-8").read())
  self.outputCtrl.SetInsertionPoint(pos)
  except IOError:
  pass
@@ -56,7 +57,9 @@
  if not filename:
  return
  try:
- file(filename, "w").write(self.outputCtrl.GetValue())
+ # codecs.open() forces binary mode, which is bad under Windows because line endings won't be converted to crlf automatically.
+ # Therefore, do the encoding manually.
+ file(filename, "w").write(self.outputCtrl.GetValue().encode("UTF-8"))
  except (IOError, OSError), e:
  wx.MessageBox(_("Error saving log: %s") % e.strerror, _("Error"), style=wx.OK | wx.ICON_ERROR)
 

Modified: trunk/source/nvda.pyw
==============================================================================
--- trunk/source/nvda.pyw (original)
+++ trunk/source/nvda.pyw Thu Apr 24 06:26:18 2008
@@ -117,7 +117,7 @@
 if logLevel<=0:
  logLevel=logging.WARN
 log=logObj.Logger("NVDA",logLevel)
-logHandler=logObj.FileHandler(globalVars.appArgs.logFileName,"w")
+logHandler=logObj.FileHandler(globalVars.appArgs.logFileName,"w", "UTF-8")
 logFormatter=logging.Formatter("%(levelname)s - %(codepath)s:\n%(message)s")
 logHandler.setFormatter(logFormatter)
 log.addHandler(logHandler)