diff --git a/ChangeLog b/ChangeLog index 1fcfac8dd..d6a5734a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-08-25 Benny Malengier/Joachim Breitner + * src/Filters/Rules/Place/_MatchesEventFilter.py : new filter feature #1182 + * src/Filters/Rules/Event/_MatchesPersonFilter.py: new filter feature #1182 + * po/POTFILES.in : add new filters + * src/Filters/Rules/_MatchesFilterBase.py : add helper function + * src/Filters/Rules/Place/Makefile.am : add new filter + * src/Filters/Rules/Place/__init__.py : add new filter + * src/Filters/Rules/Event/Makefile.am : add new filter + * src/Filters/Rules/Event/__init__.py : add new filter + * src/FilterEditor/_EditRule.py : new custom filter widgets + 2007-08-25 Don Allingham * src/Config/_GrampsConfigKeys.py; Add EXPORT_NO_PRIVATE and EXPORT_RESTRICT diff --git a/po/POTFILES.in b/po/POTFILES.in index 61657750f..6bbbc3c45 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -565,6 +565,7 @@ src/Filters/Rules/Event/_HasIdOf.py src/Filters/Rules/Event/_HasMarkerOf.py src/Filters/Rules/Event/_HasType.py src/Filters/Rules/Event/_HasNoteMatchingSubstringOf.py +src/Filters/Rules/Event/_MatchesPersonFilter.py src/Filters/Rules/Event/__init__.py # Filters.Rules.Place package @@ -576,6 +577,7 @@ src/Filters/Rules/Place/_HasNoteRegexp.py src/Filters/Rules/Place/_HasPlace.py src/Filters/Rules/Place/_InLatLonNeighborhood.py src/Filters/Rules/Place/_MatchesFilter.py +src/Filters/Rules/Place/_MatchesEventFilter.py src/Filters/Rules/Place/_PlacePrivate.py src/Filters/Rules/Place/_RegExpIdOf.py src/Filters/Rules/Place/__init__.py diff --git a/src/FilterEditor/_EditRule.py b/src/FilterEditor/_EditRule.py index 218bdb1cc..f7094cf2b 100644 --- a/src/FilterEditor/_EditRule.py +++ b/src/FilterEditor/_EditRule.py @@ -433,6 +433,13 @@ class EditRule(ManagedWindow.ManagedWindow): elif v == _('Filter name:'): t = MyFilters(self.filterdb.get_filters(self.space), self.filter_name) + # filters of another namespace + elif v == _('Person filter name:'): + t = MyFilters(self.filterdb.get_filters('Person'), + self.filter_name) + elif v == _('Event filter name:'): + t = MyFilters(self.filterdb.get_filters('Event'), + self.filter_name) elif _name2typeclass.has_key(v): t = MySelect(_name2typeclass[v]) elif v == _('Inclusive:'): @@ -441,6 +448,8 @@ class EditRule(ManagedWindow.ManagedWindow): t = MyBoolean(_('Use exact case of letters')) elif v == _('Regular-Expression matching:'): t = MyBoolean(_('Use regular expression')) + elif v == _('Include Family events:'): + t = MyBoolean(_('Also family events where person is wife/husband')) else: t = MyEntry() tlist.append(t) diff --git a/src/Filters/Rules/Event/Makefile.am b/src/Filters/Rules/Event/Makefile.am index 907843e0b..51e3eec92 100644 --- a/src/Filters/Rules/Event/Makefile.am +++ b/src/Filters/Rules/Event/Makefile.am @@ -12,6 +12,7 @@ pkgdata_PYTHON = \ _HasMarkerOf.py\ _HasType.py\ _HasNoteMatchingSubstringOf.py\ + _MatchesPersonFilter.py\ __init__.py pkgpyexecdir = @pkgpyexecdir@/Filters/Rules/Event diff --git a/src/Filters/Rules/Event/_MatchesPersonFilter.py b/src/Filters/Rules/Event/_MatchesPersonFilter.py new file mode 100644 index 000000000..72e6178b3 --- /dev/null +++ b/src/Filters/Rules/Event/_MatchesPersonFilter.py @@ -0,0 +1,90 @@ +# +# 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 Filters.Rules._MatchesFilterBase import MatchesFilterBase + +#------------------------------------------------------------------------- +# +# MatchesFilter +# +#------------------------------------------------------------------------- +class MatchesPersonFilter(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 = [_('Person filter name:'), _('Include Family events:')] + name = _('Events of persons matching the ') + description = _("Matches events of persons matched by the specified " + "person filter name") + category = _('General filters') + # we want to have this filter show person filters + namespace = 'Person' + + def prepare(self,db): + MatchesFilterBase.prepare(self, db) + + try : + if int(self.list[1]): + self.MPF_famevents = True + else: + self.MPF_famevents = False + except IndexError: + self.MPF_famevents = False + + + def apply(self,db,event): + filt = self.find_filter() + if filt: + for (classname, handle) in db.find_backlink_handles( + event.get_handle(), ['Person']): + if filt.check(db, handle): + return True + if self.MPF_famevents : + #also include if family event of the person + for (classname, handle) in db.find_backlink_handles( + event.get_handle(), ['Family']): + family = db.get_family_from_handle(handle) + if family.father_handle and filt.check(db, + family.father_handle) : + return True + if family.mother_handle and filt.check(db, + family.mother_handle) : + return True + + return False diff --git a/src/Filters/Rules/Event/__init__.py b/src/Filters/Rules/Event/__init__.py index dea0feb44..912015c89 100644 --- a/src/Filters/Rules/Event/__init__.py +++ b/src/Filters/Rules/Event/__init__.py @@ -38,6 +38,7 @@ from _HasNoteRegexp import HasNoteRegexp from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf from _EventPrivate import EventPrivate from _MatchesFilter import MatchesFilter +from _MatchesPersonFilter import MatchesPersonFilter editor_rule_list = [ AllEvents, @@ -50,4 +51,5 @@ editor_rule_list = [ HasNoteMatchingSubstringOf, EventPrivate, MatchesFilter, + MatchesPersonFilter, ] diff --git a/src/Filters/Rules/Place/Makefile.am b/src/Filters/Rules/Place/Makefile.am index 558c57b9f..cb6f0689a 100644 --- a/src/Filters/Rules/Place/Makefile.am +++ b/src/Filters/Rules/Place/Makefile.am @@ -11,6 +11,7 @@ pkgdata_PYTHON = \ _HasNoteRegexp.py\ _HasPlace.py\ _MatchesFilter.py\ + _MatchesEventFilter.py\ _PlacePrivate.py\ _RegExpIdOf.py\ __init__.py diff --git a/src/Filters/Rules/Place/_MatchesEventFilter.py b/src/Filters/Rules/Place/_MatchesEventFilter.py new file mode 100644 index 000000000..b106476e6 --- /dev/null +++ b/src/Filters/Rules/Place/_MatchesEventFilter.py @@ -0,0 +1,66 @@ +# +# 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 Filters.Rules._MatchesFilterBase import MatchesFilterBase + +#------------------------------------------------------------------------- +# +# MatchesFilter +# +#------------------------------------------------------------------------- +class MatchesEventFilter(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 = _('Places of events matching the ') + description = _("Matches places where events happened that match the " + "specified event filter name") + category = _('General filters') + # we want to have this filter show event filters + namespace = 'Event' + + + def apply(self,db,event): + filt = self.find_filter() + if filt: + for (classname, handle) in db.find_backlink_handles(event.get_handle(), ['Event']): + if filt.check(db, handle): + return True + return False diff --git a/src/Filters/Rules/Place/__init__.py b/src/Filters/Rules/Place/__init__.py index 26aa88ad0..1e3965823 100644 --- a/src/Filters/Rules/Place/__init__.py +++ b/src/Filters/Rules/Place/__init__.py @@ -36,6 +36,7 @@ from _MatchesFilter import MatchesFilter from _HasPlace import HasPlace from _HasNoLatOrLon import HasNoLatOrLon from _InLatLonNeighborhood import InLatLonNeighborhood +from _MatchesEventFilter import MatchesEventFilter editor_rule_list = [ AllPlaces, @@ -48,4 +49,5 @@ editor_rule_list = [ HasPlace, HasNoLatOrLon, InLatLonNeighborhood, + MatchesEventFilter, ] diff --git a/src/Filters/Rules/_MatchesFilterBase.py b/src/Filters/Rules/_MatchesFilterBase.py index 3754be64f..23d3b498c 100644 --- a/src/Filters/Rules/_MatchesFilterBase.py +++ b/src/Filters/Rules/_MatchesFilterBase.py @@ -87,3 +87,17 @@ class MatchesFilterBase(Rule): if filt.get_name() == self.list[0]: return filt.check(db,obj.handle) return False + + def find_filter(self): + ''' helper function that can be usefull, returning the filter + selected or None + ''' + if Filters.SystemFilters: + for filt in Filters.SystemFilters.get_filters(self.namespace): + if filt.get_name() == self.list[0]: + return filt + if Filters.CustomFilters: + for filt in Filters.CustomFilters.get_filters(self.namespace): + if filt.get_name() == self.list[0]: + return filt + return None