Search bar completion

svn: r6607
This commit is contained in:
Don Allingham 2006-05-10 16:08:56 +00:00
parent 99db21d8fe
commit e019db2e41
8 changed files with 130 additions and 61 deletions

View File

@ -1,3 +1,12 @@
2006-05-10 Don Allingham <don@gramps-project.org>
* src/ViewManager.py: remove debug statement
* src/PeopleModel.py: use SearchFilter
* src/DisplayModels.py: handle search filter
* src/PageView.py: search bar support
* src/Filters/_SearchBar.py: added
* src/Filters/_SearchFilter.py: remove SearchFilter to separate file
* src/Filters/__init__.py: added SearchBar
2006-05-10 Alex Roitman <shura@gramps-project.org> 2006-05-10 Alex Roitman <shura@gramps-project.org>
* src/GrampsDb/_DbUtils.py (db_copy): Use batch transaction. * src/GrampsDb/_DbUtils.py (db_copy): Use batch transaction.
* src/GrampsDb/_GrampsBSDDB.py (transaction_begin): Proper indentation. * src/GrampsDb/_GrampsBSDDB.py (transaction_begin): Proper indentation.

View File

@ -49,6 +49,7 @@ import RelLib
import ToolTips import ToolTips
import GrampsLocale import GrampsLocale
import const import const
from Filters import SearchFilter
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -67,7 +68,8 @@ def sfunc(a,b):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class BaseModel(gtk.GenericTreeModel): class BaseModel(gtk.GenericTreeModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,tooltip_column=None): def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING,
tooltip_column=None, search=None):
gtk.GenericTreeModel.__init__(self) gtk.GenericTreeModel.__init__(self)
self.prev_handle = None self.prev_handle = None
self.prev_data = None self.prev_data = None
@ -75,6 +77,15 @@ class BaseModel(gtk.GenericTreeModel):
self.db = db self.db = db
self.sort_func = self.smap[scol] self.sort_func = self.smap[scol]
self.sort_col = scol self.sort_col = scol
if search:
col = search[0]
text = search[1]
func = lambda x: self.on_get_value(x, col)
self.search = SearchFilter(func, text)
else:
self.search = None
self.reverse = (order == gtk.SORT_DESCENDING) self.reverse = (order == gtk.SORT_DESCENDING)
self.tooltip_column = tooltip_column self.tooltip_column = tooltip_column
self.rebuild_data() self.rebuild_data()
@ -101,7 +112,11 @@ class BaseModel(gtk.GenericTreeModel):
def rebuild_data(self): def rebuild_data(self):
if self.db.is_open(): if self.db.is_open():
self.datalist = self.sort_keys() if self.search:
self.datalist = [h for h in self.sort_keys()\
if self.search.match(h)]
else:
self.datalist = self.sort_keys()
i = 0 i = 0
self.indexlist = {} self.indexlist = {}
for key in self.datalist: for key in self.datalist:
@ -211,7 +226,7 @@ class BaseModel(gtk.GenericTreeModel):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class SourceModel(BaseModel): class SourceModel(BaseModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None):
self.map = db.get_raw_source_data self.map = db.get_raw_source_data
self.gen_cursor = db.get_source_cursor self.gen_cursor = db.get_source_cursor
self.fmap = [ self.fmap = [
@ -232,7 +247,7 @@ class SourceModel(BaseModel):
self.column_pubinfo, self.column_pubinfo,
self.sort_change, self.sort_change,
] ]
BaseModel.__init__(self,db,scol,order,tooltip_column=7) BaseModel.__init__(self,db,scol,order,tooltip_column=7,search=search)
def on_get_n_columns(self): def on_get_n_columns(self):
return len(self.fmap)+1 return len(self.fmap)+1
@ -280,7 +295,7 @@ class SourceModel(BaseModel):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class PlaceModel(BaseModel): class PlaceModel(BaseModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING,search=None):
self.gen_cursor = db.get_place_cursor self.gen_cursor = db.get_place_cursor
self.map = db.get_raw_place_data self.map = db.get_raw_place_data
self.fmap = [ self.fmap = [
@ -312,7 +327,8 @@ class PlaceModel(BaseModel):
self.column_change, self.column_change,
self.column_handle, self.column_handle,
] ]
BaseModel.__init__(self,db,scol,order,tooltip_column=12) BaseModel.__init__(self, db, scol, order, tooltip_column=12,
search=search)
def on_get_n_columns(self): def on_get_n_columns(self):
return len(self.fmap)+1 return len(self.fmap)+1
@ -393,7 +409,7 @@ class PlaceModel(BaseModel):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class FamilyModel(BaseModel): class FamilyModel(BaseModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
self.gen_cursor = db.get_family_cursor self.gen_cursor = db.get_family_cursor
self.map = db.get_raw_family_data self.map = db.get_raw_family_data
self.fmap = [ self.fmap = [
@ -414,7 +430,8 @@ class FamilyModel(BaseModel):
self.column_handle, self.column_handle,
self.column_tooltip self.column_tooltip
] ]
BaseModel.__init__(self,db,scol,order,tooltip_column=6) BaseModel.__init__(self, db, scol, order, tooltip_column=6,
search=search)
def on_get_n_columns(self): def on_get_n_columns(self):
return len(self.fmap)+1 return len(self.fmap)+1
@ -482,7 +499,7 @@ class FamilyModel(BaseModel):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class MediaModel(BaseModel): class MediaModel(BaseModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
self.gen_cursor = db.get_media_cursor self.gen_cursor = db.get_media_cursor
self.map = db.get_raw_object_data self.map = db.get_raw_object_data
@ -505,7 +522,8 @@ class MediaModel(BaseModel):
self.column_date, self.column_date,
self.column_handle, self.column_handle,
] ]
BaseModel.__init__(self,db,scol,order,tooltip_column=7) BaseModel.__init__(self, db, scol, order, tooltip_column=7,
search=search)
def on_get_n_columns(self): def on_get_n_columns(self):
return len(self.fmap)+1 return len(self.fmap)+1
@ -564,7 +582,7 @@ class MediaModel(BaseModel):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class EventModel(BaseModel): class EventModel(BaseModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
self.gen_cursor = db.get_event_cursor self.gen_cursor = db.get_event_cursor
self.map = db.get_raw_event_data self.map = db.get_raw_event_data
@ -589,7 +607,8 @@ class EventModel(BaseModel):
self.sort_change, self.sort_change,
self.column_handle, self.column_handle,
] ]
BaseModel.__init__(self,db,scol,order,tooltip_column=8) BaseModel.__init__(self, db, scol, order, tooltip_column=8,
search=search)
def on_get_n_columns(self): def on_get_n_columns(self):
return len(self.fmap)+1 return len(self.fmap)+1
@ -644,7 +663,7 @@ class EventModel(BaseModel):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class RepositoryModel(BaseModel): class RepositoryModel(BaseModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): def __init__(self, db, scol=0, order=gtk.SORT_ASCENDING, search=None):
self.gen_cursor = db.get_repository_cursor self.gen_cursor = db.get_repository_cursor
self.get_handles = db.get_repository_handles self.get_handles = db.get_repository_handles
self.map = db.get_raw_repository_data self.map = db.get_raw_repository_data
@ -681,7 +700,8 @@ class RepositoryModel(BaseModel):
self.column_handle, self.column_handle,
] ]
BaseModel.__init__(self,db,scol,order,tooltip_column=12) BaseModel.__init__(self, db, scol, order, tooltip_column=12,
search=search)
def on_get_n_columns(self): def on_get_n_columns(self):
return len(self.fmap)+1 return len(self.fmap)+1

