def get_person_tooltip(person, database): """ Get Person tooltip string. """ # get birth/christening and death/burying date strings. birth_event = get_birth_or_fallback(database, person) if birth_event: birth = datehandler.get_date(birth_event) else: birth = '' death_event = get_death_or_fallback(database, person) if death_event: death = datehandler.get_date(death_event) else: death = '' # get list of parents. parents = [] parents_list = find_parents(database, person) for parent_id in parents_list: if not parent_id: continue parent = database.get_person_from_handle(parent_id) if not parent: continue parents.append(displayer.display(parent)) # build tooltip string tooltip = '' if birth: tooltip += _('Birth: %s' % birth) if death: if tooltip: tooltip += '\n' tooltip += _('Death: %s' % death) if (birth or death) and parents: tooltip += '\n\n' if parents: tooltip += _('Parents:') for p in parents: tooltip += ('\n %s' % p) return tooltip
def sort_persons(self, person_handle_list): "sort persons by close relations" # first make a list of all persons who don't have any parents root_nodes = list() for person_handle in person_handle_list: person = self.database.get_person_from_handle(person_handle) has_parent = False for parent_handle in find_parents(self.database, person): if parent_handle not in person_handle_list: continue has_parent = True if not has_parent: root_nodes.append(person_handle) # now start from all root nodes we found and traverse their trees outlist = list() p_done = set() for person_handle in root_nodes: todolist = list() todolist.append(person_handle) while len(todolist) > 0: # take the first person from todolist and do sanity check cur = todolist.pop(0) if cur in p_done: continue if cur not in person_handle_list: p_done.add(cur) continue person = self.database.get_person_from_handle(cur) # first check whether both parents are added missing_parents = False for parent_handle in find_parents(self.database, person): if not parent_handle or parent_handle in p_done: continue if parent_handle not in person_handle_list: continue todolist.insert(0, parent_handle) missing_parents = True # if one of the parents is still missing, wait for them if missing_parents: continue # add person to the sorted output outlist.append(cur) p_done.add(cur) # add all spouses and children to the todo list family_list = person.get_family_handle_list() for fam_handle in family_list: family = self.database.get_family_from_handle(fam_handle) if family is None: continue if (family.get_father_handle() and family.get_father_handle() != cur): todolist.insert(0, family.get_father_handle()) if (family.get_mother_handle() and family.get_mother_handle() != cur): todolist.insert(0, family.get_mother_handle()) for child_ref in family.get_child_ref_list(): todolist.append(child_ref.ref) # finally store the result assert len(person_handle_list) == len(outlist) return outlist
def sort_persons(self, person_handle_list): "sort persons by close relations" # first make a list of all persons who don't have any parents root_nodes = list() for person_handle in person_handle_list: person = self.database.get_person_from_handle(person_handle) has_parent = False for parent_handle in find_parents(self.database, person): if parent_handle not in self.persons: continue has_parent = True if not has_parent: root_nodes.append(person_handle) # now start from all root nodes we found and traverse their trees outlist = list() p_done = set() for person_handle in root_nodes: todolist = list() todolist.append(person_handle) while len(todolist) > 0: # take the first person from todolist and do sanity check cur = todolist.pop(0) if cur in p_done: continue if cur not in self.persons: p_done.add(cur) continue person = self.database.get_person_from_handle(cur) # first check whether both parents are added missing_parents = False for parent_handle in find_parents(self.database, person): if not parent_handle or parent_handle in p_done: continue if parent_handle not in self.persons: continue todolist.insert(0, parent_handle) missing_parents = True # if one of the parents is still missing, wait for them if missing_parents: continue # add person to the sorted output outlist.append(cur) p_done.add(cur) # add all spouses and children to the todo list family_list = person.get_family_handle_list() for fam_handle in family_list: family = self.database.get_family_from_handle(fam_handle) if family is None: continue if (family.get_father_handle() and family.get_father_handle() != cur): todolist.insert(0, family.get_father_handle()) if (family.get_mother_handle() and family.get_mother_handle() != cur): todolist.insert(0, family.get_mother_handle()) for child_ref in family.get_child_ref_list(): todolist.append(child_ref.ref) # finally store the result assert len(person_handle_list) == len(outlist) return outlist