2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2005-01-12 04:11:15 +05:30
|
|
|
# Copyright (C) 2002-2005 Donald N. Allingham
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2003-12-08 07:53:53 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Generic Filtering Routines"""
|
|
|
|
|
|
|
|
__author__ = "Don Allingham"
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Try to abstract SAX1 from SAX2
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-04-30 08:31:51 +05:30
|
|
|
from xml.sax import make_parser,handler,SAXParseException
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
2005-01-12 04:11:15 +05:30
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gtk
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
2003-01-10 10:51:32 +05:30
|
|
|
import RelLib
|
2002-10-20 19:55:16 +05:30
|
|
|
import Date
|
2004-12-01 18:32:22 +05:30
|
|
|
import DateHandler
|
2005-01-01 09:57:15 +05:30
|
|
|
import NameDisplay
|
2004-01-21 04:58:44 +05:30
|
|
|
from TransTable import TransTable
|
2005-03-15 21:56:30 +05:30
|
|
|
from Utils import for_each_ancestor,probably_alive,get_source_referents
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# date_cmp
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
def date_cmp(rule,value):
|
|
|
|
sd = rule.get_start_date()
|
2005-05-03 03:20:15 +05:30
|
|
|
s = rule.get_modifier()
|
|
|
|
od = value.get_start_date()
|
|
|
|
cmp_rule = (sd[2],sd[1],sd[0])
|
|
|
|
cmp_value = (od[2],od[1],od[0])
|
2004-09-17 10:02:01 +05:30
|
|
|
if s == Date.MOD_BEFORE:
|
2005-05-03 03:20:15 +05:30
|
|
|
return cmp_rule > cmp_value
|
2004-09-17 10:02:01 +05:30
|
|
|
elif s == Date.MOD_AFTER:
|
2005-05-03 03:20:15 +05:30
|
|
|
return cmp_rule < cmp_value
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2005-05-03 03:20:15 +05:30
|
|
|
return cmp_rule == cmp_value
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Rule
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class Rule:
|
|
|
|
"""Base rule class"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = []
|
|
|
|
name = ''
|
|
|
|
category = _('Miscellaneous filters')
|
|
|
|
description = _('No description')
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def __init__(self,list):
|
2004-04-30 08:31:51 +05:30
|
|
|
self.set_list(list)
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def prepare(self,db):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
pass
|
2004-04-30 08:31:51 +05:30
|
|
|
|
|
|
|
def set_list(self,list):
|
2004-01-21 08:26:53 +05:30
|
|
|
assert type(list) == type([]) or list == None, "Argument is not a list"
|
2002-10-20 19:55:16 +05:30
|
|
|
self.list = list
|
|
|
|
|
|
|
|
def values(self):
|
|
|
|
return self.list
|
|
|
|
|
|
|
|
def check(self):
|
|
|
|
return len(self.list) == len(self.labels)
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2002-10-20 19:55:16 +05:30
|
|
|
return 1
|
|
|
|
|
|
|
|
def display_values(self):
|
|
|
|
v = []
|
|
|
|
for i in range(0,len(self.list)):
|
|
|
|
if self.list[i]:
|
2004-01-21 08:26:53 +05:30
|
|
|
v.append('%s="%s"' % (_(self.labels[i]),_(self.list[i])))
|
2005-01-12 04:11:15 +05:30
|
|
|
return ';'.join(v)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Everyone
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class Everyone(Rule):
|
|
|
|
"""Matches Everyone"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('Everyone')
|
|
|
|
category = _('General filters')
|
|
|
|
description = _('Matches everyone in the database')
|
2003-08-10 10:58:11 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2002-10-20 19:55:16 +05:30
|
|
|
return 1
|
|
|
|
|
2004-12-05 09:45:48 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Disconnected
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class Disconnected(Rule):
|
2005-05-18 03:45:32 +05:30
|
|
|
"""Matches disconnected people"""
|
2004-12-05 09:45:48 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('Disconnected people')
|
|
|
|
category = _('General filters')
|
|
|
|
description = _('Matches people that have no family relationships '
|
2005-05-18 03:45:32 +05:30
|
|
|
'to any other person in the database')
|
2004-12-05 09:45:48 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
person = db.get_person_from_handle(handle)
|
2004-12-05 09:45:48 +05:30
|
|
|
return (not person.get_main_parents_family_handle() and
|
|
|
|
not len(person.get_family_handle_list()))
|
|
|
|
|
2003-10-24 03:23:53 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# RelationshipPathBetween
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class RelationshipPathBetween(Rule):
|
|
|
|
"""Rule that checks for a person that is a descendant of a specified person
|
|
|
|
not more than N generations away"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('ID:'), _('ID:') ]
|
|
|
|
name = _("Relationship path between <persons>")
|
|
|
|
category = _('Relationship filters')
|
|
|
|
description = _("Matches the ancestors of two persons back to a common ancestor, "
|
|
|
|
"producing the relationship path between two persons.")
|
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
|
|
|
self.map = {}
|
2005-05-19 13:27:50 +05:30
|
|
|
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()
|
|
|
|
self.init_list(root1_handle,root2_handle)
|
|
|
|
except:
|
|
|
|
pass
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def reset(self):
|
2003-10-24 03:23:53 +05:30
|
|
|
self.map = {}
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def desc_list(self, handle, map, first):
|
2003-10-24 03:23:53 +05:30
|
|
|
if not first:
|
2005-05-19 02:26:30 +05:30
|
|
|
map[handle] = 1
|
2003-10-24 03:23:53 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
p = self.db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for fam_id in p.get_family_handle_list():
|
2004-08-22 11:03:37 +05:30
|
|
|
fam = self.db.get_family_from_handle(fam_id)
|
|
|
|
if fam:
|
2004-07-28 07:59:07 +05:30
|
|
|
for child_handle in fam.get_child_handle_list():
|
|
|
|
if child_handle:
|
|
|
|
self.desc_list(child_handle,map,0)
|
2003-10-24 03:23:53 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply_filter(self,rank,handle,plist,pmap):
|
|
|
|
person = self.db.get_person_from_handle(handle)
|
2003-10-24 03:23:53 +05:30
|
|
|
if person == None:
|
|
|
|
return
|
|
|
|
plist.append(person)
|
2004-07-28 07:59:07 +05:30
|
|
|
pmap[person.get_handle()] = rank
|
2003-10-24 03:23:53 +05:30
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
fam_id = person.get_main_parents_family_handle()
|
|
|
|
family = self.db.get_family_from_handle(fam_id)
|
2003-10-24 03:23:53 +05:30
|
|
|
if family != None:
|
2004-07-28 07:59:07 +05:30
|
|
|
self.apply_filter(rank+1,family.get_father_handle(),plist,pmap)
|
|
|
|
self.apply_filter(rank+1,family.get_mother_handle(),plist,pmap)
|
2003-10-24 03:23:53 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2003-10-24 03:23:53 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def init_list(self,p1_handle,p2_handle):
|
2003-10-24 03:23:53 +05:30
|
|
|
firstMap = {}
|
|
|
|
firstList = []
|
|
|
|
secondMap = {}
|
|
|
|
secondList = []
|
|
|
|
common = []
|
|
|
|
rank = 9999999
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
self.apply_filter(0,p1_handle,firstList,firstMap)
|
|
|
|
self.apply_filter(0,p2_handle,secondList,secondMap)
|
2003-10-24 03:23:53 +05:30
|
|
|
|
2004-07-28 07:59:07 +05:30
|
|
|
for person_handle in firstList:
|
|
|
|
if person_handle in secondList:
|
|
|
|
new_rank = firstMap[person_handle]
|
2003-10-24 03:23:53 +05:30
|
|
|
if new_rank < rank:
|
|
|
|
rank = new_rank
|
2004-07-28 07:59:07 +05:30
|
|
|
common = [ person_handle ]
|
2003-10-24 03:23:53 +05:30
|
|
|
elif new_rank == rank:
|
2004-07-28 07:59:07 +05:30
|
|
|
common.append(person_handle)
|
2003-10-24 03:23:53 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
path1 = { p1_handle : 1}
|
|
|
|
path2 = { p2_handle : 1}
|
2003-10-24 03:23:53 +05:30
|
|
|
|
2004-07-28 07:59:07 +05:30
|
|
|
for person_handle in common:
|
2003-10-24 03:23:53 +05:30
|
|
|
new_map = {}
|
2004-07-28 07:59:07 +05:30
|
|
|
self.desc_list(person_handle,new_map,1)
|
2003-10-24 03:23:53 +05:30
|
|
|
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:
|
2004-03-11 09:01:35 +05:30
|
|
|
self.map[e] = 1
|
2003-10-24 03:23:53 +05:30
|
|
|
|
|
|
|
def get_intersection(self,target, map1, map2):
|
|
|
|
for e in map1.keys():
|
|
|
|
if map2.has_key(e):
|
|
|
|
target[e] = map2[e]
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasIdOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasIdOf(Rule):
|
2003-08-10 10:58:11 +05:30
|
|
|
"""Rule that checks for a person with a specific GRAMPS ID"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('ID:') ]
|
2005-05-19 02:35:37 +05:30
|
|
|
name = _('People with <Id>')
|
2005-05-19 02:26:30 +05:30
|
|
|
description = _("Matches people with a specified GRAMPS ID")
|
|
|
|
category = _('General filters')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return db.get_person_from_handle(handle).get_gramps_id() == self.list[0]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-03-09 23:17:23 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasIdOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsDefaultPerson(Rule):
|
|
|
|
"""Rule that checks for a default person in the database"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('Default person')
|
|
|
|
category = _('General filters')
|
|
|
|
description = _("Matches the default person")
|
2005-03-09 23:17:23 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2005-03-09 23:17:23 +05:30
|
|
|
person = db.get_default_person()
|
|
|
|
if person:
|
2005-05-19 02:26:30 +05:30
|
|
|
return handle == person.get_handle()
|
2005-03-11 02:25:18 +05:30
|
|
|
return 0
|
2005-03-09 23:17:23 +05:30
|
|
|
|
2005-03-11 00:31:00 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsBookmarked
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsBookmarked(Rule):
|
|
|
|
"""Rule that checks for the bookmark list in the database"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('Bookmarked people')
|
|
|
|
category = _('General filters')
|
|
|
|
description = _("Matches the people on the bookmark list")
|
2005-03-11 00:31:00 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
if handle in db.get_bookmarks():
|
2005-03-11 00:31:00 +05:30
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
2003-12-08 07:53:53 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasCompleteRecord
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasCompleteRecord(Rule):
|
|
|
|
"""Rule that checks for a person whose record is complete"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('People with complete records')
|
|
|
|
category = _('General filters')
|
|
|
|
description = _('Matches all people whose records are complete')
|
2003-12-08 07:53:53 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return db.get_person_from_handle(handle).get_complete_flag() == 1
|
2003-12-08 07:53:53 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsFemale
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsFemale(Rule):
|
|
|
|
"""Rule that checks for a person that is a female"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('Females')
|
|
|
|
category = _('General filters')
|
|
|
|
description = _('Matches all females')
|
2003-08-10 10:58:11 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return db.get_person_from_handle(handle).get_gender() == RelLib.Person.FEMALE
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-18 03:45:32 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasUnknownGender
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasUnknownGender(Rule):
|
|
|
|
"""Rule that checks for a person that has unknown gender"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('People with unknown gender')
|
|
|
|
category = _('General filters')
|
|
|
|
description = _('Matches all people with unknown gender')
|
2005-05-18 03:45:32 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return db.get_person_from_handle(handle).get_gender() == RelLib.Person.UNKNOWN
|
2005-05-18 03:45:32 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsDescendantOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsDescendantOf(Rule):
|
|
|
|
"""Rule that checks for a person that is a descendant
|
|
|
|
of a specified person"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('ID:'), _('Inclusive:') ]
|
|
|
|
name = _('Descendants of <person>')
|
|
|
|
category = _('Descendant filters')
|
|
|
|
description = _('Matches all descendants for the specified person')
|
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
2003-06-12 07:34:42 +05:30
|
|
|
self.map = {}
|
2003-09-09 07:18:30 +05:30
|
|
|
try:
|
|
|
|
if int(self.list[1]):
|
|
|
|
first = 0
|
|
|
|
else:
|
|
|
|
first = 1
|
|
|
|
except IndexError:
|
2003-09-05 10:08:43 +05:30
|
|
|
first = 1
|
2005-05-19 13:27:50 +05:30
|
|
|
try:
|
|
|
|
root_handle = db.get_person_from_gramps_id(self.list[0]).get_handle()
|
|
|
|
self.init_list(root_handle,first)
|
|
|
|
except:
|
|
|
|
pass
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
self.map = {}
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2003-06-12 07:34:42 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def init_list(self,handle,first):
|
|
|
|
if not handle:
|
2005-05-05 15:24:23 +05:30
|
|
|
return
|
2003-08-05 09:05:42 +05:30
|
|
|
if not first:
|
2005-05-19 02:26:30 +05:30
|
|
|
self.map[handle] = 1
|
2003-06-12 07:34:42 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
p = self.db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for fam_id in p.get_family_handle_list():
|
2004-08-22 11:03:37 +05:30
|
|
|
fam = self.db.get_family_from_handle(fam_id)
|
|
|
|
if fam:
|
2004-07-28 07:59:07 +05:30
|
|
|
for child_handle in fam.get_child_handle_list():
|
|
|
|
self.init_list(child_handle,0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-07-24 22:17:36 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsDescendantOfFilterMatch
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsDescendantOfFilterMatch(IsDescendantOf):
|
|
|
|
"""Rule that checks for a person that is a descendant
|
|
|
|
of someone matched by a filter"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Filter name:'), _('Inclusive:') ]
|
|
|
|
name = _('Descendants of <filter> match')
|
|
|
|
category = _('Descendant filters')
|
|
|
|
description = _("Matches people that are descendants of anybody matched by a filter")
|
|
|
|
|
2003-07-24 22:17:36 +05:30
|
|
|
|
|
|
|
def __init__(self,list):
|
|
|
|
IsDescendantOf.__init__(self,list)
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
|
|
|
self.map = {}
|
|
|
|
try:
|
|
|
|
if int(self.list[1]):
|
|
|
|
first = 0
|
|
|
|
else:
|
|
|
|
first = 1
|
|
|
|
except IndexError:
|
|
|
|
first = 1
|
|
|
|
|
|
|
|
filt = MatchesFilter(self.list)
|
|
|
|
filt.prepare(db)
|
|
|
|
for person_handle in db.get_person_handles(sort_handles=False):
|
|
|
|
if filt.apply (db, person_handle):
|
|
|
|
self.init_list (person_handle,first)
|
|
|
|
filt.reset()
|
2003-07-24 22:17:36 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def reset(self):
|
|
|
|
self.map = {}
|
2003-08-10 10:58:11 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2003-08-05 09:05:42 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsLessThanNthGenerationDescendantOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsLessThanNthGenerationDescendantOf(Rule):
|
|
|
|
"""Rule that checks for a person that is a descendant of a specified person
|
|
|
|
not more than N generations away"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('ID:'), _('Number of generations:') ]
|
|
|
|
name = _('Descendants of <person> not more than <N> generations away')
|
|
|
|
category = _('Descendant filters')
|
|
|
|
description = _("Matches people that are descendants of a specified person "
|
|
|
|
"not more than N generations away")
|
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
|
|
|
self.map = {}
|
2005-05-19 13:27:50 +05:30
|
|
|
try:
|
|
|
|
root_handle = db.get_person_from_gramps_id(self.list[0]).get_handle()
|
|
|
|
self.init_list(root_handle,0)
|
|
|
|
except:
|
|
|
|
pass
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def reset(self):
|
2003-08-05 09:05:42 +05:30
|
|
|
self.map = {}
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2003-08-05 09:05:42 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def init_list(self,handle,gen):
|
|
|
|
if not handle:
|
2005-05-05 15:24:23 +05:30
|
|
|
return
|
2003-08-05 09:05:42 +05:30
|
|
|
if gen:
|
2005-05-19 02:26:30 +05:30
|
|
|
self.map[handle] = 1
|
2003-08-05 09:05:42 +05:30
|
|
|
if gen >= int(self.list[1]):
|
|
|
|
return
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
p = self.db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for fam_id in p.get_family_handle_list():
|
2004-08-11 22:30:38 +05:30
|
|
|
fam = self.db.get_family_from_handle(fam_id)
|
2004-07-28 07:59:07 +05:30
|
|
|
for child_handle in fam.get_child_handle_list():
|
|
|
|
self.init_list(child_handle,gen+1)
|
2003-08-05 09:05:42 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsMoreThanNthGenerationDescendantOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsMoreThanNthGenerationDescendantOf(Rule):
|
|
|
|
"""Rule that checks for a person that is a descendant of a specified person
|
|
|
|
at least N generations away"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('ID:'), _('Number of generations:') ]
|
|
|
|
name = _('Descendants of <person> at least <N> generations away')
|
|
|
|
category = _("Descendant filters")
|
|
|
|
description = _("Matches people that are descendants of a specified "
|
|
|
|
"person at least N generations away")
|
|
|
|
|
2003-08-05 09:05:42 +05:30
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
|
|
|
self.map = {}
|
2005-05-19 13:27:50 +05:30
|
|
|
try:
|
|
|
|
root_handle = db.get_person_from_gramps_id(self.list[0]).get_handle()
|
|
|
|
self.init_list(root_handle,0)
|
|
|
|
except:
|
|
|
|
pass
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def reset(self):
|
2003-08-05 09:05:42 +05:30
|
|
|
self.map = {}
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2003-08-05 09:05:42 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def init_list(self,handle,gen):
|
|
|
|
if not handle:
|
2005-05-05 15:24:23 +05:30
|
|
|
return
|
2003-08-05 09:05:42 +05:30
|
|
|
if gen >= int(self.list[1]):
|
2005-05-19 02:26:30 +05:30
|
|
|
self.map[handle] = 1
|
2003-08-05 09:05:42 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
p = self.db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for fam_id in p.get_family_handle_list():
|
2004-08-11 22:30:38 +05:30
|
|
|
fam = self.db.get_family_from_handle(fam_id)
|
2004-07-28 07:59:07 +05:30
|
|
|
for child_handle in fam.get_child_handle_list():
|
|
|
|
self.init_list(child_handle,gen+1)
|
2003-08-05 09:05:42 +05:30
|
|
|
|
2003-07-24 22:17:36 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsChildOfFilterMatch
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsChildOfFilterMatch(Rule):
|
|
|
|
"""Rule that checks for a person that is a child
|
|
|
|
of someone matched by a filter"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Filter name:') ]
|
|
|
|
name = _('Children of <filter> match')
|
|
|
|
category = _('Family filters')
|
|
|
|
description = _("Matches children of anybody matched by a filter")
|
2003-07-24 22:17:36 +05:30
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
|
|
|
self.map = {}
|
|
|
|
filt = MatchesFilter(self.list)
|
2005-04-07 18:54:16 +05:30
|
|
|
filt.prepare(db)
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
for person_handle in db.get_person_handles(sort_handles=False):
|
|
|
|
if filt.apply (db, person_handle):
|
|
|
|
self.init_list (person_handle)
|
2005-04-07 18:54:16 +05:30
|
|
|
filt.reset()
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def reset(self):
|
2003-07-24 22:17:36 +05:30
|
|
|
self.map = {}
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2003-09-05 10:08:43 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def init_list(self,handle):
|
|
|
|
if not handle:
|
2005-05-05 15:24:23 +05:30
|
|
|
return
|
2005-05-19 02:26:30 +05:30
|
|
|
p = self.db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for fam_id in p.get_family_handle_list():
|
2004-08-11 22:30:38 +05:30
|
|
|
fam = self.db.get_family_from_handle(fam_id)
|
2004-07-28 07:59:07 +05:30
|
|
|
for child_handle in fam.get_child_handle_list():
|
|
|
|
self.map[child_handle] = 1
|
2003-07-24 22:17:36 +05:30
|
|
|
|
2005-03-09 23:17:23 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsSiblingOfFilterMatch
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsSiblingOfFilterMatch(Rule):
|
2005-05-17 03:30:59 +05:30
|
|
|
"""Rule that checks for siblings of someone matched by a filter"""
|
2005-03-09 23:17:23 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Filter name:') ]
|
|
|
|
name = _('Siblings of <filter> match')
|
|
|
|
category = _('Family filters')
|
|
|
|
description = _("Matches siblings of anybody matched by a filter")
|
2005-03-09 23:17:23 +05:30
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
|
|
|
self.map = {}
|
|
|
|
filt = MatchesFilter(self.list)
|
2005-04-07 18:54:16 +05:30
|
|
|
filt.prepare(db)
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
for person_handle in db.get_person_handles(sort_handles=False):
|
|
|
|
if filt.apply (db, person_handle):
|
|
|
|
self.init_list (person_handle)
|
2005-04-07 18:54:16 +05:30
|
|
|
filt.reset()
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def reset(self):
|
2005-03-09 23:17:23 +05:30
|
|
|
self.map = {}
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2005-03-09 23:17:23 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def init_list(self,handle):
|
|
|
|
if not handle:
|
2005-05-05 15:24:23 +05:30
|
|
|
return
|
2005-05-19 02:26:30 +05:30
|
|
|
p = self.db.get_person_from_handle(handle)
|
2005-03-09 23:17:23 +05:30
|
|
|
fam_id = p.get_main_parents_family_handle()
|
|
|
|
fam = self.db.get_family_from_handle(fam_id)
|
|
|
|
if fam:
|
|
|
|
for child_handle in fam.get_child_handle_list():
|
2005-05-19 02:26:30 +05:30
|
|
|
if child_handle != handle:
|
2005-05-14 15:33:36 +05:30
|
|
|
self.map[child_handle] = 1
|
2005-03-09 23:17:23 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsDescendantFamilyOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsDescendantFamilyOf(Rule):
|
|
|
|
"""Rule that checks for a person that is a descendant or the spouse
|
|
|
|
of a descendant of a specified person"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('ID:') ]
|
|
|
|
name = _('Descendant family members of <person>')
|
|
|
|
category = _('Descendant filters')
|
|
|
|
description = _("Matches people that are descendants or the spouse "
|
2003-08-10 10:58:11 +05:30
|
|
|
"of a descendant of a specified person")
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2003-05-23 09:38:03 +05:30
|
|
|
self.map = {}
|
2005-05-19 02:26:30 +05:30
|
|
|
self.orig_handle = handle
|
2004-02-14 11:10:30 +05:30
|
|
|
self.db = db
|
2005-05-19 02:26:30 +05:30
|
|
|
return self.search(handle,1)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def search(self,handle,val):
|
2005-05-19 13:27:50 +05:30
|
|
|
try:
|
|
|
|
if handle == self.db.get_person_from_gramps_id(self.list[0]).get_handle():
|
|
|
|
self.map[handle] = 1
|
|
|
|
return 1
|
|
|
|
except:
|
|
|
|
return 0
|
2004-03-11 09:01:35 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
p = self.db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for (f,r1,r2) in p.get_parent_family_handle_list():
|
2004-08-11 22:30:38 +05:30
|
|
|
family = self.db.get_family_from_handle(f)
|
2004-07-28 07:59:07 +05:30
|
|
|
for person_handle in [family.get_mother_handle(),family.get_father_handle()]:
|
|
|
|
if person_handle:
|
|
|
|
if self.search(person_handle,0):
|
2002-10-20 19:55:16 +05:30
|
|
|
return 1
|
|
|
|
if val:
|
2004-07-28 07:59:07 +05:30
|
|
|
for family_handle in p.get_family_handle_list():
|
2004-08-11 22:30:38 +05:30
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2005-05-19 02:26:30 +05:30
|
|
|
if handle == family.get_father_handle():
|
2004-07-28 07:59:07 +05:30
|
|
|
spouse_id = family.get_mother_handle()
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-07-28 07:59:07 +05:30
|
|
|
spouse_id = family.get_father_handle()
|
2004-02-14 11:10:30 +05:30
|
|
|
if spouse_id:
|
2004-03-11 09:01:35 +05:30
|
|
|
if self.search(spouse_id,0):
|
2002-10-20 19:55:16 +05:30
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsAncestorOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsAncestorOf(Rule):
|
|
|
|
"""Rule that checks for a person that is an ancestor of a specified person"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('ID:'), _('Inclusive:') ]
|
|
|
|
name = _('Ancestors of <person>')
|
|
|
|
category = _("Ancestral filters")
|
|
|
|
description = _("Matches people that are ancestors of a specified person")
|
2003-05-23 09:38:03 +05:30
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
"""Assume that if 'Inclusive' not defined, assume inclusive"""
|
|
|
|
self.db = db
|
|
|
|
self.map = {}
|
|
|
|
try:
|
|
|
|
if int(self.list[1]):
|
|
|
|
first = 0
|
|
|
|
else:
|
|
|
|
first = 1
|
|
|
|
except IndexError:
|
|
|
|
first = 1
|
2005-05-19 13:27:50 +05:30
|
|
|
try:
|
|
|
|
root_handle = db.get_person_from_gramps_id(self.list[0]).get_handle()
|
|
|
|
self.init_ancestor_list(db,root_handle,first)
|
|
|
|
except:
|
|
|
|
pass
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def reset(self):
|
2003-05-23 09:38:03 +05:30
|
|
|
self.map = {}
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2003-09-05 10:08:43 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def init_ancestor_list(self,db,handle,first):
|
|
|
|
if not handle:
|
2005-05-05 15:24:23 +05:30
|
|
|
return
|
2003-08-05 09:05:42 +05:30
|
|
|
if not first:
|
2005-05-19 02:26:30 +05:30
|
|
|
self.map[handle] = 1
|
2003-06-12 07:34:42 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
p = db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
fam_id = p.get_main_parents_family_handle()
|
2005-03-03 10:43:47 +05:30
|
|
|
fam = db.get_family_from_handle(fam_id)
|
2004-08-22 11:03:37 +05:30
|
|
|
if fam:
|
2004-07-28 07:59:07 +05:30
|
|
|
f_id = fam.get_father_handle()
|
|
|
|
m_id = fam.get_mother_handle()
|
2003-06-12 07:34:42 +05:30
|
|
|
|
2004-03-11 09:01:35 +05:30
|
|
|
if f_id:
|
2005-03-03 10:43:47 +05:30
|
|
|
self.init_ancestor_list(db,f_id,0)
|
2004-03-11 09:01:35 +05:30
|
|
|
if m_id:
|
2005-03-03 10:43:47 +05:30
|
|
|
self.init_ancestor_list(db,m_id,0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-07-24 22:17:36 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsAncestorOfFilterMatch
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-08-05 09:05:42 +05:30
|
|
|
class IsAncestorOfFilterMatch(IsAncestorOf):
|
2003-07-24 22:17:36 +05:30
|
|
|
"""Rule that checks for a person that is an ancestor of
|
|
|
|
someone matched by a filter"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Filter name:'), _('Inclusive:') ]
|
|
|
|
name = _('Ancestors of <filter> match')
|
|
|
|
category = _("Ancestral filters")
|
|
|
|
description = _("Matches people that are ancestors "
|
|
|
|
"of anybody matched by a filter")
|
|
|
|
|
2003-07-24 22:17:36 +05:30
|
|
|
|
|
|
|
def __init__(self,list):
|
|
|
|
IsAncestorOf.__init__(self,list)
|
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
2005-05-05 15:24:23 +05:30
|
|
|
self.db = db
|
|
|
|
self.map = {}
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
try:
|
|
|
|
if int(self.list[1]):
|
|
|
|
first = 0
|
|
|
|
else:
|
|
|
|
first = 1
|
|
|
|
except IndexError:
|
|
|
|
first = 1
|
|
|
|
|
|
|
|
filt = MatchesFilter(self.list)
|
2005-04-07 18:54:16 +05:30
|
|
|
filt.prepare(db)
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
for person_handle in db.get_person_handles(sort_handles=False):
|
|
|
|
if filt.apply (db, person_handle):
|
|
|
|
self.init_ancestor_list (db,person_handle,first)
|
2005-04-07 18:54:16 +05:30
|
|
|
filt.reset()
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
2005-05-05 15:24:23 +05:30
|
|
|
def reset(self):
|
|
|
|
self.map = {}
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2003-08-05 09:05:42 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsLessThanNthGenerationAncestorOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsLessThanNthGenerationAncestorOf(Rule):
|
|
|
|
"""Rule that checks for a person that is an ancestor of a specified person
|
|
|
|
not more than N generations away"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('ID:'), _('Number of generations:') ]
|
|
|
|
name = _('Ancestors of <person> not more than <N> generations away')
|
|
|
|
category = _("Ancestral filters")
|
|
|
|
description = _("Matches people that are ancestors "
|
|
|
|
"of a specified person not more than N generations away")
|
2003-08-05 09:05:42 +05:30
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
|
|
|
self.map = {}
|
2005-05-19 13:27:50 +05:30
|
|
|
try:
|
|
|
|
root_handle = db.get_person_from_gramps_id(self.list[0]).get_handle()
|
|
|
|
self.init_ancestor_list(root_handle,0)
|
|
|
|
except:
|
|
|
|
pass
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def reset(self):
|
2003-08-05 09:05:42 +05:30
|
|
|
self.map = {}
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2003-09-05 10:08:43 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def init_ancestor_list(self,handle,gen):
|
2004-07-28 07:59:07 +05:30
|
|
|
# if self.map.has_key(p.get_handle()) == 1:
|
2003-08-05 09:05:42 +05:30
|
|
|
# loop_error(self.orig,p)
|
2005-05-19 02:26:30 +05:30
|
|
|
if not handle:
|
2005-05-05 15:24:23 +05:30
|
|
|
return
|
2003-08-05 09:05:42 +05:30
|
|
|
if gen:
|
2005-05-19 02:26:30 +05:30
|
|
|
self.map[handle] = 1
|
2003-08-05 09:05:42 +05:30
|
|
|
if gen >= int(self.list[1]):
|
|
|
|
return
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
p = self.db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
fam_id = p.get_main_parents_family_handle()
|
2004-08-22 11:03:37 +05:30
|
|
|
fam = self.db.get_family_from_handle(fam_id)
|
|
|
|
if fam:
|
2004-07-28 07:59:07 +05:30
|
|
|
f_id = fam.get_father_handle()
|
|
|
|
m_id = fam.get_mother_handle()
|
2003-08-05 09:05:42 +05:30
|
|
|
|
2004-03-11 09:01:35 +05:30
|
|
|
if f_id:
|
|
|
|
self.init_ancestor_list(f_id,gen+1)
|
|
|
|
if m_id:
|
|
|
|
self.init_ancestor_list(m_id,gen+1)
|
2003-08-05 09:05:42 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsMoreThanNthGenerationAncestorOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsMoreThanNthGenerationAncestorOf(Rule):
|
|
|
|
"""Rule that checks for a person that is an ancestor of a specified person
|
|
|
|
at least N generations away"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('ID:'), _('Number of generations:') ]
|
|
|
|
name = _('Ancestors of <person> at least <N> generations away')
|
|
|
|
category = _("Ancestral filters")
|
|
|
|
description = _("Matches people that are ancestors "
|
|
|
|
"of a specified person at least N generations away")
|
2003-08-05 09:05:42 +05:30
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
2003-08-05 09:05:42 +05:30
|
|
|
self.map = {}
|
2005-05-19 13:27:50 +05:30
|
|
|
try:
|
|
|
|
root_handle = db.get_person_from_gramps_id(self.list[0]).get_handle()
|
|
|
|
self.init_ancestor_list(root_handle,0)
|
|
|
|
except:
|
|
|
|
pass
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
self.map = []
|
2003-08-05 09:05:42 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2003-09-05 10:08:43 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def init_ancestor_list(self,handle,gen):
|
2004-07-28 07:59:07 +05:30
|
|
|
# if self.map.has_key(p.get_handle()) == 1:
|
2003-08-05 09:05:42 +05:30
|
|
|
# loop_error(self.orig,p)
|
2005-05-19 02:26:30 +05:30
|
|
|
if not handle:
|
2005-05-05 15:24:23 +05:30
|
|
|
return
|
2003-08-05 09:05:42 +05:30
|
|
|
if gen >= int(self.list[1]):
|
2005-05-19 02:26:30 +05:30
|
|
|
self.map[handle] = 1
|
2003-08-05 09:05:42 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
p = self.db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
fam_id = p.get_main_parents_family_handle()
|
2004-08-22 11:03:37 +05:30
|
|
|
fam = self.db.get_family_from_handle(fam_id)
|
|
|
|
if fam:
|
2004-07-28 07:59:07 +05:30
|
|
|
f_id = fam.get_father_handle()
|
|
|
|
m_id = fam.get_mother_handle()
|
2003-08-05 09:05:42 +05:30
|
|
|
|
2004-03-11 09:01:35 +05:30
|
|
|
if f_id:
|
|
|
|
self.init_ancestor_list(f_id,gen+1)
|
|
|
|
if m_id:
|
|
|
|
self.init_ancestor_list(m_id,gen+1)
|
2003-08-05 09:05:42 +05:30
|
|
|
|
2003-07-24 22:17:36 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsParentOfFilterMatch
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsParentOfFilterMatch(Rule):
|
|
|
|
"""Rule that checks for a person that is a parent
|
|
|
|
of someone matched by a filter"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Filter name:') ]
|
|
|
|
name = _('Parents of <filter> match')
|
|
|
|
category = _('Family filters')
|
|
|
|
description = _("Matches parents of anybody matched by a filter")
|
2003-07-24 22:17:36 +05:30
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
|
|
|
self.map = {}
|
|
|
|
filt = MatchesFilter(self.list)
|
2005-04-07 18:54:16 +05:30
|
|
|
filt.prepare(db)
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
for person_handle in db.get_person_handles(sort_handles=False):
|
|
|
|
if filt.apply (db, person_handle):
|
|
|
|
self.init_list (person_handle)
|
2005-04-07 18:54:16 +05:30
|
|
|
filt.reset()
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def reset(self):
|
2003-07-24 22:17:36 +05:30
|
|
|
self.map = {}
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return self.map.has_key(handle)
|
2003-07-24 22:17:36 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def init_list(self,handle):
|
|
|
|
p = self.db.get_person_from_handle(handle)
|
2005-03-03 10:43:47 +05:30
|
|
|
for fam_id,frel,mrel in p.get_parent_family_handle_list():
|
2004-08-11 22:30:38 +05:30
|
|
|
fam = self.db.get_family_from_handle(fam_id)
|
2004-07-28 07:59:07 +05:30
|
|
|
for parent_id in [fam.get_father_handle (), fam.get_mother_handle ()]:
|
2004-03-11 09:01:35 +05:30
|
|
|
if parent_id:
|
|
|
|
self.map[parent_id] = 1
|
2003-07-24 22:17:36 +05:30
|
|
|
|
2003-01-06 10:44:49 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasCommonAncestorWith
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasCommonAncestorWith(Rule):
|
|
|
|
"""Rule that checks for a person that has a common ancestor with a specified person"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('ID:') ]
|
|
|
|
name = _('People with a common ancestor with <person>')
|
|
|
|
category = _("Ancestral filters")
|
|
|
|
description = _("Matches people that have a common ancestor "
|
|
|
|
"with a specified person")
|
2003-09-05 10:08:43 +05:30
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
2003-01-06 10:44:49 +05:30
|
|
|
# Keys in `ancestor_cache' are ancestors of list[0].
|
|
|
|
# We delay the computation of ancestor_cache until the
|
|
|
|
# first use, because it's not uncommon to instantiate
|
|
|
|
# this class and not use it.
|
|
|
|
self.ancestor_cache = {}
|
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
def reset(self):
|
|
|
|
self.ancestor_cache = {}
|
|
|
|
|
2003-01-06 10:44:49 +05:30
|
|
|
def init_ancestor_cache(self,db):
|
|
|
|
# list[0] is an Id, but we need to pass a Person to for_each_ancestor.
|
2005-05-19 02:26:30 +05:30
|
|
|
handle = db.get_person_from_gramps_id(self.list[0]).get_handle()
|
|
|
|
if handle:
|
|
|
|
def init(self,handle): self.ancestor_cache[handle] = 1
|
|
|
|
for_each_ancestor(db,[handle],init,self)
|
2003-01-06 10:44:49 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2003-01-06 10:44:49 +05:30
|
|
|
# On the first call, we build the ancestor cache for the
|
|
|
|
# reference person. Then, for each person to test,
|
|
|
|
# we browse his ancestors until we found one in the cache.
|
|
|
|
if len(self.ancestor_cache) == 0:
|
|
|
|
self.init_ancestor_cache(db)
|
2005-05-19 02:26:30 +05:30
|
|
|
return for_each_ancestor(db,[handle],
|
|
|
|
lambda self,handle: self.ancestor_cache.has_key(handle),
|
2003-01-06 10:44:49 +05:30
|
|
|
self);
|
|
|
|
|
2003-07-24 22:17:36 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasCommonAncestorWithFilterMatch
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith):
|
|
|
|
"""Rule that checks for a person that has a common ancestor with
|
|
|
|
someone matching a filter"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Filter name:') ]
|
|
|
|
name = _('People with a common ancestor with <filter> match')
|
|
|
|
description = _("Matches people that have a common ancestor "
|
|
|
|
"with anybody matched by a filter")
|
|
|
|
category = _("Ancestral filters")
|
2003-09-05 10:08:43 +05:30
|
|
|
|
2003-07-24 22:17:36 +05:30
|
|
|
def __init__(self,list):
|
|
|
|
HasCommonAncestorWith.__init__(self,list)
|
|
|
|
|
|
|
|
def init_ancestor_cache(self,db):
|
2004-08-20 17:41:56 +05:30
|
|
|
filt = MatchesFilter(self.list)
|
2005-04-07 18:54:16 +05:30
|
|
|
filt.prepare(db)
|
2005-05-19 02:26:30 +05:30
|
|
|
def init(self,h): self.ancestor_cache[h] = 1
|
|
|
|
for handle in db.get_person_handles(sort_handles=False):
|
|
|
|
if (not self.ancestor_cache.has_key (handle)
|
|
|
|
and filt.apply (db, handle)):
|
|
|
|
for_each_ancestor(db,[handle],init,self)
|
2005-04-07 18:54:16 +05:30
|
|
|
filt.reset()
|
2003-07-24 22:17:36 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsMale
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsMale(Rule):
|
|
|
|
"""Rule that checks for a person that is a male"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('Males')
|
|
|
|
category = _('General filters')
|
|
|
|
description = _('Matches all males')
|
2003-09-05 10:08:43 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return db.get_person_from_handle(handle).get_gender() == RelLib.Person.MALE
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasEvent
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasEvent(Rule):
|
|
|
|
"""Rule that checks for a person with a particular value"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Personal event:'),
|
|
|
|
_('Date:'),
|
|
|
|
_('Place:'),
|
|
|
|
_('Description:') ]
|
2005-05-19 02:35:37 +05:30
|
|
|
name = _('People with the personal <event>')
|
2005-05-19 02:26:30 +05:30
|
|
|
description = _("Matches people with a personal event of a particular value")
|
|
|
|
category = _('Event filters')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-14 15:33:36 +05:30
|
|
|
def prepare(self,list):
|
|
|
|
self.date = None
|
|
|
|
try:
|
|
|
|
if self.list and self.list[1]:
|
|
|
|
self.date = DateHandler.parser.parse(self.list[1])
|
|
|
|
except: pass
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for event_handle in p.get_event_list():
|
|
|
|
if not event_handle:
|
2004-03-11 09:01:35 +05:30
|
|
|
continue
|
* src/AddSpouse.py, src/ChooseParents.py, src/EditPerson.py,
src/EditPlace.py, src/EditSource.py, src/EventEdit.py,
src/FamilyView.py, src/GenericFilter.py,
src/Marriage.py, src/PedView.py, src/PeopleModel.py,
src/PlaceView.py, src/RelLib.py, src/SelectChild.py,
src/Sort.py, src/SourceView.py, src/SubstKeywords.py,
src/WriteGedcom.py, src/WriteXML.py, src/plugins/AncestorReport.py,
src/plugins/Ancestors.py, src/plugins/ChangeTypes.py,
src/plugins/DescendReport.py, src/plugins/DetDescendantReport.py,
src/plugins/EventCmp.py, src/plugins/FamilyGroup.py,
src/plugins/FanChart.py, src/plugins/FtmStyleAncestors.py,
src/plugins/FtmStyleDescendants.py, src/plugins/GraphViz.py,
src/plugins/IndivComplete.py, src/plugins/IndivSummary.py,
src/plugins/Merge.py, src/plugins/RelCalc.py, src/plugins/RelGraph.py,
src/plugins/Summary.py, src/plugins/TimeLine.py, src/plugins/Verify.py,
src/plugins/WebPage.py, src/plugins/WriteCD.py,
src/plugins/WritePkg.py, src/plugins/DetAncestralReport.py:
Use get_event_from_handle (not find_ ).
svn: r3462
2004-08-22 00:26:01 +05:30
|
|
|
event = db.get_event_from_handle(event_handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 1
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.list[0] and event.get_name() != self.list[0]:
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 0
|
2005-01-12 04:11:15 +05:30
|
|
|
if self.list[3] and event.get_description().upper().find(
|
2004-04-30 08:31:51 +05:30
|
|
|
self.list[3].upper())==-1:
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 0
|
|
|
|
if self.date:
|
2004-02-14 11:10:30 +05:30
|
|
|
if date_cmp(self.date,event.get_date_object()):
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 0
|
2003-03-12 08:32:08 +05:30
|
|
|
if self.list[2]:
|
2004-07-28 07:59:07 +05:30
|
|
|
pl_id = event.get_place_handle()
|
2004-03-11 09:01:35 +05:30
|
|
|
if pl_id:
|
2004-08-07 10:46:57 +05:30
|
|
|
pl = db.get_place_from_handle(pl_id)
|
2004-03-11 09:01:35 +05:30
|
|
|
pn = pl.get_title()
|
2005-01-12 04:11:15 +05:30
|
|
|
if pn.upper().find(self.list[2].upper()) == -1:
|
2004-03-11 09:01:35 +05:30
|
|
|
val = 0
|
2005-05-14 01:51:45 +05:30
|
|
|
if val == 1:
|
|
|
|
return 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasFamilyEvent
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasFamilyEvent(Rule):
|
|
|
|
"""Rule that checks for a person who has a relationship event
|
|
|
|
with a particular value"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Family event:'),
|
|
|
|
_('Date:'),
|
|
|
|
_('Place:'),
|
|
|
|
_('Description:') ]
|
2005-05-19 02:35:37 +05:30
|
|
|
name = _('People with the family <event>')
|
2005-05-19 02:26:30 +05:30
|
|
|
description = _("Matches people with a family event of a particular value")
|
|
|
|
category = _('Event filters')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-14 15:33:36 +05:30
|
|
|
def prepare(self,list):
|
|
|
|
self.date = None
|
|
|
|
try:
|
|
|
|
if self.list and self.list[1]:
|
|
|
|
self.date = DateHandler.parser.parse(self.list[1])
|
|
|
|
except: pass
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for f_id in p.get_family_handle_list():
|
2004-08-11 22:30:38 +05:30
|
|
|
f = db.get_family_from_handle(f_id)
|
2004-07-28 07:59:07 +05:30
|
|
|
for event_handle in f.get_event_list():
|
|
|
|
if not event_handle:
|
2004-03-11 09:01:35 +05:30
|
|
|
continue
|
* src/AddSpouse.py, src/ChooseParents.py, src/EditPerson.py,
src/EditPlace.py, src/EditSource.py, src/EventEdit.py,
src/FamilyView.py, src/GenericFilter.py,
src/Marriage.py, src/PedView.py, src/PeopleModel.py,
src/PlaceView.py, src/RelLib.py, src/SelectChild.py,
src/Sort.py, src/SourceView.py, src/SubstKeywords.py,
src/WriteGedcom.py, src/WriteXML.py, src/plugins/AncestorReport.py,
src/plugins/Ancestors.py, src/plugins/ChangeTypes.py,
src/plugins/DescendReport.py, src/plugins/DetDescendantReport.py,
src/plugins/EventCmp.py, src/plugins/FamilyGroup.py,
src/plugins/FanChart.py, src/plugins/FtmStyleAncestors.py,
src/plugins/FtmStyleDescendants.py, src/plugins/GraphViz.py,
src/plugins/IndivComplete.py, src/plugins/IndivSummary.py,
src/plugins/Merge.py, src/plugins/RelCalc.py, src/plugins/RelGraph.py,
src/plugins/Summary.py, src/plugins/TimeLine.py, src/plugins/Verify.py,
src/plugins/WebPage.py, src/plugins/WriteCD.py,
src/plugins/WritePkg.py, src/plugins/DetAncestralReport.py:
Use get_event_from_handle (not find_ ).
svn: r3462
2004-08-22 00:26:01 +05:30
|
|
|
event = db.get_event_from_handle(event_handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 1
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.list[0] and event.get_name() != self.list[0]:
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 0
|
|
|
|
v = self.list[3]
|
2005-01-12 04:11:15 +05:30
|
|
|
if v and event.get_description().upper().find(v.upper())==-1:
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 0
|
|
|
|
if self.date:
|
2004-02-14 11:10:30 +05:30
|
|
|
if date_cmp(self.date,event.get_date_object()):
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 0
|
2004-07-28 07:59:07 +05:30
|
|
|
pl_id = event.get_place_handle()
|
2004-03-11 09:01:35 +05:30
|
|
|
if pl_id:
|
2004-08-07 10:46:57 +05:30
|
|
|
pl = db.get_place_from_handle(pl_id)
|
2004-03-11 09:01:35 +05:30
|
|
|
pn = pl.get_title()
|
2005-01-12 04:11:15 +05:30
|
|
|
if self.list[2] and pn.find(self.list[2].upper()) == -1:
|
2004-03-11 09:01:35 +05:30
|
|
|
val = 0
|
2005-05-14 01:51:45 +05:30
|
|
|
if val == 1:
|
|
|
|
return 1
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasRelationship
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasRelationship(Rule):
|
|
|
|
"""Rule that checks for a person who has a particular relationship"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Number of relationships:'),
|
|
|
|
_('Relationship type:'),
|
|
|
|
_('Number of children:') ]
|
2005-05-19 02:35:37 +05:30
|
|
|
name = _('People with the <relationships>')
|
2005-05-19 02:26:30 +05:30
|
|
|
description = _("Matches people with a particular relationship")
|
|
|
|
category = _('Family filters')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2002-10-20 19:55:16 +05:30
|
|
|
rel_type = 0
|
|
|
|
cnt = 0
|
2005-05-19 02:26:30 +05:30
|
|
|
p = db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
num_rel = len(p.get_family_handle_list())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
# count children and look for a relationship type match
|
2004-07-28 07:59:07 +05:30
|
|
|
for f_id in p.get_family_handle_list():
|
2004-08-11 22:30:38 +05:30
|
|
|
f = db.get_family_from_handle(f_id)
|
2004-07-28 07:59:07 +05:30
|
|
|
cnt = cnt + len(f.get_child_handle_list())
|
2005-03-03 10:43:47 +05:30
|
|
|
if self.list[1] and int(self.list[1]) == f.get_relationship():
|
2002-10-20 19:55:16 +05:30
|
|
|
rel_type = 1
|
|
|
|
|
|
|
|
# if number of relations specified
|
|
|
|
if self.list[0]:
|
|
|
|
try:
|
|
|
|
v = int(self.list[0])
|
|
|
|
except:
|
|
|
|
return 0
|
|
|
|
if v != num_rel:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
# number of childred
|
|
|
|
if self.list[2]:
|
|
|
|
try:
|
|
|
|
v = int(self.list[2])
|
|
|
|
except:
|
|
|
|
return 0
|
|
|
|
if v != cnt:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
# relation
|
|
|
|
if self.list[1]:
|
|
|
|
return rel_type == 1
|
|
|
|
else:
|
|
|
|
return 1
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasBirth
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasBirth(Rule):
|
|
|
|
"""Rule that checks for a person with a birth of a particular value"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Date:'), _('Place:'), _('Description:') ]
|
2005-05-19 02:35:37 +05:30
|
|
|
name = _('People with the <birth data>')
|
2005-05-19 02:26:30 +05:30
|
|
|
description = _("Matches people with birth data of a particular value")
|
|
|
|
category = _('Event filters')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def __init__(self,list):
|
|
|
|
Rule.__init__(self,list)
|
2004-01-21 08:26:53 +05:30
|
|
|
if self.list and self.list[0]:
|
2004-12-29 10:36:10 +05:30
|
|
|
self.date = DateHandler.parser.parse(self.list[0])
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.date = None
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
event_handle = p.get_birth_handle()
|
|
|
|
if not event_handle:
|
2005-05-03 03:20:15 +05:30
|
|
|
return False
|
* src/AddSpouse.py, src/ChooseParents.py, src/EditPerson.py,
src/EditPlace.py, src/EditSource.py, src/EventEdit.py,
src/FamilyView.py, src/GenericFilter.py,
src/Marriage.py, src/PedView.py, src/PeopleModel.py,
src/PlaceView.py, src/RelLib.py, src/SelectChild.py,
src/Sort.py, src/SourceView.py, src/SubstKeywords.py,
src/WriteGedcom.py, src/WriteXML.py, src/plugins/AncestorReport.py,
src/plugins/Ancestors.py, src/plugins/ChangeTypes.py,
src/plugins/DescendReport.py, src/plugins/DetDescendantReport.py,
src/plugins/EventCmp.py, src/plugins/FamilyGroup.py,
src/plugins/FanChart.py, src/plugins/FtmStyleAncestors.py,
src/plugins/FtmStyleDescendants.py, src/plugins/GraphViz.py,
src/plugins/IndivComplete.py, src/plugins/IndivSummary.py,
src/plugins/Merge.py, src/plugins/RelCalc.py, src/plugins/RelGraph.py,
src/plugins/Summary.py, src/plugins/TimeLine.py, src/plugins/Verify.py,
src/plugins/WebPage.py, src/plugins/WriteCD.py,
src/plugins/WritePkg.py, src/plugins/DetAncestralReport.py:
Use get_event_from_handle (not find_ ).
svn: r3462
2004-08-22 00:26:01 +05:30
|
|
|
event = db.get_event_from_handle(event_handle)
|
2004-02-14 11:10:30 +05:30
|
|
|
ed = event.get_description().upper()
|
2005-01-12 04:11:15 +05:30
|
|
|
if len(self.list) > 2 and ed.find(self.list[2].upper())==-1:
|
2005-05-03 03:20:15 +05:30
|
|
|
return False
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.date:
|
2004-02-14 11:10:30 +05:30
|
|
|
if date_cmp(self.date,event.get_date_object()) == 0:
|
2005-05-03 03:20:15 +05:30
|
|
|
return False
|
2004-07-28 07:59:07 +05:30
|
|
|
pl_id = event.get_place_handle()
|
2004-03-11 09:01:35 +05:30
|
|
|
if pl_id:
|
2004-08-07 10:46:57 +05:30
|
|
|
pl = db.get_place_from_handle(pl_id)
|
2004-03-11 09:01:35 +05:30
|
|
|
pn = pl.get_title()
|
2005-01-12 04:11:15 +05:30
|
|
|
if len(self.list) > 1 and pn.find(self.list[1].upper()) == -1:
|
2005-05-03 03:20:15 +05:30
|
|
|
return False
|
|
|
|
return True
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasDeath
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasDeath(Rule):
|
|
|
|
"""Rule that checks for a person with a death of a particular value"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Date:'), _('Place:'), _('Description:') ]
|
2005-05-19 02:35:37 +05:30
|
|
|
name = _('People with the <death data>')
|
2005-05-19 02:26:30 +05:30
|
|
|
description = _("Matches people with death data of a particular value")
|
|
|
|
category = _('Event filters')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def __init__(self,list):
|
|
|
|
Rule.__init__(self,list)
|
2004-01-21 08:26:53 +05:30
|
|
|
if self.list and self.list[0]:
|
2004-12-29 10:36:10 +05:30
|
|
|
self.date = DateHandler.parser.parse(self.list[0])
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.date = None
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
event_handle = p.get_death_handle()
|
|
|
|
if not event_handle:
|
2004-03-11 09:01:35 +05:30
|
|
|
return 0
|
* src/AddSpouse.py, src/ChooseParents.py, src/EditPerson.py,
src/EditPlace.py, src/EditSource.py, src/EventEdit.py,
src/FamilyView.py, src/GenericFilter.py,
src/Marriage.py, src/PedView.py, src/PeopleModel.py,
src/PlaceView.py, src/RelLib.py, src/SelectChild.py,
src/Sort.py, src/SourceView.py, src/SubstKeywords.py,
src/WriteGedcom.py, src/WriteXML.py, src/plugins/AncestorReport.py,
src/plugins/Ancestors.py, src/plugins/ChangeTypes.py,
src/plugins/DescendReport.py, src/plugins/DetDescendantReport.py,
src/plugins/EventCmp.py, src/plugins/FamilyGroup.py,
src/plugins/FanChart.py, src/plugins/FtmStyleAncestors.py,
src/plugins/FtmStyleDescendants.py, src/plugins/GraphViz.py,
src/plugins/IndivComplete.py, src/plugins/IndivSummary.py,
src/plugins/Merge.py, src/plugins/RelCalc.py, src/plugins/RelGraph.py,
src/plugins/Summary.py, src/plugins/TimeLine.py, src/plugins/Verify.py,
src/plugins/WebPage.py, src/plugins/WriteCD.py,
src/plugins/WritePkg.py, src/plugins/DetAncestralReport.py:
Use get_event_from_handle (not find_ ).
svn: r3462
2004-08-22 00:26:01 +05:30
|
|
|
event = db.get_event_from_handle(event_handle)
|
2004-02-14 11:10:30 +05:30
|
|
|
ed = event.get_description().upper()
|
2005-01-12 04:11:15 +05:30
|
|
|
if self.list[2] and ed.find(self.list[2].upper())==-1:
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
|
|
|
if self.date:
|
2004-02-14 11:10:30 +05:30
|
|
|
if date_cmp(self.date,event.get_date_object()) == 0:
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
2004-07-28 07:59:07 +05:30
|
|
|
pl_id = event.get_place_handle()
|
2004-03-11 09:01:35 +05:30
|
|
|
if pl_id:
|
2004-08-07 10:46:57 +05:30
|
|
|
pl = db.get_place_from_handle(pl_id)
|
2004-03-11 09:01:35 +05:30
|
|
|
pn = pl.get_title()
|
2005-01-12 04:11:15 +05:30
|
|
|
if self.list[1] and pn.find(self.list[1].upper()) == -1:
|
2004-03-11 09:01:35 +05:30
|
|
|
return 0
|
2002-10-20 19:55:16 +05:30
|
|
|
return 1
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasAttribute
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasAttribute(Rule):
|
|
|
|
"""Rule that checks for a person with a particular personal attribute"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Personal attribute:'), _('Value:') ]
|
2005-05-19 02:35:37 +05:30
|
|
|
name = _('People with the personal <attribute>')
|
2005-05-19 02:26:30 +05:30
|
|
|
description = _("Matches people with the personal attribute of a particular value")
|
|
|
|
category = _('General filters')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2005-03-03 20:30:55 +05:30
|
|
|
if not self.list[0]:
|
|
|
|
return 0
|
2005-05-19 02:26:30 +05:30
|
|
|
p = db.get_person_from_handle(handle)
|
2005-03-03 20:30:55 +05:30
|
|
|
for attr in p.get_attribute_list():
|
|
|
|
name_match = self.list[0] == attr.get_type()
|
2005-03-04 20:45:20 +05:30
|
|
|
value_match = \
|
2005-03-03 20:30:55 +05:30
|
|
|
attr.get_value().upper().find(self.list[1].upper()) != -1
|
|
|
|
if name_match and value_match:
|
|
|
|
return 1
|
|
|
|
return 0
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasFamilyAttribute
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasFamilyAttribute(Rule):
|
|
|
|
"""Rule that checks for a person with a particular family attribute"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Family attribute:'), _('Value:') ]
|
2005-05-19 02:35:37 +05:30
|
|
|
name = _('People with the family <attribute>')
|
2005-05-19 02:26:30 +05:30
|
|
|
description = _("Matches people with the family attribute of a particular value")
|
|
|
|
category = _('General filters')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2005-03-03 20:30:55 +05:30
|
|
|
if not self.list[0]:
|
|
|
|
return 0
|
2005-05-19 02:26:30 +05:30
|
|
|
p = db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for f_id in p.get_family_handle_list():
|
2004-08-11 22:30:38 +05:30
|
|
|
f = db.get_family_from_handle(f_id)
|
2005-03-03 20:30:55 +05:30
|
|
|
for attr in f.get_attribute_list():
|
|
|
|
name_match = self.list[0] == attr.get_type()
|
2005-03-04 20:45:20 +05:30
|
|
|
value_match = \
|
2005-03-03 20:30:55 +05:30
|
|
|
attr.get_value().upper().find(self.list[1].upper()) != -1
|
|
|
|
if name_match and value_match:
|
2002-10-20 19:55:16 +05:30
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasNameOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasNameOf(Rule):
|
|
|
|
"""Rule that checks for full or partial name matches"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Given name:'),
|
|
|
|
_('Family name:'),
|
|
|
|
_('Suffix:'),
|
|
|
|
_('Title:')]
|
2005-05-19 02:35:37 +05:30
|
|
|
name = _('People with the <name>')
|
2005-05-19 02:26:30 +05:30
|
|
|
description = _("Matches people with a specified (partial) name")
|
|
|
|
category = _('General filters')
|
2003-09-05 10:08:43 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.f = self.list[0]
|
|
|
|
self.l = self.list[1]
|
|
|
|
self.s = self.list[2]
|
|
|
|
self.t = self.list[3]
|
2005-05-19 02:26:30 +05:30
|
|
|
p = db.get_person_from_handle(handle)
|
2004-02-14 11:10:30 +05:30
|
|
|
for name in [p.get_primary_name()] + p.get_alternate_names():
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 1
|
2005-01-12 04:11:15 +05:30
|
|
|
if self.f and name.get_first_name().upper().find(self.f.upper()) == -1:
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 0
|
2005-01-12 04:11:15 +05:30
|
|
|
if self.l and name.get_surname().upper().find(self.l.upper()) == -1:
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 0
|
2005-01-12 04:11:15 +05:30
|
|
|
if self.s and name.get_suffix().upper().find(self.s.upper()) == -1:
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 0
|
2005-01-12 04:11:15 +05:30
|
|
|
if self.t and name.get_title().upper().find(self.t.upper()) == -1:
|
2002-10-20 19:55:16 +05:30
|
|
|
val = 0
|
|
|
|
if val == 1:
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
2004-04-30 08:31:51 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasNameOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class SearchName(Rule):
|
|
|
|
"""Rule that checks for full or partial name matches"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [_('Substring:')]
|
|
|
|
name = _('People matching the <name>')
|
|
|
|
description = _("Matches people with a specified (partial) name")
|
|
|
|
category = _('General filters')
|
2004-04-30 08:31:51 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2004-04-30 08:31:51 +05:30
|
|
|
self.f = self.list[0]
|
2005-05-19 02:26:30 +05:30
|
|
|
p = db.get_person_from_handle(handle)
|
2005-01-01 09:57:15 +05:30
|
|
|
n = NameDisplay.displayer.display(p)
|
2005-01-12 04:11:15 +05:30
|
|
|
return self.f and n.upper().find(self.f.upper()) != -1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-03-11 00:31:00 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IncompleteNames
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IncompleteNames(Rule):
|
|
|
|
"""People with incomplete names"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('People with incomplete names')
|
|
|
|
description = _("Matches people with firstname or lastname missing")
|
|
|
|
category = _('General filters')
|
2005-03-11 00:31:00 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2005-03-11 00:31:00 +05:30
|
|
|
for name in [p.get_primary_name()] + p.get_alternate_names():
|
|
|
|
if name.get_first_name() == "":
|
|
|
|
return 1
|
|
|
|
if name.get_surname() == "":
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
2003-03-25 10:56:05 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# MatchesFilter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
class MatchesFilter(Rule):
|
|
|
|
"""Rule that checks against another filter"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [_('Filter name:')]
|
|
|
|
name = _('People matching the <filter>')
|
|
|
|
description = _("Matches people macthed by the specified filter name")
|
|
|
|
category = _('General filters')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-04-07 18:54:16 +05:30
|
|
|
def prepare(self,db):
|
|
|
|
for filt in SystemFilters.get_filters():
|
|
|
|
if filt.get_name() == self.list[0]:
|
|
|
|
for rule in filt.flist:
|
|
|
|
rule.prepare(db)
|
|
|
|
for filt in CustomFilters.get_filters():
|
|
|
|
if filt.get_name() == self.list[0]:
|
|
|
|
for rule in filt.flist:
|
|
|
|
rule.prepare(db)
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
for filt in SystemFilters.get_filters():
|
|
|
|
if filt.get_name() == self.list[0]:
|
|
|
|
for rule in filt.flist:
|
|
|
|
rule.reset()
|
|
|
|
for filt in CustomFilters.get_filters():
|
|
|
|
if filt.get_name() == self.list[0]:
|
|
|
|
for rule in filt.flist:
|
|
|
|
rule.reset()
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2005-03-03 10:43:47 +05:30
|
|
|
for filt in SystemFilters.get_filters():
|
2004-08-20 17:41:56 +05:30
|
|
|
if filt.get_name() == self.list[0]:
|
2005-05-19 02:26:30 +05:30
|
|
|
return filt.check(handle)
|
2004-08-20 17:41:56 +05:30
|
|
|
for filt in CustomFilters.get_filters():
|
|
|
|
if filt.get_name() == self.list[0]:
|
2005-05-19 02:26:30 +05:30
|
|
|
return filt.check(db,handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
return 0
|
2003-06-12 07:34:42 +05:30
|
|
|
|
2003-07-24 22:17:36 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IsSpouseOfFilterMatch
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsSpouseOfFilterMatch(Rule):
|
|
|
|
"""Rule that checks for a person married to someone matching
|
|
|
|
a filter"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [_('Filter name:')]
|
|
|
|
name = _('Spouses of <filter> match')
|
|
|
|
description = _("Matches people married to anybody matching a filter")
|
|
|
|
category = _('Family filters')
|
2003-07-24 22:17:36 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2004-08-20 17:41:56 +05:30
|
|
|
filt = MatchesFilter (self.list)
|
2005-05-19 02:26:30 +05:30
|
|
|
p = db.get_person_from_handle(handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for family_handle in p.get_family_handle_list ():
|
2004-08-11 22:30:38 +05:30
|
|
|
family = db.get_family_from_handle(family_handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for spouse_id in [family.get_father_handle (), family.get_mother_handle ()]:
|
2004-03-11 09:01:35 +05:30
|
|
|
if not spouse_id:
|
2003-07-24 22:17:36 +05:30
|
|
|
continue
|
2005-05-19 02:26:30 +05:30
|
|
|
if spouse_id == handle:
|
2003-07-24 22:17:36 +05:30
|
|
|
continue
|
2004-08-20 17:41:56 +05:30
|
|
|
if filt.apply (db, spouse_id):
|
2003-07-24 22:17:36 +05:30
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
2005-03-11 00:31:00 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "People who were adopted"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HaveAltFamilies(Rule):
|
|
|
|
"""People who were adopted"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('Adopted people')
|
|
|
|
description = _("Matches people who were adopted")
|
|
|
|
category = _('Family filters')
|
2005-03-11 00:31:00 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2005-03-11 00:31:00 +05:30
|
|
|
for (fam,rel1,rel2) in p.get_parent_family_handle_list():
|
|
|
|
if rel1 == RelLib.Person.CHILD_REL_ADOPT or rel2 == RelLib.Person.CHILD_REL_ADOPT:
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "People who have images"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HavePhotos(Rule):
|
|
|
|
"""People who have images"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('People with images')
|
|
|
|
description = _("Matches people with images in the gallery")
|
|
|
|
category = _('General filters')
|
2005-03-11 00:31:00 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2005-03-11 00:31:00 +05:30
|
|
|
return len( p.get_media_list()) > 0
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "People with children"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HaveChildren(Rule):
|
|
|
|
"""People with children"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('People with children')
|
|
|
|
description = _("Matches people who have children")
|
|
|
|
category = _('Family filters')
|
2005-03-11 00:31:00 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2005-05-04 01:09:04 +05:30
|
|
|
for family_handle in p.get_family_handle_list():
|
2005-03-11 00:31:00 +05:30
|
|
|
family = db.get_family_from_handle(family_handle)
|
|
|
|
return len(family.get_child_handle_list()) > 0
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "People with no marriage records"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class NeverMarried(Rule):
|
|
|
|
"""People with no marriage records"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('People with no marriage records')
|
|
|
|
description = _("Matches people who have no spouse")
|
|
|
|
category = _('Family filters')
|
2005-03-11 00:31:00 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2005-03-11 00:31:00 +05:30
|
|
|
return len(p.get_family_handle_list()) == 0
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "People with multiple marriage records"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class MultipleMarriages(Rule):
|
|
|
|
"""People with multiple marriage records"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('People with multiple marriage records')
|
|
|
|
description = _("Matches people who have more than one spouse")
|
|
|
|
category = _('Family filters')
|
2005-03-11 00:31:00 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2005-03-11 00:31:00 +05:30
|
|
|
return len(p.get_family_handle_list()) > 1
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "People without a birth date"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class NoBirthdate(Rule):
|
|
|
|
"""People without a birth date"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('People without a known birth date')
|
|
|
|
description = _("Matches people without a known birthdate")
|
|
|
|
category = _('General filters')
|
2005-03-11 00:31:00 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2005-03-11 00:31:00 +05:30
|
|
|
birth_handle = p.get_birth_handle()
|
|
|
|
if not birth_handle:
|
|
|
|
return 1
|
|
|
|
birth = db.get_event_from_handle(birth_handle)
|
|
|
|
if not birth.get_date_object():
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
2005-03-12 02:23:53 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "People with incomplete events"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class PersonWithIncompleteEvent(Rule):
|
|
|
|
"""People with incomplete events"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('People with incomplete events')
|
|
|
|
description = _("Matches people with missing date or place in an event")
|
|
|
|
category = _('Event filters')
|
2005-03-12 02:23:53 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2005-03-12 02:23:53 +05:30
|
|
|
for event_handle in p.get_event_list() + [p.get_birth_handle(), p.get_death_handle()]:
|
|
|
|
event = db.get_event_from_handle(event_handle)
|
|
|
|
if event:
|
|
|
|
if not event.get_place_handle():
|
|
|
|
return 1
|
|
|
|
if not event.get_date_object():
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "Families with incomplete events"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class FamilyWithIncompleteEvent(Rule):
|
|
|
|
"""Families with incomplete events"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('Families with incomplete events')
|
|
|
|
description = _("Matches people with missing date or place in an event of the family")
|
|
|
|
category = _('Event filters')
|
2005-03-12 02:23:53 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2005-03-12 02:23:53 +05:30
|
|
|
for family_handle in p.get_family_handle_list():
|
|
|
|
family = db.get_family_from_handle(family_handle)
|
|
|
|
for event_handle in family.get_event_list():
|
|
|
|
event = db.get_event_from_handle(event_handle)
|
|
|
|
if event:
|
|
|
|
if not event.get_place_handle():
|
|
|
|
return 1
|
|
|
|
if not event.get_date_object():
|
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "People probably alive"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class ProbablyAlive(Rule):
|
|
|
|
"""People probably alive"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [_("On year:")]
|
|
|
|
name = _('People probably alive')
|
|
|
|
description = _("Matches people without indications of death that are not too old")
|
|
|
|
category = _('General filters')
|
2005-04-07 01:56:15 +05:30
|
|
|
|
|
|
|
def prepare(self,db):
|
|
|
|
try:
|
|
|
|
self.current_year = int(self.list[0])
|
|
|
|
except:
|
|
|
|
self.current_year = None
|
2005-03-12 02:23:53 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2005-04-07 01:56:15 +05:30
|
|
|
return probably_alive(p,db,self.current_year)
|
2005-03-12 02:23:53 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "People marked private"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class PeoplePrivate(Rule):
|
|
|
|
"""People marked private"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
name = _('People marked private')
|
|
|
|
description = _("Matches people that are indicated as private")
|
|
|
|
category = _('General filters')
|
2005-03-12 02:23:53 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
p = db.get_person_from_handle(handle)
|
2005-03-12 02:23:53 +05:30
|
|
|
return p.get_privacy()
|
|
|
|
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "Witnesses"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class IsWitness(Rule):
|
|
|
|
"""Witnesses"""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [_('Personal event:'), _('Family event:')]
|
|
|
|
name = _('Witnesses')
|
|
|
|
description = _("Matches people who are witnesses in any event")
|
|
|
|
category = _('Event filters')
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
|
|
|
self.map = []
|
|
|
|
self.build_witness_list()
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
self.map = []
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
return handle in self.map
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
|
|
|
|
def build_witness_list(self):
|
|
|
|
event_type = None
|
|
|
|
if self.list and self.list[0]:
|
|
|
|
event_type = self.list[0]
|
|
|
|
if not self.list or event_type:
|
|
|
|
for person_handle in self.db.get_person_handles():
|
|
|
|
p = self.db.get_person_from_handle(person_handle)
|
|
|
|
self.get_witness_of_events( event_type,
|
|
|
|
p.get_event_list()+[p.get_birth_handle(), p.get_death_handle()])
|
|
|
|
event_type = None
|
|
|
|
if self.list and self.list[1]:
|
|
|
|
event_type = self.list[1]
|
|
|
|
if not self.list or event_type:
|
|
|
|
for family_handle in self.db.get_family_handles():
|
|
|
|
f = self.db.get_family_from_handle(family_handle)
|
|
|
|
self.get_witness_of_events(event_type, f.get_event_list())
|
|
|
|
|
|
|
|
def get_witness_of_events(self, event_type, event_list):
|
|
|
|
if not event_list:
|
|
|
|
return
|
|
|
|
for event_handle in event_list:
|
|
|
|
event = self.db.get_event_from_handle(event_handle)
|
|
|
|
if event:
|
|
|
|
if event_type and not event.get_name() == event_type:
|
|
|
|
continue
|
|
|
|
wlist = event.get_witness_list()
|
|
|
|
if wlist:
|
|
|
|
for w in wlist:
|
|
|
|
if w.get_type() == RelLib.Event.ID:
|
|
|
|
self.map.append(w.get_value())
|
2005-03-15 18:26:14 +05:30
|
|
|
|
2005-03-16 19:43:33 +05:30
|
|
|
|
2005-03-15 18:26:14 +05:30
|
|
|
#-------------------------------------------------------------------------
|
2005-03-15 21:56:30 +05:30
|
|
|
# "HasTextMatchingSubstringOf"
|
2005-03-15 18:26:14 +05:30
|
|
|
#-------------------------------------------------------------------------
|
2005-03-15 21:56:30 +05:30
|
|
|
class HasTextMatchingSubstringOf(Rule):
|
|
|
|
"""Rule that checks for string matches in any textual information"""
|
2005-03-15 18:26:14 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Substring:'),
|
|
|
|
_('Case sensitive:'),
|
|
|
|
_('Regular-Expression matching:')]
|
2005-05-19 02:35:37 +05:30
|
|
|
name = _('People with records containing <substring>')
|
2005-05-19 02:26:30 +05:30
|
|
|
description = _("Matches people whose records contain text matching a substring")
|
|
|
|
category = _('General filters')
|
2005-03-15 18:26:14 +05:30
|
|
|
|
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
2005-03-16 19:43:33 +05:30
|
|
|
self.person_map = {}
|
2005-03-15 18:26:14 +05:30
|
|
|
self.event_map = {}
|
|
|
|
self.source_map = {}
|
|
|
|
self.family_map = {}
|
|
|
|
self.place_map = {}
|
2005-05-14 18:22:27 +05:30
|
|
|
self.media_map = {}
|
2005-03-16 19:43:33 +05:30
|
|
|
try:
|
|
|
|
if int(self.list[1]):
|
|
|
|
self.case_sensitive = True
|
|
|
|
else:
|
|
|
|
self.case_sensitive = False
|
|
|
|
except IndexError:
|
|
|
|
self.case_sensitive = False
|
|
|
|
try:
|
|
|
|
if int(self.list[2]):
|
|
|
|
self.regexp_match = True
|
|
|
|
else:
|
|
|
|
self.regexp_match = False
|
|
|
|
except IndexError:
|
|
|
|
self.regexp_match = False
|
2005-03-15 18:26:14 +05:30
|
|
|
self.cache_sources()
|
|
|
|
|
|
|
|
def reset(self):
|
2005-03-16 19:43:33 +05:30
|
|
|
self.person_map = {}
|
2005-03-15 18:26:14 +05:30
|
|
|
self.event_map = {}
|
2005-03-16 19:43:33 +05:30
|
|
|
self.source_map = {}
|
2005-03-15 18:26:14 +05:30
|
|
|
self.family_map = {}
|
2005-03-16 19:43:33 +05:30
|
|
|
self.place_map = {}
|
2005-05-14 18:22:27 +05:30
|
|
|
self.media_map = {}
|
2005-03-15 18:26:14 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
|
|
|
if handle in self.person_map: # Cached by matching Source?
|
|
|
|
return self.person_map[handle]
|
|
|
|
p = db.get_person_from_handle(handle)
|
|
|
|
if self.match_object(p): # first match the person itself
|
2005-03-15 18:26:14 +05:30
|
|
|
return 1
|
|
|
|
for event_handle in p.get_event_list()+[p.get_birth_handle(), p.get_death_handle()]:
|
2005-05-19 02:26:30 +05:30
|
|
|
if self.search_event(event_handle): # match referenced events
|
2005-03-15 18:26:14 +05:30
|
|
|
return 1
|
|
|
|
for family_handle in p.get_family_handle_list(): # match families
|
|
|
|
if self.search_family(family_handle):
|
|
|
|
return 1
|
2005-05-14 18:22:27 +05:30
|
|
|
for media_ref in p.get_media_list(): # match Media object
|
|
|
|
if self.search_media(media_ref.get_reference_handle()):
|
|
|
|
return 1
|
2005-03-15 18:26:14 +05:30
|
|
|
return 0
|
|
|
|
|
|
|
|
def search_family(self,family_handle):
|
|
|
|
if not family_handle:
|
|
|
|
return 0
|
|
|
|
# search inside the family and cache the result to not search a family twice
|
|
|
|
if not family_handle in self.family_map:
|
|
|
|
match = 0
|
|
|
|
family = self.db.get_family_from_handle(family_handle)
|
2005-03-16 19:43:33 +05:30
|
|
|
if self.match_object(family):
|
2005-03-15 18:26:14 +05:30
|
|
|
match = 1
|
|
|
|
else:
|
|
|
|
for event_handle in family.get_event_list():
|
|
|
|
if self.search_event(event_handle):
|
|
|
|
match = 1
|
|
|
|
break
|
2005-05-14 18:22:27 +05:30
|
|
|
for media_ref in family.get_media_list(): # match Media object
|
|
|
|
if self.search_media(media_ref.get_reference_handle()):
|
|
|
|
return 1
|
2005-03-15 18:26:14 +05:30
|
|
|
self.family_map[family_handle] = match
|
|
|
|
return self.family_map[family_handle]
|
|
|
|
|
|
|
|
def search_event(self,event_handle):
|
|
|
|
if not event_handle:
|
|
|
|
return 0
|
|
|
|
# search inside the event and cache the result (event sharing)
|
|
|
|
if not event_handle in self.event_map:
|
|
|
|
match = 0
|
|
|
|
event = self.db.get_event_from_handle(event_handle)
|
2005-03-16 19:43:33 +05:30
|
|
|
if self.match_object(event):
|
2005-03-15 18:26:14 +05:30
|
|
|
match = 1
|
2005-04-20 01:03:56 +05:30
|
|
|
elif event:
|
2005-03-15 18:26:14 +05:30
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
if self.search_place(place_handle):
|
|
|
|
match = 1
|
2005-05-14 18:22:27 +05:30
|
|
|
for media_ref in event.get_media_list(): # match Media object
|
|
|
|
if self.search_media(media_ref.get_reference_handle()):
|
|
|
|
return 1
|
2005-03-15 18:26:14 +05:30
|
|
|
self.event_map[event_handle] = match
|
|
|
|
return self.event_map[event_handle]
|
|
|
|
|
|
|
|
def search_place(self,place_handle):
|
|
|
|
if not place_handle:
|
|
|
|
return 0
|
|
|
|
# search inside the place and cache the result
|
|
|
|
if not place_handle in self.place_map:
|
|
|
|
place = self.db.get_place_from_handle(place_handle)
|
2005-03-16 19:43:33 +05:30
|
|
|
self.place_map[place_handle] = self.match_object(place)
|
2005-03-15 18:26:14 +05:30
|
|
|
return self.place_map[place_handle]
|
|
|
|
|
2005-05-14 18:22:27 +05:30
|
|
|
def search_media(self,media_handle):
|
|
|
|
if not media_handle:
|
|
|
|
return 0
|
|
|
|
# search inside the place and cache the result
|
|
|
|
if not media_handle in self.media_map:
|
|
|
|
media = self.db.get_object_from_handle(media_handle)
|
|
|
|
self.media_map[media_handle] = self.match_object(media)
|
|
|
|
return self.media_map[media_handle]
|
|
|
|
|
2005-03-15 18:26:14 +05:30
|
|
|
def cache_sources(self):
|
|
|
|
# search all sources and match all referents of a matching source
|
|
|
|
for source_handle in self.db.get_source_handles():
|
|
|
|
source = self.db.get_source_from_handle(source_handle)
|
2005-03-16 19:43:33 +05:30
|
|
|
if self.match_object(source):
|
2005-03-15 18:26:14 +05:30
|
|
|
(person_list,family_list,event_list,
|
|
|
|
place_list,source_list,media_list
|
|
|
|
) = get_source_referents(source_handle,self.db)
|
|
|
|
for handle in person_list:
|
|
|
|
self.person_map[handle] = 1
|
|
|
|
for handle in family_list:
|
|
|
|
self.family_map[handle] = 1
|
|
|
|
for handle in event_list:
|
|
|
|
self.event_map[handle] = 1
|
|
|
|
for handle in place_list:
|
|
|
|
self.place_map[handle] = 1
|
2005-05-14 18:22:27 +05:30
|
|
|
for handle in media_list:
|
|
|
|
self.media_map[handle] = 1
|
2005-03-15 18:26:14 +05:30
|
|
|
|
2005-03-16 22:08:20 +05:30
|
|
|
def match_object(self,obj):
|
2005-04-20 01:03:56 +05:30
|
|
|
if not obj:
|
|
|
|
return 0
|
2005-03-16 19:43:33 +05:30
|
|
|
if self.regexp_match:
|
2005-03-16 22:08:20 +05:30
|
|
|
return obj.matches_regexp(self.list[0],self.case_sensitive)
|
|
|
|
return obj.matches_string(self.list[0],self.case_sensitive)
|
2005-03-16 19:43:33 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
# "HasTextMatchingRegexOf"
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasTextMatchingRegexpOf(HasTextMatchingSubstringOf):
|
|
|
|
"""This is wrapping HasTextMatchingSubstringOf to enable the regex_match parameter"""
|
|
|
|
def __init__(self,list):
|
|
|
|
HasTextMatchingSubstringOf.__init__(self,list)
|
|
|
|
|
|
|
|
def prepare(self,db):
|
|
|
|
self.db = db
|
|
|
|
self.person_map = {}
|
|
|
|
self.event_map = {}
|
|
|
|
self.source_map = {}
|
|
|
|
self.family_map = {}
|
|
|
|
self.place_map = {}
|
2005-05-14 18:22:27 +05:30
|
|
|
self.media_map = {}
|
2005-03-16 19:43:33 +05:30
|
|
|
self.case_sensitive = False
|
|
|
|
self.regexp_match = True
|
|
|
|
self.cache_sources()
|
|
|
|
|
2005-04-06 20:33:36 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HasSourceOf
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class HasSourceOf(Rule):
|
|
|
|
"""Rule that checks people that have a particular source."""
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
labels = [ _('Source ID:') ]
|
2005-05-19 02:35:37 +05:30
|
|
|
name = _('People with the <source>')
|
2005-05-19 02:26:30 +05:30
|
|
|
category = _('General filters')
|
|
|
|
description = _('Matches people who have a particular source')
|
2005-04-06 20:33:36 +05:30
|
|
|
|
|
|
|
def prepare(self,db):
|
2005-05-19 13:27:50 +05:30
|
|
|
try:
|
|
|
|
self.source_handle = db.get_source_from_gramps_id(self.list[0]).get_handle()
|
|
|
|
except:
|
|
|
|
self.source_handle = None
|
2005-04-06 20:33:36 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def apply(self,db,handle):
|
2005-05-19 13:27:50 +05:30
|
|
|
if not self.source_handle:
|
|
|
|
return False
|
2005-05-19 02:26:30 +05:30
|
|
|
p = db.get_person_from_handle(handle)
|
2005-04-07 01:56:15 +05:30
|
|
|
return p.has_source_reference( self.source_handle)
|
2005-04-06 20:33:36 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GenericFilter
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class GenericFilter:
|
|
|
|
"""Filter class that consists of several rules"""
|
|
|
|
|
2005-01-05 10:32:19 +05:30
|
|
|
logical_functions = ['or', 'and', 'xor', 'one']
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def __init__(self,source=None):
|
|
|
|
if source:
|
2004-04-30 08:31:51 +05:30
|
|
|
self.need_param = source.need_param
|
2002-10-20 19:55:16 +05:30
|
|
|
self.flist = source.flist[:]
|
|
|
|
self.name = source.name
|
|
|
|
self.comment = source.comment
|
|
|
|
self.logical_op = source.logical_op
|
|
|
|
self.invert = source.invert
|
|
|
|
else:
|
2004-04-30 08:31:51 +05:30
|
|
|
self.need_param = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
self.flist = []
|
|
|
|
self.name = ''
|
|
|
|
self.comment = ''
|
|
|
|
self.logical_op = 'and'
|
|
|
|
self.invert = 0
|
|
|
|
|
|
|
|
def set_logical_op(self,val):
|
2005-01-05 10:32:19 +05:30
|
|
|
if val in GenericFilter.logical_functions:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.logical_op = val
|
|
|
|
else:
|
|
|
|
self.logical_op = 'and'
|
|
|
|
|
|
|
|
def get_logical_op(self):
|
|
|
|
return self.logical_op
|
|
|
|
|
|
|
|
def set_invert(self, val):
|
|
|
|
self.invert = not not val
|
|
|
|
|
|
|
|
def get_invert(self):
|
|
|
|
return self.invert
|
|
|
|
|
|
|
|
def get_name(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def set_name(self,name):
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def set_comment(self,comment):
|
|
|
|
self.comment = comment
|
|
|
|
|
|
|
|
def get_comment(self):
|
|
|
|
return self.comment
|
|
|
|
|
|
|
|
def add_rule(self,rule):
|
|
|
|
self.flist.append(rule)
|
|
|
|
|
2003-03-12 08:32:08 +05:30
|
|
|
def delete_rule(self,rule):
|
|
|
|
self.flist.remove(rule)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def set_rules(self,rules):
|
|
|
|
self.flist = rules
|
|
|
|
|
|
|
|
def get_rules(self):
|
|
|
|
return self.flist
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def check_or(self,db,handle):
|
2002-10-20 19:55:16 +05:30
|
|
|
test = 0
|
|
|
|
for rule in self.flist:
|
2005-05-19 02:26:30 +05:30
|
|
|
test = test or rule.apply(db,handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
if test:
|
|
|
|
break
|
|
|
|
if self.invert:
|
|
|
|
return not test
|
|
|
|
else:
|
|
|
|
return test
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def check_xor(self,db,handle):
|
2002-10-20 19:55:16 +05:30
|
|
|
test = 0
|
|
|
|
for rule in self.flist:
|
2005-05-19 02:26:30 +05:30
|
|
|
temp = rule.apply(db,handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
test = ((not test) and temp) or (test and (not temp))
|
|
|
|
if self.invert:
|
|
|
|
return not test
|
|
|
|
else:
|
|
|
|
return test
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def check_one(self,db,handle):
|
2002-10-20 19:55:16 +05:30
|
|
|
count = 0
|
|
|
|
for rule in self.flist:
|
2005-05-19 02:26:30 +05:30
|
|
|
if rule.apply(db,handle):
|
2002-10-20 19:55:16 +05:30
|
|
|
count = count + 1
|
|
|
|
if count > 1:
|
|
|
|
break
|
|
|
|
if self.invert:
|
|
|
|
return count != 1
|
|
|
|
else:
|
|
|
|
return count == 1
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def check_and(self,db,handle):
|
2002-10-20 19:55:16 +05:30
|
|
|
test = 1
|
|
|
|
for rule in self.flist:
|
2005-05-19 02:26:30 +05:30
|
|
|
test = test and rule.apply(db,handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
if not test:
|
|
|
|
break
|
|
|
|
if self.invert:
|
|
|
|
return not test
|
|
|
|
else:
|
|
|
|
return test
|
|
|
|
|
2003-01-06 10:44:49 +05:30
|
|
|
def get_check_func(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
try:
|
|
|
|
m = getattr(self, 'check_' + self.logical_op)
|
|
|
|
except AttributeError:
|
|
|
|
m = self.check_and
|
2003-01-06 10:44:49 +05:30
|
|
|
return m
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
def check(self,db,handle):
|
|
|
|
return self.get_check_func()(db,handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-03-11 09:01:35 +05:30
|
|
|
def apply(self,db,id_list):
|
2003-01-06 10:44:49 +05:30
|
|
|
m = self.get_check_func()
|
|
|
|
res = []
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
for rule in self.flist:
|
|
|
|
rule.prepare(db)
|
2005-05-19 02:26:30 +05:30
|
|
|
for handle in id_list:
|
|
|
|
if m(db,handle):
|
|
|
|
res.append(handle)
|
* src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and
reset(), that are called before/after a filter is applied, to properly
support query caches; (IsWitness): new filter;
(RelationshipPathBetween,IsDescendantOf,IsLessThanNthGenerationDescendantOf,
IsMoreThanNthGenerationDescendantOf,IsChildOfFilterMatch,IsSiblingOfFilterMatch,
IsAncestorOf,IsAncestorOfFilterMatch,IsLessThanNthGenerationAncestorOf,
IsMoreThanNthGenerationAncestorOf,IsParentOfFilterMatch,HasCommonAncestorWith):
use prepare() and reset() to create a proper query cache. Currently the
cache was only created once after object creation and never updated.
* src/gramps_main.py: Add new filters to the menu.
svn: r4171
2005-03-14 01:19:38 +05:30
|
|
|
for rule in self.flist:
|
|
|
|
rule.reset()
|
2003-01-06 10:44:49 +05:30
|
|
|
return res
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Name to class mappings
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-05-18 10:03:15 +05:30
|
|
|
# This dict is mapping from old names to new names, so that the existing
|
|
|
|
# custom_filters.xml will continue working
|
2005-05-19 02:26:30 +05:30
|
|
|
old_names_2_class = {
|
|
|
|
"Everyone" : Everyone,
|
|
|
|
"Is default person" : IsDefaultPerson,
|
|
|
|
"Is bookmarked person" : IsBookmarked,
|
|
|
|
"Has the Id" : HasIdOf,
|
|
|
|
"Has a name" : HasNameOf,
|
|
|
|
"Has the relationships" : HasRelationship,
|
|
|
|
"Has the death" : HasDeath,
|
|
|
|
"Has the birth" : HasBirth,
|
|
|
|
"Is a descendant of" : IsDescendantOf,
|
|
|
|
"Is a descendant family member of" : IsDescendantFamilyOf,
|
|
|
|
"Is a descendant of filter match": IsDescendantOfFilterMatch,
|
2005-05-18 10:03:15 +05:30
|
|
|
"Is a descendant of person not more than N generations away":
|
2005-05-19 02:26:30 +05:30
|
|
|
IsLessThanNthGenerationDescendantOf,
|
2005-05-19 13:27:50 +05:30
|
|
|
"Is a descendant of person at least N generations away":
|
|
|
|
IsMoreThanNthGenerationDescendantOf,
|
2005-05-19 02:26:30 +05:30
|
|
|
"Is an descendant of person at least N generations away" :
|
|
|
|
IsMoreThanNthGenerationDescendantOf,
|
|
|
|
"Is a child of filter match" : IsChildOfFilterMatch,
|
|
|
|
"Is an ancestor of" : IsAncestorOf,
|
|
|
|
"Is an ancestor of filter match": IsAncestorOfFilterMatch,
|
2005-05-18 10:03:15 +05:30
|
|
|
"Is an ancestor of person not more than N generations away" :
|
2005-05-19 02:26:30 +05:30
|
|
|
IsLessThanNthGenerationAncestorOf,
|
2005-05-18 10:03:15 +05:30
|
|
|
"Is an ancestor of person at least N generations away":
|
2005-05-19 02:26:30 +05:30
|
|
|
IsMoreThanNthGenerationAncestorOf,
|
|
|
|
"Is a parent of filter match" : IsParentOfFilterMatch,
|
|
|
|
"Has a common ancestor with" : HasCommonAncestorWith,
|
|
|
|
"Has a common ancestor with filter match" :HasCommonAncestorWithFilterMatch,
|
|
|
|
"Is a female" : IsFemale,
|
|
|
|
"Is a male" : IsMale,
|
|
|
|
"Has complete record" : HasCompleteRecord,
|
|
|
|
"Has the personal event" : HasEvent,
|
|
|
|
"Has the family event" : HasFamilyEvent,
|
|
|
|
"Has the personal attribute" : HasAttribute,
|
|
|
|
"Has the family attribute" : HasFamilyAttribute,
|
|
|
|
"Has source of" : HasSourceOf,
|
|
|
|
"Matches the filter named" : HasSourceOf,
|
|
|
|
"Is spouse of filter match" : IsSpouseOfFilterMatch,
|
|
|
|
"Is a sibling of filter match" : IsSiblingOfFilterMatch,
|
|
|
|
"Relationship path between two people" : RelationshipPathBetween,
|
|
|
|
"People who were adopted" : HaveAltFamilies,
|
|
|
|
"People who have images" : HavePhotos,
|
|
|
|
"People with children" : HaveChildren,
|
|
|
|
"People with incomplete names" : IncompleteNames,
|
|
|
|
"People with no marriage records" : NeverMarried,
|
|
|
|
"People with multiple marriage records": MultipleMarriages,
|
|
|
|
"People without a birth date" : NoBirthdate,
|
|
|
|
"People with incomplete events" : PersonWithIncompleteEvent,
|
|
|
|
"Families with incomplete events" :FamilyWithIncompleteEvent,
|
|
|
|
"People probably alive" : ProbablyAlive,
|
|
|
|
"People marked private" : PeoplePrivate,
|
|
|
|
"Witnesses" : IsWitness,
|
|
|
|
"Has text matching substring of":HasTextMatchingSubstringOf,
|
2005-05-18 10:03:15 +05:30
|
|
|
}
|
|
|
|
|
2005-05-19 02:26:30 +05:30
|
|
|
editor_rule_list = [
|
|
|
|
Everyone,
|
|
|
|
IsFemale,
|
|
|
|
HasUnknownGender,
|
|
|
|
IsMale,
|
|
|
|
IsDefaultPerson,
|
|
|
|
IsBookmarked,
|
|
|
|
HasIdOf,
|
|
|
|
HasNameOf,
|
|
|
|
HasRelationship,
|
|
|
|
HasDeath,
|
|
|
|
HasBirth,
|
|
|
|
HasCompleteRecord,
|
|
|
|
HasEvent,
|
|
|
|
HasFamilyEvent,
|
|
|
|
HasAttribute,
|
|
|
|
HasFamilyAttribute,
|
|
|
|
HasSourceOf,
|
|
|
|
HaveAltFamilies,
|
|
|
|
HavePhotos,
|
|
|
|
HaveChildren,
|
|
|
|
IncompleteNames,
|
|
|
|
NeverMarried,
|
|
|
|
MultipleMarriages,
|
|
|
|
NoBirthdate,
|
|
|
|
PersonWithIncompleteEvent,
|
|
|
|
FamilyWithIncompleteEvent,
|
|
|
|
ProbablyAlive,
|
|
|
|
PeoplePrivate,
|
|
|
|
IsWitness,
|
|
|
|
IsDescendantOf,
|
|
|
|
IsDescendantFamilyOf,
|
|
|
|
IsDescendantOfFilterMatch,
|
|
|
|
IsLessThanNthGenerationDescendantOf,
|
|
|
|
IsMoreThanNthGenerationDescendantOf,
|
|
|
|
IsAncestorOf,
|
|
|
|
IsAncestorOfFilterMatch,
|
|
|
|
IsLessThanNthGenerationAncestorOf,
|
|
|
|
IsMoreThanNthGenerationAncestorOf,
|
|
|
|
HasCommonAncestorWith,
|
|
|
|
HasCommonAncestorWithFilterMatch,
|
|
|
|
MatchesFilter,
|
|
|
|
IsChildOfFilterMatch,
|
|
|
|
IsParentOfFilterMatch,
|
|
|
|
IsSpouseOfFilterMatch,
|
|
|
|
IsSiblingOfFilterMatch,
|
|
|
|
RelationshipPathBetween,
|
|
|
|
HasTextMatchingSubstringOf,
|
|
|
|
]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GenericFilterList
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class GenericFilterList:
|
|
|
|
"""Container class for the generic filters. Stores, saves, and
|
|
|
|
loads the filters."""
|
|
|
|
|
|
|
|
def __init__(self,file):
|
|
|
|
self.filter_list = []
|
|
|
|
self.file = os.path.expanduser(file)
|
|
|
|
|
|
|
|
def get_filters(self):
|
|
|
|
return self.filter_list
|
|
|
|
|
2004-08-20 17:41:56 +05:30
|
|
|
def add(self,filt):
|
|
|
|
self.filter_list.append(filt)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def load(self):
|
2004-08-06 08:38:27 +05:30
|
|
|
try:
|
|
|
|
parser = make_parser()
|
|
|
|
parser.setContentHandler(FilterParser(self))
|
|
|
|
if self.file[0:7] != "file://":
|
|
|
|
parser.parse("file://" + self.file)
|
|
|
|
else:
|
|
|
|
parser.parse(self.file)
|
|
|
|
except (IOError,OSError):
|
|
|
|
pass
|
|
|
|
except SAXParseException:
|
|
|
|
print "Parser error"
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def fix(self,line):
|
2003-06-12 07:34:42 +05:30
|
|
|
l = line.strip()
|
|
|
|
l = l.replace('&','&')
|
|
|
|
l = l.replace('>','>')
|
|
|
|
l = l.replace('<','<')
|
|
|
|
return l.replace('"','"')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def save(self):
|
2003-09-14 09:51:44 +05:30
|
|
|
f = open(self.file.encode('utf-8'),'w')
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-01-29 10:13:12 +05:30
|
|
|
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
2002-10-20 19:55:16 +05:30
|
|
|
f.write('<filters>\n')
|
|
|
|
for i in self.filter_list:
|
|
|
|
f.write(' <filter name="%s"' % self.fix(i.get_name()))
|
|
|
|
if i.get_invert():
|
|
|
|
f.write(' invert="1"')
|
|
|
|
f.write(' function="%s"' % i.get_logical_op())
|
|
|
|
comment = i.get_comment()
|
|
|
|
if comment:
|
|
|
|
f.write(' comment="%s"' % self.fix(comment))
|
|
|
|
f.write('>\n')
|
|
|
|
for rule in i.get_rules():
|
2005-05-19 02:26:30 +05:30
|
|
|
rule_module_name = rule.__module__
|
|
|
|
rule_class_name = rule.__class__.__name__
|
|
|
|
rule_save_name = "%s.%s" % (rule_module_name,rule_class_name)
|
|
|
|
f.write(' <rule class="%s">\n' % rule_save_name)
|
2002-10-20 19:55:16 +05:30
|
|
|
for v in rule.values():
|
|
|
|
f.write(' <arg value="%s"/>\n' % self.fix(v))
|
|
|
|
f.write(' </rule>\n')
|
|
|
|
f.write(' </filter>\n')
|
|
|
|
f.write('</filters>\n')
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# FilterParser
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class FilterParser(handler.ContentHandler):
|
|
|
|
"""Parses the XML file and builds the list of filters"""
|
|
|
|
|
|
|
|
def __init__(self,gfilter_list):
|
|
|
|
handler.ContentHandler.__init__(self)
|
|
|
|
self.gfilter_list = gfilter_list
|
|
|
|
self.f = None
|
|
|
|
self.r = None
|
|
|
|
self.a = []
|
|
|
|
self.cname = None
|
|
|
|
|
|
|
|
def setDocumentLocator(self,locator):
|
|
|
|
self.locator = locator
|
|
|
|
|
|
|
|
def startElement(self,tag,attrs):
|
|
|
|
if tag == "filter":
|
|
|
|
self.f = GenericFilter()
|
2002-11-19 09:45:02 +05:30
|
|
|
self.f.set_name(attrs['name'])
|
2002-10-20 19:55:16 +05:30
|
|
|
if attrs.has_key('function'):
|
|
|
|
try:
|
2002-11-19 09:45:02 +05:30
|
|
|
if int(attrs['function']):
|
2002-10-20 19:55:16 +05:30
|
|
|
op = 'or'
|
|
|
|
else:
|
|
|
|
op = 'and'
|
|
|
|
except ValueError:
|
2002-11-19 09:45:02 +05:30
|
|
|
op = attrs['function']
|
2002-10-20 19:55:16 +05:30
|
|
|
self.f.set_logical_op(op)
|
|
|
|
if attrs.has_key('comment'):
|
2002-11-19 09:45:02 +05:30
|
|
|
self.f.set_comment(attrs['comment'])
|
2002-10-20 19:55:16 +05:30
|
|
|
if attrs.has_key('invert'):
|
|
|
|
try:
|
2002-11-19 09:45:02 +05:30
|
|
|
self.f.set_invert(int(attrs['invert']))
|
2002-10-20 19:55:16 +05:30
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
self.gfilter_list.add(self.f)
|
|
|
|
elif tag == "rule":
|
2005-05-19 02:26:30 +05:30
|
|
|
save_name = attrs['class']
|
|
|
|
if save_name in old_names_2_class.keys():
|
|
|
|
self.r = old_names_2_class[save_name]
|
2005-04-09 00:22:05 +05:30
|
|
|
else:
|
2005-05-19 13:27:50 +05:30
|
|
|
mc_match = save_name.split('.')
|
|
|
|
if len(mc_match) != 2:
|
|
|
|
# rule has an old style name, that is not in old_names_2_class
|
|
|
|
# or is not in the format "module.class"
|
2005-05-19 02:26:30 +05:30
|
|
|
print "ERROR: Filter rule '%s' in filter '%s' not found!" % (
|
2005-05-19 13:27:50 +05:30
|
|
|
save_name,self.f.get_name())
|
|
|
|
self.r = None
|
|
|
|
return
|
|
|
|
module_name,class_name = mc_match
|
|
|
|
try:
|
|
|
|
if module_name == self.__module__:
|
|
|
|
exec 'self.r = %s' % class_name
|
|
|
|
else:
|
|
|
|
exec 'import %s' % module_name
|
|
|
|
exec 'self.r = %s.%s' % (module_name,class_name)
|
|
|
|
except (ImportError,NameError):
|
|
|
|
print "ERROR: Filter rule '%s' in filter '%s' not found!" % (
|
|
|
|
save_name,self.f.get_name())
|
|
|
|
self.r = None
|
|
|
|
return
|
2005-05-19 02:26:30 +05:30
|
|
|
self.a = []
|
2002-10-20 19:55:16 +05:30
|
|
|
elif tag == "arg":
|
2002-11-19 09:45:02 +05:30
|
|
|
self.a.append(attrs['value'])
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def endElement(self,tag):
|
2005-05-19 13:27:50 +05:30
|
|
|
if tag == "rule" and self.r != None:
|
2005-05-19 02:26:30 +05:30
|
|
|
rule = self.r(self.a)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.f.add_rule(rule)
|
|
|
|
|
|
|
|
def characters(self, data):
|
|
|
|
pass
|
|
|
|
|
2004-04-30 08:31:51 +05:30
|
|
|
class ParamFilter(GenericFilter):
|
|
|
|
|
|
|
|
def __init__(self,source=None):
|
|
|
|
GenericFilter.__init__(self,source)
|
|
|
|
self.need_param = 1
|
|
|
|
self.param_list = []
|
|
|
|
|
|
|
|
def set_parameter(self,param):
|
|
|
|
self.param_list = [param]
|
|
|
|
|
|
|
|
def apply(self,db,id_list):
|
|
|
|
for rule in self.flist:
|
|
|
|
rule.set_list(self.param_list)
|
2005-05-12 20:33:17 +05:30
|
|
|
for rule in self.flist:
|
|
|
|
rule.prepare(db)
|
2005-04-07 18:54:16 +05:30
|
|
|
result = GenericFilter.apply(self,db,id_list)
|
|
|
|
for rule in self.flist:
|
|
|
|
rule.reset()
|
|
|
|
return result
|
2004-04-30 08:31:51 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
SystemFilters = None
|
|
|
|
CustomFilters = None
|
|
|
|
|
|
|
|
def reload_system_filters():
|
|
|
|
global SystemFilters
|
|
|
|
SystemFilters = GenericFilterList(const.system_filters)
|
|
|
|
SystemFilters.load()
|
|
|
|
|
|
|
|
def reload_custom_filters():
|
|
|
|
global CustomFilters
|
|
|
|
CustomFilters = GenericFilterList(const.custom_filters)
|
|
|
|
CustomFilters.load()
|
|
|
|
|
|
|
|
if not SystemFilters:
|
|
|
|
reload_system_filters()
|
|
|
|
|
|
|
|
if not CustomFilters:
|
|
|
|
reload_custom_filters()
|
|
|
|
|
2004-12-28 05:53:49 +05:30
|
|
|
|
|
|
|
class GrampsFilterComboBox(gtk.ComboBox):
|
|
|
|
|
|
|
|
def set(self,local_filters,default=""):
|
|
|
|
self.store = gtk.ListStore(str)
|
|
|
|
self.set_model(self.store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.pack_start(cell,True)
|
|
|
|
self.add_attribute(cell,'text',0)
|
|
|
|
|
|
|
|
self.map = {}
|
|
|
|
|
|
|
|
active = 0
|
|
|
|
cnt = 0
|
|
|
|
for filt in local_filters:
|
|
|
|
self.store.append(row=[filt.get_name()])
|
|
|
|
self.map[filt.get_name()] = filt
|
|
|
|
if default != "" and default == filt.get_name():
|
|
|
|
active = cnt
|
|
|
|
cnt += 1
|
|
|
|
|
|
|
|
for filt in SystemFilters.get_filters():
|
|
|
|
self.store.append(row=[_(filt.get_name())])
|
|
|
|
self.map[filt.get_name()] = filt
|
|
|
|
if default != "" and default == filt.get_name():
|
|
|
|
active = cnt
|
|
|
|
cnt += 1
|
|
|
|
|
|
|
|
for filt in CustomFilters.get_filters():
|
|
|
|
self.store.append(row=[_(filt.get_name())])
|
|
|
|
self.map[filt.get_name()] = filt
|
|
|
|
if default != "" and default == filt.get_name():
|
|
|
|
active = cnt
|
|
|
|
cnt += 1
|
|
|
|
|
|
|
|
if active:
|
|
|
|
self.set_active(active)
|
|
|
|
elif len(local_filters):
|
|
|
|
self.set_active(2)
|
|
|
|
elif len(SystemFilters.get_filters()):
|
|
|
|
self.set_active(4 + len(local_filters))
|
|
|
|
elif len(CustomFilters.get_filters()):
|
|
|
|
self.set_active(6 + len(local_filters) + len(SystemFilters.get_filters()))
|
|
|
|
else:
|
|
|
|
self.set_active(0)
|
|
|
|
|
|
|
|
def get_value(self):
|
|
|
|
active = self.get_active()
|
|
|
|
if active < 0:
|
|
|
|
return None
|
|
|
|
key = self.store[active][0]
|
|
|
|
return self.map[key]
|
|
|
|
|
|
|
|
|
2005-01-07 10:04:02 +05:30
|
|
|
class FilterStore(gtk.ListStore):
|
|
|
|
|
|
|
|
def __init__(self,local_filters=[], default=""):
|
|
|
|
gtk.ListStore.__init__(self,str)
|
|
|
|
self.list_map = []
|
|
|
|
self.def_index = 0
|
|
|
|
|
|
|
|
cnt = 0
|
|
|
|
for filt in local_filters:
|
|
|
|
name = filt.get_name()
|
|
|
|
self.append(row=[name])
|
|
|
|
self.list_map.append(filt)
|
|
|
|
if default != "" and default == name:
|
|
|
|
self.def_index = cnt
|
|
|
|
cnt += 1
|
|
|
|
|
|
|
|
for filt in SystemFilters.get_filters() + CustomFilters.get_filters():
|
|
|
|
name = _(filt.get_name())
|
|
|
|
self.append(row=[name])
|
|
|
|
self.list_map.append(filt)
|
|
|
|
if default != "" and default == name:
|
|
|
|
self.def_index = cnt
|
|
|
|
cnt += 1
|
|
|
|
|
|
|
|
def default_index(self):
|
|
|
|
return self.def_index
|
|
|
|
|
|
|
|
def get_filter(self,index):
|
|
|
|
return self.list_map[index]
|
|
|
|
|
|
|
|
|
2003-10-31 06:56:58 +05:30
|
|
|
def build_filter_menu(local_filters = [], default=""):
|
2002-10-28 19:06:39 +05:30
|
|
|
menu = gtk.Menu()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-10-31 06:56:58 +05:30
|
|
|
active = 0
|
|
|
|
cnt = 0
|
2004-08-20 17:41:56 +05:30
|
|
|
for filt in local_filters:
|
|
|
|
menuitem = gtk.MenuItem(filt.get_name())
|
2002-10-20 19:55:16 +05:30
|
|
|
menuitem.show()
|
|
|
|
menu.append(menuitem)
|
2004-08-20 17:41:56 +05:30
|
|
|
menuitem.set_data("filter", filt)
|
|
|
|
if default != "" and default == filt.get_name():
|
2003-10-31 06:56:58 +05:30
|
|
|
active = cnt
|
|
|
|
cnt += 1
|
|
|
|
|
2004-08-20 17:41:56 +05:30
|
|
|
for filt in SystemFilters.get_filters():
|
|
|
|
menuitem = gtk.MenuItem(_(filt.get_name()))
|
2002-10-20 19:55:16 +05:30
|
|
|
menuitem.show()
|
|
|
|
menu.append(menuitem)
|
2004-08-20 17:41:56 +05:30
|
|
|
menuitem.set_data("filter", filt)
|
|
|
|
if default != "" and default == filt.get_name():
|
2003-10-31 06:56:58 +05:30
|
|
|
active = cnt
|
|
|
|
cnt += 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-08-20 17:41:56 +05:30
|
|
|
for filt in CustomFilters.get_filters():
|
|
|
|
menuitem = gtk.MenuItem(_(filt.get_name()))
|
2002-10-20 19:55:16 +05:30
|
|
|
menuitem.show()
|
|
|
|
menu.append(menuitem)
|
2004-08-20 17:41:56 +05:30
|
|
|
menuitem.set_data("filter", filt)
|
|
|
|
if default != "" and default == filt.get_name():
|
2003-10-31 06:56:58 +05:30
|
|
|
active = cnt
|
|
|
|
cnt += 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-10-31 06:56:58 +05:30
|
|
|
if active:
|
|
|
|
menu.set_active(active)
|
|
|
|
elif len(local_filters):
|
2002-10-20 19:55:16 +05:30
|
|
|
menu.set_active(2)
|
|
|
|
elif len(SystemFilters.get_filters()):
|
|
|
|
menu.set_active(4 + len(local_filters))
|
|
|
|
elif len(CustomFilters.get_filters()):
|
|
|
|
menu.set_active(6 + len(local_filters) + len(SystemFilters.get_filters()))
|
|
|
|
else:
|
|
|
|
menu.set_active(0)
|
|
|
|
|
|
|
|
return menu
|