Improving error reporting
authorEd Page <eopage@byu.net>
Thu, 13 Jan 2011 02:03:34 +0000 (20:03 -0600)
committerEd Page <eopage@byu.net>
Thu, 13 Jan 2011 03:06:11 +0000 (21:06 -0600)
src/ejpi_qt.py
src/history.py
src/qhistory.py
src/util/qwrappers.py

index 7f3d718..1c79d9d 100755 (executable)
@@ -193,7 +193,7 @@ class MainWindow(qwrappers.WindowWrapper):
 
                self._history = history.RpnCalcHistory(
                        self._historyView,
-                       self._userEntry, self._errorDisplay,
+                       self._userEntry, self._app.errorLog,
                        self._constantPlugins.constants, self._operatorPlugins.operators
                )
                self._load_history()
@@ -287,44 +287,53 @@ class MainWindow(qwrappers.WindowWrapper):
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_child_close(self, something = None):
-               self._child = None
+               with qui_utils.notify_error(self._app.errorLog):
+                       self._child = None
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_copy(self, *args):
-               eqNode = self._historyView.peek()
-               resultNode = eqNode.simplify()
-               self._app._clipboard.setText(str(resultNode))
+               with qui_utils.notify_error(self._app.errorLog):
+                       eqNode = self._historyView.peek()
+                       resultNode = eqNode.simplify()
+                       self._app._clipboard.setText(str(resultNode))
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_paste(self, *args):
-               result = str(self._app._clipboard.text())
-               self._userEntry.append(result)
+               with qui_utils.notify_error(self._app.errorLog):
+                       result = str(self._app._clipboard.text())
+                       self._userEntry.append(result)
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_entry_direct(self, keys, modifiers):
-               if "shift" in modifiers:
-                       keys = keys.upper()
-               self._userEntry.append(keys)
+               with qui_utils.notify_error(self._app.errorLog):
+                       if "shift" in modifiers:
+                               keys = keys.upper()
+                       self._userEntry.append(keys)
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_push(self, *args):
-               self._history.push_entry()
+               with qui_utils.notify_error(self._app.errorLog):
+                       self._history.push_entry()
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_unpush(self, *args):
-               self._historyView.unpush()
+               with qui_utils.notify_error(self._app.errorLog):
+                       self._historyView.unpush()
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_entry_backspace(self, *args):
-               self._userEntry.pop()
+               with qui_utils.notify_error(self._app.errorLog):
+                       self._userEntry.pop()
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_entry_clear(self, *args):
-               self._userEntry.clear()
+               with qui_utils.notify_error(self._app.errorLog):
+                       self._userEntry.clear()
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_clear_all(self, *args):
-               self._history.clear()
+               with qui_utils.notify_error(self._app.errorLog):
+                       self._history.clear()
 
 
 def run():
index dcd04fa..c525027 100644 (file)
@@ -121,10 +121,6 @@ class RpnCalcHistory(object):
                self.__serialRenderer = operation.render_number()
 
        @property
-       def errorReporter(self):
-               return self.__errorReporter
-
-       @property
        def OPERATIONS(self):
                return self.__operations
 
@@ -154,7 +150,7 @@ class RpnCalcHistory(object):
                        node = self._apply_operation(Node)
                        return node
                except StandardError, e:
-                       self.errorReporter.push_exception()
+                       self.__errorReporter.push_exception()
                        return None
 
        def serialize_stack(self):
