gramps/src/SelectPerson.py

128 lines
4.1 KiB
Python
Raw Normal View History

#
# Gramps - a GTK+/GNOME based genealogy program
#
2004-05-07 09:57:16 +05:30
# Copyright (C) 2003-2004 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
#
2004-05-07 09:57:16 +05:30
# $Id$
#-------------------------------------------------------------------------
#
# internationalization
#
#-------------------------------------------------------------------------
from gettext import gettext as _
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk
import gtk.glade
2006-03-20 05:04:23 +05:30
import pango
#-------------------------------------------------------------------------
#
# gramps modules
#
#-------------------------------------------------------------------------
import const
import Utils
import PeopleModel
#-------------------------------------------------------------------------
#
# SelectPerson
#
#-------------------------------------------------------------------------
class SelectPerson:
2006-04-22 09:30:58 +05:30
def __init__(self, db, title, filter=None, skip=[]):
self.renderer = gtk.CellRendererText()
2006-03-20 05:04:23 +05:30
self.renderer.set_property('ellipsize',pango.ELLIPSIZE_END)
self.db = db
self.glade = gtk.glade.XML(const.gladeFile,"select_person","gramps")
self.top = self.glade.get_widget('select_person')
self.plist = self.glade.get_widget('plist')
self.notebook = self.glade.get_widget('notebook')
2006-03-20 05:04:23 +05:30
Utils.set_titles(self.top,
self.glade.get_widget('title'),
title)
2006-03-21 08:09:01 +05:30
# import hotshot, hotshot.stats
# pr = hotshot.Profile('profile.data')
# pr.runcall(self.foo)
# pr.close()
# stats = hotshot.stats.load('profile.data')
# stats.strip_dirs()
# stats.sort_stats('time','calls')
# stats.print_stats(35)
2006-03-20 10:12:37 +05:30
self.model = PeopleModel.PeopleModel(self.db,
data_filter=filter,
skip=skip)
self.add_columns(self.plist)
self.plist.set_model(self.model)
self.top.show()
2006-03-20 10:12:37 +05:30
def foo(self):
PeopleModel.PeopleModel(self.db)
def add_columns(self,tree):
tree.set_fixed_height_mode(True)
column = gtk.TreeViewColumn(_('Name'), self.renderer, text=0)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(225)
tree.append_column(column)
column = gtk.TreeViewColumn(_('ID'), self.renderer, text=1)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(75)
tree.append_column(column)
column = gtk.TreeViewColumn(_('Birth date'), self.renderer, text=3)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(160)
tree.append_column(column)
def select_function(self,store,path,iter,id_list):
id_list.append(self.model.get_value(iter,PeopleModel.COLUMN_INT_ID))
def get_selected_ids(self):
mlist = []
self.plist.get_selection().selected_foreach(self.select_function,mlist)
return mlist
def run(self):
val = self.top.run()
if val == gtk.RESPONSE_OK:
idlist = self.get_selected_ids()
2006-03-21 08:09:01 +05:30
self.top.destroy()
if idlist and idlist[0]:
return_value = self.db.get_person_from_handle(idlist[0])
else:
return_value = None
return return_value
else:
self.top.destroy()
return None