2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-11 06:42:06 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# 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-01-01 04:52:44 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"Utilities/Relationship calculator"
|
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import os
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME libraries
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import gtk.glade
|
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-12-29 10:36:10 +05:30
|
|
|
import RelLib
|
2007-02-21 02:26:48 +05:30
|
|
|
from BasicUtils import NameDisplay
|
2006-04-10 04:23:53 +05:30
|
|
|
import ManagedWindow
|
2002-11-19 09:45:02 +05:30
|
|
|
import ListModel
|
2005-08-06 08:27:37 +05:30
|
|
|
import DateHandler
|
2006-05-17 06:18:46 +05:30
|
|
|
from DisplayModels import PeopleModel
|
2006-04-10 04:23:53 +05:30
|
|
|
|
|
|
|
from QuestionDialog import ErrorDialog
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import Tool, relationship_class, register_tool
|
2005-12-07 01:24:16 +05:30
|
|
|
|
|
|
|
column_names = [
|
|
|
|
_('Name'),
|
|
|
|
_('ID') ,
|
|
|
|
_('Gender'),
|
|
|
|
_('Birth Date'),
|
|
|
|
_('Birth Place'),
|
|
|
|
_('Death Date'),
|
|
|
|
_('Death Place'),
|
|
|
|
_('Spouse'),
|
|
|
|
_('Last Change'),
|
|
|
|
_('Cause of Death'),
|
|
|
|
]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-10 04:23:53 +05:30
|
|
|
class RelCalc(Tool.Tool, ManagedWindow.ManagedWindow):
|
|
|
|
|
|
|
|
def __init__(self, dbstate, uistate, options_class, name, callback=None):
|
2005-12-07 01:24:16 +05:30
|
|
|
"""
|
|
|
|
Relationship calculator class.
|
|
|
|
"""
|
2006-04-10 04:23:53 +05:30
|
|
|
|
|
|
|
Tool.Tool.__init__(self, dbstate, options_class, name)
|
2006-04-27 08:05:47 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
|
2006-04-10 04:23:53 +05:30
|
|
|
|
|
|
|
if not self.person:
|
|
|
|
ErrorDialog(_('Active person has not been set'),
|
|
|
|
_('You must select an active person for this '
|
|
|
|
'tool to work properly.'))
|
|
|
|
return
|
|
|
|
|
2006-03-11 06:42:06 +05:30
|
|
|
self.RelClass = relationship_class
|
2005-12-07 01:24:16 +05:30
|
|
|
self.relationship = self.RelClass(self.db)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
base = os.path.dirname(__file__)
|
2002-11-19 09:45:02 +05:30
|
|
|
glade_file = "%s/relcalc.glade" % base
|
2003-08-17 07:44:33 +05:30
|
|
|
self.glade = gtk.glade.XML(glade_file,"relcalc","gramps")
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2006-08-28 01:16:11 +05:30
|
|
|
name = NameDisplay.displayer.display(self.person)
|
|
|
|
self.title = _('Relationship calculator: %(person_name)s'
|
|
|
|
) % {'person_name' : name}
|
2006-04-27 08:05:47 +05:30
|
|
|
window = self.glade.get_widget('relcalc')
|
|
|
|
self.set_window(window,self.glade.get_widget('title'),
|
2006-08-28 01:16:11 +05:30
|
|
|
_('Relationship to %(person_name)s'
|
|
|
|
) % {'person_name' : name },
|
2006-04-27 08:05:47 +05:30
|
|
|
self.title)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-07 01:24:16 +05:30
|
|
|
self.tree = self.glade.get_widget("peopleList")
|
|
|
|
|
2006-05-17 06:18:46 +05:30
|
|
|
self.model = PeopleModel(self.db,None)
|
2005-12-07 01:24:16 +05:30
|
|
|
self.tree.set_model(self.model)
|
|
|
|
|
|
|
|
column = gtk.TreeViewColumn(_('Name'), gtk.CellRendererText(),text=0)
|
|
|
|
column.set_resizable(True)
|
|
|
|
column.set_min_width(225)
|
|
|
|
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
|
|
|
self.tree.append_column(column)
|
|
|
|
|
|
|
|
index = 1
|
|
|
|
for pair in self.db.get_person_column_order():
|
|
|
|
if not pair[0]:
|
2004-01-01 04:52:44 +05:30
|
|
|
continue
|
2005-12-07 01:24:16 +05:30
|
|
|
name = column_names[pair[1]]
|
2006-08-28 01:16:11 +05:30
|
|
|
column = gtk.TreeViewColumn(name, gtk.CellRendererText(),
|
|
|
|
markup=pair[1])
|
2005-12-07 01:24:16 +05:30
|
|
|
column.set_resizable(True)
|
|
|
|
column.set_min_width(60)
|
|
|
|
column.set_sizing(gtk.TREE_VIEW_COLUMN_GROW_ONLY)
|
|
|
|
self.tree.append_column(column)
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
self.tree.get_selection().connect('changed',self.on_apply_clicked)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.glade.signal_autoconnect({
|
2004-05-11 07:21:56 +05:30
|
|
|
"on_close_clicked" : self.close,
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
self.show()
|
2004-05-11 07:21:56 +05:30
|
|
|
|
2006-04-27 08:05:47 +05:30
|
|
|
def build_menu_names(self,obj):
|
|
|
|
return (_("Relationship Calculator tool"),None)
|
2004-05-11 07:21:56 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def on_apply_clicked(self,obj):
|
2005-12-07 01:24:16 +05:30
|
|
|
model,node = self.tree.get_selection().get_selected()
|
2004-10-26 08:50:38 +05:30
|
|
|
if not node:
|
2002-10-20 19:55:16 +05:30
|
|
|
return
|
2002-11-19 09:45:02 +05:30
|
|
|
|
2005-12-07 01:24:16 +05:30
|
|
|
handle = model.get_value(node,len(PeopleModel.COLUMN_DEFS)-1)
|
2004-10-26 08:50:38 +05:30
|
|
|
other_person = self.db.get_person_from_handle(handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-07 01:24:16 +05:30
|
|
|
if other_person != None:
|
2006-08-28 01:16:11 +05:30
|
|
|
(rel_string,common) = self.relationship.get_relationship(
|
|
|
|
self.person,other_person)
|
|
|
|
# A quick way to get unique list
|
|
|
|
common = list(set(common))
|
2005-12-07 01:24:16 +05:30
|
|
|
length = len(common)
|
|
|
|
else:
|
|
|
|
length = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-07 01:24:16 +05:30
|
|
|
if other_person == None:
|
|
|
|
commontext = ""
|
|
|
|
elif length == 1:
|
2004-08-07 10:46:57 +05:30
|
|
|
person = self.db.get_person_from_handle(common[0])
|
2006-08-28 01:16:11 +05:30
|
|
|
name = NameDisplay.displayer.display(person)
|
2002-10-20 19:55:16 +05:30
|
|
|
commontext = " " + _("Their common ancestor is %s.") % name
|
|
|
|
elif length == 2:
|
2004-08-07 10:46:57 +05:30
|
|
|
p1 = self.db.get_person_from_handle(common[0])
|
|
|
|
p2 = self.db.get_person_from_handle(common[1])
|
2006-08-28 01:16:11 +05:30
|
|
|
p1str = NameDisplay.displayer.display(p1)
|
|
|
|
p2str = NameDisplay.displayer.display(p2)
|
|
|
|
commontext = " " + _("Their common ancestors are %s and %s."
|
|
|
|
) % (p1str,p2str)
|
2002-10-20 19:55:16 +05:30
|
|
|
elif length > 2:
|
|
|
|
index = 0
|
2006-08-28 01:16:11 +05:30
|
|
|
commontext = " " + _("Their common ancestors are: ")
|
2004-07-28 07:59:07 +05:30
|
|
|
for person_handle in common:
|
2004-08-07 10:46:57 +05:30
|
|
|
person = self.db.get_person_from_handle(person_handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
if index != 0:
|
|
|
|
commontext = commontext + ", "
|
2006-08-28 01:16:11 +05:30
|
|
|
commontext = commontext + NameDisplay.displayer.display(person)
|
2002-10-20 19:55:16 +05:30
|
|
|
index = index + 1
|
|
|
|
commontext = commontext + "."
|
|
|
|
else:
|
|
|
|
commontext = ""
|
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
text1 = self.glade.get_widget("text1").get_buffer()
|
|
|
|
|
2005-12-07 01:24:16 +05:30
|
|
|
if other_person:
|
|
|
|
p1 = NameDisplay.displayer.display(self.person)
|
|
|
|
p2 = NameDisplay.displayer.display(other_person)
|
|
|
|
|
|
|
|
if other_person == None:
|
|
|
|
rstr = ""
|
|
|
|
elif self.person.handle == other_person.handle:
|
|
|
|
rstr = _("%s and %s are the same person.") % (p1,p2)
|
|
|
|
elif rel_string == "":
|
2003-04-30 05:54:32 +05:30
|
|
|
rstr = _("%(person)s and %(active_person)s are not related.") % {
|
|
|
|
'person' : p2, 'active_person' : p1 }
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2006-08-28 01:16:11 +05:30
|
|
|
rstr = _("%(person)s is the %(relationship)s of %(active_person)s."
|
|
|
|
) % {'person' : p2, 'relationship' : rel_string,
|
|
|
|
'active_person' : p1 }
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-04-30 05:54:32 +05:30
|
|
|
text1.set_text("%s %s" % (rstr, commontext))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-07 01:24:16 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class RelCalcOptions(Tool.ToolOptions):
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self,name,person_id=None):
|
|
|
|
Tool.ToolOptions.__init__(self,name,person_id)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-03-11 06:42:06 +05:30
|
|
|
register_tool(
|
2005-12-07 01:24:16 +05:30
|
|
|
name = 'relcalc',
|
|
|
|
category = Tool.TOOL_UTILS,
|
|
|
|
tool_class = RelCalc,
|
|
|
|
options_class = RelCalcOptions,
|
|
|
|
modes = Tool.MODE_GUI,
|
|
|
|
translated_name = _("Relationship calculator"),
|
|
|
|
status=(_("Stable")),
|
|
|
|
author_name = "Donald N. Allingham",
|
|
|
|
author_email = "don@gramps-project.org",
|
2002-10-20 19:55:16 +05:30
|
|
|
description=_("Calculates the relationship between two people")
|
|
|
|
)
|