Copying of logs and simplifying logging
authorepage <eopage@byu.net>
Thu, 12 Nov 2009 03:12:55 +0000 (03:12 +0000)
committerepage <eopage@byu.net>
Thu, 12 Nov 2009 03:12:55 +0000 (03:12 +0000)
git-svn-id: file:///svnroot/ejpi/trunk@69 df6cc7de-23d0-4ae0-bb86-c17aa67b2a9d

src/constants.py
src/ejpi.py
src/ejpi_glade.py
src/gtk_toolbox.py
src/gtkhistory.py

index e1132e0..812e77c 100644 (file)
@@ -6,3 +6,4 @@ __version__ = "0.9.6"
 __build__ = 5
 _data_path_ = os.path.join(os.path.expanduser("~"), ".ejpi")
 __app_magic__ = 0xdeadbeef
+_user_logpath_ = "%s/ejpi.log" % _data_path_
index ae9cefb..193a066 100755 (executable)
@@ -19,8 +19,7 @@ except OSError, e:
        if e.errno != 17:
                raise
 
-userLogPath = "%s/ejpi.log" % constants._data_path_
-logging.basicConfig(level=logging.DEBUG, filename=userLogPath)
+logging.basicConfig(level=logging.DEBUG, filename=constants._user_logpath_)
 _moduleLogger.info("ejpi %s-%s" % (constants.__version__, constants.__build__))
 
 
index 501fd6b..47c51b3 100755 (executable)
@@ -258,14 +258,12 @@ class Calculator(object):
                        "pluginKeyboard": pluginKeyboard,
                })
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_kb_plugin_selection_button(self, *args):
-               try:
-                       pluginNames = [plugin["pluginName"] for plugin in self.__activeKeyboards]
-                       oldIndex = pluginNames.index(self.__pluginButton.get_label())
-                       newIndex = hildonize.touch_selector(self._window, "Keyboards", pluginNames, oldIndex)
-                       self._set_plugin_kb(newIndex)
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               pluginNames = [plugin["pluginName"] for plugin in self.__activeKeyboards]
+               oldIndex = pluginNames.index(self.__pluginButton.get_label())
+               newIndex = hildonize.touch_selector(self._window, "Keyboards", pluginNames, oldIndex)
+               self._set_plugin_kb(newIndex)
 
        def _set_plugin_kb(self, pluginIndex):
                plugin = self.__activeKeyboards[pluginIndex]
@@ -302,123 +300,97 @@ class Calculator(object):
                                line = " ".join(data for data in lineData)
                                f.write("%s\n" % line)
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
                """
                For system_inactivity, we have no background tasks to pause
 
                @note Hildon specific
                """
-               try:
-                       if memory_low:
-                               gc.collect()
+               if memory_low:
+                       gc.collect()
 
-                       if save_unsaved_data or shutdown:
-                               self.__save_history()
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               if save_unsaved_data or shutdown:
+                       self.__save_history()
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_window_state_change(self, widget, event, *args):
-               """
-               @note Hildon specific
-               """
-               try:
-                       if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
-                               self._isFullScreen = True
-                       else:
-                               self._isFullScreen = False
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               if event.new_window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
+                       self._isFullScreen = True
+               else:
+                       self._isFullScreen = False
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_close(self, *args, **kwds):
-               try:
-                       if self._osso is not None:
-                               self._osso.close()
+               if self._osso is not None:
+                       self._osso.close()
 
