From a89718f726fdc0bd4bb7f011576beb07399b33e6 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 12 Jul 2006 22:42:55 +0000 Subject: [PATCH] update svn: r7021 --- src/Filters/Rules/Family/Makefile.am | 10 ++- src/Filters/Rules/Family/_FamilyPrivate.py | 44 +++++++++++ src/Filters/Rules/Family/_HasEvent.py | 51 +++++++++++++ src/Filters/Rules/Family/__init__.py | 4 + src/Filters/Rules/Makefile.am | 19 +++-- src/Filters/Rules/Person/_HasEvent.py | 42 +--------- src/Filters/Rules/_HasEventBase.py | 89 ++++++++++++++++++++++ src/Filters/Rules/_HasGrampsId.py | 3 + src/Filters/_FamilySidebarFilter.py | 6 +- 9 files changed, 217 insertions(+), 51 deletions(-) create mode 100644 src/Filters/Rules/Family/_FamilyPrivate.py create mode 100644 src/Filters/Rules/Family/_HasEvent.py create mode 100644 src/Filters/Rules/_HasEventBase.py diff --git a/src/Filters/Rules/Family/Makefile.am b/src/Filters/Rules/Family/Makefile.am index 1740a30af..663bbda99 100644 --- a/src/Filters/Rules/Family/Makefile.am +++ b/src/Filters/Rules/Family/Makefile.am @@ -3,7 +3,15 @@ pkgdatadir = $(datadir)/@PACKAGE@/Filters/Rules/Family pkgdata_PYTHON = \ - __init__.py + _AllFamilies.py\ + _FamilyPrivate.py\ + _HasEvent.py\ + _HasIdOf.py\ + _HasNoteMatchingSubstringOf.py\ + _HasNoteRegexp.py\ + _HasRelType.py\ + __init__.py\ + _RegExpIdOf.py pkgpyexecdir = @pkgpyexecdir@/Filters/Rules/Family pkgpythondir = @pkgpythondir@/Filters/Rules/Family diff --git a/src/Filters/Rules/Family/_FamilyPrivate.py b/src/Filters/Rules/Family/_FamilyPrivate.py new file mode 100644 index 000000000..feb30d449 --- /dev/null +++ b/src/Filters/Rules/Family/_FamilyPrivate.py @@ -0,0 +1,44 @@ +# +# 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: _FamilyPrivate.py 6529 2006-05-03 06:29:07Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._IsPrivate import IsPrivate + +#------------------------------------------------------------------------- +# "Family marked private" +#------------------------------------------------------------------------- +class FamilyPrivate(IsPrivate): + """Family marked private""" + + name = _('Families marked private') + description = _("Matches families that are indicated as private") diff --git a/src/Filters/Rules/Family/_HasEvent.py b/src/Filters/Rules/Family/_HasEvent.py new file mode 100644 index 000000000..dc975bca5 --- /dev/null +++ b/src/Filters/Rules/Family/_HasEvent.py @@ -0,0 +1,51 @@ +# +# 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: _HasEvent.py 6635 2006-05-13 03:53:06Z dallingham $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasEventBase import HasEventBase + +#------------------------------------------------------------------------- +# +# HasEvent +# +#------------------------------------------------------------------------- +class HasEvent(HasEventBase): + """Rule that checks for a person with a particular value""" + + labels = [ _('Family event:'), + _('Date:'), + _('Place:'), + _('Description:') ] + name = _('Families with the ') + description = _("Matches families with an event of a particular value") + diff --git a/src/Filters/Rules/Family/__init__.py b/src/Filters/Rules/Family/__init__.py index 47a15ee27..c6c0d0aa3 100644 --- a/src/Filters/Rules/Family/__init__.py +++ b/src/Filters/Rules/Family/__init__.py @@ -32,6 +32,8 @@ from _HasIdOf import HasIdOf from _RegExpIdOf import RegExpIdOf from _HasNoteRegexp import HasNoteRegexp from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf +from _FamilyPrivate import FamilyPrivate +from _HasEvent import HasEvent editor_rule_list = [ AllFamilies, @@ -40,4 +42,6 @@ editor_rule_list = [ RegExpIdOf, HasNoteRegexp, HasNoteMatchingSubstringOf, + FamilyPrivate, + HasEvent, ] diff --git a/src/Filters/Rules/Makefile.am b/src/Filters/Rules/Makefile.am index f13366e09..6bd8f8edd 100644 --- a/src/Filters/Rules/Makefile.am +++ b/src/Filters/Rules/Makefile.am @@ -5,13 +5,18 @@ SUBDIRS = Person Family Event Place Source Media Repository pkgdatadir = $(datadir)/@PACKAGE@/Filters/Rules pkgdata_PYTHON = \ - _Everything.py \ - _HasTextMatchingRegexpOf.py \ - _HasTextMatchingSubstringOf.py \ - _IsPrivate.py \ - _Rule.py \ - _RuleUtils.py \ - __init__.py + _Everything.py\ + _HasEventBase.py\ + _HasGrampsId.py\ + _HasNoteRegexBase.py\ + _HasNoteSubstrBase.py\ + _HasTextMatchingRegexpOf.py\ + _HasTextMatchingSubstringOf.py\ + __init__.py\ + _IsPrivate.py\ + _RegExpIdBase.py\ + _Rule.py\ + _RuleUtils.py pkgpyexecdir = @pkgpyexecdir@/Filters/Rules pkgpythondir = @pkgpythondir@/Filters/Rules diff --git a/src/Filters/Rules/Person/_HasEvent.py b/src/Filters/Rules/Person/_HasEvent.py index 9aa279594..d238e6066 100644 --- a/src/Filters/Rules/Person/_HasEvent.py +++ b/src/Filters/Rules/Person/_HasEvent.py @@ -32,16 +32,14 @@ from gettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- -import DateHandler -from Filters.Rules._Rule import Rule -from Filters.Rules._RuleUtils import date_cmp +from Filters.Rules._HasEventBase import HasEventBase #------------------------------------------------------------------------- # # HasEvent # #------------------------------------------------------------------------- -class HasEvent(Rule): +class HasEvent(HasEventBase): """Rule that checks for a person with a particular value""" labels = [ _('Personal event:'), @@ -50,40 +48,4 @@ class HasEvent(Rule): _('Description:') ] name = _('People with the personal ') description = _("Matches people with a personal event of a particular value") - category = _('Event filters') - def prepare(self,db): - self.date = None - if self.list[0]: - self.etype = self.list[0] - else: - self.etype = None - try: - if self.list[1]: - self.date = DateHandler.parser.parse(self.list[1]) - except: pass - - def apply(self,db,person): - for event_ref in person.get_event_ref_list(): - if not event_ref: - continue - event = db.get_event_from_handle(event_ref.ref) - val = True - if self.etype and event.get_type() != self.etype: - val = False - if self.list[3] and event.get_description().upper().find( - self.list[3].upper())==-1: - val = False - if self.date: - if date_cmp(self.date,event.get_date_object()): - val = False - if self.list[2]: - pl_id = event.get_place_handle() - if pl_id: - pl = db.get_place_from_handle(pl_id) - pn = pl.get_title() - if pn.upper().find(self.list[2].upper()) == -1: - val = False - if val: - return True - return False diff --git a/src/Filters/Rules/_HasEventBase.py b/src/Filters/Rules/_HasEventBase.py new file mode 100644 index 000000000..0452d1255 --- /dev/null +++ b/src/Filters/Rules/_HasEventBase.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: _HasEvent.py 6635 2006-05-13 03:53:06Z dallingham $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +import DateHandler +from Filters.Rules._Rule import Rule +from Filters.Rules._RuleUtils import date_cmp + +#------------------------------------------------------------------------- +# +# HasEvent +# +#------------------------------------------------------------------------- +class HasEventBase(Rule): + """Rule that checks for a person with a particular value""" + + labels = [ _('Event:'), + _('Date:'), + _('Place:'), + _('Description:') ] + name = _('Objects with the ') + description = _("Matches objects with an event of a particular value") + category = _('Event filters') + + def prepare(self,db): + self.date = None + if self.list[0]: + self.etype = self.list[0] + else: + self.etype = None + try: + if self.list[1]: + self.date = DateHandler.parser.parse(self.list[1]) + except: pass + + def apply(self,db,person): + for event_ref in person.get_event_ref_list(): + if not event_ref: + continue + event = db.get_event_from_handle(event_ref.ref) + val = True + if self.etype and event.get_type() != self.etype: + val = False + if self.list[3] and event.get_description().upper().find( + self.list[3].upper())==-1: + val = False + if self.date: + if date_cmp(self.date,event.get_date_object()): + val = False + if self.list[2]: + pl_id = event.get_place_handle() + if pl_id: + pl = db.get_place_from_handle(pl_id) + pn = pl.get_title() + if pn.upper().find(self.list[2].upper()) == -1: + val = False + if val: + return True + return False diff --git a/src/Filters/Rules/_HasGrampsId.py b/src/Filters/Rules/_HasGrampsId.py index 1a44ee90a..b9f1ee3ce 100644 --- a/src/Filters/Rules/_HasGrampsId.py +++ b/src/Filters/Rules/_HasGrampsId.py @@ -46,3 +46,6 @@ class HasGrampsId(Rule): name = _('Object with ') description = _("Matches objects with a specified GRAMPS ID") category = _('General filters') + + def apply(self,db,obj): + return obj.gramps_id.find(self.list[0]) !=-1 diff --git a/src/Filters/_FamilySidebarFilter.py b/src/Filters/_FamilySidebarFilter.py index d858a1b1c..a5b28486d 100644 --- a/src/Filters/_FamilySidebarFilter.py +++ b/src/Filters/_FamilySidebarFilter.py @@ -26,8 +26,8 @@ import GrampsWidgets import RelLib from _SidebarFilter import SidebarFilter -import Filters.Rules from Filters import GenericFamilyFilter, build_filter_model, Rules +from Filters.Rules.Family import * class FamilySidebarFilter(SidebarFilter): @@ -61,7 +61,7 @@ class FamilySidebarFilter(SidebarFilter): all = GenericFamilyFilter() all.set_name(_("None")) - all.add_rule(Rules.Person.Everyone([])) + all.add_rule(Rules.Family.AllFamilies([])) self.generic = gtk.ComboBox() cell = gtk.CellRendererText() @@ -103,7 +103,7 @@ class FamilySidebarFilter(SidebarFilter): if regex: rule = RegExpIdOf([gid]) else: - rule = MatchIdOf([gid]) + rule = HasIdOf([gid]) generic_filter.add_rule(rule) etype = self.filter_event.get_type()