diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 4563fd2b0..59180a4fc 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,19 @@ 2006-08-03 Alex Roitman + * src/Filters/_GenericFilter.py (GenericFilterFactory): Add + factory function. + * src/Filters/_FilterParser.py (FilterParser.startElement): Use + factory function. + * src/Filters/Rules/_MatchesFilterBase.py: Add base module. + * src/Filters/Rules/Person/_MatchesFilter.py: Derive from base. + * src/Filters/Rules/Family/_MatchesFilter.py: Add rule. + * src/Filters/Rules/Family/_MotherHasIdOf.py: Add rule. + * src/Filters/Rules/Family/_FatherHasIdOf.py: Add rule. + * src/Filters/Rules/Family/_MotherHasNameOf.py: Add rule. + * src/Filters/Rules/Family/_ChildHasIdOf.py: Add rule. + * src/Filters/Rules/Family/_FatherHasNameOf.py: Add rule. + * src/Filters/Rules/Family/_ChildHasNameOf.py: Add rule. + * src/Filters/Rules/Family/__init__.py: Expose new rules. + * src/GrampsLogger/_ErrorReportAssistant.py (build_page5): Typo. * src/Filters/Rules/Person/_HasIdOf.py: Cleanup. * src/Filters/Rules/Person/__init__.py (editor_rule_list): Add diff --git a/gramps2/src/Filters/Rules/Family/_ChildHasIdOf.py b/gramps2/src/Filters/Rules/Family/_ChildHasIdOf.py new file mode 100644 index 000000000..5e9c16df0 --- /dev/null +++ b/gramps2/src/Filters/Rules/Family/_ChildHasIdOf.py @@ -0,0 +1,56 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# 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 +# + +# $Id: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules import HasGrampsId + +#------------------------------------------------------------------------- +# +# HasNameOf +# +#------------------------------------------------------------------------- +class ChildHasIdOf(HasGrampsId): + """Rule that checks for a person with a specific GRAMPS ID""" + + labels = [ _('Person ID:') ] + name = _('Families with child with the ') + description = _("Matches familis where child has a specified " + "GRAMPS ID") + category = _('Child filters') + + def apply(self,db,family): + for child_ref in family.get_child_ref_list(): + child = db.get_person_from_handle(child_ref.ref) + if HasGrampsId.apply(self,db,child): + return True + return False diff --git a/gramps2/src/Filters/Rules/Family/_ChildHasNameOf.py b/gramps2/src/Filters/Rules/Family/_ChildHasNameOf.py new file mode 100644 index 000000000..854a185cd --- /dev/null +++ b/gramps2/src/Filters/Rules/Family/_ChildHasNameOf.py @@ -0,0 +1,55 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# 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 +# + +# $Id: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules.Person import HasNameOf + +#------------------------------------------------------------------------- +# +# HasNameOf +# +#------------------------------------------------------------------------- +class ChildHasNameOf(HasNameOf): + """Rule that checks for full or partial name matches""" + + name = _('Families with child with the ') + description = _("Matches familis where child has a specified " + "(partial) name") + category = _('Child filters') + + def apply(self,db,family): + for child_ref in family.get_child_ref_list(): + child = db.get_person_from_handle(child_ref.ref) + if HasNameOf.apply(self,db,child): + return True + return False diff --git a/gramps2/src/Filters/Rules/Family/_FatherHasIdOf.py b/gramps2/src/Filters/Rules/Family/_FatherHasIdOf.py new file mode 100644 index 000000000..1df4b9db7 --- /dev/null +++ b/gramps2/src/Filters/Rules/Family/_FatherHasIdOf.py @@ -0,0 +1,54 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# 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 +# + +# $Id: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules import HasGrampsId + +#------------------------------------------------------------------------- +# +# HasNameOf +# +#------------------------------------------------------------------------- +class FatherHasIdOf(HasGrampsId): + """Rule that checks for a person with a specific GRAMPS ID""" + + labels = [ _('Person ID:') ] + name = _('Families with father with the ') + description = _("Matches familis whose father has a specified " + "GRAMPS ID") + category = _('Father filters') + + def apply(self,db,family): + father_handle = family.get_father_handle() + father = db.get_person_from_handle(father_handle) + return HasGrampsId.apply(self,db,father) diff --git a/gramps2/src/Filters/Rules/Family/_FatherHasNameOf.py b/gramps2/src/Filters/Rules/Family/_FatherHasNameOf.py new file mode 100644 index 000000000..d62acdf84 --- /dev/null +++ b/gramps2/src/Filters/Rules/Family/_FatherHasNameOf.py @@ -0,0 +1,53 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# 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 +# + +# $Id: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules.Person import HasNameOf + +#------------------------------------------------------------------------- +# +# HasNameOf +# +#------------------------------------------------------------------------- +class FatherHasNameOf(HasNameOf): + """Rule that checks for full or partial name matches""" + + name = _('Families with father with the ') + description = _("Matches familis whose father has a specified " + "(partial) name") + category = _('Father filters') + + def apply(self,db,family): + father_handle = family.get_father_handle() + father = db.get_person_from_handle(father_handle) + return HasNameOf.apply(self,db,father) diff --git a/gramps2/src/Filters/Rules/Family/_MatchesFilter.py b/gramps2/src/Filters/Rules/Family/_MatchesFilter.py new file mode 100644 index 000000000..20ebcacea --- /dev/null +++ b/gramps2/src/Filters/Rules/Family/_MatchesFilter.py @@ -0,0 +1,47 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# 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 +# + +# $Id: _MatchesFilter.py 6932 2006-06-21 16:30:35Z dallingham $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._MatchesFilterBase import MatchesFilterBase + +#------------------------------------------------------------------------- +# +# MatchesFilter +# +#------------------------------------------------------------------------- +class MatchesFilter(MatchesFilterBase): + """Rule that checks against another filter""" + + name = _('Families matching the ') + description = _("Matches families macthed by the specified filter name") + namespace = 'Family' diff --git a/gramps2/src/Filters/Rules/Family/_MotherHasIdOf.py b/gramps2/src/Filters/Rules/Family/_MotherHasIdOf.py new file mode 100644 index 000000000..1898f616a --- /dev/null +++ b/gramps2/src/Filters/Rules/Family/_MotherHasIdOf.py @@ -0,0 +1,54 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# 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 +# + +# $Id: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules import HasGrampsId + +#------------------------------------------------------------------------- +# +# HasNameOf +# +#------------------------------------------------------------------------- +class MotherHasIdOf(HasGrampsId): + """Rule that checks for a person with a specific GRAMPS ID""" + + labels = [ _('Person ID:') ] + name = _('Families with mother with the ') + description = _("Matches familis whose mother has a specified " + "GRAMPS ID") + category = _('Mother filters') + + def apply(self,db,family): + mother_handle = family.get_mother_handle() + mother = db.get_person_from_handle(mother_handle) + return HasGrampsId.apply(self,db,mother) diff --git a/gramps2/src/Filters/Rules/Family/_MotherHasNameOf.py b/gramps2/src/Filters/Rules/Family/_MotherHasNameOf.py new file mode 100644 index 000000000..d030ba5ed --- /dev/null +++ b/gramps2/src/Filters/Rules/Family/_MotherHasNameOf.py @@ -0,0 +1,53 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# 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 +# + +# $Id: _HasNameOf.py 6529 2006-05-03 06:29:07Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules.Person import HasNameOf + +#------------------------------------------------------------------------- +# +# HasNameOf +# +#------------------------------------------------------------------------- +class MotherHasNameOf(HasNameOf): + """Rule that checks for full or partial name matches""" + + name = _('Families with mother with the ') + description = _("Matches familis whose mother has a specified " + "(partial) name") + category = _('Mother filters') + + def apply(self,db,family): + mother_handle = family.get_mother_handle() + mother = db.get_person_from_handle(mother_handle) + return HasNameOf.apply(self,db,mother) diff --git a/gramps2/src/Filters/Rules/Family/__init__.py b/gramps2/src/Filters/Rules/Family/__init__.py index c6c0d0aa3..828d0de6c 100644 --- a/gramps2/src/Filters/Rules/Family/__init__.py +++ b/gramps2/src/Filters/Rules/Family/__init__.py @@ -34,6 +34,13 @@ from _HasNoteRegexp import HasNoteRegexp from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf from _FamilyPrivate import FamilyPrivate from _HasEvent import HasEvent +from _MatchesFilter import MatchesFilter +from _FatherHasNameOf import FatherHasNameOf +from _FatherHasIdOf import FatherHasIdOf +from _MotherHasNameOf import MotherHasNameOf +from _MotherHasIdOf import MotherHasIdOf +from _ChildHasNameOf import ChildHasNameOf +from _ChildHasIdOf import ChildHasIdOf editor_rule_list = [ AllFamilies, @@ -44,4 +51,11 @@ editor_rule_list = [ HasNoteMatchingSubstringOf, FamilyPrivate, HasEvent, + MatchesFilter, + FatherHasNameOf, + FatherHasIdOf, + MotherHasNameOf, + MotherHasIdOf, + ChildHasNameOf, + ChildHasIdOf, ] diff --git a/gramps2/src/Filters/Rules/Person/_MatchesFilter.py b/gramps2/src/Filters/Rules/Person/_MatchesFilter.py index 671f8908d..2151d5a73 100644 --- a/gramps2/src/Filters/Rules/Person/_MatchesFilter.py +++ b/gramps2/src/Filters/Rules/Person/_MatchesFilter.py @@ -32,54 +32,16 @@ from gettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -import Filters -#from Filters import SystemFilters, CustomFilters -from Filters.Rules._Rule import Rule +from Filters.Rules._MatchesFilterBase import MatchesFilterBase #------------------------------------------------------------------------- # # MatchesFilter # #------------------------------------------------------------------------- -class MatchesFilter(Rule): +class MatchesFilter(MatchesFilterBase): """Rule that checks against another filter""" - labels = [_('Filter name:')] name = _('People matching the ') description = _("Matches people macthed by the specified filter name") - category = _('General filters') - - def prepare(self,db): - if Filters.SystemFilters: - for filt in Filters.SystemFilters.get_filters('Person'): - if filt.get_name() == self.list[0]: - for rule in filt.flist: - rule.prepare(db) - if Filters.CustomFilters: - for filt in Filters.CustomFilters.get_filters('Person'): - if filt.get_name() == self.list[0]: - for rule in filt.flist: - rule.prepare(db) - - def reset(self): - if Filters.SystemFilters: - for filt in Filters.SystemFilters.get_filters('Person'): - if filt.get_name() == self.list[0]: - for rule in filt.flist: - rule.reset() - if Filters.CustomFilters: - for filt in Filters.CustomFilters.get_filters('Person'): - if filt.get_name() == self.list[0]: - for rule in filt.flist: - rule.reset() - - def apply(self,db,person): - if Filters.SystemFilters: - for filt in Filters.SystemFilters.get_filters('Person'): - if filt.get_name() == self.list[0]: - return filt.check(db,person.handle) - if Filters.CustomFilters: - for filt in Filters.CustomFilters.get_filters('Person'): - if filt.get_name() == self.list[0]: - return filt.check(db,person.handle) - return False + namespace = 'Person' diff --git a/gramps2/src/Filters/Rules/_MatchesFilterBase.py b/gramps2/src/Filters/Rules/_MatchesFilterBase.py new file mode 100644 index 000000000..c88e6beb4 --- /dev/null +++ b/gramps2/src/Filters/Rules/_MatchesFilterBase.py @@ -0,0 +1,89 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2002-2006 Donald N. Allingham +# +# 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 +# + +# $Id: _MatchesFilter.py 6932 2006-06-21 16:30:35Z dallingham $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +import Filters +from _Rule import Rule + +#------------------------------------------------------------------------- +# +# MatchesFilter +# +#------------------------------------------------------------------------- +class MatchesFilterBase(Rule): + """ + Rule that checks against another filter. + + This is a base rule for subclassing by specific objects. + Subclasses need to define the namespace class attribute. + """ + + labels = [_('Filter name:')] + name = _('Objects matching the ') + description = _("Matches objects macthed by the specified filter name") + category = _('General filters') + + def prepare(self,db): + if Filters.SystemFilters: + for filt in Filters.SystemFilters.get_filters(self.namespace): + if filt.get_name() == self.list[0]: + for rule in filt.flist: + rule.prepare(db) + if Filters.CustomFilters: + for filt in Filters.CustomFilters.get_filters(self.namespace): + if filt.get_name() == self.list[0]: + for rule in filt.flist: + rule.prepare(db) + + def reset(self): + if Filters.SystemFilters: + for filt in Filters.SystemFilters.get_filters(self.namespace): + if filt.get_name() == self.list[0]: + for rule in filt.flist: + rule.reset() + if Filters.CustomFilters: + for filt in Filters.CustomFilters.get_filters(self.namespace): + if filt.get_name() == self.list[0]: + for rule in filt.flist: + rule.reset() + + def apply(self,db,obj): + if Filters.SystemFilters: + for filt in Filters.SystemFilters.get_filters(self.namespace): + if filt.get_name() == self.list[0]: + return filt.check(db,obj.handle) + if Filters.CustomFilters: + for filt in Filters.CustomFilters.get_filters(self.namespace): + if filt.get_name() == self.list[0]: + return filt.check(db,obj.handle) + return False diff --git a/gramps2/src/Filters/_FilterParser.py b/gramps2/src/Filters/_FilterParser.py index 99ce4a874..7794232fd 100644 --- a/gramps2/src/Filters/_FilterParser.py +++ b/gramps2/src/Filters/_FilterParser.py @@ -32,7 +32,7 @@ from xml.sax import handler # Gramps modules # #------------------------------------------------------------------------- -from _GenericFilter import GenericFilter +from _GenericFilter import GenericFilterFactory import Rules #------------------------------------------------------------------------- @@ -62,7 +62,7 @@ class FilterParser(handler.ContentHandler): else: self.namespace = "generic" elif tag == "filter": - self.f = GenericFilter() + self.f = GenericFilterFactory(self.namespace)() self.f.set_name(attrs['name']) if attrs.has_key('function'): try: diff --git a/gramps2/src/Filters/_GenericFilter.py b/gramps2/src/Filters/_GenericFilter.py index c6d88875b..0b27aa405 100644 --- a/gramps2/src/Filters/_GenericFilter.py +++ b/gramps2/src/Filters/_GenericFilter.py @@ -25,7 +25,6 @@ Package providing filtering framework for GRAMPS. """ import RelLib - #------------------------------------------------------------------------- # # GenericFilter @@ -210,3 +209,8 @@ class GenericFamilyFilter(GenericFilter): return db.get_family_from_handle(handle) +def GenericFilterFactory(namespace): + if namespace == 'Person': + return GenericFilter + elif namespace == 'Family': + return GenericFamilyFilter