From 6225faf92da4e68603cc8d9e45c32de8f582ca56 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Mon, 6 Nov 2006 21:27:49 +0000 Subject: [PATCH] 2006-11-06 Don Allingham * src/Editors/_EditPerson.py: Change Unknown Gender dialog to allow the user to specify without going back to the main window * src/plugins/RemoveUnused.py: cleanup svn: r7569 --- gramps2/ChangeLog | 5 +++ gramps2/src/Editors/_EditPerson.py | 40 ++++++++++++++------- gramps2/src/plugins/RemoveUnused.py | 56 +++++++++++++---------------- 3 files changed, 56 insertions(+), 45 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 90df89146..ef414811b 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,8 @@ +2006-11-06 Don Allingham + * src/Editors/_EditPerson.py: Change Unknown Gender dialog to allow + the user to specify without going back to the main window + * src/plugins/RemoveUnused.py: cleanup + 2006-11-06 Alex Roitman * NEWS: Update. diff --git a/gramps2/src/Editors/_EditPerson.py b/gramps2/src/Editors/_EditPerson.py index 222cbbed9..e3c9273a3 100644 --- a/gramps2/src/Editors/_EditPerson.py +++ b/gramps2/src/Editors/_EditPerson.py @@ -467,17 +467,11 @@ class EditPerson(EditPrimary): def _check_for_unknown_gender(self): if self.obj.get_gender() == RelLib.Person.UNKNOWN: - dialog = QuestionDialog2( - _("Unknown gender specified"), - _("The gender of the person is currently unknown. " - "Usually, this is a mistake. You may choose to " - "either continue saving, or returning to the " - "Edit Person dialog to fix the problem."), - _("Continue saving"), _("Return to window"), - self.window) - if not dialog.run(): - return True - return False + d = GenderDialog(self.window) + gender = d.run() + d.destroy() + if gender >= 0: + self.obj.set_gender(gender) def _check_and_update_id(self): original = self.db.get_person_from_handle(self.obj.get_handle()) @@ -567,8 +561,7 @@ class EditPerson(EditPrimary): "enter data or cancel the edit.")) return - if self._check_for_unknown_gender(): - return + self._check_for_unknown_gender() set_birth_death_index(self.db, self.obj) self.window.hide() @@ -705,3 +698,24 @@ class EditPerson(EditPrimary): child_ref_list.insert(target, ref) return child_ref_list + + +class GenderDialog(gtk.MessageDialog): + def __init__(self,parent=None): + gtk.MessageDialog.__init__(self, + parent, + flags=gtk.DIALOG_MODAL, + type=gtk.MESSAGE_QUESTION, + ) + self.set_icon(ICON) + self.set_title('') + + self.set_markup('%s' % + _('Unknown gender specified')) + self.format_secondary_text( + _("The gender of the person is currently unknown. " + "Usually, this is a mistake. Please specify the gender.")) + + self.add_button(_('Male'), RelLib.Person.MALE) + self.add_button(_('Female'), RelLib.Person.FEMALE) + self.add_button(_('Unknown'), RelLib.Person.UNKNOWN) diff --git a/gramps2/src/plugins/RemoveUnused.py b/gramps2/src/plugins/RemoveUnused.py index 8a00ec603..2538e8d38 100644 --- a/gramps2/src/plugins/RemoveUnused.py +++ b/gramps2/src/plugins/RemoveUnused.py @@ -116,7 +116,7 @@ class RemoveUnused: self.place.get_active()) def run_tool(self, clean_events, clean_sources, clean_places): - trans = self.db.transaction_begin("",batch=True) + trans = self.db.transaction_begin("",batch=False) self.db.disable_signals() checker = CheckIntegrity(self.dbstate, self.uistate, trans) if clean_events: @@ -132,7 +132,7 @@ class RemoveUnused: errs = checker.build_report() if errs: - Report(uistate, checker.text.getvalue()) + Report(self.uistate, checker.text.getvalue()) #------------------------------------------------------------------------- # @@ -143,7 +143,11 @@ class CheckIntegrity: def __init__(self, dbstate, uistate, trans): self.db = dbstate.db + self.uistate = uistate self.trans = trans + self.place_cnt = 0 + self.source_cnt = 0 + self.event_cnt = 0 self.progress = Utils.ProgressMeter(_('Checking database'),'') def cleanup_events(self): @@ -152,9 +156,9 @@ class CheckIntegrity: self.event_cnt = 0 for handle in self.db.event_map.keys(): - event = self.db.get_event_from_handle(handle) - if not self.db.find_backlink_handles(handle): - self.db.remove_event(handle) + hlist = [ x for x in self.db.find_backlink_handles(handle)] + if len(hlist) == 0: + self.db.remove_event(handle, self.trans) self.event_cnt += 1 def cleanup_sources(self): @@ -163,26 +167,26 @@ class CheckIntegrity: self.source_cnt = 0 for handle in self.db.event_map.keys(): - event = self.db.get_event_from_handle(handle) - if not self.db.find_backlink_handles(handle): - self.db.remove_event(handle) + hlist = [ x for x in self.db.find_backlink_handles(handle)] + if len(hlist) == 0: + self.db.remove_source(handle, self.trans) self.source_cnt += 1 def cleanup_places(self): self.progress.set_pass(_('Removing unused places'), self.db.get_number_of_places()) - self.source_cnt = 0 + self.place_cnt = 0 for handle in self.db.place_map.keys(): - event = self.db.get_place_from_handle(handle) - if not self.db.find_backlink_handles(handle): - self.db.remove_place(handle) - self.source_cnt += 1 + hlist = [ x for x in self.db.find_backlink_handles(handle)] + if len(hlist) == 0: + self.db.remove_place(handle, self.trans) + self.place_cnt += 1 def build_report(self,cl=0): self.progress.close() - errors = self.event_cnt + self.source_cnt + errors = self.event_cnt + self.source_cnt + self.place_cnt if errors == 0: if cl: @@ -205,6 +209,12 @@ class CheckIntegrity: else: self.text.write(_("%d non-referenced source removed\n") % self.source_cnt) + if self.place_cnt > 0: + if self.place_cnt == 1: + self.text.write(_("1 non-referenced place removed\n")) + else: + self.text.write(_("%d non-referenced place removed\n") % self.place_cnt) + return errors #------------------------------------------------------------------------- @@ -252,24 +262,6 @@ class CheckOptions(Tool.ToolOptions): def __init__(self,name,person_id=None): Tool.ToolOptions.__init__(self,name,person_id) - def set_new_options(self): - self.options_dict = { - 'rm_src' : 1, - 'rm_event' : 1, - 'rm_place' : 1, - } - self.options_help = { - 'rm_src' : ("=0/1","Whether to remove unused sources", - ["Do not remove unused sources","Remove unused sources"], - True), - 'rm_event' : ("=0/1","Whether to remove unused events", - ["Do not remove unused events","Remove unused events"], - True), - 'rm_place' : ("=0/1","Whether to remove unused places", - ["Do not remove unused places","Remove unused places"], - True), - } - #------------------------------------------------------------------------ # #