diff --git a/gramps2/src/AddSpouse.py b/gramps2/src/AddSpouse.py index d4b30b2af..7231f570f 100644 --- a/gramps2/src/AddSpouse.py +++ b/gramps2/src/AddSpouse.py @@ -262,6 +262,10 @@ class AddSpouse: self.db.add_transaction(trans) Utils.destroy_passed_object(obj) self.update(self.active_family) + m = Marriage.Marriage(self.parent, self.active_family, + self.parent.db, self.parent.new_after_edit, + self.parent.family_view.load_family) + m.on_add_clicked() def relation_type_changed(self,obj): self.update_data() diff --git a/gramps2/src/ChooseParents.py b/gramps2/src/ChooseParents.py index c11d4aae8..19d773cac 100644 --- a/gramps2/src/ChooseParents.py +++ b/gramps2/src/ChooseParents.py @@ -80,8 +80,11 @@ class ChooseParents: self.parent = parent self.db = db self.child_windows = {} - self.person = person - self.family = family + self.person = self.db.find_person_from_id(person.get_id()) + if family: + self.family = self.db.find_family_from_id(family.get_id()) + else: + self.family = None self.family_update = family_update self.full_update = full_update self.old_type = "" @@ -281,7 +284,7 @@ class ChooseParents: if self.dday and pbday.get_low_year()+10 > self.dday.get_high_year(): return 0 - if self.dday and dday.get_year_valid(): + if self.dday and self.dday.get_year_valid(): if pbday and pbday.get_year_valid(): # reject if parents deathday + 3 < childs birth date if pdday and self.bday and pdday.get_high_year()+3 < self.bday.get_low_year(): @@ -353,8 +356,16 @@ class ChooseParents: for family_id in self.db.get_family_keys(): family = self.db.find_family_from_id(family_id) if family.get_father_id() == father_id and family.get_mother_id() == mother_id: + trans = self.db.start_transaction() + family.add_child_id(self.person.get_id()) + self.db.commit_family(family,trans) + self.db.add_transaction(trans) return family elif family.get_father_id() == mother_id and family.get_mother_id() == father_id: + trans = self.db.start_transaction() + family.add_child_id(self.person.get_id()) + self.db.commit_family(family,trans) + self.db.add_transaction(trans) return family trans = self.db.start_transaction() @@ -364,13 +375,13 @@ class ChooseParents: family.add_child_id(self.person.get_id()) if father_id: - father = self.db.find_person_from_id(father_id) - father.add_family_id(family.get_id()) - self.db.commit_person(father,trans) + self.father = self.db.find_person_from_id(father_id) + self.father.add_family_id(family.get_id()) + self.db.commit_person(self.father,trans) if mother_id: - mother = self.db.find_person_from_id(mother_id) - mother.add_family_id(family.get_id()) - self.db.commit_person(mother,trans) + self.mother = self.db.find_person_from_id(mother_id) + self.mother.add_family_id(family.get_id()) + self.db.commit_person(self.mother,trans) self.db.commit_family(family,trans) self.db.add_transaction(trans) @@ -498,8 +509,10 @@ class ChooseParents: self.family = None if self.family: + self.family.add_child_id(self.person.get_id()) self.family.set_relationship(self.type) self.change_family_type(self.family,mother_rel,father_rel) + self.db.commit_family(self.family) self.family_update(None) self.close(obj) @@ -548,10 +561,11 @@ class ChooseParents: Changes the family type of the specified family. If the family is None, the the relationship type shoud be deleted. """ - if self.person not in family.get_child_id_list(): + family_id = family.get_id() + if self.person.get_id() not in family.get_child_id_list(): family.add_child_id(self.person.get_id()) for fam in self.person.get_parent_family_id_list(): - if family == fam[0]: + if family_id == fam[0]: if mother_rel == fam[1] and father_rel == fam[2]: return if mother_rel != fam[1] or father_rel != fam[2]: diff --git a/gramps2/src/FamilyView.py b/gramps2/src/FamilyView.py index d560b2a93..a884aed1b 100644 --- a/gramps2/src/FamilyView.py +++ b/gramps2/src/FamilyView.py @@ -654,9 +654,10 @@ class FamilyView: self.parent.db.commit_family(self.family,trans) self.load_family(self.family) - Marriage.Marriage(self.parent,self.family,self.parent.db, - self.parent.new_after_edit, - self.load_family) + m = Marriage.Marriage(self.parent,self.family,self.parent.db, + self.parent.new_after_edit, + self.load_family) + m.on_add_clicked() def add_child_clicked(self,obj): if not self.person: @@ -849,9 +850,12 @@ class FamilyView: self.ap_model.clear() def load_family(self,family=None): - - self.person = self.parent.active_person - if not self.person: + + if self.parent.active_person: + id = self.parent.active_person.get_id() + self.person = self.parent.db.find_person_from_id(id) + else: + self.person = None self.clear() return @@ -877,6 +881,7 @@ class FamilyView: self.spouse_model.clear() self.child_model.clear() self.sp_parents_model.clear() + splist = self.person.get_family_id_list() if len(splist) > 1: @@ -983,18 +988,19 @@ class FamilyView: def display_marriage(self,family): self.child_model.clear() - self.family = family if not family: + self.family = None return + self.family = self.parent.db.find_family_from_id(family.get_id()) - if family.get_father_id() == self.person.get_id(): - sp_id = family.get_mother_id() + if self.family.get_father_id() == self.person.get_id(): + sp_id = self.family.get_mother_id() if sp_id: self.selected_spouse = self.parent.db.find_person_from_id(sp_id) else: self.selected_spouse = None else: - sp_id = family.get_father_id() + sp_id = self.family.get_father_id() if sp_id: self.selected_spouse = self.parent.db.find_person_from_id(sp_id) else: @@ -1006,7 +1012,7 @@ class FamilyView: i = 0 fiter = None - child_list = list(family.get_child_id_list()) + child_list = list(self.family.get_child_id_list()) self.child_map = {} @@ -1015,8 +1021,8 @@ class FamilyView: child = self.parent.db.find_person_from_id(child_id) for fam in child.get_parent_family_id_list(): - if fam[0] == family.get_id(): - if self.person == family.get_father_id(): + if fam[0] == self.family.get_id(): + if self.person == self.family.get_father_id(): status = "%s/%s" % (_(fam[2]),_(fam[1])) else: status = "%s/%s" % (_(fam[1]),_(fam[2])) @@ -1239,7 +1245,10 @@ class FamilyView: if not person: return try: - ChooseParents.ChooseParents(self.parent, self.parent.db,person,None, + ChooseParents.ChooseParents(self.parent, + self.parent.db, + person, + None, self.load_family, self.parent.full_update) except: diff --git a/gramps2/src/Marriage.py b/gramps2/src/Marriage.py index a246f1280..201ecc587 100644 --- a/gramps2/src/Marriage.py +++ b/gramps2/src/Marriage.py @@ -646,7 +646,7 @@ class Marriage: except: pass - def on_add_clicked(self,obj): + def on_add_clicked(self,*obj): import EventEdit name = Utils.family_name(self.family,self.db) EventEdit.EventEditor(self,name,const.marriageEvents, diff --git a/gramps2/src/PeopleModel.py b/gramps2/src/PeopleModel.py index 07a52c733..53389b4f6 100644 --- a/gramps2/src/PeopleModel.py +++ b/gramps2/src/PeopleModel.py @@ -63,6 +63,8 @@ class PeopleModel(gtk.GenericTreeModel): if not self.db.is_open(): return + import time + t = time.time() for person_id in self.db.get_person_keys(): person = self.db.find_person_from_id(person_id) @@ -91,6 +93,7 @@ class PeopleModel(gtk.GenericTreeModel): self.path2iter[tpl] = person_id val += 1 sval += 1 + print time.time() - t def byname(self,f,s): n1 = self.db.person_map.get(str(f))[2].get_sort_name() diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index 35eac08ba..a569af7bd 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -1970,7 +1970,7 @@ class Family(SourceNote): def get_id(self) : """returns the gramps ID for the Family""" - return self.id + return unicode(self.id) def set_relationship(self,type): """assigns a string indicating the relationship between the @@ -2638,14 +2638,12 @@ class GrampsDB: return Transaction(msg) def add_transaction(self,transaction): - transaction.display() self.translist.append(transaction) def undo(self): if len(self.translist) == 0: return transaction = self.translist.pop() - transaction.display() subitems = transaction.get_data() subitems.reverse() @@ -3297,7 +3295,7 @@ class GrampsDB: index = self.fprefix % self.fmap_index self.fmap_index = self.fmap_index + 1 family = Family() - family.set_id(index) + family.set_id(unicode(index)) if trans != None: trans.add(FAMILY_KEY, index, None) self.family_map.put(str(index),family.serialize()) diff --git a/gramps2/src/gramps.glade b/gramps2/src/gramps.glade index bf843cc3f..ddb218343 100644 --- a/gramps2/src/gramps.glade +++ b/gramps2/src/gramps.glade @@ -51,7 +51,7 @@ - + True gtk-new 1 @@ -73,7 +73,7 @@ - + True gtk-open 1 @@ -107,7 +107,7 @@ True - + True gtk-convert 1 @@ -135,7 +135,7 @@ - + True gtk-quit 1 @@ -171,7 +171,7 @@ - + True gtk-add 1 @@ -194,7 +194,7 @@ - + True gtk-remove 1 @@ -240,7 +240,7 @@ - + True gtk-find 1 @@ -262,7 +262,7 @@ - + True gtk-convert 1 @@ -289,7 +289,7 @@ - + True gtk-preferences 1 @@ -310,7 +310,7 @@ - + True gtk-properties 1 @@ -331,7 +331,7 @@ - + True gtk-home 1 @@ -386,21 +386,6 @@ - - - - True - - - - - - True - _Event History... - True - - - @@ -432,7 +417,7 @@ - + True gtk-index 1 @@ -454,7 +439,7 @@ - + True gnome-stock-book-open 1 @@ -527,7 +512,7 @@ - + True gtk-help 1 @@ -548,7 +533,7 @@ - + True gnome-stock-book-open 1 @@ -575,7 +560,7 @@ - + True gtk-jump-to 1 @@ -596,7 +581,7 @@ - + True gnome-stock-mail 1 @@ -650,7 +635,7 @@ - + True gnome-stock-about 1 diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index 6ff2fd18e..bef2969db 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -1302,13 +1302,13 @@ class Gramps: self.people_view.goto_active_person(first) def change_active_person(self,person,force=0): - self.active_person = person if person == None: self.set_buttons(0) self.active_person = None self.modify_statusbar() elif self.active_person == None or \ person.get_id() != self.active_person.get_id(): + self.active_person = self.db.find_person_from_id(person.get_id()) self.modify_statusbar() self.set_buttons(1) if person: @@ -1334,6 +1334,7 @@ class Gramps: self.backbtn.set_sensitive(0) self.back.set_sensitive(0) else: + self.active_person = self.db.find_person_from_id(person.get_id()) self.set_buttons(1) def modify_statusbar(self): diff --git a/gramps2/src/plugins/Check.py b/gramps2/src/plugins/Check.py index ef388fb3a..9fdb17516 100644 --- a/gramps2/src/plugins/Check.py +++ b/gramps2/src/plugins/Check.py @@ -89,27 +89,31 @@ class CheckIntegrity: def check_for_broken_family_links(self): self.broken_links = [] - for key in self.db.get_family_id_map().keys(): - family = self.db.get_family_id(key) - father = family.get_father_id() - mother = family.get_mother_id() + for family_id in self.db.get_family_keys(): + family = self.db.find_family_from_id(family_id) + father = self.db.find_family_from_id(family.get_father_id()) + mother = self.db.find_family_from_id(family.get_mother_id()) - if father and family not in father.get_family_id_list(): + if father and family_id not in father.get_family_id_list(): Utils.modified() self.broken_parent_links.append((father,family)) - father.add_family_id(family) - if mother and family not in mother.get_family_id_list(): + father.add_family_id(family_id) + self.db.commit_person(father) + if mother and family_id not in mother.get_family_id_list(): Utils.modified() self.broken_parent_links.append((mother,family)) - mother.add_family_id(family) - for child in family.get_child_id_list(): + mother.add_family_id(family_id) + self.db.commit_person(mother) + for child_id in family.get_child_id_list(): + child = self.db.find_person_from_id(child_id) if family == child.get_main_parents_family_id(): continue for family_type in child.get_parent_family_id_list(): - if family_type[0] == family: + if family_type[0] == family_id: break else: - family.remove_child_id(child) + family.remove_child_id(child_id) + self.db.commit_family(family) Utils.modified() self.broken_links.append((child,family)) @@ -118,45 +122,64 @@ class CheckIntegrity: #------------------------------------------------------------------------- def remove_clicked(): # File is lost => remove all references and the object itself - for p in self.db.get_family_id_map().values(): + for person_id in self.db.get_family_keys(): + p = self.db.find_family_from_id(person_id) nl = p.get_media_list() + changed = 0 for o in nl: if o.get_reference_id() == ObjectId: - nl.remove(o) - p.set_media_list(nl) + changed = 1 + nl.remove(o) + if changed: + p.set_media_list(nl) + self.db.commit_person(p) + for key in self.db.get_person_keys(): - p = self.db.get_person(key) + p = self.db.find_person_from_id(key) nl = p.get_media_list() + changed = 0 for o in nl: if o.get_reference_id() == ObjectId: - nl.remove(o) - p.set_media_list(nl) + changed = 1 + nl.remove(o) + if changed: + p.set_media_list(nl) + self.db.commit_person(p) + for key in self.db.get_source_keys(): - p = self.db.get_source(key) + p = self.db.find_source_from_id(key) nl = p.get_media_list() + changed = 0 for o in nl: if o.get_reference_id() == ObjectId: - nl.remove(o) - p.set_media_list(nl) + changed = 1 + nl.remove(o) + if changed: + p.set_media_list(nl) + self.db.commit_source(p) + for key in self.db.get_place_id_keys(): p = self.db.get_place_id(key) nl = p.get_media_list() + changed = 0 for o in nl: if o.get_reference_id() == ObjectId: - nl.remove(o) - p.set_media_list(nl) + changed = 1 + nl.remove(o) + if changed: + p.set_media_list(nl) + self.db.commit_place(p) self.removed_photo.append(ObjectId) self.db.remove_object(ObjectId) Utils.modified() def leave_clicked(): - self.bad_photo.append(ObjectMap[ObjectId]) - + self.bad_photo.append(ObjectId) def select_clicked(): # File is lost => select a file to replace the lost one def fs_close_window(obj): - self.bad_photo.append(ObjectMap[ObjectId]) + self.bad_photo.append(ObjectId) def fs_ok_clicked(obj): name = fs_top.get_filename() @@ -166,9 +189,9 @@ class CheckIntegrity: shutil.copystat(name,photo_name) except: pass - self.replaced_photo.append(ObjectMap[ObjectId]) + self.replaced_photo.append(ObjectId) else: - self.bad_photo.append(ObjectMap[ObjectId]) + self.bad_photo.append(ObjectId) fs_top = gtk.FileSelection("%s - GRAMPS" % _("Select file")) fs_top.hide_fileop_buttons() @@ -178,14 +201,15 @@ class CheckIntegrity: fs_top.destroy() #------------------------------------------------------------------------- - ObjectMap = self.db.get_object_map() - for ObjectId in ObjectMap.keys(): - photo_name = ObjectMap[ObjectId].get_path() + + for ObjectId in self.db.get_object_keys(): + obj = self.db.find_object_from_id(ObjectId) + photo_name = obj.get_path() if not os.path.isfile(photo_name): if cl: print "Warning: media file %s was not found." \ % os.path.basename(photo_name) - self.bad_photo.append(ObjectMap[ObjectId]) + self.bad_photo.append(ObjectId) else: if missmedia_action == 0: mmd = MissingMediaDialog(_("Media object could not be found"), @@ -204,8 +228,8 @@ class CheckIntegrity: select_clicked() def cleanup_empty_families(self,automatic): - for key in self.db.get_family_id_map().keys(): - family = self.db.get_family_id(key) + for key in self.db.get_family_keys(): + family = self.db.find_family_from_id(key) if family.get_father_id() == None and family.get_mother_id() == None: Utils.modified() self.empty_family.append(family) @@ -213,28 +237,32 @@ class CheckIntegrity: def delete_empty_family(self,family): for key in self.db.get_person_keys(): - child = self.db.get_person(key) + child = self.db.find_person_from_id(key) child.remove_parent_family_id(family.get_id()) child.remove_family_id(family.get_id()) self.db.delete_family(family.get_id()) def check_parent_relationships(self): - for key in self.db.get_family_id_map().keys(): - family = self.db.get_family_id(key) - father = family.get_father_id() - mother = family.get_mother_id() + for key in self.db.get_family_keys(): + family = self.db.find_family_from_id(key) + mother_id = family.get_mother_id() + father_id = family.get_father_id() + father = self.db.find_family_from_id(father_id) + mother = self.db.find_family_from_id(mother_id) type = family.get_relationship() if not father and not mother: continue elif father == None: if mother.get_gender() == RelLib.Person.male: - family.set_father_id(mother) + family.set_father_id(mother_id) family.set_mother_id(None) + self.db.commit_family(family) elif mother == None: if father.get_gender() == RelLib.Person.female: - family.set_mother_id(father) + family.set_mother_id(father_id) family.set_father_id(None) + self.db.commit_family(family) else: fgender = father.get_gender() mgender = mother.get_gender() @@ -242,16 +270,19 @@ class CheckIntegrity: if fgender == mgender and fgender != RelLib.Person.unknown: family.set_relationship("Partners") self.fam_rel.append(family) + self.db.commit_family(family) elif fgender == RelLib.Person.female or mgender == RelLib.Person.male: - family.set_father_id(mother) - family.set_mother_id(father) + family.set_father_id(mother_id) + family.set_mother_id(father_id) self.fam_rel.append(family) + self.db.commit_family(family) elif fgender != mgender: family.set_relationship("Unknown") self.fam_rel.append(family) if fgender == RelLib.Person.female or mgender == RelLib.Person.male: - family.set_father_id(mother) - family.set_mother_id(father) + family.set_father_id(mother_id) + family.set_mother_id(father_id) + self.db.commit_family(family) def build_report(self,cl=0): bad_photos = len(self.bad_photo) @@ -281,8 +312,8 @@ class CheckIntegrity: self.text.write(_("%d broken child/family links were found\n") % blink) for c in self.broken_links: cn = c[0].get_primary_name().get_name() - f = c[1].get_father_id() - m = c[1].get_mother_id() + f = self.db.find_person_from_id(c[1].get_father_id()) + m = self.db.find_person_from_id(c[1].get_mother_id()) if f and m: pn = _("%s and %s") % (f.get_primary_name().get_name(),\ m.get_primary_name().get_name()) @@ -302,8 +333,8 @@ class CheckIntegrity: self.text.write(_("%d broken spouse/family links were found\n") % plink) for c in self.broken_parent_links: cn = c[0].get_primary_name().get_name() - f = c[1].get_father_id() - m = c[1].get_mother_id() + f = self.db.find_person_from_id(c[1].get_father_id()) + m = self.db.find_person_from_id(c[1].get_mother_id()) if f and m: pn = _("%s and %s") % (f.get_primary_name().get_name(),\ m.get_primary_name().get_name())