From e7dc7a91255500e46870bbfdda9e4a9047ae3154 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Sat, 5 Aug 2006 04:05:05 +0000 Subject: [PATCH] * src/DataViews/_EventView.py: Add sidebar filter. * src/FilterEditor/_FilterEditor.py: Support event filters. * src/Filters/__init__.py: expose new module. * src/Filters/_PersonSidebarFilter.py: Fix type handling. * src/Filters/_FamilySidebarFilter.py: Fix type handling. * src/Filters/_GenericFilter.py: Support event filters. * src/Filters/_EventSidebarFilter.py: add new module. * src/Filters/Rules/Events/*.py: add new rules. * src/Filters/Rules/Family/_HasRelType.py (apply): Use new API. svn: r7127 --- ChangeLog | 9 ++ src/DataViews/_EventView.py | 33 ++++- src/FilterEditor/_FilterEditor.py | 2 + src/Filters/Rules/Event/_AllEvents.py | 46 ++++++ src/Filters/Rules/Event/_EventPrivate.py | 44 ++++++ src/Filters/Rules/Event/_HasIdOf.py | 47 ++++++ .../Event/_HasNoteMatchingSubstringOf.py | 46 ++++++ src/Filters/Rules/Event/_HasNoteRegexp.py | 45 ++++++ src/Filters/Rules/Event/_HasType.py | 57 +++++++ src/Filters/Rules/Event/_MatchesFilter.py | 47 ++++++ src/Filters/Rules/Event/_RegExpIdOf.py | 50 +++++++ src/Filters/Rules/Event/__init__.py | 20 +++ src/Filters/Rules/Family/_HasRelType.py | 7 +- src/Filters/_EventSidebarFilter.py | 139 ++++++++++++++++++ src/Filters/_FamilySidebarFilter.py | 4 +- src/Filters/_GenericFilter.py | 16 ++ src/Filters/_PersonSidebarFilter.py | 4 +- src/Filters/__init__.py | 1 + 18 files changed, 608 insertions(+), 9 deletions(-) create mode 100644 src/Filters/Rules/Event/_AllEvents.py create mode 100644 src/Filters/Rules/Event/_EventPrivate.py create mode 100644 src/Filters/Rules/Event/_HasIdOf.py create mode 100644 src/Filters/Rules/Event/_HasNoteMatchingSubstringOf.py create mode 100644 src/Filters/Rules/Event/_HasNoteRegexp.py create mode 100644 src/Filters/Rules/Event/_HasType.py create mode 100644 src/Filters/Rules/Event/_MatchesFilter.py create mode 100644 src/Filters/Rules/Event/_RegExpIdOf.py create mode 100644 src/Filters/_EventSidebarFilter.py diff --git a/ChangeLog b/ChangeLog index 52ebe4d91..cb879b0c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,13 @@ 2006-08-04 Alex Roitman + * src/DataViews/_EventView.py: Add sidebar filter. + * src/FilterEditor/_FilterEditor.py: Support event filters. + * src/Filters/__init__.py: expose new module. + * src/Filters/_PersonSidebarFilter.py: Fix type handling. + * src/Filters/_FamilySidebarFilter.py: Fix type handling. + * src/Filters/_GenericFilter.py: Support event filters. + * src/Filters/_EventSidebarFilter.py: add new module. + * src/Filters/Rules/Events/*.py: add new rules. + * src/Filters/Rules/Family/_HasRelType.py (apply): Use new API. * src/FilterEditor/_EditFilter.py: Support invert attribute. * src/Filters/_GenericFilter.py: Support invert attribute. * src/Filters/_FilterList.py (save): Save invert attribute. diff --git a/src/DataViews/_EventView.py b/src/DataViews/_EventView.py index 507f1baa5..a47a66c84 100644 --- a/src/DataViews/_EventView.py +++ b/src/DataViews/_EventView.py @@ -37,11 +37,12 @@ import DisplayModels import Utils import Errors import Bookmarks - +import Config +import const from DdTargets import DdTargets from QuestionDialog import QuestionDialog from Editors import EditEvent, DelEventQuery - +from Filters import EventSidebarFilter #------------------------------------------------------------------------- # # internationalization @@ -83,7 +84,10 @@ class EventView(PageView.ListView): self, _('Events'), dbstate, uistate, column_names, len(column_names), DisplayModels.EventModel, signal_map, dbstate.db.get_event_bookmarks(), - Bookmarks.EventBookmarks) + Bookmarks.EventBookmarks, filter_class=EventSidebarFilter) + + Config.client.notify_add("/apps/gramps/interface/filter", + self.filter_toggle) def get_bookmarks(self): return self.dbstate.db.get_event_bookmarks() @@ -113,6 +117,7 @@ class EventView(PageView.ListView): + @@ -134,6 +139,28 @@ class EventView(PageView.ListView): self.add_action('ColumnEdit', gtk.STOCK_PROPERTIES, _('_Column Editor'), callback=self.column_editor) + self.add_action('FilterEdit', None, _('Event Filter Editor'), + callback=self.filter_editor,) + + def filter_toggle(self, client, cnxn_id, etnry, data): + if Config.get(Config.FILTER): + self.search_bar.hide() + self.filter_pane.show() + active = True + else: + self.search_bar.show() + self.filter_pane.hide() + active = False + + def filter_editor(self,obj): + from FilterEditor import FilterEditor + + try: + FilterEditor('Event',const.custom_filters, + self.dbstate,self.uistate) + except Errors.WindowActiveError: + pass + def column_editor(self,obj): import ColumnOrder diff --git a/src/FilterEditor/_FilterEditor.py b/src/FilterEditor/_FilterEditor.py index 1702fbdce..a69b71a42 100644 --- a/src/FilterEditor/_FilterEditor.py +++ b/src/FilterEditor/_FilterEditor.py @@ -172,3 +172,5 @@ class FilterEditor(ManagedWindow.ManagedWindow): return self.db.get_person_handles(sort_handles=False) elif self.space == 'Family': return self.db.get_family_handles() + elif self.space == 'Event': + return self.db.get_event_handles() diff --git a/src/Filters/Rules/Event/_AllEvents.py b/src/Filters/Rules/Event/_AllEvents.py new file mode 100644 index 000000000..c2aa15507 --- /dev/null +++ b/src/Filters/Rules/Event/_AllEvents.py @@ -0,0 +1,46 @@ +# +# 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$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._Everything import Everything + +#------------------------------------------------------------------------- +# +# Everyone +# +#------------------------------------------------------------------------- +class AllEvents(Everything): + """Matches Everyone""" + + name = _('Every event') + description = _('Matches every event in the database') diff --git a/src/Filters/Rules/Event/_EventPrivate.py b/src/Filters/Rules/Event/_EventPrivate.py new file mode 100644 index 000000000..da8d1481c --- /dev/null +++ b/src/Filters/Rules/Event/_EventPrivate.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$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._IsPrivate import IsPrivate + +#------------------------------------------------------------------------- +# "Family marked private" +#------------------------------------------------------------------------- +class EventPrivate(IsPrivate): + """Event marked private""" + + name = _('Events marked private') + description = _("Matches events that are indicated as private") diff --git a/src/Filters/Rules/Event/_HasIdOf.py b/src/Filters/Rules/Event/_HasIdOf.py new file mode 100644 index 000000000..a0d9c59f3 --- /dev/null +++ b/src/Filters/Rules/Event/_HasIdOf.py @@ -0,0 +1,47 @@ +# +# 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$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules import HasGrampsId + +#------------------------------------------------------------------------- +# +# HasIdOf +# +#------------------------------------------------------------------------- +class HasIdOf(HasGrampsId): + """Rule that checks for a family with a specific GRAMPS ID""" + + labels = [ _('Event ID:') ] + name = _('Event with ') + description = _("Matches an event with a specified GRAMPS ID") diff --git a/src/Filters/Rules/Event/_HasNoteMatchingSubstringOf.py b/src/Filters/Rules/Event/_HasNoteMatchingSubstringOf.py new file mode 100644 index 000000000..c6040fcf6 --- /dev/null +++ b/src/Filters/Rules/Event/_HasNoteMatchingSubstringOf.py @@ -0,0 +1,46 @@ +# +# 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$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasNoteSubstrBase import HasNoteSubstrBase + +#------------------------------------------------------------------------- +# "Events having notes that contain a substring" +#------------------------------------------------------------------------- +class HasNoteMatchingSubstringOf(HasNoteSubstrBase): + """People having notes containing """ + + name = _('Events having notes containing ') + description = _("Matches events whose notes contain text " + "matching a substring") + diff --git a/src/Filters/Rules/Event/_HasNoteRegexp.py b/src/Filters/Rules/Event/_HasNoteRegexp.py new file mode 100644 index 000000000..eb4d8bef0 --- /dev/null +++ b/src/Filters/Rules/Event/_HasNoteRegexp.py @@ -0,0 +1,45 @@ +# +# 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$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +import re +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase + +#------------------------------------------------------------------------- +# "Events having notes that contain a substring" +#------------------------------------------------------------------------- +class HasNoteRegexp(HasNoteRegexBase): + + name = _('Events having notes containing ') + description = _("Matches events whose notes contain text " + "matching a regular expression") diff --git a/src/Filters/Rules/Event/_HasType.py b/src/Filters/Rules/Event/_HasType.py new file mode 100644 index 000000000..bfe846c19 --- /dev/null +++ b/src/Filters/Rules/Event/_HasType.py @@ -0,0 +1,57 @@ +# +# 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$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from RelLib import EventType +from Filters.Rules._Rule import Rule + +#------------------------------------------------------------------------- +# +# HasType +# +#------------------------------------------------------------------------- +class HasType(Rule): + """Rule that checks for an event of a particular type""" + + labels = [ _('Event type:') ] + name = _('Event with the particular type') + description = _("Matches event with the particular type ") + category = _('General filters') + + def apply(self, db, event): + if not self.list[0]: + return False + else: + specified_type = EventType() + specified_type.set_from_xml_str(self.list[0]) + return event.get_type() == specified_type diff --git a/src/Filters/Rules/Event/_MatchesFilter.py b/src/Filters/Rules/Event/_MatchesFilter.py new file mode 100644 index 000000000..674a995a3 --- /dev/null +++ b/src/Filters/Rules/Event/_MatchesFilter.py @@ -0,0 +1,47 @@ +# +# 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$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._MatchesFilterBase import MatchesFilterBase + +#------------------------------------------------------------------------- +# +# MatchesFilter +# +#------------------------------------------------------------------------- +class MatchesFilter(MatchesFilterBase): + """Rule that checks against another filter""" + + name = _('Events matching the ') + description = _("Matches events macthed by the specified filter name") + namespace = 'Event' diff --git a/src/Filters/Rules/Event/_RegExpIdOf.py b/src/Filters/Rules/Event/_RegExpIdOf.py new file mode 100644 index 000000000..4ba14529c --- /dev/null +++ b/src/Filters/Rules/Event/_RegExpIdOf.py @@ -0,0 +1,50 @@ +# +# 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$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._RegExpIdBase import RegExpIdBase + +#------------------------------------------------------------------------- +# +# HasIdOf +# +#------------------------------------------------------------------------- +class RegExpIdOf(RegExpIdBase): + """ + Rule that checks for an event whose GRAMPS ID + matches regular expression. + """ + + name = _('Events with matching regular expression') + description = _("Matches events whose GRAMPS ID matches " + "the regular expression") diff --git a/src/Filters/Rules/Event/__init__.py b/src/Filters/Rules/Event/__init__.py index b73e6d238..148e1b4af 100644 --- a/src/Filters/Rules/Event/__init__.py +++ b/src/Filters/Rules/Event/__init__.py @@ -25,3 +25,23 @@ Package providing filter rules for GRAMPS. """ __author__ = "Don Allingham" + +from _HasType import HasType +from _AllEvents import AllEvents +from _HasIdOf import HasIdOf +from _RegExpIdOf import RegExpIdOf +from _HasNoteRegexp import HasNoteRegexp +from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf +from _EventPrivate import EventPrivate +from _MatchesFilter import MatchesFilter + +editor_rule_list = [ + AllEvents, + HasType, + HasIdOf, + RegExpIdOf, + HasNoteRegexp, + HasNoteMatchingSubstringOf, + EventPrivate, + MatchesFilter, +] diff --git a/src/Filters/Rules/Family/_HasRelType.py b/src/Filters/Rules/Family/_HasRelType.py index f09a8e9e3..3ffcc9801 100644 --- a/src/Filters/Rules/Family/_HasRelType.py +++ b/src/Filters/Rules/Family/_HasRelType.py @@ -32,6 +32,7 @@ from gettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------- +from RelLib import FamilyRelType from Filters.Rules._Rule import Rule #------------------------------------------------------------------------- @@ -48,8 +49,10 @@ class HasRelType(Rule): "of a particular value") category = _('General filters') - def apply(self, db, obj): + def apply(self, db, family): if not self.list[0]: return False else: - return obj.get_relationship() == self.list[0] + specified_type = FamilyRelType() + specified_type.set_from_xml_str(self.list[0]) + return family.get_relationship() == specified_type diff --git a/src/Filters/_EventSidebarFilter.py b/src/Filters/_EventSidebarFilter.py new file mode 100644 index 000000000..0d99e8e35 --- /dev/null +++ b/src/Filters/_EventSidebarFilter.py @@ -0,0 +1,139 @@ +# +# 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$ + +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# gtk +# +#------------------------------------------------------------------------- +import gtk + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +import GrampsWidgets +import RelLib + +from _SidebarFilter import SidebarFilter +from Filters import GenericFilterFactory, build_filter_model, Rules +from Filters.Rules.Event import * + +GenericEventFilter = GenericFilterFactory('Event') +#------------------------------------------------------------------------- +# +# PersonSidebarFilter class +# +#------------------------------------------------------------------------- +class EventSidebarFilter(SidebarFilter): + + def __init__(self, clicked): + SidebarFilter.__init__(self) + self.clicked_func = clicked + + def create_widget(self): + self.filter_id = gtk.Entry() + self.filter_event = RelLib.Event() + self.filter_event.set_type((RelLib.EventType.CUSTOM,'')) + self.etype = gtk.ComboBoxEntry() + + self.event_menu = GrampsWidgets.MonitoredDataType( + self.etype, + self.filter_event.set_type, + self.filter_event.get_type) + + self.filter_note = gtk.Entry() + + self.filter_regex = gtk.CheckButton(_('Use regular expressions')) + + all = GenericEventFilter() + all.set_name(_("None")) + all.add_rule(Rules.Event.AllEvents([])) + + self.generic = gtk.ComboBox() + cell = gtk.CellRendererText() + self.generic.pack_start(cell, True) + self.generic.add_attribute(cell, 'text', 0) + self.generic.set_model(build_filter_model('Event', [all])) + self.generic.set_active(0) + + self.add_text_entry(_('ID'), self.filter_id) + self.add_entry(_('Type'), self.etype) + self.add_text_entry(_('Note'), self.filter_note) + self.add_entry(_('Custom filter'), self.generic) + self.add_entry(None, self.filter_regex) + + def clear(self, obj): + self.filter_id.set_text('') + self.filter_note.set_text('') + self.etype.child.set_text('') + self.generic.set_active(0) + + def clicked(self, obj): + self.clicked_func() + + def get_filter(self): + gid = unicode(self.filter_id.get_text()).strip() + note = unicode(self.filter_note.get_text()).strip() + regex = self.filter_regex.get_active() + gen = self.generic.get_active() > 0 + + if not gid and not str(self.filter_event.get_type()) \ + and not note and not gen: + generic_filter = None + else: + generic_filter = GenericEventFilter() + if gid: + if regex: + rule = RegExpIdOf([gid]) + else: + rule = HasIdOf([gid]) + generic_filter.add_rule(rule) + + etype = self.filter_event.get_type().xml_str() + if str(etype): + rule = HasType([etype]) + generic_filter.add_rule(rule) + + if note: + if regex: + rule = HasNoteRegexp([note]) + else: + rule = HasNoteMatchingSubstringOf([note]) + generic_filter.add_rule(rule) + + if self.generic.get_active() != 0: + model = self.generic.get_model() + iter = self.generic.get_active_iter() + obj = model.get_value(iter, 0) + rule = MatchesFilter([obj]) + generic_filter.add_rule(rule) + + return generic_filter diff --git a/src/Filters/_FamilySidebarFilter.py b/src/Filters/_FamilySidebarFilter.py index 409fabc80..b67a93f2d 100644 --- a/src/Filters/_FamilySidebarFilter.py +++ b/src/Filters/_FamilySidebarFilter.py @@ -116,7 +116,7 @@ class FamilySidebarFilter(SidebarFilter): regex = self.filter_regex.get_active() gen = self.generic.get_active() > 0 - if not gid and not str(self.filter_event.get_type()) and \ + if not gid and not self.filter_event.get_type().xml_str() and \ not str(self.family_stub.get_relationship()) and not note \ and not gen: generic_filter = None @@ -129,7 +129,7 @@ class FamilySidebarFilter(SidebarFilter): rule = HasIdOf([gid]) generic_filter.add_rule(rule) - etype = self.filter_event.get_type() + etype = self.filter_event.get_type().xml_str() if str(etype): rule = HasEvent([etype, '', '', '']) generic_filter.add_rule(rule) diff --git a/src/Filters/_GenericFilter.py b/src/Filters/_GenericFilter.py index 99d730819..7300bdc21 100644 --- a/src/Filters/_GenericFilter.py +++ b/src/Filters/_GenericFilter.py @@ -219,8 +219,24 @@ class GenericFamilyFilter(GenericFilter): return db.get_family_from_handle(handle) +class GenericEventFilter(GenericFilter): + + def __init__(self, source=None): + GenericFilter.__init__(self, source) + + def get_cursor(db, self): + return db.get_event_cursor() + + def make_obj(self): + return RelLib.Event() + + def find_from_handle(self, db, handle): + return db.get_event_from_handle(handle) + def GenericFilterFactory(namespace): if namespace == 'Person': return GenericFilter elif namespace == 'Family': return GenericFamilyFilter + elif namespace == 'Event': + return GenericEventFilter diff --git a/src/Filters/_PersonSidebarFilter.py b/src/Filters/_PersonSidebarFilter.py index 935c37aa5..1ad2fac43 100644 --- a/src/Filters/_PersonSidebarFilter.py +++ b/src/Filters/_PersonSidebarFilter.py @@ -124,7 +124,7 @@ class PersonSidebarFilter(SidebarFilter): gen = self.generic.get_active() > 0 if not name and not gid and not birth and not death \ - and not str(self.filter_event.get_type()) and \ + and not self.filter_event.get_type().xml_str() and \ not note and not gender > 0 and not gen: generic_filter = None else: @@ -149,7 +149,7 @@ class PersonSidebarFilter(SidebarFilter): else: generic_filter.add_rule(HasUnknownGender([])) - etype = self.filter_event.get_type() + etype = self.filter_event.get_type().xml_str() if str(etype): rule = HasEvent([etype, '', '', '']) generic_filter.add_rule(rule) diff --git a/src/Filters/__init__.py b/src/Filters/__init__.py index e5849b942..14a30575c 100644 --- a/src/Filters/__init__.py +++ b/src/Filters/__init__.py @@ -58,3 +58,4 @@ from _SearchFilter import SearchFilter from _SidebarFilter import SidebarFilter from _PersonSidebarFilter import PersonSidebarFilter from _FamilySidebarFilter import FamilySidebarFilter +from _EventSidebarFilter import EventSidebarFilter