index c25511c..759ba49 100644 (file)
@@ -5,6 +5,8 @@ http://www.grigoriev.ru/svgmath/ (MathML->SVG in Python)
 http://helm.cs.unibo.it/mml-widget/ (MathML widget in C++)
 """
 
+from __future__ import with_statement
+
 import logging
 
 from PyQt4 import QtGui
@@ -28,7 +30,7 @@ class QCalcHistory(history.AbstractHistory):
        def __init__(self, errorReporter):
                super(QCalcHistory, self).__init__()
                self._prettyRenderer = operation.render_number()
-               self._errorReporter = errorReporter
+               self._errorLog = errorReporter
 
                self._historyStore = QtGui.QStandardItemModel()
                self._historyStore.setHorizontalHeaderLabels(["", "Equation", "Result"])
@@ -61,10 +63,6 @@ class QCalcHistory(history.AbstractHistory):
        def toplevel(self):
                return self._historyView
 
-       @property
-       def errorReporter(self):
-               return self._errorReporter
-
        def push(self, node):
                simpleNode = node.simplify()
 
@@ -115,31 +113,33 @@ class QCalcHistory(history.AbstractHistory):
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_row_activated(self, index):
-               if index.column() == self._CLOSE_COLUMN:
-                       self._historyStore.removeRow(index.row(), index.parent())
-                       self._rowCount -= 1
-               elif index.column() == self._EQ_COLUMN:
-                       self._duplicate_row(index)
-               elif index.column() == self._RESULT_COLUMN:
-                       self._duplicate_row(index)
-               else:
-                       raise NotImplementedError("Unsupported column to activate %s" % index.column())
+               with qui_utils.notify_error(self._errorLog):
+                       if index.column() == self._CLOSE_COLUMN:
+                               self._historyStore.removeRow(index.row(), index.parent())
+                               self._rowCount -= 1
+                       elif index.column() == self._EQ_COLUMN:
+                               self._duplicate_row(index)
+                       elif index.column() == self._RESULT_COLUMN:
+                               self._duplicate_row(index)
+                       else:
+                               raise NotImplementedError("Unsupported column to activate %s" % index.column())
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_item_changed(self, item):
-               if self._programmaticUpdate:
-                       _moduleLogger.info("Blocking updating %r recursively" % item)
-                       return
-               self._programmaticUpdate = True
-               try:
-                       if item.column() in [self._EQ_COLUMN, self._RESULT_COLUMN]:
-                               self._update_input(item)
-                       else:
-                               raise NotImplementedError("Unsupported column to edit %s" % item.column())
-               except StandardError, e:
-                       self.errorReporter.push_exception()
-               finally:
-                       self._programmaticUpdate = False
+               with qui_utils.notify_error(self._errorLog):
+                       if self._programmaticUpdate:
+                               _moduleLogger.info("Blocking updating %r recursively" % item)
+                               return
+                       self._programmaticUpdate = True
+                       try:
+                               if item.column() in [self._EQ_COLUMN, self._RESULT_COLUMN]:
+                                       self._update_input(item)
+                               else:
+                                       raise NotImplementedError("Unsupported column to edit %s" % item.column())
+                       except StandardError, e:
+                               self._errorReporter.push_exception()
+                       finally:
+                               self._programmaticUpdate = False
 
        def _duplicate_row(self, index):
                item = self._historyStore.item(index.row(), self._EQ_COLUMN)
index 9527dc6..8577e63 100644 (file)
@@ -122,11 +122,13 @@ class ApplicationWrapper(object):
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_toggle_fullscreen(self, checked = False):
-               self._mainWindow.set_fullscreen(checked)
+               with qui_utils.notify_error(self._errorLog):
+                       self._mainWindow.set_fullscreen(checked)
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_toggle_orientation(self, checked = False):
-               self._mainWindow.set_orientation(checked)
+               with qui_utils.notify_error(self._errorLog):
+                       self._mainWindow.set_orientation(checked)
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_about(self, checked = True):
@@ -134,14 +136,16 @@ class ApplicationWrapper(object):
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_log(self, checked = False):
-               with open(self._constants._user_logpath_, "r") as f:
-                       logLines = f.xreadlines()
-                       log = "".join(logLines)
-                       self._clipboard.setText(log)
+               with qui_utils.notify_error(self._errorLog):
+                       with open(self._constants._user_logpath_, "r") as f:
+                               logLines = f.xreadlines()
+                               log = "".join(logLines)
+                               self._clipboard.setText(log)
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_quit(self, checked = False):
-               self._close_windows()
+               with qui_utils.notify_error(self._errorLog):
+                       self._close_windows()
 
 
 class WindowWrapper(object):
@@ -227,4 +231,5 @@ class WindowWrapper(object):
 
        @misc_utils.log_exception(_moduleLogger)
        def _on_close_window(self, checked = True):
-               self.close()
+               with qui_utils.notify_error(self._errorLog):
+                       self.close()