View File

@ -18,7 +18,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# #
# $Id: _FilterWidget.py 6521 2006-05-03 01:02:54Z rshura $ # $Id:$
""" """
Package providing filtering framework for GRAMPS. Package providing filtering framework for GRAMPS.
@ -31,15 +31,11 @@ Package providing filtering framework for GRAMPS.
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gtk import gtk
#------------------------------------------------------------------------- _RETURN = gtk.gdk.keyval_from_name("Return")
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# FilterWidget # SearchBar
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class SearchBar: class SearchBar:
@ -51,10 +47,14 @@ class SearchBar:
def build( self): def build( self):
self.filterbar = gtk.HBox() self.filterbar = gtk.HBox()
self.filterbar.set_spacing(4) self.filterbar.set_spacing(4)
self.filter_text = gtk.Entry()
self.filter_list = gtk.ComboBox() self.filter_list = gtk.ComboBox()
self.filter_text = gtk.Entry()
self.filter_text.connect('key-press-event',self.key_press)
self.filter_button = gtk.Button(stock=gtk.STOCK_FIND) self.filter_button = gtk.Button(stock=gtk.STOCK_FIND)
self.filter_button.connect( 'clicked',self.apply_filter_clicked) self.filter_button.connect( 'clicked',self.apply_filter_clicked)
self.filterbar.pack_start(self.filter_list,False) self.filterbar.pack_start(self.filter_list,False)
self.filterbar.pack_start(self.filter_text,True) self.filterbar.pack_start(self.filter_text,True)
self.filterbar.pack_end(self.filter_button,False) self.filterbar.pack_end(self.filter_button,False)
@ -75,11 +75,13 @@ class SearchBar:
self.filter_list.set_model(self.filter_model) self.filter_list.set_model(self.filter_model)
self.filter_list.set_active(0) self.filter_list.set_active(0)
self.filter_list.connect('changed',self.on_filter_name_changed)
def key_press(self, obj, event):
if event.keyval == _RETURN and not event.state:
self.on_apply_callback()
return False
def apply_filter_clicked(self, obj): def apply_filter_clicked(self, obj):
print "apply_filter_clicked"
print self.on_apply_callback
self.on_apply_callback() self.on_apply_callback()
def get_value(self): def get_value(self):
@ -87,20 +89,13 @@ class SearchBar:
index = self.filter_list.get_active() index = self.filter_list.get_active()
return (index, text) return (index, text)
def on_filter_name_changed(self,obj):
pass
def apply_filter(self,current_model=None): def apply_filter(self,current_model=None):
self.uistate.status_text(_('Updating display...')) self.uistate.status_text(_('Updating display...'))
self.on_apply_callback() self.on_apply_callback()
self.uistate.modify_statusbar() self.uistate.modify_statusbar()
def get_filter( self): def show(self):
print "get_filter"
return None
def show( self):
self.filterbar.show() self.filterbar.show()
def hide( self): def hide(self):
self.filterbar.hide() self.filterbar.hide()

