From 84648709d45d17d8893e28dab6ae87cfdbdff663 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sat, 18 Mar 2006 01:30:23 +0000 Subject: [PATCH] removal of families svn: r6169 --- gramps2/ChangeLog | 6 ++ gramps2/src/DataViews/_FamilyList.py | 21 +----- gramps2/src/DataViews/_FamilyView.py | 53 +++++++++----- gramps2/src/GrampsDb/_DbUtils.py | 106 +++++++++++++++++++++++++++ gramps2/src/GrampsDb/__init__.py | 3 +- 5 files changed, 150 insertions(+), 39 deletions(-) create mode 100644 gramps2/src/GrampsDb/_DbUtils.py diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index cae69b3c7..98d42dfcc 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,9 @@ +2006-03-17 Don Allingham + * src/DataViews/_FamilyView.py: use new Dbutils functions + * src/DataViews/_FamilyList.py: use new Dbutils functions + * src/GrampsDb/_DbUtils.py: new routines to remove families and + family relationships + 2006-03-17 Alex Roitman * help: add new dir with new gnome-doc-utils infrastructure. diff --git a/gramps2/src/DataViews/_FamilyList.py b/gramps2/src/DataViews/_FamilyList.py index af084d262..227305fbf 100644 --- a/gramps2/src/DataViews/_FamilyList.py +++ b/gramps2/src/DataViews/_FamilyList.py @@ -155,28 +155,13 @@ class FamilyListView(PageView.ListView): return True def remove(self,obj): + import GrampsDb + mlist = [] self.selection.selected_foreach(self.blist,mlist) for handle in mlist: - family = self.dbstate.db.get_family_from_handle(handle) - - trans = self.dbstate.db.transaction_begin() - - for phandle in [ family.get_father_handle(), - family.get_mother_handle()]: - if phandle: - person = self.dbstate.db.get_person_from_handle(phandle) - person.remove_family_handle(handle) - self.dbstate.db.commit_person(person,trans) - - for phandle in family.get_child_handle_list(): - person = self.dbstate.db.get_person_from_handle(phandle) - person.remove_parent_family_handle(handle) - self.dbstate.db.commit_person(person,trans) - - self.dbstate.db.remove_family(handle,trans) - self.dbstate.db.transaction_commit(trans,_("Remove Family")) + GrampsDb.remove_family_relationships(handle) self.build_tree() def edit(self,obj): diff --git a/gramps2/src/DataViews/_FamilyView.py b/gramps2/src/DataViews/_FamilyView.py index 1ee782663..8d0001108 100644 --- a/gramps2/src/DataViews/_FamilyView.py +++ b/gramps2/src/DataViews/_FamilyView.py @@ -313,8 +313,8 @@ class FamilyView(PageView.PersonNavView): # name and edit button name = NameDisplay.displayer.display(person) - text = '%s %s' % (cgi.escape(name), - _GenderCode[person.gender]) + fmt = '%s %s' + text = fmt % (cgi.escape(name),_GenderCode[person.gender]) label = GrampsWidgets.MarkupLabel(text) button = GrampsWidgets.IconButton(self.edit_button_press,person.handle) @@ -417,8 +417,10 @@ class FamilyView(PageView.PersonNavView): hbox.set_spacing(12) if is_parent: call_fcn = self.add_parent_family + del_fcn = self.delete_parent_family else: call_fcn = self.add_family + del_fcn = self.delete_family add = GrampsWidgets.IconButton(call_fcn,None,gtk.STOCK_ADD) hbox.pack_start(add,False) @@ -426,7 +428,7 @@ class FamilyView(PageView.PersonNavView): edit = GrampsWidgets.IconButton(self.edit_family,family.handle, gtk.STOCK_EDIT) hbox.pack_start(edit,False) - delete = GrampsWidgets.IconButton(self.delete_family,family.handle, + delete = GrampsWidgets.IconButton(del_fcn,family.handle, gtk.STOCK_REMOVE) hbox.pack_start(delete,False) self.attach.attach(hbox,_BTN_START,_BTN_STOP,self.row,self.row+1) @@ -473,14 +475,14 @@ class FamilyView(PageView.PersonNavView): format = "%s" label = GrampsWidgets.MarkupLabel(format % cgi.escape(title)) - self.attach.attach(label,_PLABEL_START,_PLABEL_STOP,self.row,self.row+1, - xoptions=gtk.FILL|gtk.SHRINK) + self.attach.attach(label,_PLABEL_START,_PLABEL_STOP,self.row, + self.row+1, xoptions=gtk.FILL|gtk.SHRINK) link_label = GrampsWidgets.LinkLabel(self.get_name(handle,True), self.button_press,handle) button = GrampsWidgets.IconButton(self.edit_button_press,handle) - self.attach.attach(GrampsWidgets.LinkBox(link_label,button),_PDATA_START, - _PDATA_STOP,self.row,self.row+1) + self.attach.attach(GrampsWidgets.LinkBox(link_label,button), + _PDATA_START,_PDATA_STOP,self.row,self.row+1) self.row += 1 def write_child(self,title,handle): @@ -490,23 +492,24 @@ class FamilyView(PageView.PersonNavView): format = "%s" label = GrampsWidgets.MarkupLabel(format % cgi.escape(title)) - self.attach.attach(label,_CLABEL_START,_CLABEL_STOP,self.row,self.row+1, - xoptions=gtk.FILL|gtk.SHRINK) + self.attach.attach(label,_CLABEL_START,_CLABEL_STOP,self.row, + self.row+1,xoptions=gtk.FILL|gtk.SHRINK) link_label = GrampsWidgets.LinkLabel(self.get_name(handle,True), self.button_press,handle) button = GrampsWidgets.IconButton(self.edit_button_press,handle) - self.attach.attach(GrampsWidgets.LinkBox(link_label,button),_CDATA_START, - _CDATA_STOP,self.row,self.row+1, - xoptions=gtk.EXPAND|gtk.FILL) + self.attach.attach(GrampsWidgets.LinkBox(link_label,button), + _CDATA_START, _CDATA_STOP, self.row, self.row+1, + xoptions=gtk.EXPAND|gtk.FILL) self.row += 1 if self.show_details: value = self.info_string(handle) if value: - self.attach.attach(GrampsWidgets.BasicLabel(value),_CDTLS_START, - _CDTLS_STOP,self.row, self.row+1) + self.attach.attach(GrampsWidgets.BasicLabel(value), + _CDTLS_START, _CDTLS_STOP, self.row, + self.row+1) self.row += 1 def write_data(self,title,start_col=_SDATA_START,stop_col=_SDATA_STOP): @@ -582,9 +585,7 @@ class FamilyView(PageView.PersonNavView): else: pname = None dobj = None - value = { - 'event_type' : ename, - } + value = { 'event_type' : ename, } if dobj: if pname: @@ -615,8 +616,9 @@ class FamilyView(PageView.PersonNavView): value = self.info_string(handle) if value: - self.attach.attach(GrampsWidgets.BasicLabel(value),_PDTLS_START, - _PDTLS_STOP,self.row, self.row+1) + self.attach.attach(GrampsWidgets.BasicLabel(value), + _PDTLS_START, _PDTLS_STOP, + self.row, self.row+1) self.row += 1 if not self.write_marriage(family): self.write_relationship(family) @@ -687,7 +689,18 @@ class FamilyView(PageView.PersonNavView): def delete_family(self,obj,event,handle): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: - print "Delete Family",handle + import GrampsDb + GrampsDb.remove_parent_from_family(self.dbstate.db, + self.dbstate.active.handle, + handle) + + def delete_parent_family(self,obj,event,handle): + if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: + import GrampsDb + GrampsDb.remove_child_from_family(self.dbstate.db, + self.dbstate.active.handle, + handle) def change_to(self,obj,handle): self.dbstate.change_active_handle(handle) + diff --git a/gramps2/src/GrampsDb/_DbUtils.py b/gramps2/src/GrampsDb/_DbUtils.py new file mode 100644 index 000000000..0463926fd --- /dev/null +++ b/gramps2/src/GrampsDb/_DbUtils.py @@ -0,0 +1,106 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2004-2005 Donald N. Allingham +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id: __init__.py 6086 2006-03-06 03:54:58Z dallingham $ + + +def remove_family_relationships(db, family_handle, trans=None): + family = db.get_family_from_handle(handle) + + if trans == None: + need_commit = True + trans = db.transaction_begin() + else: + need_commit = False + + for phandle in [ family.get_father_handle(), + family.get_mother_handle()]: + if phandle: + person = db.get_person_from_handle(phandle) + person.remove_family_handle(handle) + db.commit_person(person,trans) + + for phandle in family.get_child_handle_list(): + person = db.get_person_from_handle(phandle) + person.remove_parent_family_handle(handle) + db.commit_person(person,trans) + + db.remove_family(handle,trans) + + if need_commit: + db.transaction_commit(trans,_("Remove Family")) + +def remove_parent_from_family(db, person_handle, family_handle, trans=None): + """ + Removes a person as either the father or mother of a family, + deleting the family if it becomes empty. + """ + person = db.get_person_from_handle(person_handle) + family = db.get_family_from_handle(family_handle) + + if trans == None: + need_commit = True + trans = db.transaction_begin() + else: + need_commit = False + + person.remove_family_handle(family_handle) + if family.get_father_handle() == person_handle: + family.set_father_handle(None) + elif family.get_mother_handle() == person_handle: + family.set_mother_handle(None) + + if (not family.get_father_handle() and not family.get_mother_handle() and + len(family.get_child_handle_list()) <= 1): + db.remove_family(family_handle, trans) + msg = _("Remove father from family") + else: + db.commit_family(family, trans) + msg = _("Remove mother from family") + db.commit_person(person, trans) + + if need_commit: + db.transaction_commit(trans,msg) + +def remove_child_from_family(db, person_handle, family_handle, trans=None): + """ + Removes a person as a child of the family, deleting the family if + it becomes empty. + """ + person = db.get_person_from_handle(person_handle) + family = db.get_family_from_handle(family_handle) + person.remove_parent_family_handle(family_handle) + family.remove_child_handle(person_handle) + + if trans == None: + need_commit = True + trans = db.transaction_begin() + else: + need_commit = False + + if (not family.get_father_handle() and not family.get_mother_handle() and + len(family.get_child_handle_list()) <= 1): + db.remove_family(family_handle, trans) + else: + db.commit_family(family, trans) + db.commit_person(person, trans) + + if need_commit: + db.transaction_commit(trans,_("Remove child from family")) diff --git a/gramps2/src/GrampsDb/__init__.py b/gramps2/src/GrampsDb/__init__.py index fe85ca0b5..43c99bd81 100644 --- a/gramps2/src/GrampsDb/__init__.py +++ b/gramps2/src/GrampsDb/__init__.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2004-2005 Donald N. Allingham +# Copyright (C) 2004-2006 Donald N. Allingham # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -55,3 +55,4 @@ from _GrampsDbExceptions import GrampsDbException from _GrampsDBCallback import GrampsDBCallback +from _DbUtils import *