Logging exceptions in cleaned up callbacks
[gonvert] / src / gonvert_glade.py
index 9ccdf7d..bbb4482 100755 (executable)
@@ -148,8 +148,8 @@ class Gonvert(object):
                        "on_unitValue_changed": self._on_unit_value_changed,
                        "on_previousUnitValue_changed": self._on_previous_unit_value_changed,
                        "on_writeUnitsMenuItem_activate": self._on_user_write_units,
-                       "on_findButton_clicked": self._on_user_find_units,
-                       "on_findEntry_activated": self._on_user_find_units,
+                       "on_findButton_clicked": self._on_find_activate,
+                       "on_findEntry_activated": self._on_find_activate,
                        "on_findEntry_changed": self._on_findEntry_changed,
                        "on_aboutMenuItem_activate": self._on_about_clicked,
                        "on_messagebox_ok_clicked": self.messagebox_ok_clicked,
@@ -247,19 +247,30 @@ class Gonvert(object):
                pickle.dump(window_settings, open(windowDatPath, 'w'))
 
        def _on_shortlist_changed(self, a):
-               raise NotImplementedError("%s" % self._shortlistcheck.get_active())
+               try:
+                       raise NotImplementedError("%s" % self._shortlistcheck.get_active())
+               except Exception:
+                       _moduleLogger.exception()
 
        def _on_edit_shortlist(self, a):
-               raise NotImplementedError("%s" % self._toggleShortList.get_active())
+               try:
+                       raise NotImplementedError("%s" % self._toggleShortList.get_active())
+               except Exception:
+                       _moduleLogger.exception()
 
        def _on_user_clear_selections(self, a):
-               selectionsDatPath = "/".join((constants._data_path_, "selections.dat"))
-               os.remove(selectionsDatPath)
-               self._selected_units = {}
+               try:
+                       selectionsDatPath = "/".join((constants._data_path_, "selections.dat"))
+                       os.remove(selectionsDatPath)
+                       self._selected_units = {}
+               except Exception:
+                       _moduleLogger.exception()
 
        def _on_user_exit(self, a):
                try:
                        self._save_settings()
+               except Exception:
+                       _moduleLogger.exception()
                finally:
                        gtk.main_quit()
 
@@ -267,14 +278,17 @@ class Gonvert(object):
                """
                Clear out find results since the user wants to look for something new
                """
-               # switch to "new find" state
-               self._find_result = []
-               self._find_count = 0
+               try:
+                       # switch to "new find" state
+                       self._find_result = []
+                       self._find_count = 0
 
-               # Clear our user message
-               self._findLabel.set_text('')
+                       # Clear our user message
+                       self._findLabel.set_text('')
+               except Exception:
+                       _moduleLogger.exception()
 
-       def _first_find(self):
+       def _find_first(self):
                assert len(self._find_result) == 0
                assert self._find_count == 0
                findString = string.lower(string.strip(self._findEntry.get_text()))
@@ -314,7 +328,7 @@ class Gonvert(object):
                        self._categoryView.set_cursor(self._find_result[self._find_count][2], self._categoryColumn, False)
                self._unitsView.set_cursor(self._find_result[self._find_count][3], self._unitNameColumn, True)
 
-       def _on_user_find_units(self, a):
+       def _on_find_activate(self, a):
                """
                check if 'new find' or 'last find' or 'next-find'
 
@@ -327,21 +341,24 @@ class Gonvert(object):
                next-find = continue to next found location
                           = self._find_count = 0 and len(self._find_result)>0
                """
-               if len(self._find_result) == 0:
-                       self._first_find()
-               else:
-                       if self._find_count == len(self._find_result)-1:
-                               self._find_wrap_around()
+               try:
+                       if len(self._find_result) == 0:
+                               self._find_first()
                        else:
-                               self._find_next()
+                               if self._find_count == len(self._find_result)-1:
+                                       self._find_wrap_around()
+                               else:
+                                       self._find_next()
 
-               if not self._find_result:
-                       self._findLabel.set_text('Text not found')
-               else:
-                       resultsLeft = len(self._find_result) - self._find_count - 1
-                       self._findLabel.set_text(
-                               '%s result(s) left' % (resultsLeft, )
-                       )
+                       if not self._find_result:
+                               self._findLabel.set_text('Text not found')
+                       else:
+                               resultsLeft = len(self._find_result) - self._find_count - 1
+                               self._findLabel.set_text(
+                                       '%s result(s) left' % (resultsLeft, )
+                               )
+               except Exception:
+                       _moduleLogger.exception()
 
        def _on_click_unit_column(self, col):
                """
@@ -506,7 +523,6 @@ class Gonvert(object):
                #Since category has just been clicked, the list will be sorted already.
                if self._selected_category in self._selected_units:
                        if self._selected_units[self._selected_category][0]:
-                               ''"debug ''"
                                #self._selected_units[self._selected_category] = [selected_unit, self._selected_units[self._selected_category][0]]
 
                                units = unit_data.UNIT_DESCRIPTIONS[self._selected_category].keys()