From d9ad7798bc4fa80905abc59cf9cd61b6dda2fd6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Rapinat?= Date: Mon, 18 Jan 2010 14:57:54 +0000 Subject: [PATCH] 3105: general base objects svn: r14093 --- po/POTFILES.skip | 2 + .../Rules/Event/_MatchesSourceFilter.py | 20 +---- .../Rules/Person/_MatchesEventFilter.py | 20 +---- src/Filters/Rules/_MatchesEventFilterBase.py | 73 +++++++++++++++++++ src/Filters/Rules/_MatchesSourceFilterBase.py | 69 ++++++++++++++++++ src/Filters/Rules/__init__.py | 2 + 6 files changed, 152 insertions(+), 34 deletions(-) create mode 100644 src/Filters/Rules/_MatchesEventFilterBase.py create mode 100644 src/Filters/Rules/_MatchesSourceFilterBase.py diff --git a/po/POTFILES.skip b/po/POTFILES.skip index 487aeefb4..c34054955 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -3,6 +3,8 @@ src/Filters/Rules/_HasLDSBase.py src/Filters/Rules/_HasNoteBase.py src/Filters/Rules/_HasReferenceCountOf.py src/Filters/Rules/_HasSourceBase.py +src/Filters/Rules/_MatchesEventFilterBase.py +src/Filters/Rules/_MatchesSourceFilterBase.py src/gen/db/write.py src/gen/lib/styledtext.py src/gen/lib/styledtexttagtype.py diff --git a/src/Filters/Rules/Event/_MatchesSourceFilter.py b/src/Filters/Rules/Event/_MatchesSourceFilter.py index 21ee4a251..b865e7eac 100644 --- a/src/Filters/Rules/Event/_MatchesSourceFilter.py +++ b/src/Filters/Rules/Event/_MatchesSourceFilter.py @@ -2,6 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2010 Benny Malengier # # 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 @@ -32,14 +33,14 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules import MatchesFilterBase +from Filters.Rules import MatchesSourceFilterBase #------------------------------------------------------------------------- # # MatchesFilter # #------------------------------------------------------------------------- -class MatchesSourceFilter(MatchesFilterBase): +class MatchesSourceFilter(MatchesSourceFilterBase): """ Rule that checks against another filter. """ @@ -52,18 +53,3 @@ class MatchesSourceFilter(MatchesFilterBase): # we want to have this filter show source filters namespace = 'Source' - - def prepare(self, db): - MatchesFilterBase.prepare(self, db) - self.MSF_filt = self.find_filter() - - def apply(self, db, event): - if self.MSF_filt is None : - return False - - sourcelist = [x.ref for x in event.get_source_references()] - for sourcehandle in sourcelist: - #check if source in source filter - if self.MSF_filt.check(db, sourcehandle): - return True - return False diff --git a/src/Filters/Rules/Person/_MatchesEventFilter.py b/src/Filters/Rules/Person/_MatchesEventFilter.py index f1e00080f..68563bd34 100644 --- a/src/Filters/Rules/Person/_MatchesEventFilter.py +++ b/src/Filters/Rules/Person/_MatchesEventFilter.py @@ -2,6 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2002-2006 Donald N. Allingham +# Copyright (C) 2010 Benny Malengier # # 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 @@ -32,14 +33,14 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -from Filters.Rules import MatchesFilterBase +from Filters.Rules import MatchesEventFilterBase #------------------------------------------------------------------------- # # MatchesFilter # #------------------------------------------------------------------------- -class MatchesEventFilter(MatchesFilterBase): +class MatchesEventFilter(MatchesEventFilterBase): """ Rule that checks against another filter. @@ -56,18 +57,3 @@ class MatchesEventFilter(MatchesFilterBase): # we want to have this filter show event filters namespace = 'Event' - - def prepare(self, db): - MatchesFilterBase.prepare(self, db) - self.MEF_filt = self.find_filter() - - def apply(self, db, person): - if self.MEF_filt is None : - return False - - eventlist = [x.ref for x in person.get_event_ref_list()] - for eventhandle in eventlist: - #check if event in event filter - if self.MEF_filt.check(db, eventhandle): - return True - return False diff --git a/src/Filters/Rules/_MatchesEventFilterBase.py b/src/Filters/Rules/_MatchesEventFilterBase.py new file mode 100644 index 000000000..68fe4b96c --- /dev/null +++ b/src/Filters/Rules/_MatchesEventFilterBase.py @@ -0,0 +1,73 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2010 Benny Malengier +# +# 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: _MatchesEventFilterBase.py + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules import MatchesFilterBase + +#------------------------------------------------------------------------- +# +# MatchesEventFilter +# +#------------------------------------------------------------------------- +class MatchesEventFilterBase(MatchesFilterBase): + """ + 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 = [_('Event filter name:')] + name = _('Objects with events matching the ') + description = _("Matches objects who have events that match a certain" + " event filter") + category = _('General filters') + + # we want to have this filter show event filters + namespace = 'Event' + + def prepare(self, db): + MatchesFilterBase.prepare(self, db) + self.MEF_filt = self.find_filter() + + def apply(self, db, object): + if self.MEF_filt is None : + return False + + eventlist = [x.ref for x in object.get_event_ref_list()] + for eventhandle in eventlist: + #check if event in event filter + if self.MEF_filt.check(db, eventhandle): + return True + return False diff --git a/src/Filters/Rules/_MatchesSourceFilterBase.py b/src/Filters/Rules/_MatchesSourceFilterBase.py new file mode 100644 index 000000000..87d3dfaea --- /dev/null +++ b/src/Filters/Rules/_MatchesSourceFilterBase.py @@ -0,0 +1,69 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2010 Benny Malengier +# +# 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: _MatchesSourceFilterBase.py + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gen.ggettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules import MatchesFilterBase + +#------------------------------------------------------------------------- +# +# MatchesFilter +# +#------------------------------------------------------------------------- +class MatchesSourceFilterBase(MatchesFilterBase): + """ + Rule that checks against another filter. + """ + + labels = [_('Source filter name:')] + name = _('Objects with source matching the ') + description = _("Matches objects with sources that match the " + "specified source filter name") + category = _('General filters') + + # we want to have this filter show source filters + namespace = 'Source' + + def prepare(self, db): + MatchesFilterBase.prepare(self, db) + self.MSF_filt = self.find_filter() + + def apply(self, db, object): + if self.MSF_filt is None : + return False + + sourcelist = [x.ref for x in object.get_source_references()] + for sourcehandle in sourcelist: + #check if source in source filter + if self.MSF_filt.check(db, sourcehandle): + return True + return False diff --git a/src/Filters/Rules/__init__.py b/src/Filters/Rules/__init__.py index c374315ef..5e2f2ab1f 100644 --- a/src/Filters/Rules/__init__.py +++ b/src/Filters/Rules/__init__.py @@ -34,6 +34,8 @@ from Filters.Rules._IsPrivate import IsPrivate from Filters.Rules._HasTextMatchingSubstringOf import HasTextMatchingSubstringOf from Filters.Rules._HasTextMatchingRegexpOf import HasTextMatchingRegexpOf from Filters.Rules._MatchesFilterBase import MatchesFilterBase +from Filters.Rules._MatchesEventFilterBase import MatchesEventFilterBase +from Filters.Rules._MatchesSourceFilterBase import MatchesSourceFilterBase from Filters.Rules._ChangedSinceBase import ChangedSinceBase from Filters.Rules import (Person, Family, Event, Source, Place, MediaObject,