From 609bfbc9eb1144aeb6f3ecd09e6cf5731ec6f980 Mon Sep 17 00:00:00 2001 From: Martin Hawlisch Date: Sat, 24 Feb 2007 19:16:50 +0000 Subject: [PATCH] * src/Filters/_GenericFilter.py: Add GenericNoteFilter * src/Filters/Rules/Makefile.am: Add new Note subfolder * src/Filters/Rules/Note/*: Added new files * src/Filters/SideBar/_NoteSidebarFilter.py: New file * src/Filters/SideBar/Makefile.am: Add NoteSidebarFilter * src/Filters/SideBar/__init__.py: Add NoteSidebarFilter * src/DataViews/_NoteView.py: Enable NoteSidebarFilter * po/POTFILES.in: Add the new files * configure.in: Add new subfolder svn: r8226 --- ChangeLog | 11 ++ configure.in | 1 + po/POTFILES.in | 12 ++ src/DataViews/_NoteView.py | 5 +- src/Filters/Rules/Makefile.am | 2 +- src/Filters/Rules/Note/Makefile.am | 26 ++++ src/Filters/Rules/Note/_AllNotes.py | 46 ++++++ src/Filters/Rules/Note/_HasIdOf.py | 46 ++++++ src/Filters/Rules/Note/_HasNote.py | 64 +++++++++ .../Rules/Note/_HasNoteMatchingSubstringOf.py | 45 ++++++ src/Filters/Rules/Note/_HasNoteRegexp.py | 45 ++++++ src/Filters/Rules/Note/_MatchesFilter.py | 48 +++++++ src/Filters/Rules/Note/_NotePrivate.py | 44 ++++++ src/Filters/Rules/Note/_RegExpIdOf.py | 50 +++++++ src/Filters/Rules/Note/__init__.py | 46 ++++++ src/Filters/SideBar/Makefile.am | 3 +- src/Filters/SideBar/_NoteSidebarFilter.py | 131 ++++++++++++++++++ src/Filters/SideBar/__init__.py | 1 + src/Filters/_GenericFilter.py | 16 +++ 19 files changed, 638 insertions(+), 4 deletions(-) create mode 100644 src/Filters/Rules/Note/Makefile.am create mode 100644 src/Filters/Rules/Note/_AllNotes.py create mode 100644 src/Filters/Rules/Note/_HasIdOf.py create mode 100644 src/Filters/Rules/Note/_HasNote.py create mode 100644 src/Filters/Rules/Note/_HasNoteMatchingSubstringOf.py create mode 100644 src/Filters/Rules/Note/_HasNoteRegexp.py create mode 100644 src/Filters/Rules/Note/_MatchesFilter.py create mode 100644 src/Filters/Rules/Note/_NotePrivate.py create mode 100644 src/Filters/Rules/Note/_RegExpIdOf.py create mode 100644 src/Filters/Rules/Note/__init__.py create mode 100644 src/Filters/SideBar/_NoteSidebarFilter.py diff --git a/ChangeLog b/ChangeLog index 75c87bb78..46b5b0bed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-02-24 Martin Hawlisch + * src/Filters/_GenericFilter.py: Add GenericNoteFilter + * src/Filters/Rules/Makefile.am: Add new Note subfolder + * src/Filters/Rules/Note/*: Added new files + * src/Filters/SideBar/_NoteSidebarFilter.py: New file + * src/Filters/SideBar/Makefile.am: Add NoteSidebarFilter + * src/Filters/SideBar/__init__.py: Add NoteSidebarFilter + * src/DataViews/_NoteView.py: Enable NoteSidebarFilter + * po/POTFILES.in: Add the new files + * configure.in: Add new subfolder + 2007-02-23 Don Allingham * src/GrampsDbUtils./_GedcomParse.py: enhanced parsing based off testcases * src/GrampsDbUtils./_GedcomTokens.py: enhanced parsing based off testcases diff --git a/configure.in b/configure.in index 97f16e5de..94b136770 100644 --- a/configure.in +++ b/configure.in @@ -220,6 +220,7 @@ src/Filters/Rules/Source/Makefile src/Filters/Rules/Place/Makefile src/Filters/Rules/MediaObject/Makefile src/Filters/Rules/Repository/Makefile +src/Filters/Rules/Note/Makefile src/Filters/SideBar/Makefile src/DataViews/Makefile src/BasicUtils/Makefile diff --git a/po/POTFILES.in b/po/POTFILES.in index 609029f86..0def134c9 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -582,6 +582,17 @@ src/Filters/Rules/Repository/_RegExpIdOf.py src/Filters/Rules/Repository/_RepoPrivate.py src/Filters/Rules/Repository/__init__.py +# Filters.Rules.Note package +src/Filters/Rules/Note/_AllNotes.py +src/Filters/Rules/Note/_HasIdOf.py +src/Filters/Rules/Note/_HasNoteMatchingSubstringOf.py +src/Filters/Rules/Note/_HasNoteRegexp.py +src/Filters/Rules/Note/_HasNote.py +src/Filters/Rules/Note/_MatchesFilter.py +src/Filters/Rules/Note/_RegExpIdOf.py +src/Filters/Rules/Note/_NotePrivate.py +src/Filters/Rules/Note/__init__.py + # Filters.SideBar package src/Filters/SideBar/_EventSidebarFilter.py src/Filters/SideBar/_FamilySidebarFilter.py @@ -591,6 +602,7 @@ src/Filters/SideBar/_SourceSidebarFilter.py src/Filters/SideBar/_PlaceSidebarFilter.py src/Filters/SideBar/_MediaSidebarFilter.py src/Filters/SideBar/_RepoSidebarFilter.py +src/Filters/SideBar/_NoteSidebarFilter.py # FilterEditor package src/FilterEditor/_FilterEditor.py diff --git a/src/DataViews/_NoteView.py b/src/DataViews/_NoteView.py index 59e101da1..456458454 100644 --- a/src/DataViews/_NoteView.py +++ b/src/DataViews/_NoteView.py @@ -47,7 +47,7 @@ import Bookmarks import Config from DdTargets import DdTargets from QuestionDialog import QuestionDialog, ErrorDialog -from Filters.SideBar import PlaceSidebarFilter +from Filters.SideBar import NoteSidebarFilter #------------------------------------------------------------------------- # @@ -92,7 +92,8 @@ class NoteView(PageView.ListView): self, _('Notes'), dbstate, uistate, column_names, len(column_names), DisplayModels.NoteModel, signal_map, dbstate.db.get_place_bookmarks(), - Bookmarks.NoteBookmarks, + Bookmarks.NoteBookmarks, + filter_class=NoteSidebarFilter, multiple=False) Config.client.notify_add("/apps/gramps/interface/filter", diff --git a/src/Filters/Rules/Makefile.am b/src/Filters/Rules/Makefile.am index d4f495ee2..ca5d5a484 100644 --- a/src/Filters/Rules/Makefile.am +++ b/src/Filters/Rules/Makefile.am @@ -1,6 +1,6 @@ # This is the src/Filters/Rules level Makefile for Gramps -SUBDIRS = Person Family Event Place Source MediaObject Repository +SUBDIRS = Person Family Event Place Source MediaObject Repository Note pkgdatadir = $(datadir)/@PACKAGE@/Filters/Rules diff --git a/src/Filters/Rules/Note/Makefile.am b/src/Filters/Rules/Note/Makefile.am new file mode 100644 index 000000000..b986888cd --- /dev/null +++ b/src/Filters/Rules/Note/Makefile.am @@ -0,0 +1,26 @@ +# This is the src/Filters/Rules/Note level Makefile for Gramps + +pkgdatadir = $(datadir)/@PACKAGE@/Filters/Rules/Note + +pkgdata_PYTHON = \ + _AllNotes.py\ + _HasIdOf.py\ + _HasNoteMatchingSubstringOf.py\ + _HasNoteRegexp.py\ + _HasNote.py\ + _MatchesFilter.py\ + _RegExpIdOf.py\ + _NotePrivate.py\ + __init__.py + +pkgpyexecdir = @pkgpyexecdir@/Filters/Rules/Note +pkgpythondir = @pkgpythondir@/Filters/Rules/Note + +# Clean up all the byte-compiled files +MOSTLYCLEANFILES = *pyc *pyo + +GRAMPS_PY_MODPATH = "../../../" + +pycheck: + (export PYTHONPATH=$(GRAMPS_PY_MODPATH); \ + pychecker $(pkgdata_PYTHON)); diff --git a/src/Filters/Rules/Note/_AllNotes.py b/src/Filters/Rules/Note/_AllNotes.py new file mode 100644 index 000000000..263442d55 --- /dev/null +++ b/src/Filters/Rules/Note/_AllNotes.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: _AllRepos.py 7144 2006-08-07 20:16:00Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._Everything import Everything + +#------------------------------------------------------------------------- +# +# Everyone +# +#------------------------------------------------------------------------- +class AllNotes(Everything): + """Matches every note""" + + name = _('Every note') + description = _('Matches every note in the database') diff --git a/src/Filters/Rules/Note/_HasIdOf.py b/src/Filters/Rules/Note/_HasIdOf.py new file mode 100644 index 000000000..dc57d3f1a --- /dev/null +++ b/src/Filters/Rules/Note/_HasIdOf.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: _HasIdOf.py 7144 2006-08-07 20:16:00Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules import HasGrampsId + +#------------------------------------------------------------------------- +# +# HasIdOf +# +#------------------------------------------------------------------------- +class HasIdOf(HasGrampsId): + """Rule that checks for a note with a specific GRAMPS ID""" + + name = _('Note with ') + description = _("Matches a note with a specified GRAMPS ID") diff --git a/src/Filters/Rules/Note/_HasNote.py b/src/Filters/Rules/Note/_HasNote.py new file mode 100644 index 000000000..e7651e15f --- /dev/null +++ b/src/Filters/Rules/Note/_HasNote.py @@ -0,0 +1,64 @@ +# +# 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: _HasRepo.py 7737 2006-11-30 20:30:28Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from RelLib import NoteType +from Filters.Rules._Rule import Rule + +#------------------------------------------------------------------------- +# +# HasEvent +# +#------------------------------------------------------------------------- +class HasNote(Rule): + """Rule that checks for a note with a particular value""" + + + labels = [ _('Text:'), + _('Type:'), + ] + name = _('Notes matching parameters') + description = _("Matches Notes with particular parameters") + category = _('General filters') + + def apply(self,db,note): + if not self.match_substring(0,note.get()): + return False + + if self.list[1]: + specified_type = NoteType() + specified_type.set_from_xml_str(self.list[1]) + if note.type != specified_type: + return False + + return True diff --git a/src/Filters/Rules/Note/_HasNoteMatchingSubstringOf.py b/src/Filters/Rules/Note/_HasNoteMatchingSubstringOf.py new file mode 100644 index 000000000..f9436b098 --- /dev/null +++ b/src/Filters/Rules/Note/_HasNoteMatchingSubstringOf.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: _HasNoteMatchingSubstringOf.py 7144 2006-08-07 20:16:00Z rshura $ + +#------------------------------------------------------------------------- +# +# 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): + """Notes having notes containing """ + + name = _('Notes having notes containing ') + description = _("Matches notes whose notes contain text " + "matching a substring") diff --git a/src/Filters/Rules/Note/_HasNoteRegexp.py b/src/Filters/Rules/Note/_HasNoteRegexp.py new file mode 100644 index 000000000..c01e8044c --- /dev/null +++ b/src/Filters/Rules/Note/_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: _HasNoteRegexp.py 7144 2006-08-07 20:16:00Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase + +#------------------------------------------------------------------------- +# "Repos having notes that contain a substring" +#------------------------------------------------------------------------- +class HasNoteRegexp(HasNoteRegexBase): + + name = _('Notes having notes ' + 'containing ') + description = _("Matches notes whose notes contain text " + "matching a regular expression") diff --git a/src/Filters/Rules/Note/_MatchesFilter.py b/src/Filters/Rules/Note/_MatchesFilter.py new file mode 100644 index 000000000..e2ad82e5d --- /dev/null +++ b/src/Filters/Rules/Note/_MatchesFilter.py @@ -0,0 +1,48 @@ +# +# 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: _MatchesFilter.py 7686 2006-11-24 23:14:25Z romjerome $ + +#------------------------------------------------------------------------- +# +# 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 = _('Notes matching the ') + description = _("Matches notes matched " + "by the specified filter name") + namespace = 'Note' diff --git a/src/Filters/Rules/Note/_NotePrivate.py b/src/Filters/Rules/Note/_NotePrivate.py new file mode 100644 index 000000000..d1eff9aac --- /dev/null +++ b/src/Filters/Rules/Note/_NotePrivate.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: _RepoPrivate.py 7144 2006-08-07 20:16:00Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._IsPrivate import IsPrivate + +#------------------------------------------------------------------------- +# "Repo marked private" +#------------------------------------------------------------------------- +class NotePrivate(IsPrivate): + """Note marked private""" + + name = _('Notes marked private') + description = _("Matches notes that are indicated as private") diff --git a/src/Filters/Rules/Note/_RegExpIdOf.py b/src/Filters/Rules/Note/_RegExpIdOf.py new file mode 100644 index 000000000..7c4df63be --- /dev/null +++ b/src/Filters/Rules/Note/_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: _RegExpIdOf.py 7144 2006-08-07 20:16:00Z rshura $ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._RegExpIdBase import RegExpIdBase + +#------------------------------------------------------------------------- +# +# HasIdOf +# +#------------------------------------------------------------------------- +class RegExpIdOf(RegExpIdBase): + """ + Rule that checks for a note whose GRAMPS ID + matches regular expression. + """ + + name = _('Notes with matching regular expression') + description = _("Matches notes whose GRAMPS ID matches " + "the regular expression") diff --git a/src/Filters/Rules/Note/__init__.py b/src/Filters/Rules/Note/__init__.py new file mode 100644 index 000000000..e5bb1b278 --- /dev/null +++ b/src/Filters/Rules/Note/__init__.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: __init__.py 6521 2006-05-03 01:02:54Z rshura $ + +""" +Package providing filter rules for GRAMPS. +""" + +__author__ = "Don Allingham" + +from _AllNotes import AllNotes +from _HasIdOf import HasIdOf +from _RegExpIdOf import RegExpIdOf +#from _HasNoteRegexp import HasNoteRegexp +#from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf +from _NotePrivate import NotePrivate +from _MatchesFilter import MatchesFilter +from _HasNote import HasNote + +editor_rule_list = [ + AllNotes, + HasIdOf, + RegExpIdOf, +# HasNoteRegexp, +# HasNoteMatchingSubstringOf, + NotePrivate, + MatchesFilter, +] diff --git a/src/Filters/SideBar/Makefile.am b/src/Filters/SideBar/Makefile.am index eb3262037..404497a04 100644 --- a/src/Filters/SideBar/Makefile.am +++ b/src/Filters/SideBar/Makefile.am @@ -11,7 +11,8 @@ pkgdata_PYTHON = \ _SourceSidebarFilter.py\ _PlaceSidebarFilter.py\ _MediaSidebarFilter.py\ - _RepoSidebarFilter.py + _RepoSidebarFilter.py\ + _NoteSidebarFilter.py pkgpyexecdir = @pkgpyexecdir@/Filters/SideBar pkgpythondir = @pkgpythondir@/Filters/SideBar diff --git a/src/Filters/SideBar/_NoteSidebarFilter.py b/src/Filters/SideBar/_NoteSidebarFilter.py new file mode 100644 index 000000000..6de440b46 --- /dev/null +++ b/src/Filters/SideBar/_NoteSidebarFilter.py @@ -0,0 +1,131 @@ +# +# 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: _RepoSidebarFilter.py 7866 2007-01-04 05:09:41Z dallingham $ + +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# gtk +# +#------------------------------------------------------------------------- +import gtk + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +import GrampsWidgets +from RelLib import Note, NoteType + +from _SidebarFilter import SidebarFilter +from Filters import GenericFilterFactory, build_filter_model, Rules +from Filters.Rules.Note import * + +GenericNoteFilter = GenericFilterFactory('Note') +#------------------------------------------------------------------------- +# +# PersonSidebarFilter class +# +#------------------------------------------------------------------------- +class NoteSidebarFilter(SidebarFilter): + + def __init__(self,uistate, clicked): + SidebarFilter.__init__(self,uistate) + self.clicked_func = clicked + + def create_widget(self): + self.filter_id = gtk.Entry() + self.filter_text = gtk.Entry() + + self.note = Note() + self.note.set_type((NoteType.CUSTOM,'')) + self.ntype = gtk.ComboBoxEntry() + self.event_menu = GrampsWidgets.MonitoredDataType( + self.ntype, + self.note.set_type, + self.note.get_type) + + self.filter_regex = gtk.CheckButton(_('Use regular expressions')) + + self.generic = gtk.ComboBox() + cell = gtk.CellRendererText() + self.generic.pack_start(cell, True) + self.generic.add_attribute(cell, 'text', 0) + self.on_filters_changed('Note') + + self.add_text_entry(_('ID'), self.filter_id) + self.add_text_entry(_('Text'), self.filter_text) + self.add_entry(_('Type'), self.ntype) + 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_text.set_text('') + self.ntype.child.set_text('') + self.generic.set_active(0) + + def get_filter(self): + gid = unicode(self.filter_id.get_text()).strip() + text = unicode(self.filter_text.get_text()).strip() + ntype = self.note.get_type().xml_str() + regex = self.filter_regex.get_active() + gen = self.generic.get_active() > 0 + + empty = not (gid or text or ntype or regex or gen) + if empty: + generic_filter = None + else: + generic_filter = GenericNoteFilter() + if gid: + if regex: + rule = RegExpIdOf([gid]) + else: + rule = HasIdOf([gid]) + generic_filter.add_rule(rule) + + rule = HasNote([text,ntype]) + generic_filter.add_rule(rule) + + + if self.generic.get_active() != 0: + model = self.generic.get_model() + node = self.generic.get_active_iter() + obj = model.get_value(node, 0) + rule = MatchesFilter([obj]) + generic_filter.add_rule(rule) + + return generic_filter + + def on_filters_changed(self,name_space): + if name_space == 'Note': + all = GenericNoteFilter() + all.set_name(_("None")) + all.add_rule(Rules.Note.AllNotes([])) + self.generic.set_model(build_filter_model('Note', [all])) + self.generic.set_active(0) diff --git a/src/Filters/SideBar/__init__.py b/src/Filters/SideBar/__init__.py index eaf5639d1..5661cde25 100644 --- a/src/Filters/SideBar/__init__.py +++ b/src/Filters/SideBar/__init__.py @@ -34,3 +34,4 @@ from _SourceSidebarFilter import SourceSidebarFilter from _PlaceSidebarFilter import PlaceSidebarFilter from _MediaSidebarFilter import MediaSidebarFilter from _RepoSidebarFilter import RepoSidebarFilter +from _NoteSidebarFilter import NoteSidebarFilter diff --git a/src/Filters/_GenericFilter.py b/src/Filters/_GenericFilter.py index b00b8d9b4..bbbd70b8b 100644 --- a/src/Filters/_GenericFilter.py +++ b/src/Filters/_GenericFilter.py @@ -288,6 +288,20 @@ class GenericRepoFilter(GenericFilter): def find_from_handle(self, db, handle): return db.get_repository_from_handle(handle) +class GenericNoteFilter(GenericFilter): + + def __init__(self, source=None): + GenericFilter.__init__(self, source) + + def get_cursor(self, db): + return db.get_note_cursor() + + def make_obj(self): + return RelLib.Note() + + def find_from_handle(self, db, handle): + return db.get_note_from_handle(handle) + def GenericFilterFactory(namespace): if namespace == 'Person': @@ -304,3 +318,5 @@ def GenericFilterFactory(namespace): return GenericMediaFilter elif namespace == 'Repository': return GenericRepoFilter + elif namespace == 'Note': + return GenericNoteFilter