* src/DataViews/_PersonView.py: merge functionality

* src/ViewManager.py: merge functionality
	* src/MergePeople.py: fix merge (ui and birth/death events)
	* src/GrampsDb/_WriteXML.py: remove redundant birth/death entries


svn: r6773
This commit is contained in:
Don Allingham 2006-05-25 04:08:05 +00:00
parent 93cd3d0832
commit ba91817471
5 changed files with 93 additions and 46 deletions

View File

@ -1,4 +1,8 @@
2006-05-24 Don Allingham <don@gramps-project.org>
* src/DataViews/_PersonView.py: merge functionality
* src/ViewManager.py: merge functionality
* src/MergePeople.py: fix merge (ui and birth/death events)
* src/GrampsDb/_WriteXML.py: remove redundant birth/death entries
* src/GrampsDb/_DbUtils.py: fix index setting of death index
* src/GrampsDb/_WriteGedcom.py: remove redundant birth/death
references

View File

@ -136,6 +136,59 @@ class PersonView(PageView.PersonNavView):
self.add_action('ColumnEdit', gtk.STOCK_PROPERTIES,
_('_Column Editor'), callback=self.column_editor,)
self.add_action('CmpMerge', None, _('_Compare and merge'),
callback=self.cmp_merge)
self.add_action('FastMerge', None, _('_Fast merge'),
callback=self.fast_merge)
def cmp_merge(self, obj):
mlist = self.get_selected_objects()
if len(mlist) != 2:
from QuestionDialog import ErrorDialog
msg = _("Cannot merge people")
msg2 = _("Exactly two people must be selected to perform a merge. "
"A second person can be selected by holding down the "
"control key while clicking on the desired person.")
ErrorDialog(msg,msg2)
else:
from QuestionDialog import ErrorDialog
import MergePeople
p1 = self.db.get_person_from_handle(mlist[0])
p2 = self.db.get_person_from_handle(mlist[1])
if p1 and p2:
merger = MergePeople.Compare(self.dbstate, self.uistate, p1, p2)
else:
msg = _("Cannot merge people")
msg2 = _("Exactly two people must be selected to perform a merge. "
"A second person can be selected by holding down the "
"control key while clicking on the desired person.")
ErrorDialog(msg,msg2)
def fast_merge(self, obj):
mlist = self.get_selected_objects()
if len(mlist) != 2:
msg = _("Cannot merge people")
msg2 = _("Exactly two people must be selected to perform a merge. "
"A second person can be selected by holding down the "
"control key while clicking on the desired person.")
ErrorDialog(msg,msg2)
else:
from MergePeople import MergePeopleUI
p1 = self.db.get_person_from_handle(mlist[0])
p2 = self.db.get_person_from_handle(mlist[1])
if p1 and p2:
MergePeopleUI(self.dbstate, self.uistate, p1, p2)
else:
msg = _("Cannot merge people")
msg2 = _("Exactly two people must be selected to perform a merge. "
"A second person can be selected by holding down the "
"control key while clicking on the desired person.")
ErrorDialog(msg,msg2)
def column_editor(self,obj):
import ColumnOrder
@ -254,6 +307,10 @@ class PersonView(PageView.PersonNavView):
</placeholder>
<menuitem action="SetActive"/>
<menuitem action="ColumnEdit"/>
<placeholder name="Merge">
<menuitem action="CmpMerge"/>
<menuitem action="FastMerge"/>
</placeholder>
</menu>
</menubar>
<toolbar name="ToolBar">

View File

@ -404,8 +404,8 @@ class XmlWriter(UpdateCallback):
for name in person.get_alternate_names():
self.dump_name(name,True,index+1)
self.dump_event_ref(person.get_birth_ref(),index+1)
self.dump_event_ref(person.get_death_ref(),index+1)
#self.dump_event_ref(person.get_birth_ref(),index+1)
#self.dump_event_ref(person.get_death_ref(),index+1)
for event_ref in person.get_event_ref_list():
self.dump_event_ref(event_ref,index+1)

View File

