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

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

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

NVDA Subversion
Author: jteh
Date: Thu Apr 24 05:06:49 2008
New Revision: 1957

Log:
logViewer:
        * Introduce a menu bar containing a single "Log" menu.
        * Don't update in realtime. This is pretty useless, as there will rarely be any useful log output while one is focused on the log viewer. Also, this updating can be more of a hinderance than a help.
        * Instead, provide the ability to refresh the view by pressing f5 or by selecting "Refresh" from the menu.
        * Refresh the view automatically when the window becomes the foreground window.
        * Provide the ability to save the current content. This is accessible from the menu.


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

Modified: trunk/source/gui/logViewer.py
==============================================================================
--- trunk/source/gui/logViewer.py (original)
+++ trunk/source/gui/logViewer.py Thu Apr 24 05:06:49 2008
@@ -1,7 +1,6 @@
 """Provides functionality to view the NVDA log.
 """
 
-import logging
 import wx
 import globalVars
 import gui
@@ -13,6 +12,7 @@
  def __init__(self):
  super(LogViewer, self).__init__(None, wx.ID_ANY, _("NVDA Log Viewer"))
  gui.topLevelWindows.append(self)
+ self.Bind(wx.EVT_ACTIVATE, self.onActivate)
  self.Bind(wx.EVT_CLOSE, self.onClose)
  mainSizer = wx.BoxSizer(wx.VERTICAL)
  self.outputCtrl = wx.TextCtrl(self, wx.ID_ANY, size=(500, 500), style=wx.TE_MULTILINE | wx.TE_READONLY)
@@ -20,26 +20,46 @@
  self.SetSizer(mainSizer)
  mainSizer.Fit(self)
 
+ menuBar = wx.MenuBar()
+ menu = wx.Menu()
+ item = menu.Append(wx.ID_ANY, _("Refresh F5"))
+ self.Bind(wx.EVT_MENU, self.refresh, item)
+ item = menu.Append(wx.ID_SAVEAS)
+ self.Bind(wx.EVT_MENU, self.onSaveAsCommand, item)
+ menu.AppendSeparator()
+ item = menu.Append(wx.ID_EXIT, _("E&xit"))
+ self.Bind(wx.EVT_MENU, self.onClose, item)
+ menuBar.Append(menu, _("Log"))
+ self.SetMenuBar(menuBar)
+
+ self.refresh()
+ self.outputCtrl.SetFocus()
+
+ def refresh(self, evt=None):
+ 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.SetInsertionPoint(pos)
  except IOError:
  pass
 
- # Install a log handler to direct future output to the output control.
- # wx.TextCtrl does not support flush(), so fudge it.
- self.outputCtrl.flush = lambda: None
- self.logHandler = logging.StreamHandler(self.outputCtrl)
- self.logHandler.setFormatter(globalVars.log.handlers[0].formatter)
- globalVars.log.addHandler(self.logHandler)
-
- self.outputCtrl.SetFocus()
+ def onActivate(self, evt):
+ self.refresh()
+ evt.Skip()
 
  def onClose(self, evt):
  self.Destroy()
 
+ def onSaveAsCommand(self, evt):
+ filename = wx.FileSelector(_("Save As"), default_filename="nvda.log", flags=wx.SAVE | wx.OVERWRITE_PROMPT, parent=self)
+ if not filename:
+ return
+ try:
+ file(filename, "w").write(self.outputCtrl.GetValue())
+ except (IOError, OSError), e:
+ wx.MessageBox(_("Error saving log: %s") % e.strerror, _("Error"), style=wx.OK | wx.ICON_ERROR)
+
  def Destroy(self):
  gui.topLevelWindows.remove(self)
- globalVars.log.removeHandler(self.logHandler)
- self.logHandler.close()
  super(LogViewer, self).Destroy()