From 68db1c3efa15af6b7ee3b8e50b3adb9a2598a306 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 9 Oct 2006 03:57:41 +0000 Subject: [PATCH] * src/GrampsDb/_GrampsDbBase.py: error message on disk space full * src/Bookmarks.py: removed deleted items svn: r7375 --- gramps2/ChangeLog | 2 + gramps2/src/Bookmarks.py | 57 +++++++++++++++++++++------ gramps2/src/GrampsDb/_GrampsDbBase.py | 30 ++++++++------ 3 files changed, 67 insertions(+), 22 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 38f6e3036..a7f70c061 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -3,6 +3,8 @@ * src/plugins/DetDescendantReport.py: fix DDR-Endnotes indent 2006-10-08 Don Allingham + * src/GrampsDb/_GrampsDbBase.py: error message on disk space full + * src/Bookmarks.py: removed deleted items * src/Editors/_EditReference.py: call cancel_and_close on window cancel * src/DisplayTabs/_SourceRefModel.py: remove debug diff --git a/gramps2/src/Bookmarks.py b/gramps2/src/Bookmarks.py index 1ce4d59d8..39e38c9f6 100644 --- a/gramps2/src/Bookmarks.py +++ b/gramps2/src/Bookmarks.py @@ -85,6 +85,14 @@ class Bookmarks : self.bookmarks = bookmarks self.active = DISABLED self.action_group = gtk.ActionGroup('Bookmarks') + self.connect_signals() + self.dbstate.connect('database-changed', self.db_changed) + + def db_changed(self, data): + self.connect_signals() + + def connect_signals(self): + self.dbstate.db.connect('person-delete', self.remove_handles) def update_bookmarks(self, bookmarks): self.bookmarks = bookmarks @@ -110,14 +118,22 @@ class Bookmarks : if len(self.bookmarks) > 0: f.write('') + + new_list = [] for item in self.bookmarks: - label, obj = self.make_label(item) - func = self.callback(item) - action_id = "BM:%s" % item - actions.append((action_id,None,label,None,None,func)) - f.write('' % action_id) - count +=1 + try: + label, obj = self.make_label(item) + func = self.callback(item) + action_id = "BM:%s" % item + actions.append((action_id,None,label,None,None,func)) + f.write('' % action_id) + count +=1 + new_list.append(item) + except AttributeError: + pass f.write('') + self.bookmarks = new_list + f.write(_btm) self.action_group.add_actions(actions) self.uistate.uimanager.insert_action_group(self.action_group,1) @@ -133,23 +149,24 @@ class Bookmarks : def callback(self, handle): return make_callback(handle, self.dbstate.change_active_handle) - def add(self,person_handle): + def add(self, person_handle): """appends the person to the bottom of the bookmarks""" if person_handle not in self.bookmarks: self.bookmarks.append(person_handle) self.redraw() - def remove_people(self,person_handle_list): + def remove_handles(self, handle_list): """ Removes people from the list of bookmarked people. This function is for use *outside* the bookmark editor (removal when person is deleted or merged away). """ + modified = False - for person_handle in person_handle_list: - if person_handle in self.bookmarks: - self.bookmarks.remove(person_handle) + for handle in handle_list: + if handle in self.bookmarks: + self.bookmarks.remove(handle) modified = True if modified: self.redraw() @@ -285,6 +302,9 @@ class FamilyBookmarks(ListBookmarks) : name = Utils.family_name(obj, self.dbstate.db) return ("%s [%s]" % (name, obj.gramps_id), obj) + def connect_signals(self): + self.dbstate.db.connect('family-delete', self.remove_handles) + class EventBookmarks(ListBookmarks) : "Handle the bookmarks interface for Gramps" @@ -300,6 +320,9 @@ class EventBookmarks(ListBookmarks) : name = obj.get_description() return ("%s [%s]" % (name, obj.gramps_id), obj) + def connect_signals(self): + self.dbstate.db.connect('event-delete', self.remove_handles) + class SourceBookmarks(ListBookmarks) : "Handle the bookmarks interface for Gramps" def __init__(self,dbstate,uistate,bookmarks, goto_handle): @@ -311,6 +334,9 @@ class SourceBookmarks(ListBookmarks) : name = obj.get_title() return ("%s [%s]" % (name, obj.gramps_id), obj) + def connect_signals(self): + self.dbstate.db.connect('source-delete', self.remove_handles) + class MediaBookmarks(ListBookmarks) : "Handle the bookmarks interface for Gramps" @@ -323,6 +349,9 @@ class MediaBookmarks(ListBookmarks) : name = obj.get_description() return ("%s [%s]" % (name, obj.gramps_id), obj) + def connect_signals(self): + self.dbstate.db.connect('media-delete', self.remove_handles) + class RepoBookmarks(ListBookmarks) : "Handle the bookmarks interface for Gramps" @@ -335,6 +364,9 @@ class RepoBookmarks(ListBookmarks) : name = obj.get_name() return ("%s [%s]" % (name, obj.gramps_id), obj) + def connect_signals(self): + self.dbstate.db.connect('repository-delete', self.remove_handles) + class PlaceBookmarks(ListBookmarks) : "Handle the bookmarks interface for Gramps" @@ -347,5 +379,8 @@ class PlaceBookmarks(ListBookmarks) : name = obj.get_title() return ("%s [%s]" % (name, obj.gramps_id), obj) + def connect_signals(self): + self.dbstate.db.connect('place-delete', self.remove_handles) + def make_callback(n,f): return lambda x: f(n) diff --git a/gramps2/src/GrampsDb/_GrampsDbBase.py b/gramps2/src/GrampsDb/_GrampsDbBase.py index 39b6da359..e3c4b4470 100644 --- a/gramps2/src/GrampsDb/_GrampsDbBase.py +++ b/gramps2/src/GrampsDb/_GrampsDbBase.py @@ -413,18 +413,26 @@ class GrampsDbBase(GrampsDBCallback): handle = str(obj.handle) self._update_reference_map(obj, transaction) - - if transaction.batch: - data_map[handle] = obj.serialize() - old_data = None - else: - old_data = data_map.get(handle) - new_data = obj.serialize() - transaction.add(key, handle, old_data, new_data) - if old_data: - update_list.append((handle, new_data)) + + try: + if transaction.batch: + data_map[handle] = obj.serialize() + old_data = None else: - add_list.append((handle, new_data)) + old_data = data_map.get(handle) + new_data = obj.serialize() + transaction.add(key, handle, old_data, new_data) + if old_data: + update_list.append((handle, new_data)) + else: + add_list.append((handle, new_data)) + except db.DBNoSpaceError, msg: + from QuestionDialog import ErrorDialog + + ErrorDialog(_("Out of disk space"), + _("Your data cannot be saved because you are out " + "of disk space. Please free up some disk space " + "and try again.\n\n%s") % msg[1]) return old_data def commit_person(self, person, transaction, change_time=None):