2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
* src/RelLib.py (try_to_find_person_from_id): Remove transaction;
(try_to_find_source_from_id, try_to_find_object_from_id,
try_to_find_place_from_id): Add functions.
* src/plugins/WriteCD.py, src/plugins/WritePkg.py,
src/plugins/WebPage.py, src/plugins/Verify.py,
src/plugins/TimeLine.py, src/plugins/Summary.py,
src/plugins/SoundGen.py, src/plugins/RelGraph.py,
src/plugins/RelCalc.py, src/plugins/PatchNames.py,
src/plugins/Merge.py, src/plugins/IndivSummary.py,
src/plugins/IndivComplete.py, src/plugins/GraphViz.py,
src/plugins/FtmStyleDescendants.py,
src/plugins/FtmStyleAncestors.py, src/plugins/FilterEditor.py,
src/plugins/FanChart.py, src/plugins/FamilyGroup.py,
src/plugins/EventCmp.py, src/plugins/DetDescendantReport.py,
src/plugins/DetAncestralReport.py, src/plugins/DescendReport.py,
src/plugins/Desbrowser.py, src/plugins/CountAncestors.py,
src/plugins/Check.py, src/plugins/ChangeTypes.py,
src/plugins/BookReport.py, src/plugins/Ancestors.py,
src/plugins/AncestorReport.py, src/plugins/AncestorChart.py,
src/plugins/AncestorChart2.py, src/Relationship.py,
src/Sort.py, src/GenericFilter.py, src/SubstKeywords.py,
src/GraphLayout.py: Switch from find_* to try_to_find_* methods.
svn: r3191
2004-05-26 07:35:02 +05:30
|
|
|
# Copyright (C) 2000-2004 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
|
|
|
|
|
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
|
2002-10-20 19:55:16 +05:30
|
|
|
import Utils
|
2005-01-01 09:57:15 +05:30
|
|
|
import NameDisplay
|
2002-11-19 09:45:02 +05:30
|
|
|
import ListModel
|
2005-01-05 10:32:19 +05:30
|
|
|
import PluginMgr
|
2003-08-17 07:44:33 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-05-11 07:21:56 +05:30
|
|
|
def runTool(database,person,callback,parent=None):
|
|
|
|
RelCalc(database,person,parent)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class RelCalc:
|
|
|
|
"""
|
|
|
|
Relationship calculator class.
|
|
|
|
"""
|
|
|
|
|
2004-05-11 07:21:56 +05:30
|
|
|
def __init__(self,database,person,parent):
|
2002-10-20 19:55:16 +05:30
|
|
|
self.person = person
|
|
|
|
self.db = database
|
2005-01-05 10:32:19 +05:30
|
|
|
self.RelClass = PluginMgr.relationship_class
|
2004-02-15 22:15:33 +05:30
|
|
|
self.relationship = self.RelClass(database)
|
2004-05-11 07:21:56 +05:30
|
|
|
self.parent = parent
|
|
|
|
self.win_key = self
|
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
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
name = self.person.get_primary_name().get_regular_name()
|
2003-03-19 09:57:34 +05:30
|
|
|
|
2004-05-11 07:21:56 +05:30
|
|
|
self.window = self.glade.get_widget('relcalc')
|
|
|
|
Utils.set_titles(self.window,
|
2003-03-19 09:57:34 +05:30
|
|
|
self.glade.get_widget('title'),
|
2003-04-12 02:19:05 +05:30
|
|
|
_('Relationship to %s') % name,
|
2003-03-19 09:57:34 +05:30
|
|
|
_('Relationship calculator'))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.people = self.glade.get_widget("peopleList")
|
|
|
|
|
2004-12-29 10:36:10 +05:30
|
|
|
self.clist = ListModel.ListModel(self.people,
|
|
|
|
[(_('Name'),3,150),(_('ID'),1,50),
|
|
|
|
(_('Birth Date'),4,150),
|
|
|
|
('',-1,0),('',-1,0)],
|
2003-03-19 09:57:34 +05:30
|
|
|
self.on_apply_clicked)
|
2002-11-19 09:45:02 +05:30
|
|
|
self.clist.new_model()
|
2004-08-13 10:04:07 +05:30
|
|
|
for key in self.db.get_person_handles(sort_handles=False):
|
2004-08-07 10:46:57 +05:30
|
|
|
p = self.db.get_person_from_handle(key)
|
2004-01-01 04:52:44 +05:30
|
|
|
if p == self.person:
|
|
|
|
continue
|
2004-12-29 10:36:10 +05:30
|
|
|
bh = p.get_birth_handle()
|
|
|
|
if bh:
|
|
|
|
bdate = self.db.get_event_from_handle(bh).get_date()
|
|
|
|
else:
|
|
|
|
bdate = ""
|
|
|
|
name = p.get_primary_name()
|
|
|
|
if p.get_gender() == RelLib.Person.male:
|
|
|
|
gender = _("male")
|
|
|
|
elif p.get_gender() == RelLib.Person.female:
|
|
|
|
gender = _("female")
|
|
|
|
else:
|
|
|
|
gender = _("unknown")
|
|
|
|
self.clist.add([name.get_name(), gender, bdate,
|
|
|
|
name.get_sort_name(), bdate],
|
|
|
|
p.get_handle())
|
2002-11-19 09:45:02 +05:30
|
|
|
|
|
|
|
self.clist.connect_model()
|
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,
|
|
|
|
"on_delete_event" : self.on_delete_event,
|
2002-10-20 19:55:16 +05:30
|
|
|
"on_apply_clicked" : self.on_apply_clicked
|
|
|
|
})
|
|
|
|
|
2004-05-11 07:21:56 +05:30
|
|
|
self.add_itself_to_menu()
|
|
|
|
self.window.show()
|
|
|
|
|
|
|
|
def on_delete_event(self,obj,b):
|
|
|
|
self.remove_itself_from_menu()
|
|
|
|
|
|
|
|
def close(self,obj):
|
|
|
|
self.remove_itself_from_menu()
|
|
|
|
self.window.destroy()
|
|
|
|
|
|
|
|
def add_itself_to_menu(self):
|
|
|
|
self.parent.child_windows[self.win_key] = self
|
|
|
|
self.parent_menu_item = gtk.MenuItem(_('Relationship calculator tool'))
|
|
|
|
self.parent_menu_item.connect("activate",self.present)
|
|
|
|
self.parent_menu_item.show()
|
|
|
|
self.parent.winsmenu.append(self.parent_menu_item)
|
|
|
|
|
|
|
|
def remove_itself_from_menu(self):
|
|
|
|
del self.parent.child_windows[self.win_key]
|
|
|
|
self.parent_menu_item.destroy()
|
|
|
|
|
|
|
|
def present(self,obj):
|
|
|
|
self.window.present()
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def on_apply_clicked(self,obj):
|
2004-10-26 08:50:38 +05:30
|
|
|
model,node = self.clist.get_selected()
|
|
|
|
if not node:
|
2002-10-20 19:55:16 +05:30
|
|
|
return
|
2002-11-19 09:45:02 +05:30
|
|
|
|
2004-10-26 08:50:38 +05:30
|
|
|
handle = self.clist.get_object(node)
|
|
|
|
other_person = self.db.get_person_from_handle(handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-15 22:15:33 +05:30
|
|
|
(rel_string,common) = self.relationship.get_relationship(self.person,other_person)
|
2002-10-20 19:55:16 +05:30
|
|
|
length = len(common)
|
|
|
|
|
|
|
|
if length == 1:
|
2004-08-07 10:46:57 +05:30
|
|
|
person = self.db.get_person_from_handle(common[0])
|
2004-02-14 11:10:30 +05:30
|
|
|
name = person.get_primary_name().get_regular_name()
|
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])
|
2002-10-20 19:55:16 +05:30
|
|
|
commontext = " " + _("Their common ancestors are %s and %s.") % \
|
2004-02-14 11:10:30 +05:30
|
|
|
(p1.get_primary_name().get_regular_name(),\
|
|
|
|
p2.get_primary_name().get_regular_name())
|
2002-10-20 19:55:16 +05:30
|
|
|
elif length > 2:
|
|
|
|
index = 0
|
|
|
|
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 + ", "
|
2004-02-14 11:10:30 +05:30
|
|
|
commontext = commontext + person.get_primary_name().get_regular_name()
|
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-01-01 09:57:15 +05:30
|
|
|
p1 = NameDisplay.displayer.display(self.person)
|
|
|
|
p2 = NameDisplay.displayer.display(other_person)
|
2003-04-30 05:54:32 +05:30
|
|
|
|
|
|
|
if rel_string == "":
|
|
|
|
rstr = _("%(person)s and %(active_person)s are not related.") % {
|
|
|
|
'person' : p2, 'active_person' : p1 }
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2003-04-30 05:54:32 +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-01-05 10:32:19 +05:30
|
|
|
PluginMgr.register_tool(
|
2002-10-20 19:55:16 +05:30
|
|
|
runTool,
|
|
|
|
_("Relationship calculator"),
|
|
|
|
category=_("Utilities"),
|
|
|
|
description=_("Calculates the relationship between two people")
|
|
|
|
)
|