View File

@ -0,0 +1,34 @@
#
# 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:$
"""
Package providing filtering framework for GRAMPS.
"""
class SearchFilter:
def __init__(self, func, text):
self.func = func
self.text = text.upper()
def match(self, handle):
return self.func(handle).upper().find(self.text) != -1

View File

@ -56,3 +56,4 @@ from _FilterComboBox import FilterComboBox
from _FilterMenu import build_filter_menu from _FilterMenu import build_filter_menu
from _FilterStore import FilterStore from _FilterStore import FilterStore
from _SearchBar import SearchBar from _SearchBar import SearchBar
from _SearchFilter import SearchFilter

View File

@ -42,9 +42,10 @@ from gtk.gdk import ACTION_COPY, BUTTON1_MASK
# GRAMPS # GRAMPS
# #
#---------------------------------------------------------------- #----------------------------------------------------------------
import Config
import TreeTips import TreeTips
import Bookmarks import Bookmarks
from Filters import FilterWidget, Rules from Filters import SearchBar
import const import const
NAVIGATION_NONE = -1 NAVIGATION_NONE = -1
@ -471,8 +472,8 @@ class ListView(BookMarkView):
self.vbox.set_border_width(0) self.vbox.set_border_width(0)
self.vbox.set_spacing(4) self.vbox.set_spacing(4)
self.generic_filter_widget = FilterWidget( self.uistate, self.build_tree) self.search_bar = SearchBar(self.uistate, self.build_tree)
filter_box = self.generic_filter_widget.build() filter_box = self.search_bar.build()
self.list = gtk.TreeView() self.list = gtk.TreeView()
self.list.set_rules_hint(True) self.list.set_rules_hint(True)
@ -531,13 +532,10 @@ class ListView(BookMarkView):
""" """
Builds the default filters and add them to the filter menu. Builds the default filters and add them to the filter menu.
""" """
default_filters = [ cols = []
[Rules.Everything, []], for pair in [pair for pair in self.column_order() if pair[0]]:
[Rules.HasTextMatchingSubstringOf, ['',0,0]], cols.append(self.colinfo[pair[1]])
[Rules.HasTextMatchingRegexpOf, ['',0,1]], self.search_bar.setup_filter(cols)
[Rules.IsPrivate, []],
]
self.generic_filter_widget.setup_filter( default_filters)
def goto_handle(self, handle): def goto_handle(self, handle):
if not self.dbstate.active or self.inactive: if not self.dbstate.active or self.inactive:
@ -559,7 +557,6 @@ class ListView(BookMarkView):
# disable the inactive flag # disable the inactive flag
self.inactive = False self.inactive = False
def column_clicked(self,obj,data): def column_clicked(self,obj,data):
if self.sort_col != data: if self.sort_col != data:
order = gtk.SORT_ASCENDING order = gtk.SORT_ASCENDING
@ -571,7 +568,14 @@ class ListView(BookMarkView):
order = gtk.SORT_DESCENDING order = gtk.SORT_DESCENDING
self.sort_col = data self.sort_col = data
handle = self.first_selected() handle = self.first_selected()
self.model = self.make_model(self.dbstate.db, self.sort_col,order)
if Config.get(Config.FILTER):
search = (0, '')
else:
search = self.search_bar.get_value()
self.model = self.make_model(self.dbstate.db, self.sort_col, order,
search=search)
self.list.set_model(self.model) self.list.set_model(self.model)
colmap = self.column_order() colmap = self.column_order()
@ -604,7 +608,14 @@ class ListView(BookMarkView):
def build_tree(self): def build_tree(self):
if self.active: if self.active:
self.model = self.make_model(self.dbstate.db,self.sort_col)
if Config.get(Config.FILTER):
search = (0, '')
else:
search = self.search_bar.get_value()
self.model = self.make_model(self.dbstate.db,self.sort_col,
search=search)
self.list.set_model(self.model) self.list.set_model(self.model)
self.selection = self.list.get_selection() self.selection = self.list.get_selection()
@ -618,7 +629,14 @@ class ListView(BookMarkView):
def change_db(self,db): def change_db(self,db):
for sig in self.signal_map: for sig in self.signal_map:
db.connect(sig, self.signal_map[sig]) db.connect(sig, self.signal_map[sig])
self.model = self.make_model(self.dbstate.db,0)
if Config.get(Config.FILTER):
search = (0, '')
else:
search = self.search_bar.get_value()
self.model = self.make_model(self.dbstate.db, 0, search=search)
self.list.set_model(self.model) self.list.set_model(self.model)
self.build_columns() self.build_columns()
self.bookmarks.update_bookmarks(self.get_bookmarks()) self.bookmarks.update_bookmarks(self.get_bookmarks())
@ -687,7 +705,7 @@ class ListView(BookMarkView):
def filter_toggle(self,obj): def filter_toggle(self,obj):
if obj.get_active(): if obj.get_active():
self.generic_filter_widget.show() self.search_bar.show()
else: else:
self.generic_filter_widget.hide() self.search_bar.hide()

