From d5225778081a69095a139de7361af88bf8a625a9 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Mon, 7 Aug 2006 02:49:12 +0000 Subject: [PATCH] In .: * src/DataViews/_PlaceView.py: Add sidebar filter. * src/FilterEditor/_EditRule.py: Support place filters. * src/FilterEditor/_FilterEditor.py: Support place filters. * src/FilterEditor/_ShowResults.py: Support place filters. * src/Filters/_GenericFilter.py: Support place filters. * src/Filters/SideBar/__init__.py: Expose new module. * src/Filters/SideBar/Makefile.am (pkgdata_PYTHON): Ship new file. * src/Filters/SideBar/_PlaceSidebarFilter.py: Add module. * src/Filters/Rules/Place/Makefile.am (pkgdata_PYTHON): Ship new files. * src/Filters/Rules/Place/_AllPlaces.py: Add module. * src/Filters/Rules/Place/_HasIdOf.py: Add module. * src/Filters/Rules/Place/_HasNoteMatchingSubstringOf.py: Add module. * src/Filters/Rules/Place/_HasNoteRegexp.py: Add module. * src/Filters/Rules/Place/_MatchesFilter.py: Add module. * src/Filters/Rules/Place/_RegExpIdOf.py: Add module. * src/Filters/Rules/Place/_PlacePrivate.py: Add module. * src/Filters/Rules/Place/_HasPlace.py: Add module. * src/Filters/Rules/Place/__init__.py (editor_rule_list): Expose new module. In po: 2006-08-06 Alex Roitman * POTFILES.in: Add new files. svn: r7142 --- gramps2/ChangeLog | 20 +++ gramps2/po/ChangeLog | 3 + gramps2/po/POTFILES.in | 9 + gramps2/src/DataViews/_PlaceView.py | 32 +++- gramps2/src/FilterEditor/_EditRule.py | 2 + gramps2/src/FilterEditor/_FilterEditor.py | 2 + gramps2/src/FilterEditor/_ShowResults.py | 7 + gramps2/src/Filters/Rules/Place/Makefile.am | 8 + gramps2/src/Filters/Rules/Place/_AllPlaces.py | 46 ++++++ gramps2/src/Filters/Rules/Place/_HasIdOf.py | 46 ++++++ .../Place/_HasNoteMatchingSubstringOf.py | 46 ++++++ .../src/Filters/Rules/Place/_HasNoteRegexp.py | 44 +++++ gramps2/src/Filters/Rules/Place/_HasPlace.py | 87 ++++++++++ .../src/Filters/Rules/Place/_MatchesFilter.py | 47 ++++++ .../src/Filters/Rules/Place/_PlacePrivate.py | 44 +++++ .../src/Filters/Rules/Place/_RegExpIdOf.py | 50 ++++++ gramps2/src/Filters/Rules/Place/__init__.py | 19 +++ gramps2/src/Filters/SideBar/Makefile.am | 3 +- .../Filters/SideBar/_PlaceSidebarFilter.py | 156 ++++++++++++++++++ gramps2/src/Filters/SideBar/__init__.py | 1 + gramps2/src/Filters/_GenericFilter.py | 17 ++ 21 files changed, 686 insertions(+), 3 deletions(-) create mode 100644 gramps2/src/Filters/Rules/Place/_AllPlaces.py create mode 100644 gramps2/src/Filters/Rules/Place/_HasIdOf.py create mode 100644 gramps2/src/Filters/Rules/Place/_HasNoteMatchingSubstringOf.py create mode 100644 gramps2/src/Filters/Rules/Place/_HasNoteRegexp.py create mode 100644 gramps2/src/Filters/Rules/Place/_HasPlace.py create mode 100644 gramps2/src/Filters/Rules/Place/_MatchesFilter.py create mode 100644 gramps2/src/Filters/Rules/Place/_PlacePrivate.py create mode 100644 gramps2/src/Filters/Rules/Place/_RegExpIdOf.py create mode 100644 gramps2/src/Filters/SideBar/_PlaceSidebarFilter.py diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 4e21f2f8d..a6565de98 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,24 @@ 2006-08-06 Alex Roitman + * src/DataViews/_PlaceView.py: Add sidebar filter. + * src/FilterEditor/_EditRule.py: Support place filters. + * src/FilterEditor/_FilterEditor.py: Support place filters. + * src/FilterEditor/_ShowResults.py: Support place filters. + * src/Filters/_GenericFilter.py: Support place filters. + * src/Filters/SideBar/__init__.py: Expose new module. + * src/Filters/SideBar/Makefile.am (pkgdata_PYTHON): Ship new file. + * src/Filters/SideBar/_PlaceSidebarFilter.py: Add module. + * src/Filters/Rules/Place/Makefile.am (pkgdata_PYTHON): Ship new files. + * src/Filters/Rules/Place/_AllPlaces.py: Add module. + * src/Filters/Rules/Place/_HasIdOf.py: Add module. + * src/Filters/Rules/Place/_HasNoteMatchingSubstringOf.py: Add module. + * src/Filters/Rules/Place/_HasNoteRegexp.py: Add module. + * src/Filters/Rules/Place/_MatchesFilter.py: Add module. + * src/Filters/Rules/Place/_RegExpIdOf.py: Add module. + * src/Filters/Rules/Place/_PlacePrivate.py: Add module. + * src/Filters/Rules/Place/_HasPlace.py: Add module. + * src/Filters/Rules/Place/__init__.py (editor_rule_list): Expose + new module. + * src/GrampsDb/_GrampsBSDDB.py (GrampsBSDDB.close): Try to reset the log sequence numbers to make grdb file portable. * data/gramps.schemas.in: Typo. diff --git a/gramps2/po/ChangeLog b/gramps2/po/ChangeLog index 9c76269b2..1606b960f 100644 --- a/gramps2/po/ChangeLog +++ b/gramps2/po/ChangeLog @@ -1,3 +1,6 @@ +2006-08-06 Alex Roitman + * POTFILES.in: Add new files. + 2006-08-05 Alex Roitman * POTFILES.in: Add new files. diff --git a/gramps2/po/POTFILES.in b/gramps2/po/POTFILES.in index d04253ff4..343da00fa 100644 --- a/gramps2/po/POTFILES.in +++ b/gramps2/po/POTFILES.in @@ -520,6 +520,14 @@ src/Filters/Rules/Event/_HasNoteMatchingSubstringOf.py src/Filters/Rules/Event/__init__.py # Filters.Rules.Place package +src/Filters/Rules/Place/_AllPlaces.py +src/Filters/Rules/Place/_HasIdOf.py +src/Filters/Rules/Place/_HasNoteMatchingSubstringOf.py +src/Filters/Rules/Place/_HasNoteRegexp.py +src/Filters/Rules/Place/_HasPlace.py +src/Filters/Rules/Place/_MatchesFilter.py +src/Filters/Rules/Place/_PlacePrivate.py +src/Filters/Rules/Place/_RegExpIdOf.py src/Filters/Rules/Place/__init__.py # Filters.Rules.Source package @@ -545,6 +553,7 @@ src/Filters/SideBar/_FamilySidebarFilter.py src/Filters/SideBar/_PersonSidebarFilter.py src/Filters/SideBar/_SidebarFilter.py src/Filters/SideBar/_SourceSidebarFilter.py +src/Filters/SideBar/_PlaceSidebarFilter.py # FilterEditor package src/FilterEditor/_FilterEditor.py diff --git a/gramps2/src/DataViews/_PlaceView.py b/gramps2/src/DataViews/_PlaceView.py index 4eb1248e5..2d5207685 100644 --- a/gramps2/src/DataViews/_PlaceView.py +++ b/gramps2/src/DataViews/_PlaceView.py @@ -37,9 +37,11 @@ import DisplayModels import Utils import Errors import Bookmarks - +import const +import Config from Editors import EditPlace, DeletePlaceQuery from QuestionDialog import QuestionDialog, ErrorDialog +from Filters.SideBar import PlaceSidebarFilter #------------------------------------------------------------------------- # @@ -87,7 +89,11 @@ class PlaceView(PageView.ListView): len(column_names), DisplayModels.PlaceModel, signal_map, dbstate.db.get_place_bookmarks(), Bookmarks.PlaceBookmarks, - multiple=True) + multiple=True, + filter_class=PlaceSidebarFilter) + + Config.client.notify_add("/apps/gramps/interface/filter", + self.filter_toggle) def get_bookmarks(self): return self.dbstate.db.get_place_bookmarks() @@ -101,6 +107,27 @@ class PlaceView(PageView.ListView): self.add_action('GoogleMaps', gtk.STOCK_JUMP_TO, _('_Google Maps'), callback=self.google, tip=_("Attempt to map location on Google Maps")) + self.add_action('FilterEdit', None, _('Place 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('Place',const.custom_filters, + self.dbstate,self.uistate) + except Errors.WindowActiveError: + pass def google(self, obj): import GrampsDisplay @@ -156,6 +183,7 @@ class PlaceView(PageView.ListView): + diff --git a/gramps2/src/FilterEditor/_EditRule.py b/gramps2/src/FilterEditor/_EditRule.py index f051fcd31..e34f18a2b 100644 --- a/gramps2/src/FilterEditor/_EditRule.py +++ b/gramps2/src/FilterEditor/_EditRule.py @@ -375,6 +375,8 @@ class EditRule(ManagedWindow.ManagedWindow): class_list = Rules.Event.editor_rule_list elif self.space == 'Source': class_list = Rules.Source.editor_rule_list + elif self.space == 'Place': + class_list = Rules.Place.editor_rule_list for class_obj in class_list: arglist = class_obj.labels diff --git a/gramps2/src/FilterEditor/_FilterEditor.py b/gramps2/src/FilterEditor/_FilterEditor.py index fc19076b7..23729c286 100644 --- a/gramps2/src/FilterEditor/_FilterEditor.py +++ b/gramps2/src/FilterEditor/_FilterEditor.py @@ -176,3 +176,5 @@ class FilterEditor(ManagedWindow.ManagedWindow): return self.db.get_event_handles() elif self.space == 'Source': return self.db.get_source_handles() + elif self.space == 'Place': + return self.db.get_place_handles() diff --git a/gramps2/src/FilterEditor/_ShowResults.py b/gramps2/src/FilterEditor/_ShowResults.py index 042ef38fa..0015fc9cf 100644 --- a/gramps2/src/FilterEditor/_ShowResults.py +++ b/gramps2/src/FilterEditor/_ShowResults.py @@ -119,6 +119,10 @@ class ShowResults(ManagedWindow.ManagedWindow): source = self.db.get_source_from_handle(handle) name = source.get_title() gid = source.get_gramps_id() + elif self.space == 'Place': + place = self.db.get_place_from_handle(handle) + name = place.get_title() + gid = place.get_gramps_id() return (name,gid) def sort_val_from_handle(self, handle): @@ -135,4 +139,7 @@ class ShowResults(ManagedWindow.ManagedWindow): elif self.space == 'Source': name = self.db.get_source_from_handle(handle).get_title() sortname = locale.strxfrm(name) + elif self.space == 'Place': + name = self.db.get_place_from_handle(handle).get_title() + sortname = locale.strxfrm(name) return (sortname,handle) diff --git a/gramps2/src/Filters/Rules/Place/Makefile.am b/gramps2/src/Filters/Rules/Place/Makefile.am index 551818bba..309c4d1af 100644 --- a/gramps2/src/Filters/Rules/Place/Makefile.am +++ b/gramps2/src/Filters/Rules/Place/Makefile.am @@ -3,6 +3,14 @@ pkgdatadir = $(datadir)/@PACKAGE@/Filters/Rules/Place pkgdata_PYTHON = \ + _AllPlaces.py\ + _HasIdOf.py\ + _HasNoteMatchingSubstringOf.py\ + _HasNoteRegexp.py\ + _HasPlace.py\ + _MatchesFilter.py\ + _PlacePrivate.py\ + _RegExpIdOf.py\ __init__.py pkgpyexecdir = @pkgpyexecdir@/Filters/Rules/Place diff --git a/gramps2/src/Filters/Rules/Place/_AllPlaces.py b/gramps2/src/Filters/Rules/Place/_AllPlaces.py new file mode 100644 index 000000000..a763c2fdd --- /dev/null +++ b/gramps2/src/Filters/Rules/Place/_AllPlaces.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 AllPlaces(Everything): + """Matches Everyone""" + + name = _('Every place') + description = _('Matches every place in the database') diff --git a/gramps2/src/Filters/Rules/Place/_HasIdOf.py b/gramps2/src/Filters/Rules/Place/_HasIdOf.py new file mode 100644 index 000000000..f2c8fb575 --- /dev/null +++ b/gramps2/src/Filters/Rules/Place/_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 place with a specific GRAMPS ID""" + + name = _('Place with ') + description = _("Matches a place with a specified GRAMPS ID") diff --git a/gramps2/src/Filters/Rules/Place/_HasNoteMatchingSubstringOf.py b/gramps2/src/Filters/Rules/Place/_HasNoteMatchingSubstringOf.py new file mode 100644 index 000000000..9605cad42 --- /dev/null +++ b/gramps2/src/Filters/Rules/Place/_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): + """Places having notes containing """ + + name = _('Places having notes containing ') + description = _("Matches places whose notes contain text " + "matching a substring") + diff --git a/gramps2/src/Filters/Rules/Place/_HasNoteRegexp.py b/gramps2/src/Filters/Rules/Place/_HasNoteRegexp.py new file mode 100644 index 000000000..4c94ff4c7 --- /dev/null +++ b/gramps2/src/Filters/Rules/Place/_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 + +#------------------------------------------------------------------------- +# "Places having notes that contain a substring" +#------------------------------------------------------------------------- +class HasNoteRegexp(HasNoteRegexBase): + + name = _('Places having notes containing ') + description = _("Matches places whose notes contain text " + "matching a regular expression") diff --git a/gramps2/src/Filters/Rules/Place/_HasPlace.py b/gramps2/src/Filters/Rules/Place/_HasPlace.py new file mode 100644 index 000000000..a52590e9d --- /dev/null +++ b/gramps2/src/Filters/Rules/Place/_HasPlace.py @@ -0,0 +1,87 @@ +# +# 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 HasPlace(Rule): + """Rule that checks for a place with a particular value""" + + + labels = [ _('Name:'), + _('Church Parish:'), + _('ZIP/Postal Code:'), + _('City:'), + _('County:'), + _('State:'), + _('Country:'), + ] + name = _('Places matching parameters') + description = _("Matches places with particular parameters") + category = _('General filters') + + def apply(self,db,place): + if not self.match_substring(0,place.get_title()): + return False + + for loc in [place.main_loc] + place.alt_loc: + if not loc: + # Empty mail locaiton does not contradict any parameters + return True + + if not self.match_substring(1,loc.get_parish()): + continue + + if not self.match_substring(2,loc.get_postal_code()): + continue + + if not self.match_substring(3,loc.get_city()): + continue + + if not self.match_substring(4,loc.get_county()): + continue + + if not self.match_substring(5,loc.get_state()): + continue + + if not self.match_substring(6,loc.get_country()): + continue + + return True + + return False diff --git a/gramps2/src/Filters/Rules/Place/_MatchesFilter.py b/gramps2/src/Filters/Rules/Place/_MatchesFilter.py new file mode 100644 index 000000000..c2705cad2 --- /dev/null +++ b/gramps2/src/Filters/Rules/Place/_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 = _('Places matching the ') + description = _("Matches places macthed by the specified filter name") + namespace = 'Place' diff --git a/gramps2/src/Filters/Rules/Place/_PlacePrivate.py b/gramps2/src/Filters/Rules/Place/_PlacePrivate.py new file mode 100644 index 000000000..64394d095 --- /dev/null +++ b/gramps2/src/Filters/Rules/Place/_PlacePrivate.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 PlacePrivate(IsPrivate): + """Place marked private""" + + name = _('Places marked private') + description = _("Matches places that are indicated as private") diff --git a/gramps2/src/Filters/Rules/Place/_RegExpIdOf.py b/gramps2/src/Filters/Rules/Place/_RegExpIdOf.py new file mode 100644 index 000000000..48a045d5b --- /dev/null +++ b/gramps2/src/Filters/Rules/Place/_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 place whose GRAMPS ID + matches regular expression. + """ + + name = _('Places with matching regular expression') + description = _("Matches places whose GRAMPS ID matches " + "the regular expression") diff --git a/gramps2/src/Filters/Rules/Place/__init__.py b/gramps2/src/Filters/Rules/Place/__init__.py index b73e6d238..97f3a1968 100644 --- a/gramps2/src/Filters/Rules/Place/__init__.py +++ b/gramps2/src/Filters/Rules/Place/__init__.py @@ -25,3 +25,22 @@ Package providing filter rules for GRAMPS. """ __author__ = "Don Allingham" + +from _AllPlaces import AllPlaces +from _HasIdOf import HasIdOf +from _RegExpIdOf import RegExpIdOf +from _HasNoteRegexp import HasNoteRegexp +from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf +from _PlacePrivate import PlacePrivate +from _MatchesFilter import MatchesFilter +from _HasPlace import HasPlace + +editor_rule_list = [ + AllPlaces, + HasIdOf, + RegExpIdOf, + HasNoteRegexp, + HasNoteMatchingSubstringOf, + PlacePrivate, + MatchesFilter, +] diff --git a/gramps2/src/Filters/SideBar/Makefile.am b/gramps2/src/Filters/SideBar/Makefile.am index a0e194574..dced63166 100644 --- a/gramps2/src/Filters/SideBar/Makefile.am +++ b/gramps2/src/Filters/SideBar/Makefile.am @@ -8,7 +8,8 @@ pkgdata_PYTHON = \ __init__.py \ _SidebarFilter.py \ _PersonSidebarFilter.py\ - _SourceSidebarFilter.py + _SourceSidebarFilter.py\ + _PlaceSidebarFilter.py pkgpyexecdir = @pkgpyexecdir@/Filters/SideBar pkgpythondir = @pkgpythondir@/Filters/SideBar diff --git a/gramps2/src/Filters/SideBar/_PlaceSidebarFilter.py b/gramps2/src/Filters/SideBar/_PlaceSidebarFilter.py new file mode 100644 index 000000000..91957aa51 --- /dev/null +++ b/gramps2/src/Filters/SideBar/_PlaceSidebarFilter.py @@ -0,0 +1,156 @@ +# +# 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.Place import * + +GenericPlaceFilter = GenericFilterFactory('Place') +#------------------------------------------------------------------------- +# +# PersonSidebarFilter class +# +#------------------------------------------------------------------------- +class PlaceSidebarFilter(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_parish = gtk.Entry() + self.filter_zip = gtk.Entry() + self.filter_city = gtk.Entry() + self.filter_county = gtk.Entry() + self.filter_state = gtk.Entry() + self.filter_country = gtk.Entry() + + self.filter_note = gtk.Entry() + + self.filter_regex = gtk.CheckButton(_('Use regular expressions')) + + all = GenericPlaceFilter() + all.set_name(_("None")) + all.add_rule(Rules.Place.AllPlaces([])) + + 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('Place', [all])) + self.generic.set_active(0) + + self.add_text_entry(_('ID'), self.filter_id) + self.add_text_entry(_('Name'), self.filter_title) + self.add_text_entry(_('Church parish'), self.filter_parish) + self.add_text_entry(_('Zip/Postal code'), self.filter_zip) + self.add_text_entry(_('City'), self.filter_city) + self.add_text_entry(_('County'), self.filter_county) + self.add_text_entry(_('State'), self.filter_state) + self.add_text_entry(_('Country'), self.filter_country) + 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_parish.set_text('') + self.filter_zip.set_text('') + self.filter_city.set_text('') + self.filter_county.set_text('') + self.filter_state.set_text('') + self.filter_country.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() + parish = unicode(self.filter_parish.get_text()).strip() + zipc = unicode(self.filter_zip.get_text()).strip() + city = unicode(self.filter_city.get_text()).strip() + county = unicode(self.filter_county.get_text()).strip() + state = unicode(self.filter_state.get_text()).strip() + country = unicode(self.filter_country.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 parish or zipc or city or county + or state or country or note or regex or gen) + if empty: + generic_filter = None + else: + generic_filter = GenericPlaceFilter() + if gid: + if regex: + rule = RegExpIdOf([gid]) + else: + rule = HasIdOf([gid]) + generic_filter.add_rule(rule) + + rule = HasPlace([title,parish,zipc,city,county,state,country]) + 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 176488006..50b61c70e 100644 --- a/gramps2/src/Filters/SideBar/__init__.py +++ b/gramps2/src/Filters/SideBar/__init__.py @@ -31,3 +31,4 @@ from _PersonSidebarFilter import PersonSidebarFilter from _FamilySidebarFilter import FamilySidebarFilter from _EventSidebarFilter import EventSidebarFilter from _SourceSidebarFilter import SourceSidebarFilter +from _PlaceSidebarFilter import PlaceSidebarFilter diff --git a/gramps2/src/Filters/_GenericFilter.py b/gramps2/src/Filters/_GenericFilter.py index 17f11734f..2e04ec5c3 100644 --- a/gramps2/src/Filters/_GenericFilter.py +++ b/gramps2/src/Filters/_GenericFilter.py @@ -246,6 +246,21 @@ class GenericSourceFilter(GenericFilter): def find_from_handle(self, db, handle): return db.get_source_from_handle(handle) +class GenericPlaceFilter(GenericFilter): + + def __init__(self, source=None): + GenericFilter.__init__(self, source) + + def get_cursor(db, self): + return db.get_place_cursor() + + def make_obj(self): + return RelLib.Place() + + def find_from_handle(self, db, handle): + return db.get_place_from_handle(handle) + + def GenericFilterFactory(namespace): if namespace == 'Person': return GenericFilter @@ -255,3 +270,5 @@ def GenericFilterFactory(namespace): return GenericEventFilter elif namespace == 'Source': return GenericSourceFilter + elif namespace == 'Place': + return GenericPlaceFilter