* src/MergePeople.py: Adapt to RelLib changes.
* src/plugins/Merge.py: Properly call MergePeople; properly call update; set dbstate and uistate as instance attributes. svn: r6456
This commit is contained in:
parent
0d35757371
commit
b695db42c4
@ -1,4 +1,8 @@
|
|||||||
2006-04-26 Alex Roitman <shura@gramps-project.org>
|
2006-04-26 Alex Roitman <shura@gramps-project.org>
|
||||||
|
* src/MergePeople.py: Adapt to RelLib changes.
|
||||||
|
* src/plugins/Merge.py: Properly call MergePeople; properly call
|
||||||
|
update; set dbstate and uistate as instance attributes.
|
||||||
|
|
||||||
* src/plugins/Check.py: Adapt to new family relation types.
|
* src/plugins/Check.py: Adapt to new family relation types.
|
||||||
|
|
||||||
2006-04-26 Don Allingham <don@gramps-project.org>
|
2006-04-26 Don Allingham <don@gramps-project.org>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
# Copyright (C) 2000-2005 Donald N. Allingham
|
# Copyright (C) 2000-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
|
||||||
@ -43,40 +43,41 @@ import pango
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
import RelLib
|
import RelLib
|
||||||
from PluginUtils import ReportUtils
|
from PluginUtils import ReportUtils
|
||||||
import Utils
|
|
||||||
import NameDisplay
|
import NameDisplay
|
||||||
import const
|
import const
|
||||||
import DateHandler
|
import DateHandler
|
||||||
import QuestionDialog
|
import QuestionDialog
|
||||||
import GrampsDisplay
|
import GrampsDisplay
|
||||||
|
import ManagedWindow
|
||||||
|
import Utils
|
||||||
|
|
||||||
sex = ( _("female"), _("male"), _("unknown"))
|
sex = ( _("female"), _("male"), _("unknown"))
|
||||||
|
|
||||||
class Compare:
|
class Compare(ManagedWindow.ManagedWindow):
|
||||||
|
|
||||||
|
def __init__(self, dbstate, uistate, person1, person2, update) :
|
||||||
|
|
||||||
|
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
|
||||||
|
|
||||||
def __init__(self, db, person1, person2, update) :
|
|
||||||
self.glade = gtk.glade.XML(const.merge_glade, "merge")
|
self.glade = gtk.glade.XML(const.merge_glade, "merge")
|
||||||
self.top = self.glade.get_widget('merge')
|
window = self.glade.get_widget('merge')
|
||||||
self.text1 = self.glade.get_widget('text1')
|
self.text1 = self.glade.get_widget('text1')
|
||||||
self.text2 = self.glade.get_widget('text2')
|
self.text2 = self.glade.get_widget('text2')
|
||||||
self.db = db
|
self.db = dbstate.db
|
||||||
|
|
||||||
self.p1 = person1
|
self.p1 = person1
|
||||||
self.p2 = person2
|
self.p2 = person2
|
||||||
self.update = update
|
self.update = update
|
||||||
|
|
||||||
Utils.set_titles(self.top,self.glade.get_widget('title'),
|
self.set_window(window,self.glade.get_widget('title'),
|
||||||
_("Compare People"))
|
_("Compare People"))
|
||||||
self.display(self.text1.get_buffer(), person1)
|
self.display(self.text1.get_buffer(), person1)
|
||||||
self.display(self.text2.get_buffer(), person2)
|
self.display(self.text2.get_buffer(), person2)
|
||||||
|
|
||||||
self.glade.get_widget('cancel').connect('clicked',self.cancel)
|
self.glade.get_widget('cancel').connect('clicked',self.close)
|
||||||
self.glade.get_widget('close').connect('clicked',self.merge)
|
self.glade.get_widget('close').connect('clicked',self.merge)
|
||||||
self.glade.get_widget('help').connect('clicked',self.help)
|
self.glade.get_widget('help').connect('clicked',self.help)
|
||||||
|
|
||||||
def cancel(self,obj):
|
|
||||||
self.top.destroy()
|
|
||||||
|
|
||||||
def help(self,obj):
|
def help(self,obj):
|
||||||
"""Display the relevant portion of GRAMPS manual"""
|
"""Display the relevant portion of GRAMPS manual"""
|
||||||
GrampsDisplay.help('adv-merge-people')
|
GrampsDisplay.help('adv-merge-people')
|
||||||
@ -99,7 +100,7 @@ class Compare:
|
|||||||
merge = MergePeople(self.db,self.p1,self.p2)
|
merge = MergePeople(self.db,self.p1,self.p2)
|
||||||
else:
|
else:
|
||||||
merge = MergePeople(self.db,self.p2,self.p1)
|
merge = MergePeople(self.db,self.p2,self.p1)
|
||||||
self.top.destroy()
|
self.close()
|
||||||
merge.merge()
|
merge.merge()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
@ -135,18 +136,20 @@ class Compare:
|
|||||||
for name in nlist:
|
for name in nlist:
|
||||||
self.add(tobj,normal,NameDisplay.displayer.display_name(name))
|
self.add(tobj,normal,NameDisplay.displayer.display_name(name))
|
||||||
|
|
||||||
elist = person.get_event_list()
|
elist = person.get_event_ref_list()
|
||||||
if len(elist) > 0:
|
if len(elist) > 0:
|
||||||
self.add(tobj,title,_("Events"))
|
self.add(tobj,title,_("Events"))
|
||||||
for event_handle in person.get_event_list():
|
for event_ref in person.get_event_ref_list():
|
||||||
name = self.db.get_event_from_handle(event_handle).get_name()
|
event_handle = event_ref.ref
|
||||||
|
name = str(
|
||||||
|
self.db.get_event_from_handle(event_handle).get_type())
|
||||||
self.add(tobj,normal,"%s:\t%s" % (name,self.get_event_info(event_handle)))
|
self.add(tobj,normal,"%s:\t%s" % (name,self.get_event_info(event_handle)))
|
||||||
plist = person.get_parent_family_handle_list()
|
plist = person.get_parent_family_handle_list()
|
||||||
|
|
||||||
if len(plist) > 0:
|
if len(plist) > 0:
|
||||||
self.add(tobj,title,_("Parents"))
|
self.add(tobj,title,_("Parents"))
|
||||||
for fid in person.get_parent_family_handle_list():
|
for fid in person.get_parent_family_handle_list():
|
||||||
(fn,mn,gid) = self.get_parent_info(fid[0])
|
(fn,mn,gid) = self.get_parent_info(fid)
|
||||||
self.add(tobj,normal,"%s:\t%s" % (_('Family ID'),gid))
|
self.add(tobj,normal,"%s:\t%s" % (_('Family ID'),gid))
|
||||||
if fn:
|
if fn:
|
||||||
self.add(tobj,indent,"%s:\t%s" % (_('Father'),fn))
|
self.add(tobj,indent,"%s:\t%s" % (_('Father'),fn))
|
||||||
@ -172,8 +175,8 @@ class Compare:
|
|||||||
if event:
|
if event:
|
||||||
self.add(tobj,indent,"%s:\t%s" % (
|
self.add(tobj,indent,"%s:\t%s" % (
|
||||||
_('Marriage'), self.get_event_info(event.get_handle())))
|
_('Marriage'), self.get_event_info(event.get_handle())))
|
||||||
for child_id in family.get_child_handle_list():
|
for child_ref in family.get_child_ref_list():
|
||||||
child = self.db.get_person_from_handle(child_id)
|
child = self.db.get_person_from_handle(child_ref.ref)
|
||||||
self.add(tobj,indent,"%s:\t%s" % (_('Child'),name_of(child)))
|
self.add(tobj,indent,"%s:\t%s" % (_('Child'),name_of(child)))
|
||||||
else:
|
else:
|
||||||
self.add(tobj,normal,_("No spouses or children found"))
|
self.add(tobj,normal,_("No spouses or children found"))
|
||||||
@ -257,7 +260,7 @@ class MergePeopleUI:
|
|||||||
|
|
||||||
def __init__(self,db,person1,person2,update):
|
def __init__(self,db,person1,person2,update):
|
||||||
glade = gtk.glade.XML(const.merge_glade, 'merge_people')
|
glade = gtk.glade.XML(const.merge_glade, 'merge_people')
|
||||||
top = glade.get_widget('merge_people')
|
window = glade.get_widget('merge_people')
|
||||||
p1 = glade.get_widget('person1')
|
p1 = glade.get_widget('person1')
|
||||||
p2 = glade.get_widget('person2')
|
p2 = glade.get_widget('person2')
|
||||||
n1 = name_of(person1)
|
n1 = name_of(person1)
|
||||||
@ -336,7 +339,7 @@ class MergePeople:
|
|||||||
fam = self.db.get_family_from_handle(h)
|
fam = self.db.get_family_from_handle(h)
|
||||||
print " - family %s has father: %s, mother: %s" % \
|
print " - family %s has father: %s, mother: %s" % \
|
||||||
(h,fam.get_father_handle(),fam.get_mother_handle())
|
(h,fam.get_father_handle(),fam.get_mother_handle())
|
||||||
for h,m1,m2 in person.get_parent_family_handle_list():
|
for h in person.get_parent_family_handle_list():
|
||||||
print " - parent family %s" % h
|
print " - parent family %s" % h
|
||||||
|
|
||||||
def merge(self):
|
def merge(self):
|
||||||
@ -491,14 +494,16 @@ class MergePeople:
|
|||||||
ref2 = self.p2.get_birth_ref()
|
ref2 = self.p2.get_birth_ref()
|
||||||
|
|
||||||
if ref1:
|
if ref1:
|
||||||
new.set_birth_handle(ref1.ref)
|
new.set_birth_ref(ref1)
|
||||||
if ref2:
|
if ref2:
|
||||||
event = self.db.get_event_from_handle(ref2.ref)
|
event = self.db.get_event_from_handle(ref2.ref)
|
||||||
event.set_name('Alternate Birth')
|
event.set_name('Alternate Birth')
|
||||||
self.db.add_event(event,trans)
|
self.db.add_event(event,trans)
|
||||||
new.add_event_handle(event.get_handle())
|
event_ref = RelLib.EventRef()
|
||||||
elif not handle1 and handle2:
|
event_ref.ref = event.get_handle()
|
||||||
new.set_birth_handle(handle2)
|
new.add_event_ref(event_ref)
|
||||||
|
elif not ref1 and ref2:
|
||||||
|
new.set_birth_ref(ref2)
|
||||||
|
|
||||||
def merge_death(self, new, trans):
|
def merge_death(self, new, trans):
|
||||||
"""
|
"""
|
||||||
@ -509,33 +514,37 @@ class MergePeople:
|
|||||||
death event, and the secondary person's death event is added
|
death event, and the secondary person's death event is added
|
||||||
as a 'Alternate Death' event.
|
as a 'Alternate Death' event.
|
||||||
"""
|
"""
|
||||||
handle1 = self.p1.get_death_handle()
|
ref1 = self.p1.get_death_ref()
|
||||||
handle2 = self.p2.get_death_handle()
|
ref2 = self.p2.get_death_ref()
|
||||||
|
|
||||||
if handle1:
|
if ref1:
|
||||||
new.set_death_handle(handle1)
|
new.set_death_ref(ref1)
|
||||||
if handle2:
|
if ref2:
|
||||||
event = self.db.get_event_from_handle(handle2)
|
event = self.db.get_event_from_handle(ref2)
|
||||||
event.set_handle(Utils.create_id())
|
event.set_handle(Utils.create_id())
|
||||||
event.set_name('Alternate Death')
|
event.set_name('Alternate Death')
|
||||||
new.add_event_handle(event.get_handle())
|
event_ref = RelLib.EventRef()
|
||||||
|
event_ref.ref = event.get_handle()
|
||||||
|
new.add_event_ref(event_ref)
|
||||||
self.db.add_event(event,trans)
|
self.db.add_event(event,trans)
|
||||||
elif not handle1 and handle2:
|
elif not ref1 and ref2:
|
||||||
new.set_death_handle(handle2)
|
new.set_death_ref(ref2)
|
||||||
|
|
||||||
def merge_event_lists(self, new):
|
def merge_event_lists(self, new):
|
||||||
"""
|
"""
|
||||||
Merges the events from the two people into the destination
|
Merges the events from the two people into the destination
|
||||||
person. Duplicates are not transferred.
|
person. Duplicates are not transferred.
|
||||||
"""
|
"""
|
||||||
data_list = new.get_event_list()
|
data_list = new.get_event_ref_list()
|
||||||
for handle in self.p1.get_event_list():
|
data_handle_list = [ref.ref for ref in data_list]
|
||||||
if handle not in data_list:
|
|
||||||
data_list.append(handle)
|
add_ref_list1 = [ref for ref in self.p1.get_event_ref_list()
|
||||||
for handle in self.p2.get_event_list():
|
if ref.ref not in data_handle_list]
|
||||||
if handle not in data_list:
|
|
||||||
data_list.append(handle)
|
add_ref_list2 = [ref for ref in self.p2.get_event_ref_list()
|
||||||
new.set_event_list(data_list)
|
if ref.ref not in data_handle_list]
|
||||||
|
|
||||||
|
new.set_event_ref_list(data_list+add_ref_list1+add_ref_list2)
|
||||||
|
|
||||||
def merge_family_information(self, new, trans):
|
def merge_family_information(self, new, trans):
|
||||||
"""
|
"""
|
||||||
@ -575,32 +584,35 @@ class MergePeople:
|
|||||||
for family_handle in parent_list:
|
for family_handle in parent_list:
|
||||||
self.convert_child_ids(family_handle, self.new_handle,
|
self.convert_child_ids(family_handle, self.new_handle,
|
||||||
self.old_handle, trans)
|
self.old_handle, trans)
|
||||||
new.add_parent_family_handle(family_handle, mrel, frel)
|
new.add_parent_family_handle(family_handle)
|
||||||
|
|
||||||
def convert_child_ids(self, fhandle, new_handle, old_handle, trans):
|
def convert_child_ids(self, fhandle, new_handle, old_handle, trans):
|
||||||
"""
|
"""
|
||||||
Search the family associated with fhandle, and replace all
|
Search the family associated with fhandle, and replace
|
||||||
child handles that match old_handle with new_handle.
|
old handle with the new handle in all child references.
|
||||||
"""
|
"""
|
||||||
family = self.db.get_family_from_handle(fhandle)
|
family = self.db.get_family_from_handle(fhandle)
|
||||||
new_child_list = []
|
orig_ref_list = family.get_child_ref_list()
|
||||||
orig_list = family.get_child_ref_list()
|
new_ref_list = []
|
||||||
|
|
||||||
# loop through original child list. If a handle matches the
|
# loop through original child list. If a handle matches the
|
||||||
# old handle, replace it with the new handle if the new handle
|
# old handle, replace it with the new handle if the new handle
|
||||||
# is not already in the list
|
# is not already in the list
|
||||||
|
|
||||||
for child_ref in orig_list:
|
for child_ref in orig_ref_list:
|
||||||
if child_ref.ref == old_handle:
|
if child_ref.ref == old_handle:
|
||||||
if new_handle not in new_child_list:
|
if new_handle not in [ref.ref for ref in new_ref_list]:
|
||||||
new_child_list.append(new_handle)
|
new_ref = RelLib.ChildRef()
|
||||||
elif child_id not in new_child_list:
|
new_ref.ref = new_handle
|
||||||
new_child_list.append(child_id)
|
new_ref_list.append(new_ref)
|
||||||
|
elif child_ref.ref not in [ref.ref for ref in new_ref_list]:
|
||||||
|
new_ref_list.append(child_ref)
|
||||||
|
|
||||||
# compare the new list with the original list. If this list
|
# compare the new list with the original list. If this list
|
||||||
# is different, we need to save the changes to the database.
|
# is different, we need to save the changes to the database.
|
||||||
if new_child_list != orig_list:
|
if [ref.ref for ref in new_ref_list] \
|
||||||
family.set_child_ref_list(new_child_list)
|
!= [ref.ref for ref in orig_ref_list]:
|
||||||
|
family.set_child_ref_list(new_ref_list)
|
||||||
self.db.commit_family(family,trans)
|
self.db.commit_family(family,trans)
|
||||||
|
|
||||||
def merge_relationships(self,new,trans):
|
def merge_relationships(self,new,trans):
|
||||||
@ -668,21 +680,21 @@ class MergePeople:
|
|||||||
|
|
||||||
# a little debugging here
|
# a little debugging here
|
||||||
|
|
||||||
cursor = self.db.get_family_cursor()
|
## cursor = self.db.get_family_cursor()
|
||||||
data = cursor.first()
|
## data = cursor.first()
|
||||||
while data:
|
## while data:
|
||||||
fam = RelLib.Family()
|
## fam = RelLib.Family()
|
||||||
fam.unserialize(data[1])
|
## fam.unserialize(data[1])
|
||||||
if self.p2 in fam.get_child_handle_list():
|
## if self.p2 in [ref.ref for ref in fam.get_child_ref_list()]:
|
||||||
fam.remove_child_handle(self.p2)
|
## fam.remove_child_ref(self.p2)
|
||||||
fam.add_child_handle(self.p1)
|
## fam.add_child_ref(self.p1)
|
||||||
if self.p2 == fam.get_father_handle():
|
## if self.p2 == fam.get_father_handle():
|
||||||
fam.set_father_handle(self.p1)
|
## fam.set_father_handle(self.p1)
|
||||||
if self.p2 == fam.get_mother_handle():
|
## if self.p2 == fam.get_mother_handle():
|
||||||
fam.set_mother_handle(self.p1)
|
## fam.set_mother_handle(self.p1)
|
||||||
if fam.get_father_handle() == None and fam.get_mother_handle() == None:
|
## if fam.get_father_handle() == None and fam.get_mother_handle() == None:
|
||||||
self.delete_empty_family(fam,trans)
|
## self.delete_empty_family(fam,trans)
|
||||||
data = cursor.next()
|
## data = cursor.next()
|
||||||
|
|
||||||
def find_modified_family(self,family):
|
def find_modified_family(self,family):
|
||||||
"""
|
"""
|
||||||
@ -795,10 +807,13 @@ class MergePeople:
|
|||||||
|
|
||||||
# merge family events
|
# merge family events
|
||||||
|
|
||||||
elist = tgt_family.get_event_list()[:]
|
ereflist = tgt_family.get_event_ref_list()
|
||||||
for event_id in src_family.get_event_list():
|
eref_handle_list = [ref.ref for ref in ereflist]
|
||||||
if event_id not in elist:
|
|
||||||
tgt_family.add_event_handle(event_id)
|
add_ref_list = [ref for ref in src_family.get_event_ref_list()
|
||||||
|
if ref.ref not in eref_handle_list]
|
||||||
|
tgt_family.set_event_ref_list(ereflist+add_ref_list)
|
||||||
|
|
||||||
|
|
||||||
# merge family attributes
|
# merge family attributes
|
||||||
|
|
||||||
|
@ -545,6 +545,8 @@ class ShowMatches(ManagedWindow.ManagedWindow):
|
|||||||
self.length = len(self.list)
|
self.length = len(self.list)
|
||||||
self.update = callback
|
self.update = callback
|
||||||
self.db = dbstate.db
|
self.db = dbstate.db
|
||||||
|
self.dbstate = dbstate
|
||||||
|
self.uistate = uistate
|
||||||
|
|
||||||
base = os.path.dirname(__file__)
|
base = os.path.dirname(__file__)
|
||||||
self.glade_file = "%s/%s" % (base,"merge.glade")
|
self.glade_file = "%s/%s" % (base,"merge.glade")
|
||||||
@ -607,14 +609,14 @@ class ShowMatches(ManagedWindow.ManagedWindow):
|
|||||||
pn1 = self.db.get_person_from_handle(self.p1)
|
pn1 = self.db.get_person_from_handle(self.p1)
|
||||||
pn2 = self.db.get_person_from_handle(self.p2)
|
pn2 = self.db.get_person_from_handle(self.p2)
|
||||||
|
|
||||||
MergePeople.Compare(self.db,pn1,pn2,self.on_update)
|
MergePeople.Compare(self.dbstate,self.uistate,pn1,pn2,self.on_update)
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
self.dellist[self.p2] = self.p1
|
self.dellist[self.p2] = self.p1
|
||||||
for key in self.dellist.keys():
|
for key in self.dellist.keys():
|
||||||
if self.dellist[key] == self.p2:
|
if self.dellist[key] == self.p2:
|
||||||
self.dellist[key] = self.p1
|
self.dellist[key] = self.p1
|
||||||
self.update(None,None)
|
self.update()
|
||||||
self.redraw()
|
self.redraw()
|
||||||
|
|
||||||
def update_and_destroy(self,obj):
|
def update_and_destroy(self,obj):
|
||||||
|
Loading…
Reference in New Issue
Block a user