From 11411b48851f7c8da9039da8a16351a13bc51837 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Tue, 2 Nov 2010 13:19:27 +0000 Subject: [PATCH] 4340: Error when adding source reference svn: r16111 --- src/gui/editors/displaytabs/backreflist.py | 6 +++--- src/gui/editors/displaytabs/backrefmodel.py | 10 +++++++++- src/gui/editors/editprimary.py | 18 ++++++++++++++++++ src/gui/editors/editreference.py | 18 ++++++++++++++++++ src/gui/editors/editsecondary.py | 18 ++++++++++++++++++ 5 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/gui/editors/displaytabs/backreflist.py b/src/gui/editors/displaytabs/backreflist.py index ec87a812c..ae06bbf09 100644 --- a/src/gui/editors/displaytabs/backreflist.py +++ b/src/gui/editors/displaytabs/backreflist.py @@ -66,7 +66,7 @@ class BackRefList(EmbeddedList): EmbeddedList.__init__(self, dbstate, uistate, track, _('_References'), refmodel) self._callback = callback - self.model.connect('row-inserted', self.update_label) + self.connectid = self.model.connect('row-inserted', self.update_label) self.track_ref_for_deletion("model") def update_label(self, *obj): @@ -78,8 +78,8 @@ class BackRefList(EmbeddedList): def right_click(self, obj, event): return - def close(self): - self.model.close() + def _cleanup_local_connects(self): + self.model.disconnect(self.connectid) def is_empty(self): return self.model.count == 0 diff --git a/src/gui/editors/displaytabs/backrefmodel.py b/src/gui/editors/displaytabs/backrefmodel.py index eb4c0749b..0efd1b77e 100644 --- a/src/gui/editors/displaytabs/backrefmodel.py +++ b/src/gui/editors/displaytabs/backrefmodel.py @@ -54,10 +54,18 @@ class BackRefModel(gtk.ListStore): self.count = 0 self.idle = gobject.idle_add(self.load_model().next) - def close(self): + def destroy(self): gobject.source_remove(self.idle) def load_model(self): + """ + Objects can have very large backreferences. To avoid blocking the + interface up to the moment that the model is created, this method is + called via gobject.idle_add. + WARNING: a consequence of above is that loading can still be happening + while the GUI using this model is no longer used. Disconnect any + methods before closing the GUI. + """ self.count = 0 for ref in self.sref_list: self.count += 1 diff --git a/src/gui/editors/editprimary.py b/src/gui/editors/editprimary.py index 6aa9e1bf6..18d77f622 100644 --- a/src/gui/editors/editprimary.py +++ b/src/gui/editors/editprimary.py @@ -178,6 +178,7 @@ class EditPrimary(ManagedWindow.ManagedWindow, DbGUIElement): def _do_close(self, *obj): self._cleanup_db_connects() self.dbstate.disconnect(self.dbstate_connect_key) + self._cleanup_connects() self._cleanup_on_exit() self.get_from_handle = None self.get_from_gramps_id = None @@ -198,6 +199,23 @@ class EditPrimary(ManagedWindow.ManagedWindow, DbGUIElement): for tab in self.__tabs: if hasattr(tab, 'callman'): tab._cleanup_callbacks() + + def _cleanup_connects(self): + """ + Connects to interface elements to things outside the element should be + removed before destroying the interface + """ + self._cleanup_local_connects() + for tab in [tab for tab in self.__tabs if hasattr(tab, '_cleanup_local_connects')]: + tab._cleanup_local_connects() + + def _cleanup_local_connects(self): + """ + Connects to interface elements to things outside the element should be + removed before destroying the interface. This methods cleans connects + of the main interface, not of the displaytabs. + """ + pass def check_for_close(self, handles): """ diff --git a/src/gui/editors/editreference.py b/src/gui/editors/editreference.py index 0aed5afb5..730da2ca4 100644 --- a/src/gui/editors/editreference.py +++ b/src/gui/editors/editreference.py @@ -223,6 +223,7 @@ class EditReference(ManagedWindow.ManagedWindow, DbGUIElement): def close(self,*obj): self._cleanup_db_connects() + self._cleanup_connects() ManagedWindow.ManagedWindow.close(self) self._cleanup_on_exit() @@ -237,3 +238,20 @@ class EditReference(ManagedWindow.ManagedWindow, DbGUIElement): self._cleanup_callbacks() for tab in [tab for tab in self.__tabs if hasattr(tab, 'callman')]: tab._cleanup_callbacks() + + def _cleanup_connects(self): + """ + Connects to interface elements to things outside the element should be + removed before destroying the interface + """ + self._cleanup_local_connects() + for tab in [tab for tab in self.__tabs if hasattr(tab, '_cleanup_local_connects')]: + tab._cleanup_local_connects() + + def _cleanup_local_connects(self): + """ + Connects to interface elements to things outside the element should be + removed before destroying the interface. This methods cleans connects + of the main interface, not of the displaytabs. + """ + pass diff --git a/src/gui/editors/editsecondary.py b/src/gui/editors/editsecondary.py index fa3dd2de0..4f9d78ec1 100644 --- a/src/gui/editors/editsecondary.py +++ b/src/gui/editors/editsecondary.py @@ -142,6 +142,7 @@ class EditSecondary(ManagedWindow.ManagedWindow, DbGUIElement): def close(self, *obj): self._cleanup_db_connects() + self._cleanup_connects() ManagedWindow.ManagedWindow.close(self) self._cleanup_on_exit() @@ -156,3 +157,20 @@ class EditSecondary(ManagedWindow.ManagedWindow, DbGUIElement): self._cleanup_callbacks() for tab in [tab for tab in self.__tabs if hasattr(tab, 'callman')]: tab._cleanup_callbacks() + + def _cleanup_connects(self): + """ + Connects to interface elements to things outside the element should be + removed before destroying the interface + """ + self._cleanup_local_connects() + for tab in [tab for tab in self.__tabs if hasattr(tab, '_cleanup_local_connects')]: + tab._cleanup_local_connects() + + def _cleanup_local_connects(self): + """ + Connects to interface elements to things outside the element should be + removed before destroying the interface. This methods cleans connects + of the main interface, not of the displaytabs. + """ + pass