3105: general base objects

svn: r14093
This commit is contained in:
Jérôme Rapinat 2010-01-18 14:57:54 +00:00
parent c207134fe4
commit d9ad7798bc
6 changed files with 152 additions and 34 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <event filter>')
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

View File

@ -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 <source filter>')
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

View File

@ -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,