diff --git a/ChangeLog b/ChangeLog index 59dc38106..9bf9ef818 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ 2006-12-18 Don Allingham + * src/DataViews/_PersonView.py: exact search for gender (bug #633) + * src/DisplayModels/_PeopleModel.py: exact search for gender (bug #633) + * src/Filters/_SearchFilter.py: exact search for gender (bug #633) + * src/Filters/__init__.py: export ExactSearchFilter * src/DataViews/_EventView.py: disable items with readonly db (bug #771) * src/DataViews/_PersonView.py: disable items with readonly db (bug #771) * src/DataViews/_RelationView.py: disable items with readonly db (bug #771) diff --git a/src/DataViews/_PersonView.py b/src/DataViews/_PersonView.py index 3de61a977..3a9759a74 100644 --- a/src/DataViews/_PersonView.py +++ b/src/DataViews/_PersonView.py @@ -721,7 +721,12 @@ class PersonView(PageView.PersonNavView): else: col,text,inv = self.search_bar.get_value() func = lambda x: self.model.on_get_value(x, col) or u"" - data_filter = SearchFilter(func, text, inv) + print col, PeopleModel.PeopleModel._GENDER_COL + if col == PeopleModel.PeopleModel._GENDER_COL: + data_filter = ExactSearchFilter(func, text, inv) + else: + data_filter = SearchFilter(func, text, inv) + print data_filter self.model.clear_cache() for node in handle_list: diff --git a/src/DisplayModels/_PeopleModel.py b/src/DisplayModels/_PeopleModel.py index f5e8bf8a1..dd1f50c08 100644 --- a/src/DisplayModels/_PeopleModel.py +++ b/src/DisplayModels/_PeopleModel.py @@ -65,7 +65,7 @@ import DateHandler import ToolTips import GrampsLocale import Config -from Filters import SearchFilter +from Filters import SearchFilter, ExactSearchFilter from Lru import LRU _CACHE_SIZE = 250 @@ -169,7 +169,12 @@ class PeopleModel(gtk.GenericTreeModel): text = filter_info[1][1] inv = filter_info[1][2] func = lambda x: self.on_get_value(x, col) or u"" - data_filter = SearchFilter(func, text, inv) + + if col == self._GENDER_COL: + data_filter = ExactSearchFilter(func, text, inv) + else: + data_filter = SearchFilter(func, text, inv) + self._build_data = self._build_search_sub else: data_filter = filter_info[1] diff --git a/src/Filters/_SearchFilter.py b/src/Filters/_SearchFilter.py index 0fb8c3b9c..f1c78ca04 100644 --- a/src/Filters/_SearchFilter.py +++ b/src/Filters/_SearchFilter.py @@ -18,7 +18,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id:$ +# $Id$ """ Package providing filtering framework for GRAMPS. @@ -32,4 +32,13 @@ class SearchFilter: def match(self, handle): return self.invert ^ (self.func(handle).upper().find(self.text) != -1) + +class ExactSearchFilter(SearchFilter): + def __init__(self, func, text, invert): + self.func = func + self.text = text.upper() + self.invert = invert + + def match(self, handle): + return self.invert ^ (self.func(handle).upper() == self.text.strip()) diff --git a/src/Filters/__init__.py b/src/Filters/__init__.py index 6542b734d..48fe22417 100644 --- a/src/Filters/__init__.py +++ b/src/Filters/__init__.py @@ -54,4 +54,4 @@ from _FilterComboBox import FilterComboBox from _FilterMenu import build_filter_menu, build_filter_model from _FilterStore import FilterStore from _SearchBar import SearchBar -from _SearchFilter import SearchFilter +from _SearchFilter import SearchFilter, ExactSearchFilter