def save(self): if not self.files_to_merge.files: messagebox.showinfo(_('Error'), message=_('Please add GEDCOM files')) return filename = filedialog.asksaveasfilename(title=_('Save as'), defaultextension='.ged', filetypes=(('GEDCOM', '.ged'), (_('All files'), '*.*'))) tree = Tree() indi_counter = 0 fam_counter = 0 # read the GEDCOM data for file in self.files_to_merge.files.values(): ged = Gedcom(file, tree) # add informations about individuals for num in ged.indi: fid = ged.indi[num].fid if fid not in tree.indi: indi_counter += 1 tree.indi[fid] = Indi(tree=tree, num=indi_counter) tree.indi[fid].tree = tree tree.indi[fid].fid = ged.indi[num].fid tree.indi[fid].fams_fid |= ged.indi[num].fams_fid tree.indi[fid].famc_fid |= ged.indi[num].famc_fid tree.indi[fid].name = ged.indi[num].name tree.indi[fid].birthnames = ged.indi[num].birthnames tree.indi[fid].nicknames = ged.indi[num].nicknames tree.indi[fid].aka = ged.indi[num].aka tree.indi[fid].married = ged.indi[num].married tree.indi[fid].gender = ged.indi[num].gender tree.indi[fid].facts = ged.indi[num].facts tree.indi[fid].notes = ged.indi[num].notes tree.indi[fid].sources = ged.indi[num].sources tree.indi[fid].memories = ged.indi[num].memories tree.indi[fid].baptism = ged.indi[num].baptism tree.indi[fid].confirmation = ged.indi[num].confirmation tree.indi[fid].endowment = ged.indi[num].endowment if not (tree.indi[fid].sealing_child and tree.indi[fid].sealing_child.famc): tree.indi[fid].sealing_child = ged.indi[num].sealing_child # add informations about families for num in ged.fam: husb, wife = (ged.fam[num].husb_fid, ged.fam[num].wife_fid) if (husb, wife) not in tree.fam: fam_counter += 1 tree.fam[(husb, wife)] = Fam(husb, wife, tree, fam_counter) tree.fam[(husb, wife)].tree = tree tree.fam[(husb, wife)].chil_fid |= ged.fam[num].chil_fid tree.fam[(husb, wife)].fid = ged.fam[num].fid tree.fam[(husb, wife)].facts = ged.fam[num].facts tree.fam[(husb, wife)].notes = ged.fam[num].notes tree.fam[(husb, wife)].sources = ged.fam[num].sources tree.fam[(husb, wife)].sealing_spouse = ged.fam[num].sealing_spouse # merge notes by text tree.notes = sorted(tree.notes, key=lambda x: x.text) for i, n in enumerate(tree.notes): if i == 0: n.num = 1 continue if n.text == tree.notes[i - 1].text: n.num = tree.notes[i - 1].num else: n.num = tree.notes[i - 1].num + 1 # compute number for family relationships and print GEDCOM file tree.reset_num() with open(filename, 'w', encoding='utf-8') as file: tree.print(file) messagebox.showinfo(_('Info'), message=_('Files successfully merged'))
# add informations about families for num in ged.fam: husb, wife = (ged.fam[num].husb_fid, ged.fam[num].wife_fid) if (husb, wife) not in tree.fam: fam_counter += 1 tree.fam[(husb, wife)] = Fam(husb, wife, tree, fam_counter) tree.fam[(husb, wife)].tree = tree tree.fam[(husb, wife)].chil_fid |= ged.fam[num].chil_fid tree.fam[(husb, wife)].fid = ged.fam[num].fid tree.fam[(husb, wife)].marriage_facts = ged.fam[num].marriage_facts tree.fam[(husb, wife)].notes = ged.fam[num].notes tree.fam[(husb, wife)].sources = ged.fam[num].sources tree.fam[(husb, wife)].sealing_spouse = ged.fam[num].sealing_spouse # merge notes by text tree.notes = sorted(tree.notes, key=lambda x: x.text) for i, n in enumerate(tree.notes): if i == 0: n.num = 1 continue if n.text == tree.notes[i - 1].text: n.num = tree.notes[i - 1].num else: n.num = tree.notes[i - 1].num + 1 # merge sources by fid tree.sources = sorted(tree.sources, key=lambda x: x.fid) for i, n in enumerate(tree.sources): if i == 0: n.num = 1 continue