diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index b36105d37..c5c9a349e 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,23 @@ 2006-08-09 Alex Roitman + * src/DataViews/_PlaceView.py: Add filter sidebar. + * src/FilterEditor/_ShowResults.py: Support media filters. + * src/FilterEditor/_EditRule.py: Support media filters. + * src/FilterEditor/_FilterEditor.py: Support media filters. + * src/Filters/_GenericFilter.py: Support media filters. + * src/Filters/SideBar/Makefile.am (pkgdata_PYTHON): Ship new file. + * src/Filters/SideBar/__init__.py: Expose new module. + * src/Filters/SideBar/_MediaSidebarFilter.py: Add module. + * src/Filters/Rules/Media/Makefile.am (pkgdata_PYTHON): Ship new files. + * src/Filters/Rules/Media/_HasIdOf.py: Add module. + * src/Filters/Rules/Media/_HasNoteMatchingSubstringOf.py: Add module. + * src/Filters/Rules/Media/_HasNoteRegexp.py: Add module. + * src/Filters/Rules/Media/_MatchesFilter.py: Add module. + * src/Filters/Rules/Media/_RegExpIdOf.py: Add module. + * src/Filters/Rules/Media/_MediaPrivate.py: Add module. + * src/Filters/Rules/Media/__init__.py: Expose new modules. + * src/Filters/Rules/Media/_AllMedia.py: Add module. + * src/Filters/Rules/Media/_HasMedia.py: Add module. + * src/Filters/SideBar/Makefile.am (pkgdatadir): Typo. 2006-08-08 Brian Matherly diff --git a/gramps2/po/ChangeLog b/gramps2/po/ChangeLog index 2d1b1ccd8..398ffeefb 100644 --- a/gramps2/po/ChangeLog +++ b/gramps2/po/ChangeLog @@ -1,3 +1,6 @@ +2006-08-09 Alex Roitman + * POTFILES.in: Add new files. + 2006-08-07 Alex Roitman * POTFILES.in: Add new files. diff --git a/gramps2/po/POTFILES.in b/gramps2/po/POTFILES.in index 8aae90099..6ee1affc8 100644 --- a/gramps2/po/POTFILES.in +++ b/gramps2/po/POTFILES.in @@ -542,6 +542,14 @@ src/Filters/Rules/Source/_HasIdOf.py src/Filters/Rules/Source/__init__.py # Filters.Rules.Media package +src/Filters/Rules/Media/_AllMedia.py +src/Filters/Rules/Media/_HasIdOf.py +src/Filters/Rules/Media/_HasMedia.py +src/Filters/Rules/Media/_HasNoteMatchingSubstringOf.py +src/Filters/Rules/Media/_HasNoteRegexp.py +src/Filters/Rules/Media/_MatchesFilter.py +src/Filters/Rules/Media/_MediaPrivate.py +src/Filters/Rules/Media/_RegExpIdOf.py src/Filters/Rules/Media/__init__.py # Filters.Rules.Repository package @@ -562,6 +570,7 @@ src/Filters/SideBar/_PersonSidebarFilter.py src/Filters/SideBar/_SidebarFilter.py src/Filters/SideBar/_SourceSidebarFilter.py src/Filters/SideBar/_PlaceSidebarFilter.py +src/Filters/SideBar/_MediaSidebarFilter.py src/Filters/SideBar/_RepoSidebarFilter.py # FilterEditor package diff --git a/gramps2/src/DataViews/_MediaView.py b/gramps2/src/DataViews/_MediaView.py index 2ddcf6bfb..5121ffec5 100644 --- a/gramps2/src/DataViews/_MediaView.py +++ b/gramps2/src/DataViews/_MediaView.py @@ -42,11 +42,13 @@ import PageView import DisplayModels import ImgManip import const +import Config import Utils import Bookmarks from Editors import EditMedia import Errors from QuestionDialog import QuestionDialog +from Filters.SideBar import MediaSidebarFilter column_names = [ _('Title'), @@ -81,7 +83,10 @@ class MediaView(PageView.ListView): self, _('Media'), dbstate, uistate, column_names,len(column_names), DisplayModels.MediaModel, signal_map, dbstate.db.get_media_bookmarks(), - Bookmarks.MediaBookmarks) + Bookmarks.MediaBookmarks,filter_class=MediaSidebarFilter) + + Config.client.notify_add("/apps/gramps/interface/filter", + self.filter_toggle) def get_bookmarks(self): return self.dbstate.db.get_media_bookmarks() @@ -90,7 +95,27 @@ class MediaView(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, _('Media 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('Media',const.custom_filters, + self.dbstate,self.uistate) + except Errors.WindowActiveError: + pass def column_editor(self,obj): import ColumnOrder @@ -151,6 +176,7 @@ class MediaView(PageView.ListView): + diff --git a/gramps2/src/FilterEditor/_EditRule.py b/gramps2/src/FilterEditor/_EditRule.py index 502d1aa4b..64ba4aa49 100644 --- a/gramps2/src/FilterEditor/_EditRule.py +++ b/gramps2/src/FilterEditor/_EditRule.py @@ -225,18 +225,18 @@ class MyID(gtk.HBox): 'Event' : _('Event'), 'Place' : _('Place'), 'Source' : _('Source'), - 'MediaObject' : _('Media Object'), + 'Media' : _('Media Object'), 'Repository' : _('Repository'), } - def __init__(self, dbstate, uistate, track, obj_class='Person'): + def __init__(self, dbstate, uistate, track, namespace='Person'): gtk.HBox.__init__(self,False,6) self.dbstate = dbstate self.db = dbstate.db self.uistate = uistate self.track = track - self.obj_class = obj_class + self.namespace = namespace self.entry = gtk.Entry() self.entry.show() self.button = gtk.Button() @@ -247,13 +247,17 @@ class MyID(gtk.HBox): self.add(self.button) self.tooltips = gtk.Tooltips() self.tooltips.set_tip(self.button,_('Select %s from a list') - % self.obj_name[obj_class]) + % self.obj_name[namespace]) self.tooltips.enable() self.show() self.set_text('') def button_press(self,obj): - selector = selector_factory(self.obj_class) + if self.namespace == 'Media': + obj_class = 'MediaObject' + else: + obj_class = self.namespace + selector = selector_factory(obj_class) inst = selector(self.dbstate, self.uistate, self.track) val = inst.run() if val == None: @@ -265,25 +269,25 @@ class MyID(gtk.HBox): return unicode(self.entry.get_text()) def name_from_gramps_id(self,gramps_id): - if self.obj_class == 'Person': + if self.namespace == 'Person': person = self.db.get_person_from_gramps_id(gramps_id) name = _nd.display_name(person.get_primary_name()) - elif self.obj_class == 'Family': + elif self.namespace == 'Family': family = self.db.get_family_from_gramps_id(gramps_id) name = Utils.family_name(family, self.db) - elif self.obj_class == 'Event': + elif self.namespace == 'Event': event = self.db.get_event_from_gramps_id(gramps_id) name = str(event.get_type) - elif self.obj_class == 'Place': + elif self.namespace == 'Place': place = self.db.get_place_from_gramps_id(gramps_id) name = place.get_title() - elif self.obj_class == 'Source': + elif self.namespace == 'Source': source = self.db.get_source_from_gramps_id(gramps_id) name = source.get_title() - elif self.obj_class == 'MediaObject': + elif self.namespace == 'Media': obj = self.db.get_object_from_gramps_id(gramps_id) name = obj.get_path() - elif self.obj_class == 'Repository': + elif self.namespace == 'Repository': repo = self.db.get_repository_from_gramps_id(gramps_id) name = repo.get_name() return name @@ -377,6 +381,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 == 'Media': + class_list = Rules.Media.editor_rule_list elif self.space == 'Repository': class_list = Rules.Repository.editor_rule_list diff --git a/gramps2/src/FilterEditor/_FilterEditor.py b/gramps2/src/FilterEditor/_FilterEditor.py index d244bb374..2d568ec1d 100644 --- a/gramps2/src/FilterEditor/_FilterEditor.py +++ b/gramps2/src/FilterEditor/_FilterEditor.py @@ -178,5 +178,7 @@ class FilterEditor(ManagedWindow.ManagedWindow): return self.db.get_source_handles() elif self.space == 'Place': return self.db.get_place_handles() + elif self.space == 'Media': + return self.db.get_media_object_handles() elif self.space == 'Repository': return self.db.get_repository_handles() diff --git a/gramps2/src/FilterEditor/_ShowResults.py b/gramps2/src/FilterEditor/_ShowResults.py index a81412755..ef4ff68cc 100644 --- a/gramps2/src/FilterEditor/_ShowResults.py +++ b/gramps2/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 == 'Media': + obj = self.db.get_object_from_handle(handle) + name = obj.get_description() + gid = obj.get_gramps_id() elif self.space == 'Repository': repo = self.db.get_repository_from_handle(handle) name = repo.get_name() @@ -146,6 +150,9 @@ 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 == 'Media': + name = self.db.get_object_from_handle(handle).get_description() + sortname = locale.strxfrm(name) elif self.space == 'Repository': name = self.db.get_repository_from_handle(handle).get_name() sortname = locale.strxfrm(name) diff --git a/gramps2/src/Filters/Rules/Media/Makefile.am b/gramps2/src/Filters/Rules/Media/Makefile.am index e4fae5432..de5c30d84 100644 --- a/gramps2/src/Filters/Rules/Media/Makefile.am +++ b/gramps2/src/Filters/Rules/Media/Makefile.am @@ -3,6 +3,14 @@ pkgdatadir = $(datadir)/@PACKAGE@/Filters/Rules/Media pkgdata_PYTHON = \ + _AllMedia.py\ + _HasIdOf.py\ + _HasMedia.py\ + _HasNoteMatchingSubstringOf.py\ + _HasNoteRegexp.py\ + _MatchesFilter.py\ + _MediaPrivate.py\ + _RegExpIdOf.py\ __init__.py pkgpyexecdir = @pkgpyexecdir@/Filters/Rules/Media diff --git a/gramps2/src/Filters/Rules/Media/_AllMedia.py b/gramps2/src/Filters/Rules/Media/_AllMedia.py new file mode 100644 index 000000000..e420c0e93 --- /dev/null +++ b/gramps2/src/Filters/Rules/Media/_AllMedia.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 AllMedia(Everything): + """Matches Everyone""" + + name = _('Every media object') + description = _('Matches every media object in the database') diff --git a/gramps2/src/Filters/Rules/Media/_HasIdOf.py b/gramps2/src/Filters/Rules/Media/_HasIdOf.py new file mode 100644 index 000000000..28ebdf945 --- /dev/null +++ b/gramps2/src/Filters/Rules/Media/_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 media object with a specific GRAMPS ID""" + + name = _('Media object with ') + description = _("Matches a media object with a specified GRAMPS ID") diff --git a/gramps2/src/Filters/Rules/Media/_HasMedia.py b/gramps2/src/Filters/Rules/Media/_HasMedia.py new file mode 100644 index 000000000..dedb1ac11 --- /dev/null +++ b/gramps2/src/Filters/Rules/Media/_HasMedia.py @@ -0,0 +1,79 @@ +# +# 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 +# +#------------------------------------------------------------------------- +import DateHandler +from Filters.Rules._Rule import Rule +from Filters.Rules._RuleUtils import loose_date_cmp + +#------------------------------------------------------------------------- +# +# HasEvent +# +#------------------------------------------------------------------------- +class HasMedia(Rule): + """Rule that checks for a media with a particular value""" + + + labels = [ _('Title:'), + _('Type:'), + _('Path:'), + _('Date:'), + ] + name = _('Media objects matching parameters') + description = _("Matches media objects with particular parameters") + category = _('General filters') + + def prepare(self,db): + self.date = None + try: + if self.list[3]: + self.date = DateHandler.parser.parse(self.list[3]) + except: + pass + + def apply(self,db,obj): + if not self.match_substring(0,obj.get_description()): + return False + + if not self.match_substring(1,obj.get_mime_type()): + return False + + if not self.match_substring(2,obj.get_path()): + return False + + if self.date: + if not loose_date_cmp(self.date,obj.get_date_object()): + return False + + return True diff --git a/gramps2/src/Filters/Rules/Media/_HasNoteMatchingSubstringOf.py b/gramps2/src/Filters/Rules/Media/_HasNoteMatchingSubstringOf.py new file mode 100644 index 000000000..7b94724c9 --- /dev/null +++ b/gramps2/src/Filters/Rules/Media/_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 + +#------------------------------------------------------------------------- +# "Media having notes that contain a substring" +#------------------------------------------------------------------------- +class HasNoteMatchingSubstringOf(HasNoteSubstrBase): + """Media having notes containing """ + + name = _('Media objects having notes containing ') + description = _("Matches media objects whose notes contain text " + "matching a substring") + diff --git a/gramps2/src/Filters/Rules/Media/_HasNoteRegexp.py b/gramps2/src/Filters/Rules/Media/_HasNoteRegexp.py new file mode 100644 index 000000000..be52f3de9 --- /dev/null +++ b/gramps2/src/Filters/Rules/Media/_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 + +#------------------------------------------------------------------------- +# "Media having notes that contain a substring" +#------------------------------------------------------------------------- +class HasNoteRegexp(HasNoteRegexBase): + + name = _('Media objects having notes ' + 'containing ') + description = _("Matches media objects whose notes contain text " + "matching a regular expression") diff --git a/gramps2/src/Filters/Rules/Media/_MatchesFilter.py b/gramps2/src/Filters/Rules/Media/_MatchesFilter.py new file mode 100644 index 000000000..ab19acc5f --- /dev/null +++ b/gramps2/src/Filters/Rules/Media/_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 = _('Media objects matching the ') + description = _("Matches media objects macthed by the " + "specified filter name") + namespace = 'MediaObject' diff --git a/gramps2/src/Filters/Rules/Media/_MediaPrivate.py b/gramps2/src/Filters/Rules/Media/_MediaPrivate.py new file mode 100644 index 000000000..86337824f --- /dev/null +++ b/gramps2/src/Filters/Rules/Media/_MediaPrivate.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 + +#------------------------------------------------------------------------- +# "Media marked private" +#------------------------------------------------------------------------- +class MediaPrivate(IsPrivate): + """Media marked private""" + + name = _('Media objects marked private') + description = _("Matches Media objects that are indicated as private") diff --git a/gramps2/src/Filters/Rules/Media/_RegExpIdOf.py b/gramps2/src/Filters/Rules/Media/_RegExpIdOf.py new file mode 100644 index 000000000..6d55f08f3 --- /dev/null +++ b/gramps2/src/Filters/Rules/Media/_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 media object whose GRAMPS ID + matches regular expression. + """ + + name = _('Media Objects with matching regular expression') + description = _("Matches media objects whose GRAMPS ID matches " + "the regular expression") diff --git a/gramps2/src/Filters/Rules/Media/__init__.py b/gramps2/src/Filters/Rules/Media/__init__.py index b73e6d238..c1ac1d73c 100644 --- a/gramps2/src/Filters/Rules/Media/__init__.py +++ b/gramps2/src/Filters/Rules/Media/__init__.py @@ -25,3 +25,22 @@ Package providing filter rules for GRAMPS. """ __author__ = "Don Allingham" + +from _AllMedia import AllMedia +from _HasIdOf import HasIdOf +from _RegExpIdOf import RegExpIdOf +from _HasNoteRegexp import HasNoteRegexp +from _HasNoteMatchingSubstringOf import HasNoteMatchingSubstringOf +from _MediaPrivate import MediaPrivate +from _MatchesFilter import MatchesFilter +from _HasMedia import HasMedia + +editor_rule_list = [ + AllMedia, + HasIdOf, + RegExpIdOf, + HasNoteRegexp, + HasNoteMatchingSubstringOf, + MediaPrivate, + MatchesFilter, +] diff --git a/gramps2/src/Filters/SideBar/Makefile.am b/gramps2/src/Filters/SideBar/Makefile.am index 36a84710b..eb3262037 100644 --- a/gramps2/src/Filters/SideBar/Makefile.am +++ b/gramps2/src/Filters/SideBar/Makefile.am @@ -10,6 +10,7 @@ pkgdata_PYTHON = \ _PersonSidebarFilter.py\ _SourceSidebarFilter.py\ _PlaceSidebarFilter.py\ + _MediaSidebarFilter.py\ _RepoSidebarFilter.py pkgpyexecdir = @pkgpyexecdir@/Filters/SideBar diff --git a/gramps2/src/Filters/SideBar/_MediaSidebarFilter.py b/gramps2/src/Filters/SideBar/_MediaSidebarFilter.py new file mode 100644 index 000000000..616118ae3 --- /dev/null +++ b/gramps2/src/Filters/SideBar/_MediaSidebarFilter.py @@ -0,0 +1,144 @@ +# +# 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.Media import * + +GenericMediaFilter = GenericFilterFactory('Media') +#------------------------------------------------------------------------- +# +# PersonSidebarFilter class +# +#------------------------------------------------------------------------- +class MediaSidebarFilter(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_type = gtk.Entry() + self.filter_path = gtk.Entry() + self.filter_date = gtk.Entry() + + self.filter_note = gtk.Entry() + + self.filter_regex = gtk.CheckButton(_('Use regular expressions')) + + all = GenericMediaFilter() + all.set_name(_("None")) + all.add_rule(Rules.Media.AllMedia([])) + + 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('MediaObject', [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(_('Type'), self.filter_type) + self.add_text_entry(_('Path'), self.filter_path) + self.add_text_entry(_('Date'), self.filter_date) + 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_type.set_text('') + self.filter_path.set_text('') + self.filter_date.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() + mime = unicode(self.filter_type.get_text()).strip() + path = unicode(self.filter_path.get_text()).strip() + date = unicode(self.filter_date.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 mime or path or date + or note or regex or gen) + if empty: + generic_filter = None + else: + generic_filter = GenericMediaFilter() + if gid: + if regex: + rule = RegExpIdOf([gid]) + else: + rule = HasIdOf([gid]) + generic_filter.add_rule(rule) + + rule = HasMedia([title,mime,path,date]) + 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 3b7385ea1..eaf5639d1 100644 --- a/gramps2/src/Filters/SideBar/__init__.py +++ b/gramps2/src/Filters/SideBar/__init__.py @@ -32,4 +32,5 @@ from _FamilySidebarFilter import FamilySidebarFilter from _EventSidebarFilter import EventSidebarFilter from _SourceSidebarFilter import SourceSidebarFilter from _PlaceSidebarFilter import PlaceSidebarFilter +from _MediaSidebarFilter import MediaSidebarFilter from _RepoSidebarFilter import RepoSidebarFilter diff --git a/gramps2/src/Filters/_GenericFilter.py b/gramps2/src/Filters/_GenericFilter.py index af53c964d..ef0561b11 100644 --- a/gramps2/src/Filters/_GenericFilter.py +++ b/gramps2/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 GenericMediaFilter(GenericFilter): + + def __init__(self, source=None): + GenericFilter.__init__(self, source) + + def get_cursor(db, self): + return db.get_media_cursor() + + def make_obj(self): + return RelLib.MediaObject() + + def find_from_handle(self, db, handle): + return db.get_object_from_handle(handle) + class GenericRepoFilter(GenericFilter): def __init__(self, source=None): @@ -286,5 +300,7 @@ def GenericFilterFactory(namespace): return GenericSourceFilter elif namespace == 'Place': return GenericPlaceFilter + elif namespace == 'Media': + return GenericMediaFilter elif namespace == 'Repository': return GenericRepoFilter