gramps/src/Find.py

216 lines
6.7 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"""
2003-04-04 11:18:25 +05:30
def __init__(self,task,name,db):
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
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):
text = self.entry.get_text()
2003-04-04 11:18:25 +05:30
if type(text) != self.t:
text = unicode(text.upper())
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
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()
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"""
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 person.
task - function to call to change the active person"""
2003-04-04 11:18:25 +05:30
FindBase.__init__(self,task,_("Find Person"),db)
self.list = db.personTable.values()
self.list.sort()
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