From 40ec7acd41d8a3090c57819964766e8bdec8dcaa Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 10 May 2006 20:56:22 +0000 Subject: [PATCH] inverted searches svn: r6611 --- ChangeLog | 10 +++++++++- src/DataViews/_PersonView.py | 7 +++---- src/DisplayModels.py | 5 +++-- src/Filters/_SearchBar.py | 35 ++++++++++++++++++++++++++--------- src/Filters/_SearchFilter.py | 5 +++-- src/PageView.py | 4 ++-- src/PeopleModel.py | 5 +++-- 7 files changed, 49 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b7228f70..f83cc5957 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-05-10 Don Allingham + * src/DataViews/_PersonView.py: support for inverted searchs + * src/PeopleModel.py: support for inverted searchs + * src/DisplayModel.py: support for inverted searchs + * src/PageView.py: support for inverted searchs, correct col index + * src/Filters/_SearchBar.py: support for inverted searchs + * src/Filters/_SearchFilter.py: support for inverted searchs + 2006-05-10 Alex Roitman * src/GrampsDb/_ReadGedcom.py (func_person_attr): Typos. @@ -7,7 +15,7 @@ * src/DisplayModels.py: handle search filter * src/PageView.py: search bar support * src/Filters/_SearchBar.py: remove SearchFilter to separate file, - fix status bar message + fix status bar message, improved buttons. * src/Filters/_SearchFilter.py: added * src/Filters/__init__.py: added SearchBar diff --git a/src/DataViews/_PersonView.py b/src/DataViews/_PersonView.py index 0c314dc6e..ace759aee 100644 --- a/src/DataViews/_PersonView.py +++ b/src/DataViews/_PersonView.py @@ -333,7 +333,6 @@ class PersonView(PageView.PersonNavView): db.connect('person-delete', self.person_removed) db.connect('person-rebuild', self.build_tree) self.build_tree() - #self.search_bar.apply_filter() self.goto_active_person() self.bookmarks.update_bookmarks(db.get_bookmarks()) if self.active: @@ -399,11 +398,11 @@ class PersonView(PageView.PersonNavView): """ cols = [] - cols.append(_("Name")) + cols.append((_("Name"),0)) for pair in self.dbstate.db.get_person_column_order(): if not pair[0]: continue - cols.append(column_names[pair[1]]) + cols.append((column_names[pair[1]],pair[1])) self.search_bar.setup_filter(cols) @@ -415,7 +414,7 @@ class PersonView(PageView.PersonNavView): if self.active: if Config.get(Config.FILTER): - search = (0, '') + search = (0, '', False) else: search = self.search_bar.get_value() diff --git a/src/DisplayModels.py b/src/DisplayModels.py index 52a9a7459..7a2d30054 100644 --- a/src/DisplayModels.py +++ b/src/DisplayModels.py @@ -81,8 +81,9 @@ class BaseModel(gtk.GenericTreeModel): if search: col = search[0] text = search[1] - func = lambda x: self.on_get_value(x, col) - self.search = SearchFilter(func, text) + inv = search[2] + func = lambda x: self.on_get_value(x, col) or u"" + self.search = SearchFilter(func, text, inv) else: self.search = None diff --git a/src/Filters/_SearchBar.py b/src/Filters/_SearchBar.py index 98630445c..75fd6fffb 100644 --- a/src/Filters/_SearchBar.py +++ b/src/Filters/_SearchBar.py @@ -49,6 +49,7 @@ class SearchBar: self.filterbar = gtk.HBox() self.filterbar.set_spacing(4) self.filter_list = gtk.ComboBox() + self.filter_list.connect('changed', self.filter_changed) self.filter_text = gtk.Entry() self.filter_text.connect('key-press-event',self.key_press) @@ -69,20 +70,34 @@ class SearchBar: return self.filterbar - def setup_filter( self, column_names ): + def setup_filter( self, column_data ): + old_value = self.filter_list.get_active() + cell = gtk.CellRendererText() self.filter_list.clear() self.filter_list.pack_start(cell,True) self.filter_list.add_attribute(cell,'text',0) - self.filter_model = gtk.ListStore(str) - - for col in column_names: - rule = _("Search %s") % col - self.filter_model.append(row=[rule]) + self.filter_model = gtk.ListStore(str, int, bool) + + maxval = 0 + for col,index in column_data: + rule = _("%s contains") % col + self.filter_model.append(row=[rule,index,False]) + maxval += 1 + rule = _("%s does not contain") % col + self.filter_model.append(row=[rule,index,True]) + maxval += 1 self.filter_list.set_model(self.filter_model) - self.filter_list.set_active(0) + if old_value == -1 or old_value >= maxval: + self.filter_list.set_active(0) + else: + self.filter_list.set_active(old_value) + + def filter_changed(self, obj): + self.filter_button.set_sensitive(True) + self.clear_button.set_sensitive(True) def text_changed(self, obj): text = obj.get_text() @@ -112,8 +127,10 @@ class SearchBar: def get_value(self): text = self.filter_text.get_text().strip() - index = self.filter_list.get_active() - return (index, text) + node = self.filter_list.get_active_iter() + index = self.filter_model.get_value(node,1) + inv = self.filter_model.get_value(node,2) + return (index, text, inv) def apply_filter(self,current_model=None): self.apply_text = self.filter_text.get_text() diff --git a/src/Filters/_SearchFilter.py b/src/Filters/_SearchFilter.py index dc36bde50..0fb8c3b9c 100644 --- a/src/Filters/_SearchFilter.py +++ b/src/Filters/_SearchFilter.py @@ -25,10 +25,11 @@ Package providing filtering framework for GRAMPS. """ class SearchFilter: - def __init__(self, func, text): + def __init__(self, func, text, invert): self.func = func self.text = text.upper() + self.invert = invert def match(self, handle): - return self.func(handle).upper().find(self.text) != -1 + return self.invert ^ (self.func(handle).upper().find(self.text) != -1) diff --git a/src/PageView.py b/src/PageView.py index 0f6043ff6..2b17e4b05 100644 --- a/src/PageView.py +++ b/src/PageView.py @@ -534,7 +534,7 @@ class ListView(BookMarkView): """ cols = [] for pair in [pair for pair in self.column_order() if pair[0]]: - cols.append(self.colinfo[pair[1]]) + cols.append((self.colinfo[pair[1]],pair[1])) self.search_bar.setup_filter(cols) def goto_handle(self, handle): @@ -570,7 +570,7 @@ class ListView(BookMarkView): handle = self.first_selected() if Config.get(Config.FILTER): - search = (0, '') + search = (0, '', False) else: search = self.search_bar.get_value() diff --git a/src/PeopleModel.py b/src/PeopleModel.py index 13b84336f..df8c0df88 100644 --- a/src/PeopleModel.py +++ b/src/PeopleModel.py @@ -151,8 +151,9 @@ class PeopleModel(gtk.GenericTreeModel): if search: col = search[0] text = search[1] - func = lambda x: self.on_get_value(x, col) - data_filter = SearchFilter(func, text) + inv = search[2] + func = lambda x: self.on_get_value(x, col) or u"" + data_filter = SearchFilter(func, text, inv) self.rebuild_data(data_filter, skip) def rebuild_data(self, data_filter=None, skip=[]):