View File

@ -63,12 +63,13 @@ import gtk
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import const
from RelLib import * from RelLib import *
import NameDisplay import NameDisplay
import DateHandler import DateHandler
import ToolTips import ToolTips
import GrampsLocale import GrampsLocale
import const from Filters import SearchFilter
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -119,14 +120,6 @@ else:
return mylist return mylist
class Search:
def __init__(self, func, text):
self.func = func
self.text = text
def match(self, handle):
return self.func(handle).find(self.text) != -1
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# PeopleModel # PeopleModel
@ -159,7 +152,7 @@ class PeopleModel(gtk.GenericTreeModel):
col = search[0] col = search[0]
text = search[1] text = search[1]
func = lambda x: self.on_get_value(x, col) func = lambda x: self.on_get_value(x, col)
data_filter = Search(func, text) data_filter = SearchFilter(func, text)
self.rebuild_data(data_filter, skip) self.rebuild_data(data_filter, skip)
def rebuild_data(self, data_filter=None, skip=[]): def rebuild_data(self, data_filter=None, skip=[]):

View File

@ -605,7 +605,6 @@ class ViewManager:
hbox.pack_start(image,False,False) hbox.pack_start(image,False,False)
hbox.set_spacing(4) hbox.set_spacing(4)
print use_text
if use_text: if use_text:
label = gtk.Label(page_title) label = gtk.Label(page_title)
label.show() label.show()