-                       try:
-                               self.__save_history()
-                       finally:
-                               gtk.main_quit()
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               try:
+                       self.__save_history()
+               finally:
+                       gtk.main_quit()
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_copy(self, *args):
-               try:
-                       equationNode = self.__history.history.peek()
-                       result = str(equationNode.evaluate())
-                       self._clipboard.set_text(result)
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               equationNode = self.__history.history.peek()
+               result = str(equationNode.evaluate())
+               self._clipboard.set_text(result)
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_copy_equation(self, *args):
-               try:
-                       equationNode = self.__history.history.peek()
-                       equation = str(equationNode)
-                       self._clipboard.set_text(equation)
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               equationNode = self.__history.history.peek()
+               equation = str(equationNode)
+               self._clipboard.set_text(equation)
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_paste(self, *args):
-               try:
-                       contents = self._clipboard.wait_for_text()
-                       self.__userEntry.append(contents)
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               contents = self._clipboard.wait_for_text()
+               self.__userEntry.append(contents)
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_key_press(self, widget, event, *args):
-               """
-               @note Hildon specific
-               """
-               try:
-                       RETURN_TYPES = (gtk.keysyms.Return, gtk.keysyms.ISO_Enter, gtk.keysyms.KP_Enter)
-                       if (
-                               event.keyval == gtk.keysyms.F6 or
-                               event.keyval in RETURN_TYPES and event.get_state() & gtk.gdk.CONTROL_MASK
-                       ):
-                               if self._isFullScreen:
-                                       self._window.unfullscreen()
-                               else:
-                                       self._window.fullscreen()
-               except Exception:
-                       self.__errorDisplay.push_exception()
-
+               RETURN_TYPES = (gtk.keysyms.Return, gtk.keysyms.ISO_Enter, gtk.keysyms.KP_Enter)
+               if (
+                       event.keyval == gtk.keysyms.F6 or
+                       event.keyval in RETURN_TYPES and event.get_state() & gtk.gdk.CONTROL_MASK
+               ):
+                       if self._isFullScreen:
+                               self._window.unfullscreen()
+                       else:
+                               self._window.fullscreen()
+               elif event.keyval == ord("l") and event.get_state() & gtk.gdk.CONTROL_MASK:
+                       with open(constants._user_logpath_, "r") as f:
+                               logLines = f.xreadlines()
+                               log = "".join(logLines)
+                               self._clipboard.set_text(str(log))
+
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_push(self, *args):
-               try:
-                       self.__history.push_entry()
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               self.__history.push_entry()
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_unpush(self, *args):
-               try:
-                       self.__historyStore.unpush()
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               self.__historyStore.unpush()
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_entry_direct(self, keys, modifiers):
-               try:
-                       if "shift" in modifiers:
-                               keys = keys.upper()
-                       self.__userEntry.append(keys)
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               if "shift" in modifiers:
+                       keys = keys.upper()
+               self.__userEntry.append(keys)
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_entry_backspace(self, *args):
-               try:
-                       self.__userEntry.pop()
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               self.__userEntry.pop()
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_entry_clear(self, *args):
-               try:
-                       self.__userEntry.clear()
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               self.__userEntry.clear()
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_clear_all(self, *args):
-               try:
-                       self.__history.clear()
-               except Exception:
-                       self.__errorDisplay.push_exception()
+               self.__history.clear()
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_about_activate(self, *args):
                dlg = gtk.AboutDialog()
                dlg.set_name(constants.__pretty_app_name__)
index dc1b403..8c2947d 100644 (file)
@@ -284,6 +284,22 @@ def threaded_stage(target, thread_factory = threading.Thread):
        return queue_sink(messages)
 
 
+def log_exception(logger):
+
+       def log_exception_decorator(func):
+
+               @functools.wraps(func)
+               def wrapper(*args, **kwds):
+                       try:
+                               return func(*args, **kwds)
+                       except Exception:
+                               logger.exception(func.__name__)
+
+               return wrapper
+
+       return log_exception_decorator
+
+
 class LoginWindow(object):
 
        def __init__(self, widgetTree):
index ca7f741..0904578 100755 (executable)
@@ -5,16 +5,21 @@ http://www.grigoriev.ru/svgmath/ (MathML->SVG in Python)
 http://helm.cs.unibo.it/mml-widget/ (MathML widget in C++)
 """
 
+import logging
 
 import gobject
 import pango
 import gtk
 
 
+import gtk_toolbox
 import history
 import operation
 
 
+_moduleLogger = logging.getLogger("gtkhistory")
+
+
 class GtkCalcHistory(history.AbstractHistory):
 
        BUTTON_IDX = 0
@@ -112,6 +117,7 @@ class GtkCalcHistory(history.AbstractHistory):
                        data = row[self.DATA_IDX]
                        yield data
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def _on_close_activated(self, treeView, path, viewColumn):
                if viewColumn is self.__closeColumn:
                        del self.__historyStore[path[0]]