diff --git a/src/FilterEditor/_EditRule.py b/src/FilterEditor/_EditRule.py index dca278c76..7e34e657a 100644 --- a/src/FilterEditor/_EditRule.py +++ b/src/FilterEditor/_EditRule.py @@ -2,6 +2,8 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2007 Donald N. Allingham +# Copyright (C) 2007-2008 Brian G. Matherly +# Copyright (C) 2008 Benny Malengier # # 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 @@ -469,9 +471,13 @@ class EditRule(ManagedWindow.ManagedWindow): l.show() if v == _('Place:'): t = MyPlaces([]) - elif v == _('Reference count:'): + elif v in [_('Reference count:'), + _('Number of instances:') + ]: t = MyInteger(0, 999) - elif v == _('Reference count must be:'): + elif v in [_('Reference count must be:'), + _('Number must be') + ]: t = MyLesserEqualGreater() elif v == _('Number of generations:'): t = MyInteger(1, 32) diff --git a/src/Filters/Rules/Person/_HasGallery.py b/src/Filters/Rules/Person/_HasGallery.py index f8633b5e4..ab6a8091e 100644 --- a/src/Filters/Rules/Person/_HasGallery.py +++ b/src/Filters/Rules/Person/_HasGallery.py @@ -40,5 +40,5 @@ from Filters.Rules._HasGalleryBase import HasGalleryBase class HavePhotos(HasGalleryBase): """Rule that checks for person who has media object reference""" - name = _('People with media') - description = _("Matches people with media object in the gallery") + name = _('People with media') + description = _("Matches people with a certain number of items in the gallery") diff --git a/src/Filters/Rules/_HasGalleryBase.py b/src/Filters/Rules/_HasGalleryBase.py index 04238f5ca..f13d2bdd5 100755 --- a/src/Filters/Rules/_HasGalleryBase.py +++ b/src/Filters/Rules/_HasGalleryBase.py @@ -40,9 +40,27 @@ from Filters.Rules import Rule class HasGalleryBase(Rule): """Objects who have Media Object""" - name = _('Object with Media reference') - description = _("Matches objects with reference in the gallery") + labels = [ _('Number of instances:'), _('Number must be')] + name = _('Object with Media reference') + description = _("Matches objects with certain number of items in the gallery") category = _('General filters') + def prepare(self, db): + # things we want to do just once, not for every handle + if self.list[1] == _('lesser than'): + self.count_type = 0 + elif self.list[1] == _('greater than'): + self.count_type = 2 + else: + self.count_type = 1 # "equal to" + + self.userSelectedCount = int(self.list[0]) + def apply(self, db, obj): - return len( obj.get_media_list()) > 0 + count = len( obj.get_media_list()) + if self.count_type == 0: # "lesser than" + return count < self.userSelectedCount + elif self.count_type == 2: # "greater than" + return count > self.userSelectedCount + # "equal to" + return count == self.userSelectedCount diff --git a/src/Filters/Rules/_HasNoteBase.py b/src/Filters/Rules/_HasNoteBase.py index 35909d3e3..92c5fa4fa 100755 --- a/src/Filters/Rules/_HasNoteBase.py +++ b/src/Filters/Rules/_HasNoteBase.py @@ -41,9 +41,28 @@ from Filters.Rules._Rule import Rule class HasNoteBase(Rule): """Objects having notes""" - name = _('Object with note') - description = _("Matches objects that have a note") + labels = [ _('Number of instances:'), _('Number must be')] + name = _('Object with notes') + description = _("Matches objects that have a certain number of notes") category = _('General filters') + def prepare(self, db): + # things we want to do just once, not for every handle + if self.list[1] == _('lesser than'): + self.count_type = 0 + elif self.list[1] == _('greater than'): + self.count_type = 2 + else: + self.count_type = 1 # "equal to" + + self.userSelectedCount = int(self.list[0]) + + def apply(self, db, obj): - return len( obj.get_note_list()) > 0 + count = len( obj.get_note_list()) + if self.count_type == 0: # "lesser than" + return count < self.userSelectedCount + elif self.count_type == 2: # "greater than" + return count > self.userSelectedCount + # "equal to" + return count == self.userSelectedCount diff --git a/src/Filters/Rules/_HasSourceBase.py b/src/Filters/Rules/_HasSourceBase.py index 6be2b03ee..d52bdb851 100755 --- a/src/Filters/Rules/_HasSourceBase.py +++ b/src/Filters/Rules/_HasSourceBase.py @@ -41,9 +41,27 @@ from Filters.Rules._Rule import Rule class HasSourceBase(Rule): """Objects having notes""" - name = _('Objects with source') - description = _("Matches objects that have a source") + labels = [ _('Number of instances:'), _('Number must be')] + name = _('Objects with sources') + description = _("Matches objects that have a certain number of sources") category = _('General filters') + def prepare(self, db): + # things we want to do just once, not for every handle + if self.list[1] == _('lesser than'): + self.count_type = 0 + elif self.list[1] == _('greater than'): + self.count_type = 2 + else: + self.count_type = 1 # "equal to" + + self.userSelectedCount = int(self.list[0]) + def apply(self, db, obj): - return len( obj.get_source_references()) > 0 + count = len(obj.get_source_references()) + if self.count_type == 0: # "lesser than" + return count < self.userSelectedCount + elif self.count_type == 2: # "greater than" + return count > self.userSelectedCount + # "equal to" + return count == self.userSelectedCount