From b1522eab91d52e5157dfb6d8a32afdd6efe4670b Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Mon, 7 Aug 2006 20:16:00 +0000 Subject: [PATCH] In .: 2006-08-07 Alex Roitman * src/DataViews/_RepositoryView.py: Add filter sidebar. * src/FilterEditor/_ShowResults.py: Support repo filters. * src/FilterEditor/_EditRule.py: Support repo filters. * src/FilterEditor/_FilterEditor.py: Support repo filters. * src/Filters/_GenericFilter.py: Support repo filters. * src/Filters/SideBar/Makefile.am (pkgdata_PYTHON): Ship new file. * src/Filters/SideBar/__init__.py: Expose new module. * src/Filters/SideBar/_RepoSidebarFilter.py: Add module. * src/Filters/Rules/Repository/Makefile.am (pkgdata_PYTHON): Ship new files. * src/Filters/Rules/Repository/__init__.py: Expose new modules. * src/Filters/Rules/Repository/_HasRepo.py: Add module. * src/Filters/Rules/Repository/_RepoPrivate.py: Add module. * src/Filters/Rules/Repository/_RegExpIdOf.py: Add module. * src/Filters/Rules/Repository/_MatchesFilter.py: Add module. * src/Filters/Rules/Repository/_HasNoteRegexp.py: Add module. * src/Filters/Rules/Repository/_HasNoteMatchingSubstringOf.py: Add module. * src/Filters/Rules/Repository/_HasIdOf.py: Add module. * src/Filters/Rules/Repository/_AllRepos.py: Add module. In po: 2006-08-07 Alex Roitman * POTFILES.in: Add new files. svn: r7144 --- ChangeLog | 22 +++ po/ChangeLog | 3 + po/POTFILES.in | 9 ++ src/DataViews/_RepositoryView.py | 30 +++- src/FilterEditor/_EditRule.py | 2 + src/FilterEditor/_FilterEditor.py | 2 + src/FilterEditor/_ShowResults.py | 7 + src/Filters/Rules/Repository/Makefile.am | 8 + src/Filters/Rules/Repository/_AllRepos.py | 46 ++++++ src/Filters/Rules/Repository/_HasIdOf.py | 46 ++++++ .../Repository/_HasNoteMatchingSubstringOf.py | 46 ++++++ .../Rules/Repository/_HasNoteRegexp.py | 45 ++++++ src/Filters/Rules/Repository/_HasRepo.py | 83 ++++++++++ .../Rules/Repository/_MatchesFilter.py | 48 ++++++ src/Filters/Rules/Repository/_RegExpIdOf.py | 50 ++++++ src/Filters/Rules/Repository/_RepoPrivate.py | 44 +++++ src/Filters/Rules/Repository/__init__.py | 19 +++ src/Filters/SideBar/Makefile.am | 3 +- src/Filters/SideBar/_RepoSidebarFilter.py | 151 ++++++++++++++++++ src/Filters/SideBar/__init__.py | 1 + src/Filters/_GenericFilter.py | 16 ++ 21 files changed, 679 insertions(+), 2 deletions(-) create mode 100644 src/Filters/Rules/Repository/_AllRepos.py create mode 100644 src/Filters/Rules/Repository/_HasIdOf.py create mode 100644 src/Filters/Rules/Repository/_HasNoteMatchingSubstringOf.py create mode 100644 src/Filters/Rules/Repository/_HasNoteRegexp.py create mode 100644 src/Filters/Rules/Repository/_HasRepo.py create mode 100644 src/Filters/Rules/Repository/_MatchesFilter.py create mode 100644 src/Filters/Rules/Repository/_RegExpIdOf.py create mode 100644 src/Filters/Rules/Repository/_RepoPrivate.py create mode 100644 src/Filters/SideBar/_RepoSidebarFilter.py diff --git a/ChangeLog b/ChangeLog index 4c61e7e5e..4a377bb3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2006-08-07 Alex Roitman + * src/DataViews/_RepositoryView.py: Add filter sidebar. + * src/FilterEditor/_ShowResults.py: Support repo filters. + * src/FilterEditor/_EditRule.py: Support repo filters. + * src/FilterEditor/_FilterEditor.py: Support repo filters. + * src/Filters/_GenericFilter.py: Support repo filters. + * src/Filters/SideBar/Makefile.am (pkgdata_PYTHON): Ship new file. + * src/Filters/SideBar/__init__.py: Expose new module. + * src/Filters/SideBar/_RepoSidebarFilter.py: Add module. + * src/Filters/Rules/Repository/Makefile.am (pkgdata_PYTHON): Ship + new files. + * src/Filters/Rules/Repository/__init__.py: Expose new modules. + * src/Filters/Rules/Repository/_HasRepo.py: Add module. + * src/Filters/Rules/Repository/_RepoPrivate.py: Add module. + * src/Filters/Rules/Repository/_RegExpIdOf.py: Add module. + * src/Filters/Rules/Repository/_MatchesFilter.py: Add module. + * src/Filters/Rules/Repository/_HasNoteRegexp.py: Add module. + * src/Filters/Rules/Repository/_HasNoteMatchingSubstringOf.py: Add + module. + * src/Filters/Rules/Repository/_HasIdOf.py: Add module. + * src/Filters/Rules/Repository/_AllRepos.py: Add module. + 2006-08-06 Brian Matherly * src/plugins/DetAncestralReport.py: print children when no mother exists diff --git a/po/ChangeLog b/po/ChangeLog index 1606b960f..2d1b1ccd8 100644 --- a/po/ChangeLog +++ b/po/ChangeLog @@ -1,3 +1,6 @@ +2006-08-07 Alex Roitman + * POTFILES.in: Add new files. + 2006-08-06 Alex Roitman * POTFILES.in: Add new files. diff --git a/po/POTFILES.in b/po/POTFILES.in index 343da00fa..8aae90099 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -545,6 +545,14 @@ src/Filters/Rules/Source/__init__.py src/Filters/Rules/Media/__init__.py # Filters.Rules.Repository package +src/Filters/Rules/Repository/_AllRepos.py +src/Filters/Rules/Repository/_HasIdOf.py +src/Filters/Rules/Repository/_HasNoteMatchingSubstringOf.py +src/Filters/Rules/Repository/_HasNoteRegexp.py +src/Filters/Rules/Repository/_HasRepo.py +src/Filters/Rules/Repository/_MatchesFilter.py +src/Filters/Rules/Repository/_RegExpIdOf.py +src/Filters/Rules/Repository/_RepoPrivate.py src/Filters/Rules/Repository/__init__.py # Filters.SideBar package @@ -554,6 +562,7 @@ src/Filters/SideBar/_PersonSidebarFilter.py src/Filters/SideBar/_SidebarFilter.py src/Filters/SideBar/_SourceSidebarFilter.py src/Filters/SideBar/_PlaceSidebarFilter.py +src/Filters/SideBar/_RepoSidebarFilter.py # FilterEditor package src/FilterEditor/_FilterEditor.py diff --git a/src/DataViews/_RepositoryView.py b/src/DataViews/_RepositoryView.py index ae3431ce6..fa9bb17cd 100644 --- a/src/DataViews/_RepositoryView.py +++ b/src/DataViews/_RepositoryView.py @@ -37,10 +37,13 @@ import DisplayModels import Utils import Bookmarks import Errors +import const +import Config from Editors import EditRepository, DelRepositoryQuery from DdTargets import DdTargets from QuestionDialog import QuestionDialog +from Filters.SideBar import RepoSidebarFilter #------------------------------------------------------------------------- # @@ -89,7 +92,10 @@ class RepositoryView(PageView.ListView): column_names, len(column_names), DisplayModels.RepositoryModel, signal_map, dbstate.db.get_repo_bookmarks(), - Bookmarks.RepoBookmarks) + Bookmarks.RepoBookmarks,filter_class=RepoSidebarFilter) + + Config.client.notify_add("/apps/gramps/interface/filter", + self.filter_toggle) def get_bookmarks(self): return self.dbstate.db.get_repo_bookmarks() @@ -101,6 +107,27 @@ class RepositoryView(PageView.ListView): PageView.ListView.define_actions(self) self.add_action('ColumnEdit', gtk.STOCK_PROPERTIES, _('_Column Editor'), callback=self.column_editor) + self.add_action('FilterEdit', None, _('Repository 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('Repository',const.custom_filters, + self.dbstate,self.uistate) + except Errors.WindowActiveError: + pass def column_editor(self,obj): import ColumnOrder @@ -138,6 +165,7 @@ class RepositoryView(PageView.ListView): + diff --git a/src/FilterEditor/_EditRule.py b/src/FilterEditor/_EditRule.py index e34f18a2b..502d1aa4b 100644 --- a/src/FilterEditor/_EditRule.py +++ b/src/FilterEditor/_EditRule.py @@ -377,6 +377,8 @@ class EditRule(ManagedWindow.ManagedWindow): class_list = Rules.Source.editor_rule_list elif self.space == 'Place': class_list = Rules.Place.editor_rule_list + elif self.space == 'Repository': + class_list = Rules.Repository.editor_rule_list for class_obj in class_list: arglist = class_obj.labels diff --git a/src/FilterEditor/_FilterEditor.py b/src/FilterEditor/_FilterEditor.py index 23729c286..d244bb374 100644 --- a/src/FilterEditor/_FilterEditor.py +++ b/src/FilterEditor/_FilterEditor.py @@ -178,3 +178,5 @@ class FilterEditor(ManagedWindow.ManagedWindow): return self.db.get_source_handles() elif self.space == 'Place': return self.db.get_place_handles() + elif self.space == 'Repository': + return self.db.get_repository_handles() diff --git a/src/FilterEditor/_ShowResults.py b/src/FilterEditor/_ShowResults.py index 0015fc9cf..a81412755 100644 --- a/src/FilterEditor/_ShowResults.py +++ b/src/FilterEditor/_ShowResults.py @@ -123,6 +123,10 @@ class ShowResults(ManagedWindow.ManagedWindow): place = self.db.get_place_from_handle(handle) name = place.get_title() gid = place.get_gramps_id() + elif self.space == 'Repository': + repo = self.db.get_repository_from_handle(handle) + name = repo.get_name() + gid = repo.get_gramps_id() return (name,gid) def sort_val_from_handle(self, handle): @@ -142,4 +146,7 @@ class ShowResults(ManagedWindow.ManagedWindow): elif self.space == 'Place': name = self.db.get_place_from_handle(handle).get_title() sortname = locale.strxfrm(name) + elif self.space == 'Repository': + name = self.db.get_repository_from_handle(handle).get_name() + sortname = locale.strxfrm(name) return (sortname,handle) diff --git a/src/Filters/Rules/Repository/Makefile.am b/src/Filters/Rules/Repository/Makefile.am index 13fa0f23a..98a6b207c 100644 --- a/src/Filters/Rules/Repository/Makefile.am +++ b/src/Filters/Rules/Repository/Makefile.am @@ -3,6 +3,14 @@ pkgdatadir = $(datadir)/@PACKAGE@/Filters/Rules/Repository pkgdata_PYTHON = \ + _AllRepos.py\ + _HasIdOf.py\ + _HasNoteMatchingSubstringOf.py\ + _HasNoteRegexp.py\ + _HasRepo.py\ + _MatchesFilter.py\ + _RegExpIdOf.py\ + _RepoPrivate.py\ __init__.py pkgpyexecdir = @pkgpyexecdir@/Filters/Rules/Repository diff --git a/src/Filters/Rules/Repository/_AllRepos.py b/src/Filters/Rules/Repository/_AllRepos.py new file mode 100644 index 000000000..d1ce74471 --- /dev/null +++ b/src/Filters/Rules/Repository/_AllRepos.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 AllRepos(Everything): + """Matches Everyone""" + + name = _('Every repository') + description = _('Matches every repository in the database') diff --git a/src/Filters/Rules/Repository/_HasIdOf.py b/src/Filters/Rules/Repository/_HasIdOf.py new file mode 100644 index 000000000..208f97496 --- /dev/null +++ b/src/Filters/Rules/Repository/_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$ + +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules import HasGrampsId + +#------------------------------------------------------------------------- +# +# HasIdOf +# +#------------------------------------------------------------------------- +class HasIdOf(HasGrampsId): + """Rule that checks for a repo with a specific GRAMPS ID""" + + name = _('Repository with ') + description = _("Matches a repository with a specified GRAMPS ID") diff --git a/src/Filters/Rules/Repository/_HasNoteMatchingSubstringOf.py b/src/Filters/Rules/Repository/_HasNoteMatchingSubstringOf.py new file mode 100644 index 000000000..6d138fe64 --- /dev/null +++ b/src/Filters/Rules/Repository/_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): + """Repos having notes containing """ + + name = _('Repositories having notes containing ') + description = _("Matches repositories whose notes contain text " + "matching a substring") + diff --git a/src/Filters/Rules/Repository/_HasNoteRegexp.py b/src/Filters/Rules/Repository/_HasNoteRegexp.py new file mode 100644 index 000000000..b93a7d76c --- /dev/null +++ b/src/Filters/Rules/Repository/_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 +# +#------------------------------------------------------------------------- +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from Filters.Rules._HasNoteRegexBase import HasNoteRegexBase + +#------------------------------------------------------------------------- +# "Repos having notes that contain a substring" +#------------------------------------------------------------------------- +class HasNoteRegexp(HasNoteRegexBase): + + name = _('Repositoriess having notes ' + 'containing ') + description = _("Matches repositories whose notes contain text " + "matching a regular expression") diff --git a/src/Filters/Rules/Repository/_HasRepo.py b/src/Filters/Rules/Repository/_HasRepo.py new file mode 100644 index 000000000..8bc9537dd --- /dev/null +++ b/src/Filters/Rules/Repository/_HasRepo.py @@ -0,0 +1,83 @@ +# +# 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 RepositoryType +from Filters.Rules._Rule import Rule + +#------------------------------------------------------------------------- +# +# HasEvent +# +#------------------------------------------------------------------------- +class HasRepo(Rule): + """Rule that checks for a repo with a particular value""" + + + labels = [ _('Name:'), + _('Type:'), + _('Address:'), + _('URL:'), + ] + name = _('Repositories matching parameters') + description = _("Matches Repositories with particular parameters") + category = _('General filters') + + def apply(self,db,repo): + if not self.match_substring(0,repo.get_name()): + return False + + if self.list[1]: + specified_type = RepositoryType() + specified_type.set_from_xml_str(self.list[1]) + if repo.type != specified_type: + return False + + addr_match = False + for addr in repo.address_list: + addr_text = addr.city + addr.state + addr.country + addr.postal \ + + addr.phone + addr.street + + if not self.match_substring(2,addr_text): + continue + + addr_match = True + + url_match = False + for url in repo.urls: + url_text = url.path + url.desc + if not self.match_substring(3,url_text): + continue + url_match = True + + return (addr_match or url_match) diff --git a/src/Filters/Rules/Repository/_MatchesFilter.py b/src/Filters/Rules/Repository/_MatchesFilter.py new file mode 100644 index 000000000..8bdef5dfe --- /dev/null +++ b/src/Filters/Rules/Repository/_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$ + +#------------------------------------------------------------------------- +# +# 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 = _('Repositories matching the ') + description = _("Matches repositoriess macthed " + "by the specified filter name") + namespace = 'Repository' diff --git a/src/Filters/Rules/Repository/_RegExpIdOf.py b/src/Filters/Rules/Repository/_RegExpIdOf.py new file mode 100644 index 000000000..fd18616ec --- /dev/null +++ b/src/Filters/Rules/Repository/_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 a repo whose GRAMPS ID + matches regular expression. + """ + + name = _('Repositories with matching regular expression') + description = _("Matches repositories whose GRAMPS ID matches " + "the regular expression") diff --git a/src/Filters/Rules/Repository/_RepoPrivate.py b/src/Filters/Rules/Repository/_RepoPrivate.py new file mode 100644 index 000000000..1b31aa832 --- /dev/null +++ b/src/Filters/Rules/Repository/_RepoPrivate.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 + +#------------------------------------------------------------------------- +# "Repo marked private" +#------------------------------------------------------------------------- +class RepoPrivate(IsPrivate): + """Repo marked private""" + + name = _('Repositories marked private') + description = _("Matches repositories that are indicated as private") diff --git a/src/Filters/Rules/Repository/__init__.py b/src/Filters/Rules/Repository/__init__.py index b73e6d238..ebae3c982 100644 --- a/src/Filters/Rules/Repository/__init__.py +++ b/src/Filters/Rules/Repository/__init__.py @@ -25,3 +25,22 @@ Package providing filter rules for GRAMPS. """ __author__ = "Don Allingham" + +from _AllRepos import AllRepos +from _HasIdOf import HasIdOf +from _RegExpIdOf import RegExpIdOf +from _HasNoteRegexp import HasNoteRegexp +from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf +from _RepoPrivate import RepoPrivate +from _MatchesFilter import MatchesFilter +from _HasRepo import HasRepo + +editor_rule_list = [ + AllRepos, + HasIdOf, + RegExpIdOf, + HasNoteRegexp, + HasNoteMatchingSubstringOf, + RepoPrivate, + MatchesFilter, +] diff --git a/src/Filters/SideBar/Makefile.am b/src/Filters/SideBar/Makefile.am index dced63166..fd670d56e 100644 --- a/src/Filters/SideBar/Makefile.am +++ b/src/Filters/SideBar/Makefile.am @@ -9,7 +9,8 @@ pkgdata_PYTHON = \ _SidebarFilter.py \ _PersonSidebarFilter.py\ _SourceSidebarFilter.py\ - _PlaceSidebarFilter.py + _PlaceSidebarFilter.py\ + _RepoSidebarFilter.py pkgpyexecdir = @pkgpyexecdir@/Filters/SideBar pkgpythondir = @pkgpythondir@/Filters/SideBar diff --git a/src/Filters/SideBar/_RepoSidebarFilter.py b/src/Filters/SideBar/_RepoSidebarFilter.py new file mode 100644 index 000000000..aa2126db5 --- /dev/null +++ b/src/Filters/SideBar/_RepoSidebarFilter.py @@ -0,0 +1,151 @@ +# +# 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 +from RelLib import Repository, RepositoryType + +from _SidebarFilter import SidebarFilter +from Filters import GenericFilterFactory, build_filter_model, Rules +from Filters.Rules.Repository import * + +GenericRepoFilter = GenericFilterFactory('Repository') +#------------------------------------------------------------------------- +# +# PersonSidebarFilter class +# +#------------------------------------------------------------------------- +class RepoSidebarFilter(SidebarFilter): + + def __init__(self, clicked): + SidebarFilter.__init__(self) + self.clicked_func = clicked + + def create_widget(self): + self.filter_id = gtk.Entry() + self.filter_title = gtk.Entry() + self.filter_address = gtk.Entry() + self.filter_url = gtk.Entry() + + self.repo = Repository() + self.repo.set_type((RepositoryType.CUSTOM,'')) + self.rtype = gtk.ComboBoxEntry() + self.event_menu = GrampsWidgets.MonitoredDataType( + self.rtype, + self.repo.set_type, + self.repo.get_type) + + self.filter_note = gtk.Entry() + + self.filter_regex = gtk.CheckButton(_('Use regular expressions')) + + all = GenericRepoFilter() + all.set_name(_("None")) + all.add_rule(Rules.Repository.AllRepos([])) + + 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('Repository', [all])) + self.generic.set_active(0) + + self.add_text_entry(_('ID'), self.filter_id) + self.add_text_entry(_('Name'), self.filter_title) + self.add_entry(_('Type'), self.rtype) + self.add_text_entry(_('Address'), self.filter_address) + self.add_text_entry(_('URL'), self.filter_url) + 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_title.set_text('') + self.filter_address.set_text('') + self.filter_url.set_text('') + self.rtype.child.set_text('') + self.filter_note.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() + title = unicode(self.filter_title.get_text()).strip() + address = unicode(self.filter_address.get_text()).strip() + url = unicode(self.filter_url.get_text()).strip() + rtype = self.repo.get_type().xml_str() + note = unicode(self.filter_note.get_text()).strip() + regex = self.filter_regex.get_active() + gen = self.generic.get_active() > 0 + + empty = not (gid or title or address or url or rtype + or note or regex or gen) + if empty: + generic_filter = None + else: + generic_filter = GenericRepoFilter() + if gid: + if regex: + rule = RegExpIdOf([gid]) + else: + rule = HasIdOf([gid]) + generic_filter.add_rule(rule) + + rule = HasRepo([title,rtype,address,url]) + 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/SideBar/__init__.py b/src/Filters/SideBar/__init__.py index 50b61c70e..3b7385ea1 100644 --- a/src/Filters/SideBar/__init__.py +++ b/src/Filters/SideBar/__init__.py @@ -32,3 +32,4 @@ from _FamilySidebarFilter import FamilySidebarFilter from _EventSidebarFilter import EventSidebarFilter from _SourceSidebarFilter import SourceSidebarFilter from _PlaceSidebarFilter import PlaceSidebarFilter +from _RepoSidebarFilter import RepoSidebarFilter diff --git a/src/Filters/_GenericFilter.py b/src/Filters/_GenericFilter.py index 2e04ec5c3..af53c964d 100644 --- a/src/Filters/_GenericFilter.py +++ b/src/Filters/_GenericFilter.py @@ -260,6 +260,20 @@ class GenericPlaceFilter(GenericFilter): def find_from_handle(self, db, handle): return db.get_place_from_handle(handle) +class GenericRepoFilter(GenericFilter): + + def __init__(self, source=None): + GenericFilter.__init__(self, source) + + def get_cursor(db, self): + return db.get_repository_cursor() + + def make_obj(self): + return RelLib.Repository() + + def find_from_handle(self, db, handle): + return db.get_repository_from_handle(handle) + def GenericFilterFactory(namespace): if namespace == 'Person': @@ -272,3 +286,5 @@ def GenericFilterFactory(namespace): return GenericSourceFilter elif namespace == 'Place': return GenericPlaceFilter + elif namespace == 'Repository': + return GenericRepoFilter