|
| 1 | +# |
| 2 | +# Gramps - a GTK+/GNOME based genealogy program |
| 3 | +# |
| 4 | +# Copyright (C) 2018 Paul Culley |
| 5 | +# |
| 6 | +# This program is free software; you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation; either version 2 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with this program; if not, write to the Free Software |
| 18 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | +# |
| 20 | + |
| 21 | +""" |
| 22 | +Filter rule to match persons with a particular event. |
| 23 | +""" |
| 24 | +#------------------------------------------------------------------------- |
| 25 | +# |
| 26 | +# Standard Python modules |
| 27 | +# |
| 28 | +#------------------------------------------------------------------------- |
| 29 | +from gramps.gen.const import GRAMPS_LOCALE as glocale |
| 30 | +_ = glocale.translation.gettext |
| 31 | + |
| 32 | +#------------------------------------------------------------------------- |
| 33 | +# |
| 34 | +# Gramps modules |
| 35 | +# |
| 36 | +#------------------------------------------------------------------------- |
| 37 | +from gramps.gen.lib.eventroletype import EventRoleType |
| 38 | +from gramps.gui.editors.filtereditor import MySelect, MyBoolean |
| 39 | +from gramps.gen.filters.rules import Rule |
| 40 | + |
| 41 | + |
| 42 | +class Roletype(MySelect): |
| 43 | + """ Provide a Role type selector """ |
| 44 | + def __init__(self, db): |
| 45 | + MySelect.__init__(self, EventRoleType, db.get_event_roles()) |
| 46 | + |
| 47 | + |
| 48 | +class NoMatch(MyBoolean): |
| 49 | + """ Provide a negation switch """ |
| 50 | + def __init__(self, db): |
| 51 | + MyBoolean.__init__(self, _("Does NOT match with selected Role")) |
| 52 | + self.set_tooltip_text(_("Finds the items that don't have event Roles " |
| 53 | + "of the selected type.")) |
| 54 | +#------------------------------------------------------------------------- |
| 55 | +# |
| 56 | +# HasEvent |
| 57 | +# |
| 58 | +#------------------------------------------------------------------------- |
| 59 | +class HasPersonEventRole(Rule): |
| 60 | + """Rule that checks for a person with a selected event role""" |
| 61 | + |
| 62 | + labels = [(_('Role'), Roletype), |
| 63 | + (_('Inverse'), NoMatch)] |
| 64 | + name = _('People with events with a selected role') |
| 65 | + description = _("Matches people with an event with a selected role") |
| 66 | + category = _('Event filters') |
| 67 | + |
| 68 | + def apply(self, dbase, person): |
| 69 | + if not self.list[0]: |
| 70 | + return False |
| 71 | + for event_ref in person.get_event_ref_list(): |
| 72 | + if not event_ref: |
| 73 | + continue |
| 74 | + if self.list[1] == '1': |
| 75 | + if event_ref.role.xml_str() != self.list[0]: |
| 76 | + return True |
| 77 | + else: |
| 78 | + if event_ref.role.xml_str() == self.list[0]: |
| 79 | + return True |
| 80 | + return False |
| 81 | + |
| 82 | + |
| 83 | +class HasFamilyEventRole(Rule): |
| 84 | + """Rule that checks for a family with a selected event role""" |
| 85 | + |
| 86 | + labels = [(_('Role'), Roletype), |
| 87 | + (_('Inverse'), NoMatch)] |
| 88 | + name = _('Families with events with a selected role') |
| 89 | + description = _("Matches families with an event with a selected role") |
| 90 | + category = _('Event filters') |
| 91 | + |
| 92 | + def apply(self, dbase, family): |
| 93 | + if not self.list[0]: |
| 94 | + return False |
| 95 | + for event_ref in family.get_event_ref_list(): |
| 96 | + if not event_ref: |
| 97 | + continue |
| 98 | + if self.list[1] == '1': |
| 99 | + if event_ref.role.xml_str() != self.list[0]: |
| 100 | + return True |
| 101 | + else: |
| 102 | + if event_ref.role.xml_str() == self.list[0]: |
| 103 | + return True |
| 104 | + return False |
0 commit comments