gramps/gramps2/src/Find.py

220 lines
6.9 KiB
Python
Raw Normal View History

2002-10-20 19:55:16 +05:30
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000 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
#
"""interface for opening a find person dialog for gramps
"""
__author__ = 'Don Allingham'
#-------------------------------------------------------------------------
#
# python modules
#
#-------------------------------------------------------------------------
import string
#-------------------------------------------------------------------------
#
# Gnome modules
#
#-------------------------------------------------------------------------
import gtk
2003-03-23 08:56:55 +05:30
import gtk.glade
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# gramps modules
#
#-------------------------------------------------------------------------
2003-03-23 08:56:55 +05:30
import const
import Utils
2003-08-17 07:44:33 +05:30
from gettext import gettext as _
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# FindBase
#
#-------------------------------------------------------------------------
class FindBase:
"""Opens find person dialog for gramps"""
def __init__(self,task,name,db,valid_map=None):
2002-10-20 19:55:16 +05:30
"""Opens a dialog box instance that allows users to
search for a person.
task - function to call to change the active person"""
2003-04-04 11:18:25 +05:30
self.t = type(u' ')
2002-10-20 19:55:16 +05:30
self.db = db
self.task = task
2003-08-17 07:44:33 +05:30
self.glade = gtk.glade.XML(const.gladeFile,"find","gramps")
2003-03-23 08:56:55 +05:30
self.glade.signal_autoconnect({
'on_next_clicked' : self.on_next_clicked,
'on_back_clicked' : self.on_prev_clicked,
'on_close_clicked' : self.on_close_clicked,
})
self.top = self.glade.get_widget('find')
self.top.connect('delete_event',self.on_destroy)
2003-03-23 08:56:55 +05:30
self.entry = self.glade.get_widget('entry')
2003-04-04 11:18:25 +05:30
self.forward_button = self.glade.get_widget('forward')
self.back_button = self.glade.get_widget('back')
2003-03-23 08:56:55 +05:30
Utils.set_titles(self.top, self.glade.get_widget('title'), name)
2003-04-09 08:59:08 +05:30
self.list = None
2003-04-04 11:18:25 +05:30
self.index = 0
self.visible = 1
self.valid = valid_map
2003-04-04 11:18:25 +05:30
2002-10-20 19:55:16 +05:30
def get_value(self,id):
2003-04-04 11:18:25 +05:30
return id
2002-10-20 19:55:16 +05:30
def advance(self,func):
* src/PlaceView.py: Make sure to add new place after edit * src/AddMedia.py: unicode conversion from gtk.Entry * src/AddSpouse.py: unicode conversion from gtk.Entry * src/AddrEdit.py: unicode conversion from gtk.Entry * src/AttrEdit.py: unicode conversion from gtk.Entry * src/AutoComp.py: unicode conversion from gtk.Entry * src/ChooseParents.py: unicode conversion from gtk.Entry * src/DateEdit.py: unicode conversion from gtk.Entry * src/EditPerson.py: unicode conversion from gtk.Entry * src/EditPlace.py: unicode conversion from gtk.Entry * src/EditSource.py: unicode conversion from gtk.Entry * src/EventEdit.py: unicode conversion from gtk.Entry * src/Find.py: unicode conversion from gtk.Entry * src/GrampsCfg.py: unicode conversion from gtk.Entry * src/ImageSelect.py: unicode conversion from gtk.Entry * src/LocEdit.py: unicode conversion from gtk.Entry * src/Marriage.py: unicode conversion from gtk.Entry * src/MergeData.py: unicode conversion from gtk.Entry * src/NameEdit.py: unicode conversion from gtk.Entry * src/PeopleView.py: unicode conversion from gtk.Entry * src/Report.py: unicode conversion from gtk.Entry * src/SelectChild.py: unicode conversion from gtk.Entry * src/Sources.py: unicode conversion from gtk.Entry * src/StartupDialog.py: unicode conversion from gtk.Entry * src/StyleEditor.py: unicode conversion from gtk.Entry * src/UrlEdit.py: unicode conversion from gtk.Entry * src/Utils.py: unicode conversion from gtk.Entry * src/VersionControl.py: unicode conversion from gtk.Entry * src/Witness.py: unicode conversion from gtk.Entry svn: r2534
2003-12-17 10:53:16 +05:30
text = unicode(self.entry.get_text().upper())
2003-04-04 11:18:25 +05:30
orow = self.index
2002-10-20 19:55:16 +05:30
func()
2003-04-04 11:18:25 +05:30
while self.index != orow:
vals = self.list[self.index]
id = vals[1]
name = vals[0]
2002-10-20 19:55:16 +05:30
if id == None:
func()
continue
if self.valid and not self.valid.has_key(id):
func()
continue
2003-04-04 11:18:25 +05:30
if string.find(name.upper(),text) >= 0:
self.back_button.set_sensitive(0)
self.forward_button.set_sensitive(0)
self.task(self.get_value(id))
self.back_button.set_sensitive(1)
self.forward_button.set_sensitive(1)
2002-10-20 19:55:16 +05:30
return
func()
def forward(self):
2003-04-04 11:18:25 +05:30
self.index = self.index + 1
if self.index == len(self.list):
self.index = 0
2002-10-20 19:55:16 +05:30
def backward(self):
2003-04-04 11:18:25 +05:30
self.index = self.index - 1
if self.index < 0:
2003-04-23 06:15:07 +05:30
self.index = len(self.list)-1
2002-10-20 19:55:16 +05:30
def on_close_clicked(self,obj):
"""Destroys the window in response to a close window button press"""
self.visible = 0
self.top.hide()
def on_destroy(self,obj,event):
self.on_close_clicked(obj)
return 1
2002-10-20 19:55:16 +05:30
def show(self):
2003-04-23 08:27:38 +05:30
self.top.window.raise_()
self.top.show()
self.entry.grab_focus ()
2002-10-20 19:55:16 +05:30
def on_next_clicked(self,obj):
"""Advances to the next person that matches the dialog text"""
self.advance(self.forward)
def on_prev_clicked(self,obj):
"""Advances to the previous person that matches the dialog text"""
self.advance(self.backward)
#-------------------------------------------------------------------------
#
# FindPerson
#
#-------------------------------------------------------------------------
class FindPerson(FindBase):
"""Opens a Find Person dialog for GRAMPS"""
def __init__(self,task,db,valid_map):
2002-10-20 19:55:16 +05:30
"""Opens a dialog box instance that allows users to
search for a person.
task - function to call to change the active person"""
FindBase.__init__(self,task,_("Find Person"),db,valid_map)
self.list = []
for val in db.sortPersonKeys():
self.list.append(db.getPersonDisplay(val))
2002-10-20 19:55:16 +05:30
def get_value(self,id):
2003-04-04 11:18:25 +05:30
return self.db.getPerson(id)
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# FindPlace
#
#-------------------------------------------------------------------------
class FindPlace(FindBase):
"""Opens a Find Place dialog for GRAMPS"""
2003-04-04 11:18:25 +05:30
def __init__(self,task,db):
2002-10-20 19:55:16 +05:30
"""Opens a dialog box instance that allows users to
search for a place.
task - function to call to change the active person"""
2003-04-04 11:18:25 +05:30
FindBase.__init__(self,task,_("Find Place"),db)
self.list = db.placeTable.values()
self.list.sort()
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# FindSource
#
#-------------------------------------------------------------------------
class FindSource(FindBase):
"""Opens a Find Place dialog for GRAMPS"""
2003-04-04 11:18:25 +05:30
def __init__(self,task,db):
2002-10-20 19:55:16 +05:30
"""Opens a dialog box instance that allows users to
search for a place.
task - function to call to change the active person"""
2003-04-04 11:18:25 +05:30
FindBase.__init__(self,task,_("Find Source"),db)
self.list = db.sourceTable.values()
self.list.sort()
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# FindMedia
#
#-------------------------------------------------------------------------
class FindMedia(FindBase):
"""Opens a Find Media Object dialog for GRAMPS"""
2003-04-04 11:18:25 +05:30
def __init__(self,task,db):
2002-10-20 19:55:16 +05:30
"""Opens a dialog box instance that allows users to
search for a place.
task - function to call to change the active person"""
2003-04-04 11:18:25 +05:30
FindBase.__init__(self,task,_("Find Media Object"),db)
self.list = []
2002-10-20 19:55:16 +05:30
for n in self.db.getObjectMap().values():
2003-04-04 11:18:25 +05:30
self.list.append((n.getDescription(),n.getId()))
self.list.sort()
2002-10-20 19:55:16 +05:30