2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-28 11:11:40 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
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$
|
|
|
|
|
2008-03-02 04:17:48 +05:30
|
|
|
"""Tools/Utilities/Relationship Calculator"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
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
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-02-19 01:37:09 +05:30
|
|
|
import gtk
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2010-01-14 09:38:04 +05:30
|
|
|
from gen.display.name import displayer as name_displayer
|
2006-04-10 04:23:53 +05:30
|
|
|
import ManagedWindow
|
2009-11-08 22:11:49 +05:30
|
|
|
from gui.views.treemodels import PeopleModel
|
2009-10-25 19:22:29 +05:30
|
|
|
import Relationship
|
2006-04-10 04:23:53 +05:30
|
|
|
|
|
|
|
from QuestionDialog import ErrorDialog
|
2008-10-02 09:32:10 +05:30
|
|
|
from PluginUtils import Tool
|
2009-05-15 01:45:59 +05:30
|
|
|
from glade import Glade
|
2005-12-07 01:24:16 +05:30
|
|
|
|
2009-04-16 00:57:17 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
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
|
|
|
|
2007-11-22 04:45:10 +05:30
|
|
|
self.dbstate = dbstate
|
2009-10-25 19:22:29 +05:30
|
|
|
self.relationship = Relationship.get_relationship_calculator()
|
2007-11-22 04:45:10 +05:30
|
|
|
self.relationship.connect_db_signals(dbstate)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2009-05-15 01:45:59 +05:30
|
|
|
self.glade = Glade()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-01-03 20:24:26 +05:30
|
|
|
name = ''
|
|
|
|
if self.person:
|
|
|
|
name = name_displayer.display(self.person)
|
2006-08-28 01:16:11 +05:30
|
|
|
self.title = _('Relationship calculator: %(person_name)s'
|
|
|
|
) % {'person_name' : name}
|
2009-05-15 01:45:59 +05:30
|
|
|
window = self.glade.toplevel
|
2009-04-09 01:39:30 +05:30
|
|
|
self.titlelabel = self.glade.get_object('title')
|
2007-11-22 04:45:10 +05:30
|
|
|
self.set_window(window, self.titlelabel,
|
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
|
|
|
|
2009-04-09 01:39:30 +05:30
|
|
|
self.tree = self.glade.get_object("peopleList")
|
|
|
|
self.text = self.glade.get_object("text1")
|
2008-02-19 01:37:09 +05:30
|
|
|
self.textbuffer = gtk.TextBuffer()
|
2007-11-22 04:45:10 +05:30
|
|
|
self.text.set_buffer(self.textbuffer)
|
2005-12-07 01:24:16 +05:30
|
|
|
|
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)
|
|
|
|
|
2008-03-02 21:46:14 +05:30
|
|
|
self.tree.connect('key-press-event', self._key_press)
|
|
|
|
self.selection = self.tree.get_selection()
|
|
|
|
self.selection.set_mode(gtk.SELECTION_SINGLE)
|
|
|
|
|
2005-12-07 01:24:16 +05:30
|
|
|
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)
|
2007-11-22 04:45:10 +05:30
|
|
|
#keep reference of column so garbage collection works
|
|
|
|
self.columns = [column]
|
2005-12-07 01:24:16 +05:30
|
|
|
|
|
|
|
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)
|
2007-11-22 04:45:10 +05:30
|
|
|
#keep reference of column so garbage collection works
|
|
|
|
self.columns.append(column)
|
2005-12-07 01:24:16 +05:30
|
|
|
index += 1
|
|
|
|
|
2007-11-22 04:45:10 +05:30
|
|
|
self.sel = self.tree.get_selection()
|
|
|
|
self.changedkey = self.sel.connect('changed',self.on_apply_clicked)
|
2009-04-09 01:39:30 +05:30
|
|
|
self.closebtn = self.glade.get_object("button5")
|
2007-11-22 04:45:10 +05:30
|
|
|
self.closebtn.connect('clicked', self.close)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-01-03 20:24:26 +05:30
|
|
|
if not self.person:
|
|
|
|
self.window.hide()
|
|
|
|
ErrorDialog(_('Active person has not been set'),
|
|
|
|
_('You must select an active person for this '
|
|
|
|
'tool to work properly.'))
|
|
|
|
self.close()
|
|
|
|
return
|
|
|
|
|
2006-04-10 04:23:53 +05:30
|
|
|
self.show()
|
2004-05-11 07:21:56 +05:30
|
|
|
|
2007-11-22 04:45:10 +05:30
|
|
|
def close(self, *obj):
|
2008-02-18 21:22:40 +05:30
|
|
|
""" Close relcalc tool. Remove non-gtk connections so garbage
|
2007-11-22 04:45:10 +05:30
|
|
|
collection can do its magic.
|
2008-02-18 21:22:40 +05:30
|
|
|
"""
|
2007-11-22 04:45:10 +05:30
|
|
|
self.relationship.disconnect_db_signals(self.dbstate)
|
|
|
|
self.sel.disconnect(self.changedkey)
|
|
|
|
ManagedWindow.ManagedWindow.close(self, *obj)
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def build_menu_names(self, obj):
|
2006-04-27 08:05:47 +05:30
|
|
|
return (_("Relationship Calculator tool"),None)
|
2004-05-11 07:21:56 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def on_apply_clicked(self, obj):
|
|
|
|
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)
|
2007-11-22 04:45:10 +05:30
|
|
|
other_person = self.db.get_person_from_handle(handle)
|
2007-11-19 05:09:14 +05:30
|
|
|
if other_person is None :
|
2007-11-22 04:45:10 +05:30
|
|
|
self.textbuffer.set_text("")
|
2007-11-19 05:09:14 +05:30
|
|
|
return
|
|
|
|
|
|
|
|
#now determine the relation, and print it out
|
|
|
|
rel_strings, common_an = self.relationship.get_all_relationships(
|
|
|
|
self.db, self.person, other_person)
|
|
|
|
|
|
|
|
p1 = name_displayer.display(self.person)
|
|
|
|
p2 = name_displayer.display(other_person)
|
|
|
|
|
|
|
|
text = []
|
2008-06-16 20:31:46 +05:30
|
|
|
if other_person is None:
|
2007-11-19 05:09:14 +05:30
|
|
|
pass
|
2005-12-07 01:24:16 +05:30
|
|
|
elif self.person.handle == other_person.handle:
|
2007-11-19 05:09:14 +05:30
|
|
|
rstr = _("%s and %s are the same person.") % (p1, p2)
|
|
|
|
text.append((rstr, ""))
|
|
|
|
elif len(rel_strings) == 0:
|
2003-04-30 05:54:32 +05:30
|
|
|
rstr = _("%(person)s and %(active_person)s are not related.") % {
|
2007-11-19 05:09:14 +05:30
|
|
|
'person' : p2, 'active_person' : p1 }
|
|
|
|
text.append((rstr, ""))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-11-19 05:09:14 +05:30
|
|
|
for rel_string, common in zip(rel_strings, common_an):
|
|
|
|
rstr = _("%(person)s is the %(relationship)s of %(active_person)s."
|
|
|
|
) % {'person' : p2, 'relationship' : rel_string,
|
|
|
|
'active_person' : p1 }
|
|
|
|
length = len(common)
|
|
|
|
if length == 1:
|
|
|
|
person = self.db.get_person_from_handle(common[0])
|
2009-04-09 01:39:30 +05:30
|
|
|
if common[0] in [other_person.handle, self.person.handle]:
|
2007-11-19 05:09:14 +05:30
|
|
|
commontext = ''
|
|
|
|
else :
|
|
|
|
name = name_displayer.display(person)
|
|
|
|
commontext = " " + _("Their common ancestor is %s.") % name
|
|
|
|
elif length == 2:
|
|
|
|
p1c = self.db.get_person_from_handle(common[0])
|
|
|
|
p2c = self.db.get_person_from_handle(common[1])
|
|
|
|
p1str = name_displayer.display(p1c)
|
|
|
|
p2str = name_displayer.display(p2c)
|
|
|
|
commontext = " " + _("Their common ancestors are %s and %s."
|
|
|
|
) % (p1str,p2str)
|
|
|
|
elif length > 2:
|
|
|
|
index = 0
|
|
|
|
commontext = " " + _("Their common ancestors are: ")
|
|
|
|
for person_handle in common:
|
|
|
|
person = self.db.get_person_from_handle(person_handle)
|
2009-04-09 01:39:30 +05:30
|
|
|
if index:
|
|
|
|
commontext += ", "
|
|
|
|
commontext += name_displayer.display(person)
|
|
|
|
index += 1
|
|
|
|
commontext += "."
|
2007-11-19 05:09:14 +05:30
|
|
|
else:
|
|
|
|
commontext = ""
|
|
|
|
text.append((rstr, commontext))
|
|
|
|
|
|
|
|
textval = ""
|
|
|
|
for val in text:
|
|
|
|
textval += "%s %s\n" % (val[0], val[1])
|
2007-11-22 04:45:10 +05:30
|
|
|
self.textbuffer.set_text(textval)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-03-02 21:46:14 +05:30
|
|
|
def _key_press(self, obj, event):
|
|
|
|
if not event.state or event.state in (gtk.gdk.MOD2_MASK, ):
|
|
|
|
if event.keyval in (gtk.keysyms.Return, gtk.keysyms.KP_Enter):
|
|
|
|
store, paths = self.selection.get_selected_rows()
|
|
|
|
if paths and len(paths[0]) == 1 :
|
|
|
|
if self.tree.row_expanded(paths[0]):
|
|
|
|
self.tree.collapse_row(paths[0])
|
|
|
|
else:
|
|
|
|
self.tree.expand_row(paths[0], 0)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2005-12-07 01:24:16 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class RelCalcOptions(Tool.ToolOptions):
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def __init__(self, name,person_id=None):
|
|
|
|
Tool.ToolOptions.__init__(self, name,person_id)
|