diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 46d1ef8ae..ab026032d 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,26 @@ 2006-08-05 Alex Roitman + * src/Filters/_GenericFilter.py: Support Source filters. + * src/Filters/SideBar/Makefile.am (pkgdata_PYTHON): Ship new file. + * src/Filters/Rules/Source/Makefile.am: Ship new files. + * src/FilterEditor/_EditRule.py: Support Source filters. + * src/FilterEditor/_FilterEditor.py: Support Source filters. + * src/FilterEditor/_ShowResults.py: Support Source filters. + * src/Filters/Rules/Source/__init__.py: Expose new modules. + * src/Filters/SideBar/_SourceSidebarFilter.py: Add module. + * src/Filters/SideBar/__init__.py: Expose new module. + * src/Filters/Rules/_Rule.py (Rule.match_substring): Add + convenience method for simple substring search. + * src/Filters/Rules/Source/_RegExpIdOf.py: Add module. + * src/Filters/Rules/Source/_MatchesFilter.py: Add module. + * src/Filters/Rules/Source/_HasNoteRegexp.py: Add module. + * src/Filters/Rules/Source/_HasNoteMatchingSubstringOf.py: Add module. + * src/Filters/Rules/Source/_HasIdOf.py: Add module. + * src/Filters/Rules/Source/_SourcePrivate.py: Add module. + * src/Filters/Rules/Source/_AllSources.py: Add module. + + + + * src/Filters/Rules/Family/Makefile.am (pkgdata_PYTHON): Ship new file. * src/Filters/Rules/Family/_MemberBase.py: Add new module. * src/Filters/SideBar/_PersonSidebarFilter.py: Minor changes. diff --git a/gramps2/po/POTFILES.in b/gramps2/po/POTFILES.in index e39b73ed0..d04253ff4 100644 --- a/gramps2/po/POTFILES.in +++ b/gramps2/po/POTFILES.in @@ -518,9 +518,25 @@ src/Filters/Rules/Event/_HasIdOf.py src/Filters/Rules/Event/_HasType.py src/Filters/Rules/Event/_HasNoteMatchingSubstringOf.py src/Filters/Rules/Event/__init__.py + +# Filters.Rules.Place package src/Filters/Rules/Place/__init__.py + +# Filters.Rules.Source package +src/Filters/Rules/Source/_MatchesFilter.py +src/Filters/Rules/Source/_SourcePrivate.py +src/Filters/Rules/Source/_RegExpIdOf.py +src/Filters/Rules/Source/_HasSource.py +src/Filters/Rules/Source/_HasNoteMatchingSubstringOf.py +src/Filters/Rules/Source/_AllSources.py +src/Filters/Rules/Source/_HasNoteRegexp.py +src/Filters/Rules/Source/_HasIdOf.py src/Filters/Rules/Source/__init__.py + +# Filters.Rules.Media package src/Filters/Rules/Media/__init__.py + +# Filters.Rules.Repository package src/Filters/Rules/Repository/__init__.py # Filters.SideBar package @@ -528,6 +544,7 @@ src/Filters/SideBar/_EventSidebarFilter.py src/Filters/SideBar/_FamilySidebarFilter.py src/Filters/SideBar/_PersonSidebarFilter.py src/Filters/SideBar/_SidebarFilter.py +src/Filters/SideBar/_SourceSidebarFilter.py # FilterEditor package src/FilterEditor/_FilterEditor.py diff --git a/gramps2/src/DataViews/_SourceView.py b/gramps2/src/DataViews/_SourceView.py index 29f559faa..3b603b93b 100644 --- a/gramps2/src/DataViews/_SourceView.py +++ b/gramps2/src/DataViews/_SourceView.py @@ -32,6 +32,8 @@ import gtk # #------------------------------------------------------------------------- import RelLib +import const +import Config import PageView import DisplayModels import Utils @@ -40,6 +42,7 @@ import Errors from DdTargets import DdTargets from Editors import EditSource, DelSrcQuery from QuestionDialog import QuestionDialog, ErrorDialog +from Filters.SideBar import SourceSidebarFilter #------------------------------------------------------------------------- # @@ -81,7 +84,11 @@ class SourceView(PageView.ListView): self, _('Sources'), dbstate, uistate, column_names, len(column_names), DisplayModels.SourceModel, signal_map, dbstate.db.get_source_bookmarks(), - Bookmarks.SourceBookmarks, multiple=True) + Bookmarks.SourceBookmarks, multiple=True, + filter_class=SourceSidebarFilter) + + Config.client.notify_add("/apps/gramps/interface/filter", + self.filter_toggle) def get_bookmarks(self): return self.dbstate.db.get_source_bookmarks() @@ -95,6 +102,27 @@ class SourceView(PageView.ListView): _('_Column Editor'), callback=self.column_editor) self.add_action('FastMerge', None, _('_Merge'), callback=self.fast_merge) + self.add_action('FilterEdit', None, _('Source 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('Source',const.custom_filters, + self.dbstate,self.uistate) + except Errors.WindowActiveError: + pass def column_editor(self,obj): import ColumnOrder @@ -132,6 +160,7 @@ class SourceView(PageView.ListView): + diff --git a/gramps2/src/FilterEditor/_EditRule.py b/gramps2/src/FilterEditor/_EditRule.py index dbd0bb8b5..f051fcd31 100644 --- a/gramps2/src/FilterEditor/_EditRule.py +++ b/gramps2/src/FilterEditor/_EditRule.py @@ -373,6 +373,8 @@ class EditRule(ManagedWindow.ManagedWindow): class_list = Rules.Family.editor_rule_list elif self.space == "Event": class_list = Rules.Event.editor_rule_list + elif self.space == 'Source': + class_list = Rules.Source.editor_rule_list for class_obj in class_list: arglist = class_obj.labels @@ -404,10 +406,8 @@ class EditRule(ManagedWindow.ManagedWindow): t = MyPlaces([]) elif v == _('Number of generations:'): t = MyInteger(1,32) - elif v == _('Person ID:'): - t = MyID(self.dbstate, self.uistate, self.track, 'Person') - elif v == _('Family ID:'): - t = MyID(self.dbstate, self.uistate, self.track, 'Family') + elif v == _('ID:'): + t = MyID(self.dbstate,self.uistate,self.track,self.space) elif v == _('Source ID:'): t = MySource(self.db) elif v == _('Filter name:'): diff --git a/gramps2/src/FilterEditor/_FilterEditor.py b/gramps2/src/FilterEditor/_FilterEditor.py index a69b71a42..fc19076b7 100644 --- a/gramps2/src/FilterEditor/_FilterEditor.py +++ b/gramps2/src/FilterEditor/_FilterEditor.py @@ -174,3 +174,5 @@ class FilterEditor(ManagedWindow.ManagedWindow): return self.db.get_family_handles() elif self.space == 'Event': return self.db.get_event_handles() + elif self.space == 'Source': + return self.db.get_source_handles() diff --git a/gramps2/src/FilterEditor/_ShowResults.py b/gramps2/src/FilterEditor/_ShowResults.py index b5ad68e1c..042ef38fa 100644 --- a/gramps2/src/FilterEditor/_ShowResults.py +++ b/gramps2/src/FilterEditor/_ShowResults.py @@ -115,6 +115,10 @@ class ShowResults(ManagedWindow.ManagedWindow): event = self.db.get_event_from_handle(handle) name = event.get_description() gid = event.get_gramps_id() + elif self.space == 'Source': + source = self.db.get_source_from_handle(handle) + name = source.get_title() + gid = source.get_gramps_id() return (name,gid) def sort_val_from_handle(self, handle): @@ -128,4 +132,7 @@ class ShowResults(ManagedWindow.ManagedWindow): elif self.space == 'Event': name = self.db.get_event_from_handle(handle).get_description() sortname = locale.strxfrm(name) + elif self.space == 'Source': + name = self.db.get_source_from_handle(handle).get_title() + sortname = locale.strxfrm(name) return (sortname,handle) diff --git a/gramps2/src/Filters/Rules/Event/_HasIdOf.py b/gramps2/src/Filters/Rules/Event/_HasIdOf.py index a0d9c59f3..8d2eae945 100644 --- a/gramps2/src/Filters/Rules/Event/_HasIdOf.py +++ b/gramps2/src/Filters/Rules/Event/_HasIdOf.py @@ -42,6 +42,5 @@ from Filters.Rules import HasGrampsId 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/gramps2/src/Filters/Rules/Event/__init__.py b/gramps2/src/Filters/Rules/Event/__init__.py index 776ca8e07..977a1ca63 100644 --- a/gramps2/src/Filters/Rules/Event/__init__.py +++ b/gramps2/src/Filters/Rules/Event/__init__.py @@ -25,6 +25,7 @@ Package providing filter rules for GRAMPS. """ __author__ = "Don Allingham" + from Filters.Rules._HasEventBase import HasEventBase as HasEvent from _HasType import HasType diff --git a/gramps2/src/Filters/Rules/Family/_HasIdOf.py b/gramps2/src/Filters/Rules/Family/_HasIdOf.py index 24cb2a572..2764f633e 100644 --- a/gramps2/src/Filters/Rules/Family/_HasIdOf.py +++ b/gramps2/src/Filters/Rules/Family/_HasIdOf.py @@ -42,6 +42,5 @@ from Filters.Rules import HasGrampsId class HasIdOf(HasGrampsId): """Rule that checks for a family with a specific GRAMPS ID""" - labels = [ _('Family ID:') ] name = _('Family with ') description = _("Matches a family with a specified GRAMPS ID") diff --git a/gramps2/src/Filters/Rules/Person/_HasIdOf.py b/gramps2/src/Filters/Rules/Person/_HasIdOf.py index 3ffbda604..ef41e1a54 100644 --- a/gramps2/src/Filters/Rules/Person/_HasIdOf.py +++ b/gramps2/src/Filters/Rules/Person/_HasIdOf.py @@ -42,6 +42,5 @@ from Filters.Rules import HasGrampsId class HasIdOf(HasGrampsId): """Rule that checks for a person with a specific GRAMPS ID""" - labels = [ _('Person ID:') ] name = _('People with ') description = _("Matches people with a specified GRAMPS ID") diff --git a/gramps2/src/Filters/Rules/Source/Makefile.am b/gramps2/src/Filters/Rules/Source/Makefile.am index 87e292b62..c54d08742 100644 --- a/gramps2/src/Filters/Rules/Source/Makefile.am +++ b/gramps2/src/Filters/Rules/Source/Makefile.am @@ -3,6 +3,14 @@ pkgdatadir = $(datadir)/@PACKAGE@/Filters/Rules/Source pkgdata_PYTHON = \ + _MatchesFilter.py\ + _SourcePrivate.py\ + _RegExpIdOf.py\ + _HasNoteMatchingSubstringOf.py\ + _AllSources.py\ + _HasIdOf.py\ + _HasSource.py\ + _HasNoteRegexp.py\ __init__.py pkgpyexecdir = @pkgpyexecdir@/Filters/Rules/Source diff --git a/gramps2/src/Filters/Rules/Source/_AllSources.py b/gramps2/src/Filters/Rules/Source/_AllSources.py new file mode 100644 index 000000000..101628bb3 --- /dev/null +++ b/gramps2/src/Filters/Rules/Source/_AllSources.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 AllSources(Everything): + """Matches Everyone""" + + name = _('Every source') + description = _('Matches every source in the database') diff --git a/gramps2/src/Filters/Rules/Source/_HasIdOf.py b/gramps2/src/Filters/Rules/Source/_HasIdOf.py new file mode 100644 index 000000000..4b9f6cfad --- /dev/null +++ b/gramps2/src/Filters/Rules/Source/_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 source with a specific GRAMPS ID""" + + name = _('Source with ') + description = _("Matches a source with a specified GRAMPS ID") diff --git a/gramps2/src/Filters/Rules/Source/_HasNoteMatchingSubstringOf.py b/gramps2/src/Filters/Rules/Source/_HasNoteMatchingSubstringOf.py new file mode 100644 index 000000000..ee860c75f --- /dev/null +++ b/gramps2/src/Filters/Rules/Source/_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): + """Sources having notes containing """ + + name = _('Sources having notes containing ') + description = _("Matches sources whose notes contain text " + "matching a substring") + diff --git a/gramps2/src/Filters/Rules/Source/_HasNoteRegexp.py b/gramps2/src/Filters/Rules/Source/_HasNoteRegexp.py new file mode 100644 index 000000000..cd2debb53 --- /dev/null +++ b/gramps2/src/Filters/Rules/Source/_HasNoteRegexp.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._HasNoteRegexBase import HasNoteRegexBase + +#------------------------------------------------------------------------- +# "Sources having notes that contain a substring" +#------------------------------------------------------------------------- +class HasNoteRegexp(HasNoteRegexBase): + + name = _('Sources having notes containing ') + description = _("Matches sources whose notes contain text " + "matching a regular expression") diff --git a/gramps2/src/Filters/Rules/Source/_HasSource.py b/gramps2/src/Filters/Rules/Source/_HasSource.py new file mode 100644 index 000000000..aba51bbca --- /dev/null +++ b/gramps2/src/Filters/Rules/Source/_HasSource.py @@ -0,0 +1,63 @@ +# +# 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._Rule import Rule + +#------------------------------------------------------------------------- +# +# HasEvent +# +#------------------------------------------------------------------------- +class HasSource(Rule): + """Rule that checks for a person with a particular value""" + + + labels = [ _('Title:'), + _('Author:'), + _('Publication:') ] + name = _('Sources matching parameters') + description = _("Matches sources with particular parameters") + category = _('General filters') + + def apply(self,db,source): + if not self.match_substring(0,source.get_title()): + return False + + if not self.match_substring(1,source.get_author()): + return False + + if not self.match_substring(2,source.get_publication_info()): + return False + + return True diff --git a/gramps2/src/Filters/Rules/Source/_MatchesFilter.py b/gramps2/src/Filters/Rules/Source/_MatchesFilter.py new file mode 100644 index 000000000..123183964 --- /dev/null +++ b/gramps2/src/Filters/Rules/Source/_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 = _('Sources matching the ') + description = _("Matches sources macthed by the specified filter name") + namespace = 'Source' diff --git a/gramps2/src/Filters/Rules/Source/_RegExpIdOf.py b/gramps2/src/Filters/Rules/Source/_RegExpIdOf.py new file mode 100644 index 000000000..1d514c3d0 --- /dev/null +++ b/gramps2/src/Filters/Rules/Source/_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 source whose GRAMPS ID + matches regular expression. + """ + + name = _('Sources with matching regular expression') + description = _("Matches sources whose GRAMPS ID matches " + "the regular expression") diff --git a/gramps2/src/Filters/Rules/Source/_SourcePrivate.py b/gramps2/src/Filters/Rules/Source/_SourcePrivate.py new file mode 100644 index 000000000..164aed867 --- /dev/null +++ b/gramps2/src/Filters/Rules/Source/_SourcePrivate.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 SourcePrivate(IsPrivate): + """Source marked private""" + + name = _('Sources marked private') + description = _("Matches sources that are indicated as private") diff --git a/gramps2/src/Filters/Rules/Source/__init__.py b/gramps2/src/Filters/Rules/Source/__init__.py index b73e6d238..d10a3df52 100644 --- a/gramps2/src/Filters/Rules/Source/__init__.py +++ b/gramps2/src/Filters/Rules/Source/__init__.py @@ -25,3 +25,22 @@ Package providing filter rules for GRAMPS. """ __author__ = "Don Allingham" + +from _AllSources import AllSources +from _HasIdOf import HasIdOf +from _RegExpIdOf import RegExpIdOf +from _HasNoteRegexp import HasNoteRegexp +from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf +from _SourcePrivate import SourcePrivate +from _MatchesFilter import MatchesFilter +from _HasSource import HasSource + +editor_rule_list = [ + AllSources, + HasIdOf, + RegExpIdOf, + HasNoteRegexp, + HasNoteMatchingSubstringOf, + SourcePrivate, + MatchesFilter, +] diff --git a/gramps2/src/Filters/Rules/_Rule.py b/gramps2/src/Filters/Rules/_Rule.py index 7ea4872a8..af181abe3 100644 --- a/gramps2/src/Filters/Rules/_Rule.py +++ b/gramps2/src/Filters/Rules/_Rule.py @@ -73,3 +73,10 @@ class Rule: for ix in range(0,len(self.list)) if self.list[ix] ] return ';'.join(v) + + def match_substring(self,param_index,str_var): + if self.list[param_index] and \ + (str_var.upper().find(self.list[param_index].upper()) == -1): + return False + else: + return True diff --git a/gramps2/src/Filters/SideBar/Makefile.am b/gramps2/src/Filters/SideBar/Makefile.am index 9d2b521c1..a0e194574 100644 --- a/gramps2/src/Filters/SideBar/Makefile.am +++ b/gramps2/src/Filters/SideBar/Makefile.am @@ -7,7 +7,8 @@ pkgdata_PYTHON = \ _FamilySidebarFilter.py \ __init__.py \ _SidebarFilter.py \ - _PersonSidebarFilter.py + _PersonSidebarFilter.py\ + _SourceSidebarFilter.py pkgpyexecdir = @pkgpyexecdir@/Filters/SideBar pkgpythondir = @pkgpythondir@/Filters/SideBar diff --git a/gramps2/src/Filters/SideBar/_SourceSidebarFilter.py b/gramps2/src/Filters/SideBar/_SourceSidebarFilter.py new file mode 100644 index 000000000..974314469 --- /dev/null +++ b/gramps2/src/Filters/SideBar/_SourceSidebarFilter.py @@ -0,0 +1,138 @@ +# +# 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.Source import * + +GenericSourceFilter = GenericFilterFactory('Source') +#------------------------------------------------------------------------- +# +# PersonSidebarFilter class +# +#------------------------------------------------------------------------- +class SourceSidebarFilter(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_author = gtk.Entry() + self.filter_pub = gtk.Entry() + self.filter_note = gtk.Entry() + + self.filter_regex = gtk.CheckButton(_('Use regular expressions')) + + all = GenericSourceFilter() + all.set_name(_("None")) + all.add_rule(Rules.Source.AllSources([])) + + 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('Source', [all])) + self.generic.set_active(0) + + self.add_text_entry(_('ID'), self.filter_id) + self.add_text_entry(_('Title'), self.filter_title) + self.add_text_entry(_('Author'), self.filter_author) + self.add_text_entry(_('Publication'), self.filter_pub) + 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_author.set_text('') + self.filter_pub.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() + author = unicode(self.filter_author.get_text()).strip() + pub = unicode(self.filter_pub.get_text()).strip() + 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 author or pub or note or regex or gen) + if empty: + generic_filter = None + else: + generic_filter = GenericSourceFilter() + if gid: + if regex: + rule = RegExpIdOf([gid]) + else: + rule = HasIdOf([gid]) + generic_filter.add_rule(rule) + + rule = HasSource([title,author,pub]) + 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/gramps2/src/Filters/SideBar/__init__.py b/gramps2/src/Filters/SideBar/__init__.py index 5ce6e7eda..176488006 100644 --- a/gramps2/src/Filters/SideBar/__init__.py +++ b/gramps2/src/Filters/SideBar/__init__.py @@ -30,3 +30,4 @@ from _SidebarFilter import SidebarFilter from _PersonSidebarFilter import PersonSidebarFilter from _FamilySidebarFilter import FamilySidebarFilter from _EventSidebarFilter import EventSidebarFilter +from _SourceSidebarFilter import SourceSidebarFilter diff --git a/gramps2/src/Filters/_GenericFilter.py b/gramps2/src/Filters/_GenericFilter.py index 7300bdc21..17f11734f 100644 --- a/gramps2/src/Filters/_GenericFilter.py +++ b/gramps2/src/Filters/_GenericFilter.py @@ -218,7 +218,6 @@ class GenericFamilyFilter(GenericFilter): def find_from_handle(self, db, handle): return db.get_family_from_handle(handle) - class GenericEventFilter(GenericFilter): def __init__(self, source=None): @@ -232,6 +231,20 @@ class GenericEventFilter(GenericFilter): def find_from_handle(self, db, handle): return db.get_event_from_handle(handle) + +class GenericSourceFilter(GenericFilter): + + def __init__(self, source=None): + GenericFilter.__init__(self, source) + + def get_cursor(db, self): + return db.get_source_cursor() + + def make_obj(self): + return RelLib.Source() + + def find_from_handle(self, db, handle): + return db.get_source_from_handle(handle) def GenericFilterFactory(namespace): if namespace == 'Person': @@ -240,3 +253,5 @@ def GenericFilterFactory(namespace): return GenericFamilyFilter elif namespace == 'Event': return GenericEventFilter + elif namespace == 'Source': + return GenericSourceFilter