diff --git a/ChangeLog b/ChangeLog index dba520d1a..aa95442a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-05-09 Alex Roitman + * 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 * src/plugins/EventCmp.py: Convert to db. * src/plugins/eventcmp.glade: HIGify dialogs. diff --git a/src/plugins/Merge.py b/src/plugins/Merge.py index 78d3ebd1e..adc37fa20 100644 --- a/src/plugins/Merge.py +++ b/src/plugins/Merge.py @@ -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) diff --git a/src/plugins/PatchNames.py b/src/plugins/PatchNames.py index fe5d67a2d..4d9b3f01d 100644 --- a/src/plugins/PatchNames.py +++ b/src/plugins/PatchNames.py @@ -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.") ) - - - diff --git a/src/plugins/merge.glade b/src/plugins/merge.glade index d82d2ce12..1f92f1bca 100644 --- a/src/plugins/merge.glade +++ b/src/plugins/merge.glade @@ -11,6 +11,11 @@ True True False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST @@ -73,10 +78,6 @@ GTK_PROGRESS_LEFT_TO_RIGHT 0 0.1 - False - False - 0.5 - 0.5 20 @@ -105,6 +106,11 @@ 350 True False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST False @@ -118,19 +124,6 @@ True GTK_BUTTONBOX_END - - - True - True - True - _Merge - True - GTK_RELIEF_NORMAL - 0 - - - - True @@ -139,10 +132,25 @@ gtk-close True GTK_RELIEF_NORMAL + True 0 + + + + True + True + True + _Merge + True + GTK_RELIEF_NORMAL + True + 0 + + + 0 @@ -225,6 +233,11 @@ 350 True False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST False @@ -238,19 +251,6 @@ True GTK_BUTTONBOX_END - - - True - True - True - gtk-ok - True - GTK_RELIEF_NORMAL - 0 - - - - True @@ -259,10 +259,25 @@ gtk-cancel True GTK_RELIEF_NORMAL + True 0 + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + 0 + + + 0 @@ -365,6 +380,7 @@ Use soundex codes True GTK_RELIEF_NORMAL + True True False True diff --git a/src/plugins/patchnames.glade b/src/plugins/patchnames.glade index d55bbfa83..b8332010f 100644 --- a/src/plugins/patchnames.glade +++ b/src/plugins/patchnames.glade @@ -13,6 +13,11 @@ 450 True False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST @@ -98,18 +103,6 @@ that have been selected. GTK_BUTTONBOX_END 6 - - - True - True - True - _Accept changes and close - True - GTK_RELIEF_NORMAL - - - - True @@ -118,9 +111,23 @@ that have been selected. gtk-cancel True GTK_RELIEF_NORMAL + True + + + + True + True + True + _Accept changes and close + True + GTK_RELIEF_NORMAL + True + + + 6