diff --git a/src/Filters/Rules/Person/_IsAncestorOf.py b/src/Filters/Rules/Person/_IsAncestorOf.py index 65147b841..51ad11056 100644 --- a/src/Filters/Rules/Person/_IsAncestorOf.py +++ b/src/Filters/Rules/Person/_IsAncestorOf.py @@ -47,15 +47,12 @@ class IsAncestorOf(Rule): category = _("Ancestral filters") description = _("Matches people that are ancestors of a specified person") - def prepare(self,db): + def prepare(self, db): """Assume that if 'Inclusive' not defined, assume inclusive""" self.db = db - self.map = {} + self.map = set() try: - if int(self.list[1]): - first = 0 - else: - first = 1 + first = 0 if int(self.list[1]) else 1 except IndexError: first = 1 try: @@ -65,16 +62,16 @@ class IsAncestorOf(Rule): pass def reset(self): - self.map = {} + self.map.clear() - def apply(self,db,person): + def apply(self, db, person): return person.handle in self.map - def init_ancestor_list(self,db,person,first): + def init_ancestor_list(self, db, person,first): if not person: return if not first: - self.map[person.handle] = 1 + self.map.add(person.handle) fam_id = person.get_main_parents_family_handle() fam = db.get_family_from_handle(fam_id) diff --git a/src/Filters/Rules/Person/_IsLessThanNthGenerationAncestorOf.py b/src/Filters/Rules/Person/_IsLessThanNthGenerationAncestorOf.py index 356537750..a52e2d533 100644 --- a/src/Filters/Rules/Person/_IsLessThanNthGenerationAncestorOf.py +++ b/src/Filters/Rules/Person/_IsLessThanNthGenerationAncestorOf.py @@ -51,7 +51,7 @@ class IsLessThanNthGenerationAncestorOf(Rule): def prepare(self,db): self.db = db - self.map = {} + self.map = set() try: root_handle = db.get_person_from_gramps_id(self.list[0]).get_handle() self.init_ancestor_list(root_handle,0) @@ -59,7 +59,7 @@ class IsLessThanNthGenerationAncestorOf(Rule): pass def reset(self): - self.map = {} + self.map.clear() def apply(self,db,person): return person.handle in self.map @@ -70,7 +70,7 @@ class IsLessThanNthGenerationAncestorOf(Rule): if not handle: return if gen: - self.map[handle] = 1 + self.map.add(handle) if gen >= int(self.list[1]): return diff --git a/src/Filters/Rules/Person/_IsParentOfFilterMatch.py b/src/Filters/Rules/Person/_IsParentOfFilterMatch.py index bf4b8c493..0d405c827 100644 --- a/src/Filters/Rules/Person/_IsParentOfFilterMatch.py +++ b/src/Filters/Rules/Person/_IsParentOfFilterMatch.py @@ -50,7 +50,7 @@ class IsParentOfFilterMatch(MatchesFilter): def prepare(self,db): self.db = db - self.map = {} + self.map = set() filt = MatchesFilter(self.list) filt.prepare(db) for person in db.iter_people(): @@ -59,7 +59,7 @@ class IsParentOfFilterMatch(MatchesFilter): filt.reset() def reset(self): - self.map = {} + self.map.clear() def apply(self,db,person): return person.handle in self.map @@ -67,6 +67,6 @@ class IsParentOfFilterMatch(MatchesFilter): def init_list(self,person): for fam_id in person.get_parent_family_handle_list(): fam = self.db.get_family_from_handle(fam_id) - for parent_id in [fam.get_father_handle(), fam.get_mother_handle()]: - if parent_id: - self.map[parent_id] = 1 + self.map.update(parent_id + for parent_id in [fam.get_father_handle(), fam.get_mother_handle()] + if parent_id) diff --git a/src/Filters/Rules/Person/_IsSiblingOfFilterMatch.py b/src/Filters/Rules/Person/_IsSiblingOfFilterMatch.py index 01d71e979..e34b09213 100644 --- a/src/Filters/Rules/Person/_IsSiblingOfFilterMatch.py +++ b/src/Filters/Rules/Person/_IsSiblingOfFilterMatch.py @@ -49,7 +49,7 @@ class IsSiblingOfFilterMatch(MatchesFilter): def prepare(self,db): self.db = db - self.map = {} + self.map = set() filt = MatchesFilter(self.list) filt.prepare(db) for person in db.iter_people(): @@ -58,7 +58,7 @@ class IsSiblingOfFilterMatch(MatchesFilter): filt.reset() def reset(self): - self.map = {} + self.map.clear() def apply(self,db,person): return person.handle in self.map @@ -69,6 +69,6 @@ class IsSiblingOfFilterMatch(MatchesFilter): fam_id = person.get_main_parents_family_handle() fam = self.db.get_family_from_handle(fam_id) if fam: - for child_ref in fam.get_child_ref_list(): - if child_ref.ref != person.handle: - self.map[child_ref.ref] = 1 + self.map.update(child_ref.ref + for child_ref in fam.get_child_ref_list() + if child_ref.ref != person.handle) diff --git a/src/Filters/Rules/Person/_RelationshipPathBetween.py b/src/Filters/Rules/Person/_RelationshipPathBetween.py index 1ccde9eba..0430919b5 100644 --- a/src/Filters/Rules/Person/_RelationshipPathBetween.py +++ b/src/Filters/Rules/Person/_RelationshipPathBetween.py @@ -50,9 +50,9 @@ class RelationshipPathBetween(Rule): "to a common ancestor, producing the relationship " "path between two persons.") - def prepare(self,db): + def prepare(self, db): self.db = db - self.map = {} + self.map = set() try: root1_handle = db.get_person_from_gramps_id(self.list[0]).get_handle() root2_handle = db.get_person_from_gramps_id(self.list[1]).get_handle() @@ -61,11 +61,11 @@ class RelationshipPathBetween(Rule): pass def reset(self): - self.map = {} + self.map = () def desc_list(self, handle, map, first): if not first: - map[handle] = 1 + map.add(handle) p = self.db.get_person_from_handle(handle) for fam_id in p.get_family_handle_list(): @@ -73,61 +73,49 @@ class RelationshipPathBetween(Rule): if fam: for child_ref in fam.get_child_ref_list(): if child_ref.ref: - self.desc_list(child_ref.ref,map,0) + self.desc_list(child_ref.ref, map, 0) - def apply_filter(self,rank, handle,plist,pmap): + def apply_filter(self, rank, handle, plist, pmap): person = self.db.get_person_from_handle(handle) if person is None: return - plist.append(handle) + plist.add(handle) pmap[person.get_handle()] = rank fam_id = person.get_main_parents_family_handle() family = self.db.get_family_from_handle(fam_id) if family is not None: - self.apply_filter(rank+1,family.get_father_handle(),plist,pmap) - self.apply_filter(rank+1,family.get_mother_handle(),plist,pmap) + self.apply_filter(rank+1, family.get_father_handle(), plist, pmap) + self.apply_filter(rank+1, family.get_mother_handle(), plist, pmap) - def apply(self,db,person): + def apply(self, db, person): return person.handle in self.map - def init_list(self,p1_handle,p2_handle): + def init_list(self, p1_handle, p2_handle): firstMap = {} - firstList = [] + firstList = set() secondMap = {} - secondList = [] + secondList = set() common = [] rank = 9999999 - self.apply_filter(0,p1_handle,firstList,firstMap) - self.apply_filter(0,p2_handle,secondList,secondMap) + self.apply_filter(0, p1_handle, firstList, firstMap) + self.apply_filter(0, p2_handle ,secondList, secondMap) - for person_handle in firstList: - if person_handle in secondList: - new_rank = firstMap[person_handle] - if new_rank < rank: - rank = new_rank - common = [ person_handle ] - elif new_rank == rank: - common.append(person_handle) + for person_handle in firstList & secondList: + new_rank = firstMap[person_handle] + if new_rank < rank: + rank = new_rank + common = [person_handle] + elif new_rank == rank: + common.append(person_handle) - path1 = { p1_handle : 1} - path2 = { p2_handle : 1} + path1 = set([p1_handle]) + path2 = set([p2_handle]) for person_handle in common: - new_map = {} - self.desc_list(person_handle, new_map,1) - self.get_intersection(path1,firstMap, new_map) - self.get_intersection(path2,secondMap, new_map) - - for e in path1: - self.map[e] = 1 - for e in path2: - self.map[e] = 1 - for e in common: - self.map[e] = 1 - - def get_intersection(self,target, map1, map2): - for e in map1: - if e in map2: - target[e] = map2[e] + new_map = set() + self.desc_list(person_handle, new_map, 1) + path1.update(new_map.intersection(firstMap)) + path2.update(new_map.intersection(secondMap)) + self.map.update(path1, path2, common) diff --git a/src/plugins/gramplet/DeepConnections.py b/src/plugins/gramplet/DeepConnections.py index c731ea4d3..c589fb6b7 100644 --- a/src/plugins/gramplet/DeepConnections.py +++ b/src/plugins/gramplet/DeepConnections.py @@ -75,24 +75,31 @@ class DeepConnectionsGramplet(Gramplet): family_list = person.get_family_handle_list() for family_handle in family_list: family = self.dbstate.db.get_family_from_handle(family_handle) + children = family.get_child_ref_list() - for child_ref in children: - retval += [(child_ref.ref, (path, (_("child"), person_handle)))] + retval.extend((child_ref.ref, (path, (_("child"), person_handle))) + for child_ref in children) + husband = family.get_father_handle() if husband: retval += [(husband, (path, (_("husband"), person_handle)))] + wife = family.get_mother_handle() if wife: retval += [(wife, (path, (_("wife"), person_handle)))] + parent_family_list = person.get_parent_family_handle_list() for family_handle in parent_family_list: family = self.dbstate.db.get_family_from_handle(family_handle) + children = family.get_child_ref_list() - for child_ref in children: - retval += [(child_ref.ref, (path, (_("sibling"), person_handle)))] + retval.extend((child_ref.ref, (path, (_("child"), person_handle))) + for child_ref in children) + husband = family.get_father_handle() if husband: retval += [(husband, (path, (_("father"), person_handle)))] + wife = family.get_mother_handle() if wife: retval += [(wife, (path, (_("mother"), person_handle)))] @@ -132,7 +139,7 @@ class DeepConnectionsGramplet(Gramplet): if active_person == None: self.set_text(_("No Active Person set.")) return - self.cache = {} + self.cache = set() self.queue = [(default_person.handle, (None, (_("self"), default_person.handle)))] default_name = default_person.get_primary_name() active_name = active_person.get_primary_name() @@ -160,7 +167,7 @@ class DeepConnectionsGramplet(Gramplet): break elif current_handle in self.cache: continue - self.cache[current_handle] = 1 + self.cache.add(current_handle) relatives = self.get_relatives(current_handle, current_path) for (person_handle, path) in relatives: if person_handle is not None and person_handle not in self.cache: