diff --git a/ChangeLog b/ChangeLog index 19cfda78a..c56e4431a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-10-21 Benny Malengier + * src/DisplayTabs/_EmbeddedList.py: during rebuild, don't do select change + * src/DisplayTabs/_NoteTab.py: connect db note changes so tab updates + * src/DisplayTabs/_ButtonTab.py: avoid double call of selection_change + * src/DisplayTabs/_GrampsTab.py: method to add db connects, and set connects + * src/Editors/_EditPrimary.py: on add tab pass db connection method + * src/Editors/_EditSecondary.py: on add tab pass db connection method + * src/Editors/_EditReference.py: on add tab pass db connection method + 2007-10-21 Benny Malengier * src/Editors/_EditPerson.py: If a family changes, rebuild family backref of all open editors. issue #1309, causing corrupt database. diff --git a/src/DisplayTabs/_ButtonTab.py b/src/DisplayTabs/_ButtonTab.py index c44260e38..06388cbdf 100644 --- a/src/DisplayTabs/_ButtonTab.py +++ b/src/DisplayTabs/_ButtonTab.py @@ -90,6 +90,7 @@ class ButtonTab(GrampsTab): @param move_buttons: Add up and down button to the Notebook tab or not @type name: bool """ + self.dirty_selection = False GrampsTab.__init__(self,dbstate, uistate, track, name) self.tooltips = gtk.Tooltips() self.create_buttons(share_button, move_buttons, jump_button) @@ -237,6 +238,10 @@ class ButtonTab(GrampsTab): """ # Comparing to None is important, as empty strings # and 0 can be returned + # This method is called as callback on change, and can be called + # explicitly, dirty_selection must make sure they do not interact + if self.dirty_selection: + return if self.get_selected() != None: self.edit_btn.set_sensitive(True) if self.jump_btn: diff --git a/src/DisplayTabs/_EmbeddedList.py b/src/DisplayTabs/_EmbeddedList.py index 019691b30..f2f0b2629 100644 --- a/src/DisplayTabs/_EmbeddedList.py +++ b/src/DisplayTabs/_EmbeddedList.py @@ -402,6 +402,8 @@ class EmbeddedList(ButtonTab): Rebuilds the data in the database by creating a new model, using the build_model function passed at creation time. """ + #during rebuild, don't do _selection_changed + self.dirty_selection = True try: self.model = self.build_model(self.get_data(), self.dbstate.db) except AttributeError, msg: @@ -413,4 +415,6 @@ class EmbeddedList(ButtonTab): self.tree.set_model(self.model) self._set_label() + #model and tree are reset, allow _selection_changed again, and force it + self.dirty_selection = False self._selection_changed() diff --git a/src/DisplayTabs/_GrampsTab.py b/src/DisplayTabs/_GrampsTab.py index 2ea666d9a..ec14da672 100644 --- a/src/DisplayTabs/_GrampsTab.py +++ b/src/DisplayTabs/_GrampsTab.py @@ -66,6 +66,8 @@ class GrampsTab(gtk.HBox): self.track = track self.changed = False + self._add_db_signal = None + # save name used for notebook label, and build the widget used # for the label @@ -135,6 +137,19 @@ class GrampsTab(gtk.HBox): """ return self.label_container + def add_db_signal_callback(self, add_db_signal): + """ + The grampstab must be able to react to database signals, however + on destroy of the editor to which the tab is attached, these signals + must be disconnected. + This method sets the method with which to add database signals on tabs, + typically EditPrimary and EditSecondary add tabs, and have methods to + connect signals and register them so they are correctly disconnected + on close + """ + self._add_db_signal = add_db_signal + self.connect_db_signals() + def _set_label(self): """ Updates the label based of if the tab contains information. Tabs @@ -158,4 +173,12 @@ class GrampsTab(gtk.HBox): can be used to add widgets to the interface. """ pass - \ No newline at end of file + + def connect_db_signals(self): + """ + Function to connect db signals to GrampsTab methods. This function + should be overridden in the derived class. + It is called after the interface is build. + """ + pass + diff --git a/src/DisplayTabs/_NoteTab.py b/src/DisplayTabs/_NoteTab.py index edfd091b9..40c55fd32 100644 --- a/src/DisplayTabs/_NoteTab.py +++ b/src/DisplayTabs/_NoteTab.py @@ -80,6 +80,12 @@ class NoteTab(EmbeddedList): EmbeddedList.__init__(self, dbstate, uistate, track, _("Notes"), NoteModel, share=True, move=True) + def connect_db_signals(self): + #connect external remove/change of object to rebuild of grampstab + self._add_db_signal('note-delete', self.note_delete) + self._add_db_signal('note-rebuild', self.rebuild) + self._add_db_signal('note-update',self.note_update) + def get_editor(self): pass @@ -116,7 +122,7 @@ class NoteTab(EmbeddedList): try: from Editors import EditNote EditNote(self.dbstate, self.uistate, self.track, note, - self.edit_callback, self.callertitle, + callertitle = self.callertitle, extratype = [self.notetype] ) except Errors.WindowActiveError: pass @@ -132,7 +138,29 @@ class NoteTab(EmbeddedList): def get_icon_name(self): return 'gramps-notes' - - def edit_callback(self, name): - self.changed = True - self.rebuild() + + def note_delete(self, del_note_handle_list): + """ + Outside of this tab note objects have been deleted. Check if tab + and object must be changed. + Note: delete of object will cause reference on database to be removed, + so this method need not do this + """ + rebuild = False + for handle in del_note_handle_list : + while self.data.count(handle) > 0: + self.data.remove(handle) + rebuild = True + if rebuild: + self.rebuild() + + def note_update(self, upd_note_handle_list): + """ + Outside of this tab note objects have been updated. Check if tab + and object must be updated. + """ + ref_handles = self.data + for handle in upd_note_handle_list : + if handle in self.data: + self.rebuild() + break diff --git a/src/Editors/_EditPrimary.py b/src/Editors/_EditPrimary.py index 1771535bb..4a3602c79 100644 --- a/src/Editors/_EditPrimary.py +++ b/src/Editors/_EditPrimary.py @@ -106,6 +106,7 @@ class EditPrimary(ManagedWindow.ManagedWindow): def _add_tab(self,notebook,page): notebook.insert_page(page, page.get_tab_widget()) + page.add_db_signal_callback(self._add_db_signal) return page def _cleanup_on_exit(self): diff --git a/src/Editors/_EditReference.py b/src/Editors/_EditReference.py index 88b3b93c1..fe230e4ff 100644 --- a/src/Editors/_EditReference.py +++ b/src/Editors/_EditReference.py @@ -103,6 +103,7 @@ class EditReference(ManagedWindow.ManagedWindow): def _add_tab(self,notebook,page): notebook.insert_page(page, page.get_tab_widget()) + page.add_db_signal_callback(self._add_db_signal) return page def _add_db_signal(self, name, callback): diff --git a/src/Editors/_EditSecondary.py b/src/Editors/_EditSecondary.py index 3354d49d3..487befc87 100644 --- a/src/Editors/_EditSecondary.py +++ b/src/Editors/_EditSecondary.py @@ -99,6 +99,7 @@ class EditSecondary(ManagedWindow.ManagedWindow): def _add_tab(self,notebook,page): notebook.insert_page(page, page.get_tab_widget()) + page.add_db_signal_callback(self._add_db_signal) return page def _cleanup_on_exit(self):