@ -50,12 +50,13 @@ import QuestionDialog
import GrampsDisplay
import ManagedWindow
import Utils
import GrampsDb
sex = ( _("female"), _("male"), _("unknown"))
class Compare(ManagedWindow.ManagedWindow):
def __init__(self, dbstate, uistate, person1, person2, update) :
def __init__(self, dbstate, uistate, person1, person2, update=None) :
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
@ -102,7 +103,8 @@ class Compare(ManagedWindow.ManagedWindow):
merge = MergePeople(self.db,self.p2,self.p1)
self.close()
merge.merge()
self.update()
if self.update:
self.update()
def add(self, tobj, tag, text):
text += "\n"
@ -256,11 +258,17 @@ def check_for_child(p1, p2):
# Merge People UI
#
#-------------------------------------------------------------------------
class MergePeopleUI:
class MergePeopleUI(ManagedWindow.ManagedWindow):
def __init__(self,db,person1,person2,update):
def __init__(self, dbstate, uistate, person1, person2, update=None):
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
glade = gtk.glade.XML(const.merge_glade, 'merge_people')
window = glade.get_widget('merge_people')
self.set_window(window, glade.get_widget('title'), _("Merge People"))
p1 = glade.get_widget('person1')
p2 = glade.get_widget('person2')
n1 = name_of(person1)
@ -268,12 +276,12 @@ class MergePeopleUI:
p1.set_label(n1)
p2.set_label(n2)
Utils.set_titles(top,glade.get_widget('title'),_("Merge People"))
glade.get_widget('help').connect('clicked',self.help)
ret = gtk.RESPONSE_HELP
while ret == gtk.RESPONSE_HELP:
ret = top.run()
ret = window.run()
if ret == gtk.RESPONSE_OK:
@ -290,12 +298,16 @@ class MergePeopleUI:
"them."))
else:
if p1.get_active():
merge = MergePeople(db,person1,person2)
merge = MergePeople(dbstate.db,person1,person2)
else:
merge = MergePeople(db,person2,person1)
merge = MergePeople(dbstate.db,person2,person1)
merge.merge()
update()
top.destroy()
if update:
update()
window.destroy()
def build_menu_names(self,obj):
return (_('Merge People'),None)
def help(self,obj):
"""Display the relevant portion of GRAMPS manual"""
@ -395,15 +407,11 @@ class MergePeople:
# copy names
self.merge_names(new)
# copy the birth event
self.merge_birth(new,trans)
# copy the death event
self.merge_death(new,trans)
# merge the event lists
self.merge_event_lists(new)
GrampsDb.set_birth_death_index(self.db, new)
# copy attributes
new.set_attribute_list(self.p1.get_attribute_list() +
self.p2.get_attribute_list())
@ -483,17 +491,8 @@ class MergePeople:
ref1 = self.p1.get_birth_ref()
ref2 = self.p2.get_birth_ref()
if ref1:
new.set_birth_ref(ref1)
if ref2:
event = self.db.get_event_from_handle(ref2.ref)
event.set_name('Alternate Birth')
self.db.add_event(event,trans)
event_ref = RelLib.EventRef()
event_ref.ref = event.get_handle()
new.add_event_ref(event_ref)
elif not ref1 and ref2:
new.set_birth_ref(ref2)
if not ref1.is_equal(ref2):
new.add_event_ref(ref2)
def merge_death(self, new, trans):
"""
@ -507,18 +506,8 @@ class MergePeople:
ref1 = self.p1.get_death_ref()
ref2 = self.p2.get_death_ref()
if ref1:
new.set_death_ref(ref1)
if ref2:
event = self.db.get_event_from_handle(ref2)
event.set_handle(Utils.create_id())
event.set_name('Alternate Death')
event_ref = RelLib.EventRef()
event_ref.ref = event.get_handle()
new.add_event_ref(event_ref)
self.db.add_event(event,trans)
elif not ref1 and ref2:
new.set_death_ref(ref2)
if not ref1.is_equal(ref2):
new.add_event_ref(ref2)
def merge_event_lists(self, new):
"""

View File

@ -115,9 +115,8 @@ uidefault = '''<ui>
<separator/>
<placeholder name="CommonEdit"/>
<separator/>
<menuitem action="ScratchPad"/>
<menuitem action="CmpMerge"/>
<menuitem action="FastMerge"/>
<menuitem action="ScratchPad"/>
<placeholder name="Merge"/>
<separator/>
<menuitem action="Preferences"/>
</menu>
@ -343,8 +342,6 @@ class ViewManager:
self.export_data),
('Abandon', gtk.STOCK_REVERT_TO_SAVED,
_('_Abandon changes and quit'), None, None, self.abort),
('CmpMerge', None, _('_Compare and merge')),
('FastMerge', None, _('_Fast merge')),
('ScratchPad', gtk.STOCK_PASTE, _('_ScratchPad'), "",
_("Open the ScratchPad dialog"), self.scratchpad),
('Import', gtk.STOCK_CONVERT, _('_Import'), "<control>i", None,