From 47d6700f60b284034e40c12a4d11cbffbfcd7f09 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Fri, 4 Aug 2006 21:59:57 +0000 Subject: [PATCH] * src/Filters/Rules/Person/_IsWitness.py: Rewrite with new API. debugging output; (_name2typeclass): Add name->type mapping. svn: r7123 --- ChangeLog | 5 ++- src/FilterEditor/_EditRule.py | 1 + src/Filters/Rules/Person/_IsWitness.py | 53 ++++++++------------------ 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4e9931c7c..93d7072fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ 2006-08-04 Alex Roitman + * src/Filters/Rules/Person/_IsWitness.py: Rewrite with new API. * src/FilterEditor/_FilterEditor.py (__init__): Remove unneeded argument, namespace is enough to get the filter class via factory; (add_new_filter): Use factory; (get_all_handles): Get handles for @@ -12,7 +13,9 @@ * src/Filters/_FamilySidebarFilter.py (GenericFamilyFilter): Use factory. * src/FilterEditor/_EditRule.py (MyID.name_from_gramps_id): Remove - debugginb output. + debugging output; + (_name2typeclass): Add name->type mapping. + * src/DataViews/_MediaView.py (row_change): Work around older pygtk. * src/Filters/Rules/Family/Makefile.am (pkgdata_PYTHON): Ship new files. diff --git a/src/FilterEditor/_EditRule.py b/src/FilterEditor/_EditRule.py index 5de47b2fa..cba7d429b 100644 --- a/src/FilterEditor/_EditRule.py +++ b/src/FilterEditor/_EditRule.py @@ -80,6 +80,7 @@ def by_rule_name(f,s): _name2typeclass = { _('Personal event:') : RelLib.EventType, _('Family event:') : RelLib.EventType, + _('Event type:') : RelLib.EventType, _('Personal attribute:') : RelLib.AttributeType, _('Family attribute:') : RelLib.AttributeType, _('Relationship type:') : RelLib.FamilyRelType, diff --git a/src/Filters/Rules/Person/_IsWitness.py b/src/Filters/Rules/Person/_IsWitness.py index 502cbc9cf..b8bd4128f 100644 --- a/src/Filters/Rules/Person/_IsWitness.py +++ b/src/Filters/Rules/Person/_IsWitness.py @@ -33,6 +33,7 @@ from gettext import gettext as _ # #------------------------------------------------------------------------- from Filters.Rules._Rule import Rule +from RelLib import EventRoleType, EventType #------------------------------------------------------------------------- # "Witnesses" @@ -40,45 +41,23 @@ from Filters.Rules._Rule import Rule class IsWitness(Rule): """Witnesses""" - labels = [_('Personal event:'), _('Family event:')] + labels = [_('Event type:')] name = _('Witnesses') description = _("Matches people who are witnesses in any event") category = _('Event filters') - def prepare(self,db): - self.db = db - self.map = [] - self.build_witness_list() - - def reset(self): - self.map = [] - def apply(self,db,person): - return person.handle in self.map - - def build_witness_list(self): - for person_handle in self.db.get_person_handles(): - p = self.db.get_person_from_handle(person_handle) - self.get_witness_of_events(self.list[0], - p.get_event_ref_list()+ - [p.get_birth_ref(), - p.get_death_ref()] - ) - - for family_handle in self.db.get_family_handles(): - f = self.db.get_family_from_handle(family_handle) - self.get_witness_of_events(self.list[1],f.get_event_ref_list()) - - def get_witness_of_events(self, event_type, event_list): - if not event_list: - return - for event_ref in event_list: - if event_ref: - event = self.db.get_event_from_handle(event_ref.ref) - if event_type and not event.get_name() == event_type: - continue - wlist = event.get_witness_list() - if wlist: - for w in wlist: - if w.get_type() == 1: - self.map.append(w.get_value()) + for event_ref in person.event_ref_list: + if event_ref.role == EventRoleType.WITNESS: + # This is the witness. + # If event type was given, then check it. + if self.list[0]: + event = db.get_event_from_handle(event_ref.ref) + specified_type = EventType() + specified_type.set_from_xml_str(self.list[0]) + if event.type == specified_type: + return True + else: + # event type was not specified, we're returning a match + return True + return False