removal of families

svn: r6169
This commit is contained in:
Don Allingham 2006-03-18 01:30:23 +00:00
parent 11cc321764
commit 84648709d4
5 changed files with 150 additions and 39 deletions

View File

@ -1,3 +1,9 @@
2006-03-17 Don Allingham <don@gramps-project.org>
* 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 <shura@gramps-project.org> 2006-03-17 Alex Roitman <shura@gramps-project.org>
* help: add new dir with new gnome-doc-utils infrastructure. * help: add new dir with new gnome-doc-utils infrastructure.

View File

@ -155,28 +155,13 @@ class FamilyListView(PageView.ListView):
return True return True
def remove(self,obj): def remove(self,obj):
import GrampsDb
mlist = [] mlist = []
self.selection.selected_foreach(self.blist,mlist) self.selection.selected_foreach(self.blist,mlist)
for handle in mlist: for handle in mlist:
family = self.dbstate.db.get_family_from_handle(handle) GrampsDb.remove_family_relationships(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"))
self.build_tree() self.build_tree()
def edit(self,obj): def edit(self,obj):

View File

@ -313,8 +313,8 @@ class FamilyView(PageView.PersonNavView):
# name and edit button # name and edit button
name = NameDisplay.displayer.display(person) name = NameDisplay.displayer.display(person)
text = '<span size="larger" weight="bold">%s %s</span>' % (cgi.escape(name), fmt = '<span size="larger" weight="bold">%s %s</span>'
_GenderCode[person.gender]) text = fmt % (cgi.escape(name),_GenderCode[person.gender])
label = GrampsWidgets.MarkupLabel(text) label = GrampsWidgets.MarkupLabel(text)
button = GrampsWidgets.IconButton(self.edit_button_press,person.handle) button = GrampsWidgets.IconButton(self.edit_button_press,person.handle)
@ -417,8 +417,10 @@ class FamilyView(PageView.PersonNavView):
hbox.set_spacing(12) hbox.set_spacing(12)
if is_parent: if is_parent:
call_fcn = self.add_parent_family call_fcn = self.add_parent_family
del_fcn = self.delete_parent_family
else: else:
call_fcn = self.add_family call_fcn = self.add_family
del_fcn = self.delete_family
add = GrampsWidgets.IconButton(call_fcn,None,gtk.STOCK_ADD) add = GrampsWidgets.IconButton(call_fcn,None,gtk.STOCK_ADD)
hbox.pack_start(add,False) hbox.pack_start(add,False)
@ -426,7 +428,7 @@ class FamilyView(PageView.PersonNavView):
edit = GrampsWidgets.IconButton(self.edit_family,family.handle, edit = GrampsWidgets.IconButton(self.edit_family,family.handle,
gtk.STOCK_EDIT) gtk.STOCK_EDIT)
hbox.pack_start(edit,False) hbox.pack_start(edit,False)
delete = GrampsWidgets.IconButton(self.delete_family,family.handle, delete = GrampsWidgets.IconButton(del_fcn,family.handle,
gtk.STOCK_REMOVE) gtk.STOCK_REMOVE)
hbox.pack_start(delete,False) hbox.pack_start(delete,False)
self.attach.attach(hbox,_BTN_START,_BTN_STOP,self.row,self.row+1) self.attach.attach(hbox,_BTN_START,_BTN_STOP,self.row,self.row+1)
@ -473,14 +475,14 @@ class FamilyView(PageView.PersonNavView):
format = "%s" format = "%s"
label = GrampsWidgets.MarkupLabel(format % cgi.escape(title)) label = GrampsWidgets.MarkupLabel(format % cgi.escape(title))
self.attach.attach(label,_PLABEL_START,_PLABEL_STOP,self.row,self.row+1, self.attach.attach(label,_PLABEL_START,_PLABEL_STOP,self.row,
xoptions=gtk.FILL|gtk.SHRINK) self.row+1, xoptions=gtk.FILL|gtk.SHRINK)
link_label = GrampsWidgets.LinkLabel(self.get_name(handle,True), link_label = GrampsWidgets.LinkLabel(self.get_name(handle,True),
self.button_press,handle) self.button_press,handle)
button = GrampsWidgets.IconButton(self.edit_button_press,handle) button = GrampsWidgets.IconButton(self.edit_button_press,handle)
self.attach.attach(GrampsWidgets.LinkBox(link_label,button),_PDATA_START, self.attach.attach(GrampsWidgets.LinkBox(link_label,button),
_PDATA_STOP,self.row,self.row+1) _PDATA_START,_PDATA_STOP,self.row,self.row+1)
self.row += 1 self.row += 1
def write_child(self,title,handle): def write_child(self,title,handle):
@ -490,14 +492,14 @@ class FamilyView(PageView.PersonNavView):
format = "%s" format = "%s"
label = GrampsWidgets.MarkupLabel(format % cgi.escape(title)) label = GrampsWidgets.MarkupLabel(format % cgi.escape(title))
self.attach.attach(label,_CLABEL_START,_CLABEL_STOP,self.row,self.row+1, self.attach.attach(label,_CLABEL_START,_CLABEL_STOP,self.row,
xoptions=gtk.FILL|gtk.SHRINK) self.row+1,xoptions=gtk.FILL|gtk.SHRINK)
link_label = GrampsWidgets.LinkLabel(self.get_name(handle,True), link_label = GrampsWidgets.LinkLabel(self.get_name(handle,True),
self.button_press,handle) self.button_press,handle)
button = GrampsWidgets.IconButton(self.edit_button_press,handle) button = GrampsWidgets.IconButton(self.edit_button_press,handle)
self.attach.attach(GrampsWidgets.LinkBox(link_label,button),_CDATA_START, self.attach.attach(GrampsWidgets.LinkBox(link_label,button),
_CDATA_STOP,self.row,self.row+1, _CDATA_START, _CDATA_STOP, self.row, self.row+1,
xoptions=gtk.EXPAND|gtk.FILL) xoptions=gtk.EXPAND|gtk.FILL)
self.row += 1 self.row += 1
@ -505,8 +507,9 @@ class FamilyView(PageView.PersonNavView):
if self.show_details: if self.show_details:
value = self.info_string(handle) value = self.info_string(handle)
if value: if value:
self.attach.attach(GrampsWidgets.BasicLabel(value),_CDTLS_START, self.attach.attach(GrampsWidgets.BasicLabel(value),
_CDTLS_STOP,self.row, self.row+1) _CDTLS_START, _CDTLS_STOP, self.row,
self.row+1)
self.row += 1 self.row += 1
def write_data(self,title,start_col=_SDATA_START,stop_col=_SDATA_STOP): def write_data(self,title,start_col=_SDATA_START,stop_col=_SDATA_STOP):
@ -582,9 +585,7 @@ class FamilyView(PageView.PersonNavView):
else: else:
pname = None pname = None
dobj = None dobj = None
value = { value = { 'event_type' : ename, }
'event_type' : ename,
}
if dobj: if dobj:
if pname: if pname:
@ -615,8 +616,9 @@ class FamilyView(PageView.PersonNavView):
value = self.info_string(handle) value = self.info_string(handle)
if value: if value:
self.attach.attach(GrampsWidgets.BasicLabel(value),_PDTLS_START, self.attach.attach(GrampsWidgets.BasicLabel(value),
_PDTLS_STOP,self.row, self.row+1) _PDTLS_START, _PDTLS_STOP,
self.row, self.row+1)
self.row += 1 self.row += 1
if not self.write_marriage(family): if not self.write_marriage(family):
self.write_relationship(family) self.write_relationship(family)
@ -687,7 +689,18 @@ class FamilyView(PageView.PersonNavView):
def delete_family(self,obj,event,handle): def delete_family(self,obj,event,handle):
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1: 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): def change_to(self,obj,handle):
self.dbstate.change_active_handle(handle) self.dbstate.change_active_handle(handle)

View File

@ -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"))

View File

@ -1,7 +1,7 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # 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 # 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 # 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 _GrampsDBCallback import GrampsDBCallback
from _DbUtils import *