* src/plugins/PatchNames.py: Clean up conversion to db.

* src/plugins/patchnames.glade: HIGify dialog.
* src/plugins/Merge.py: Convert to db.
* src/plugins/merge.glade: HIGify dialogs.


svn: r3148
This commit is contained in:
Alex Roitman 2004-05-09 16:32:13 +00:00
parent 797ceddf6c
commit 62be72e287
5 changed files with 203 additions and 130 deletions

View File

@ -1,3 +1,9 @@
2004-05-09 Alex Roitman <shura@alex.neuro.umn.edu>
* src/plugins/PatchNames.py: Clean up conversion to db.
* src/plugins/patchnames.glade: HIGify dialog.
* src/plugins/Merge.py: Convert to db.
* src/plugins/merge.glade: HIGify dialogs.
2004-05-08 Alex Roitman <shura@alex.neuro.umn.edu>
* src/plugins/EventCmp.py: Convert to db.
* src/plugins/eventcmp.glade: HIGify dialogs.

View File

@ -71,15 +71,6 @@ def is_initial(name):
#
#
#-------------------------------------------------------------------------
def ancestors_of(p1,list):
if p1 == None or p1 in list:
return
list.append(p1)
f1 = p1.get_main_parents_family_id()
if f1 != None:
ancestors_of(f1.get_father_id(),list)
ancestors_of(f1.get_mother_id(),list)
#-------------------------------------------------------------------------
#
#
@ -98,8 +89,8 @@ class Merge:
self.update = callback
self.use_soundex = 1
self.family_list = database.get_family_id_map().values()[:]
self.person_list = database.get_person_id_map().values()[:]
self.family_list = database.get_family_keys()[:]
self.person_list = database.get_person_keys()[:]
base = os.path.dirname(__file__)
self.glade_file = "%s/%s" % (base,"merge.glade")
@ -131,6 +122,17 @@ class Merge:
"destroy_passed_object" : Utils.destroy_passed_object
})
def ancestors_of(self,p1_id,id_list):
if (not p1_id) or (p1_id in id_list):
return
id_list.append(p1_id)
p1 = self.db.find_person_from_id(p1_id)
f1_id = p1.get_main_parents_family_id()
if f1_id:
f1 = self.db.find_family_from_id(f1_id)
self.ancestors_of(f1.get_father_id(),id_list)
self.ancestors_of(f1.get_mother_id(),id_list)
def on_merge_ok_clicked(self,obj):
active = self.menu.get_menu().get_active().get_data("v")
self.use_soundex = self.soundex_obj.get_active()
@ -141,7 +143,7 @@ class Merge:
def progress_update(self,val):
self.progress.set_fraction(val/100.0)
while gtk.events_pending():
gtk.mainiteration()
gtk.main_iteration()
def find_potentials(self,thresh):
top = gtk.glade.XML(self.glade_file,"message","gramps")
@ -155,24 +157,25 @@ class Merge:
males = {}
females = {}
for p1 in self.person_list:
for p1_id in self.person_list:
p1 = self.db.find_person_from_id(p1_id)
key = self.gen_key(p1.get_primary_name().get_surname())
if p1.get_gender() == RelLib.Person.male:
if males.has_key(key):
males[key].append(p1.get_id())
males[key].append(p1_id)
else:
males[key] = [p1.get_id()]
males[key] = [p1_id]
else:
if females.has_key(key):
females[key].append(p1.get_id())
females[key].append(p1_id)
else:
females[key] = [p1.get_id()]
females[key] = [p1_id]
length = len(self.person_list)
num = 0
for p1 in self.person_list:
p1key = p1.get_id()
for p1key in self.person_list:
p1 = self.db.find_person_from_id(p1key)
if num % 25 == 0:
self.progress_update((float(num)/float(length))*100)
num = num + 1
@ -188,10 +191,10 @@ class Merge:
index = index + 1
if p1key == p2key:
continue
p2 = self.db.get_person(p2key)
p2 = self.db.find_person_from_id(p2key)
if self.map.has_key(p2key):
(v,c) = self.map[p2key]
if v == p1:
if v == p1key:
continue
chance = self.compare_people(p1,p2)
@ -199,9 +202,9 @@ class Merge:
if self.map.has_key(p1key):
val = self.map[p1key]
if val[1] > chance:
self.map[p1key] = (p2,chance)
self.map[p1key] = (p2key,chance)
else:
self.map[p1key] = (p2,chance)
self.map[p1key] = (p2key,chance)
self.list = self.map.keys()
self.list.sort()
@ -231,24 +234,21 @@ class Merge:
def redraw(self):
list = []
for p1 in self.map.keys():
if self.dellist.has_key(p1):
for p1key in self.map.keys():
if self.dellist.has_key(p1key):
continue
(p2,c) = self.map[p1]
p2key = p2.get_id()
if self.dellist.has_key(p2key):
p2 = self.dellist[p2key]
if p1 == p2:
(p2key,c) = self.map[p1key]
if p1key == p2key:
continue
list.append((c,p1,p2.get_id()))
list.append((c,p1key,p2key))
self.list.clear()
for (c,p1,p2) in list:
for (c,p1key,p2key) in list:
c1 = "%5.2f" % c
c2 = "%5.2f" % (100-c)
pn1 = self.db.get_person(p1).get_primary_name().get_name()
pn2 = self.db.get_person(p2).get_primary_name().get_name()
self.list.add([c, pn1, pn2,c2],(p1,p2))
pn1 = self.db.find_person_from_id(p1key).get_primary_name().get_name()
pn2 = self.db.find_person_from_id(p2key).get_primary_name().get_name()
self.list.add([c, pn1, pn2,c2],(p1key,p2key))
def on_do_merge_clicked(self,obj):
store,iter = self.list.selection.get_selected()
@ -256,15 +256,15 @@ class Merge:
return
(p1,p2) = self.list.get_object(iter)
pn1 = self.db.get_person(p1)
pn2 = self.db.get_person(p2)
pn1 = self.db.find_person_from_id(p1)
pn2 = self.db.find_person_from_id(p2)
MergeData.MergePeople(self.db,pn1,pn2,self.on_update)
def on_update(self,p1,p2,old_id):
self.dellist[p2.get_id()] = p1.get_id()
def on_update(self,p1_id,p2_id,old_id):
self.dellist[p2_id] = p1_id
for key in self.dellist.keys():
if self.dellist[key] == p2.get_id():
self.dellist[key] = p1.get_id()
if self.dellist[key] == p2_id:
self.dellist[key] = p1_id
self.redraw()
def update_and_destroy(self,obj):
@ -316,16 +316,16 @@ class Merge:
if date1.get_date() == date2.get_date():
return 1
if date1.isRange() or date2.isRange():
if date1.is_range() or date2.is_range():
return self.range_compare(date1,date2)
date1 = date1.get_start_date()
date2 = date2.get_start_date()
if date1.getYear() == date2.getYear():
if date1.getMonth() == date2.getMonth():
if date1.get_year() == date2.get_year():
if date1.get_month() == date2.get_month():
return 0.75
if not date1.getMonthValid() or not date2.getMonthValid():
if not date1.get_month_valid() or not date2.get_month_valid():
return 0.75
else:
return -1
@ -333,7 +333,7 @@ class Merge:
return -1
def range_compare(self,date1,date2):
if date1.isRange() and date2.isRange():
if date1.is_range() and date2.is_range():
if date1.get_start_date() >= date2.get_start_date() and \
date1.get_start_date() <= date2.get_stop_date() or \
date2.get_start_date() >= date1.get_start_date() and \
@ -345,7 +345,7 @@ class Merge:
return 0.5
else:
return -1
elif date2.isRange():
elif date2.is_range():
if date1.get_start_date() >= date2.get_start_date() and \
date1.get_start_date() <= date2.get_stop_date():
return 0.5
@ -385,21 +385,23 @@ class Merge:
else:
return self.list_reduce(list2,list1)
def place_match(self,p1,p2):
if p1 == p2:
def place_match(self,p1_id,p2_id):
if p1_id == p2_id:
return 1
if p1 == None:
if not p1_id:
name1 = ""
else:
p1 = self.db.find_place_from_id(p1_id)
name1 = p1.get_title()
if p2 == None:
if not p2_id:
name2 = ""
else:
p2 = self.db.find_place_from_id(p2_id)
name2 = p2.get_title()
if name1 == "" or name2 == "":
if not (name1 and name2):
return 0
if name1 == name2:
return 1
@ -430,10 +432,29 @@ class Merge:
if chance == -1 :
return -1
birth1 = p1.get_birth()
death1 = p1.get_death()
birth2 = p2.get_birth()
death2 = p2.get_death()
birth1_id = p1.get_birth_id()
if birth1_id:
birth1 = self.db.find_event_from_id(birth1_id)
else:
birth1 = RelLib.Event()
death1_id = p1.get_death_id()
if death1_id:
death1 = self.db.find_event_from_id(death1_id)
else:
death1 = RelLib.Event()
birth2_id = p2.get_birth_id()
if birth2_id:
birth2 = self.db.find_event_from_id(birth2_id)
else:
birth2 = RelLib.Event()
death2_id = p2.get_death_id()
if death2_id:
death2 = self.db.find_event_from_id(death2_id)
else:
death2 = RelLib.Event()
value = self.date_match(birth1.get_date_object(),birth2.get_date_object())
if value == -1 :
@ -456,21 +477,31 @@ class Merge:
chance = chance + value
ancestors = []
ancestors_of(p1,ancestors)
if p2 in ancestors:
self.ancestors_of(p1.get_id(),ancestors)
if p2.get_id() in ancestors:
return -1
ancestors = []
ancestors_of(p2,ancestors)
if p1 in ancestors:
self.ancestors_of(p2.get_id(),ancestors)
if p1.get_id() in ancestors:
return -1
f1 = p1.get_main_parents_family_id()
f2 = p2.get_main_parents_family_id()
f1_id = p1.get_main_parents_family_id()
f2_id = p2.get_main_parents_family_id()
if f1 and f2:
dad1 = get_name_obj(f1.get_father_id())
dad2 = get_name_obj(f2.get_father_id())
if f1_id and f2_id:
f1 = self.db.find_family_from_id(f1_id)
f2 = self.db.find_family_from_id(f2_id)
dad1_id = f1.get_father_id()
if dad1_id:
dad1 = get_name_obj(self.db.find_person_from_id(dad1_id))
else:
dad1 = None
dad2_id = f2.get_father_id()
if dad2_id:
dad2 = get_name_obj(self.db.find_person_from_id(dad2_id))
else:
dad2 = None
value = self.name_match(dad1,dad2)
@ -479,8 +510,16 @@ class Merge:
chance = chance + value
mom1 = get_name_obj(f1.get_mother_id())
mom2 = get_name_obj(f2.get_mother_id())
mom1_id = f1.get_mother_id()
if mom1_id:
mom1 = get_name_obj(self.db.find_person_from_id(mom1_id))
else:
mom1 = None
mom2_id = f2.get_mother_id()
if mom2_id:
mom2 = get_name_obj(self.db.find_person_from_id(mom2_id))
else:
mom2 = None
value = self.name_match(mom1,mom2)
if value == -1:
@ -488,27 +527,33 @@ class Merge:
chance = chance + value
for f1 in p1.get_family_id_list():
for f2 in p2.get_family_id_list():
for f1_id in p1.get_family_id_list():
f1 = self.db.find_family_from_id(f1_id)
for f2_id in p2.get_family_id_list():
f2 = self.db.find_family_from_id(f2_id)
if p1.get_gender() == RelLib.Person.female:
father1 = f1.get_father_id()
father2 = f2.get_father_id()
if father1 and father2:
if father1 == father2:
father1_id = f1.get_father_id()
father2_id = f2.get_father_id()
if father1_id and father2_id:
if father1_id == father2_id:
chance = chance + 1
else:
father1 = self.db.find_person_from_id(father1_id)
father2 = self.db.find_person_from_id(father2_id)
fname1 = get_name_obj(father1)
fname2 = get_name_obj(father2)
value = self.name_match(fname1,fname2)
if value != -1:
chance = chance + value
else:
mother1 = f1.get_mother_id()
mother2 = f2.get_mother_id()
if mother1 and mother2:
if mother1 == mother2:
mother1_id = f1.get_mother_id()
mother2_id = f2.get_mother_id()
if mother1_id and mother2_id:
if mother1_id == mother2_id:
chance = chance + 1
else:
mother1 = self.db.find_person_from_id(mother1_id)
mother2 = self.db.find_person_from_id(mother2_id)
mname1 = get_name_obj(mother1)
mname2 = get_name_obj(mother2)
value = self.name_match(mname1,mname2)

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000 Donald N. Allingham
# Copyright (C) 2000-2004 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
@ -18,6 +18,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
"Database Processing/Extract information from names"
#-------------------------------------------------------------------------
@ -83,7 +85,7 @@ class PatchNames:
for key in self.db.get_person_keys():
person = self.db.get_person(key)
person = self.db.find_person_from_id(key)
first = person.get_primary_name().get_first_name()
match = _title_re.match(first)
if match:
@ -97,7 +99,7 @@ class PatchNames:
msg = ""
if len(self.nick_list) > 0 or len(self.title_list) > 0:
if self.nick_list or self.title_list:
self.display()
else:
OkDialog(_('No modifications made'),
@ -151,7 +153,7 @@ class PatchNames:
self.title_hash = {}
for (id,name,nick) in self.nick_list:
p = self.db.get_person(id)
p = self.db.find_person_from_id(id)
iter = self.model.append()
self.model.set_value(iter,0,1)
self.model.set_value(iter,1,id)
@ -161,7 +163,7 @@ class PatchNames:
self.nick_hash[id] = iter
for (id,title,nick) in self.title_list:
p = self.db.get_person(id)
p = self.db.find_person_from_id(id)
iter = self.model.append()
self.model.set_value(iter,0,1)
self.model.set_value(iter,1,id)
@ -179,18 +181,18 @@ class PatchNames:
name = p.get_primary_name()
name.set_first_name(grp[1])
p.set_nick_name(grp[2])
self.db.build_person_display(grp[0])
self.db.commit_person(p)
Utils.modified()
for grp in self.title_list:
iter = self.title_hash[grp[0]]
val = self.model.get_value(iter,0)
if val:
p = self.db.get_person(grp[0])
p = self.db.find_person_from_id(grp[0])
name = p.get_primary_name()
name.set_first_name(grp[2])
name.set_title(grp[1])
self.db.build_person_display(grp[0])
self.db.commit_person(p)
Utils.modified()
Utils.destroy_passed_object(obj)
@ -209,6 +211,3 @@ register_tool(
category=_("Database Processing"),
description=_("Searches the entire database and attempts to extract titles and nicknames that may be embedded in a person's given name field.")
)

View File

@ -11,6 +11,11 @@
<property name="modal">True</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<child>
<widget class="GtkVBox" id="vbox2">
@ -73,10 +78,6 @@
<property name="orientation">GTK_PROGRESS_LEFT_TO_RIGHT</property>
<property name="fraction">0</property>
<property name="pulse_step">0.1</property>
<property name="activity_mode">False</property>
<property name="show_text">False</property>
<property name="text_xalign">0.5</property>
<property name="text_yalign">0.5</property>
</widget>
<packing>
<property name="padding">20</property>
@ -105,6 +106,11 @@
<property name="default_height">350</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
@ -118,19 +124,6 @@
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button7">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Merge</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_do_merge_clicked"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button9">
<property name="visible">True</property>
@ -139,10 +132,25 @@
<property name="label">gtk-close</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="destroy_passed_object" object="mergelist"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button7">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Merge</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_do_merge_clicked"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
@ -225,6 +233,11 @@
<property name="default_width">350</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
@ -238,19 +251,6 @@
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button10">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_merge_ok_clicked" object="dialog"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button12">
<property name="visible">True</property>
@ -259,10 +259,25 @@
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="destroy_passed_object" object="dialog"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button10">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_merge_ok_clicked" object="dialog"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
@ -365,6 +380,7 @@
<property name="label" translatable="yes">Use soundex codes</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">True</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>

View File

@ -13,6 +13,11 @@
<property name="default_height">450</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<child>
<widget class="GtkVBox" id="vbox2">
@ -98,18 +103,6 @@ that have been selected.</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<property name="spacing">6</property>
<child>
<widget class="GtkButton" id="button5">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Accept changes and close</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<signal name="clicked" handler="on_ok_clicked" object="top" last_modification_time="Wed, 16 Apr 2003 05:07:24 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button6">
<property name="visible">True</property>
@ -118,9 +111,23 @@ that have been selected.</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="destroy_passed_object" object="top" last_modification_time="Wed, 16 Apr 2003 05:06:50 GMT"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button5">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Accept changes and close</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="on_ok_clicked" object="top" last_modification_time="Wed, 16 Apr 2003 05:07:24 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">6</property>