* src/Relationship.py: new algorithm to calculate relation
	* src/plugins/all_relations.py: begin of quick report to show extended relationship.



svn: r9237
This commit is contained in:
Benny Malengier
2007-10-23 20:47:13 +00:00
parent 48b7b5db8f
commit cb3771a715
3 changed files with 759 additions and 90 deletions

View File

@@ -0,0 +1,177 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2007 B. Malengier
#
# 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
#
"""
Display a person's relations to the home person
"""
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from Simple import SimpleAccess, SimpleDoc
from gettext import gettext as _
from PluginUtils import register_quick_report
from ReportBase import CATEGORY_QR_PERSON
from PluginUtils import Tool, relationship_class, register_tool
import RelLib
# define the formatting string once as a constant. Since this is reused
__FMT = "%-3d %s"
__FMT_DET1 ="%-3s %-15s"
__FMT_DET2 ="%-30s %-15s\t%-10s %-2s"
def run(database, document, person):
"""
Obtains all relationships, displays the relations, and in details, the
relation path
"""
sdb = SimpleAccess(database)
sdoc = SimpleDoc(document)
rel_class = relationship_class()
#get home_person
home_person = database.get_default_person()
if not home_person :
sdoc.paragraph(_("Home person not set."))
return
#print title
sdoc.title(_("Relationships of %s to %s") % (sdb.name(person) ,
sdb.name(home_person)))
sdoc.paragraph("")
#obtain all relationships, assume home person has largest tree
common, msg_list = rel_class.get_relationship_distance_new(
database, person, home_person,
all_families=True,
all_dist=True,
only_birth=False,
max_depth=20)
#check if not a family too:
is_spouse = rel_class.is_spouse(database,person,home_person)
if is_spouse:
msg_list.insert(0,_('Additional relation:')+is_spouse)
#all relations
if not common or common[0][0]== -1 :
rel_str = _("Not related.")
remarks(msg_list,sdoc)
return
count = 1
for relation in common:
rel_str = rel_class.get_single_relationship_string(len(relation[4]),
len(relation[2]),person.get_gender())
sdoc.paragraph(__FMT % (count, rel_str))
count += 1
remarks(msg_list, sdoc)
sdoc.paragraph("")
sdoc.header1(_("Detailed path to common ancestor"))
sdoc.paragraph("")
sdoc.header2(__FMT_DET1 % (_(' '), _('Name Common ancestor')))
sdoc.header2(__FMT_DET2 % (' ', _('Parent'), _('Birth'), _('Family')))
sdoc.paragraph("")
count = 1
for relation in common:
counter = str(count)
name = sdb.name(database.get_person_from_handle(relation[1]))
sdoc.paragraph(__FMT_DET1 % (counter, name))
for rel,fam in zip(relation[2],relation[3]) :
par_str = _('Unknown')
if rel == rel_class.REL_MOTHER \
or rel == rel_class.REL_MOTHER_NOTBIRTH:
par_str = _('Mother')
if rel == rel_class.REL_FATHER \
or rel == rel_class.REL_FATHER_NOTBIRTH:
par_str = _('Father')
birth_str = _('Yes')
if rel == rel_class.REL_MOTHER_NOTBIRTH \
or rel == rel_class.REL_FATHER_NOTBIRTH:
birth_str = _('No')
sdoc.paragraph(__FMT_DET2 % (' ', par_str, birth_str, str(fam+1)))
counter=''
name = ''
count += 1
sdoc.paragraph("")
sdoc.header1(_("Detailed path for home person to common ancestor"))
sdoc.paragraph("")
sdoc.header2(__FMT_DET1 % (_(' '), _('Name Common ancestor')))
sdoc.header2(__FMT_DET2 % (' ', _('Parent'), _('Birth'), _('Family')))
sdoc.paragraph("")
count = 1
for relation in common:
counter = str(count)
name = sdb.name(database.get_person_from_handle(relation[1]))
sdoc.paragraph(__FMT_DET1 % (counter, name))
for rel,fam in zip(relation[4],relation[5]) :
par_str = _('Unknown')
if rel == rel_class.REL_MOTHER \
or rel == rel_class.REL_MOTHER_NOTBIRTH:
par_str = _('Mother')
if rel == rel_class.REL_FATHER \
or rel == rel_class.REL_FATHER_NOTBIRTH:
par_str = _('Father')
birth_str = _('Yes')
if rel == rel_class.REL_MOTHER_NOTBIRTH \
or rel == rel_class.REL_FATHER_NOTBIRTH:
birth_str = _('No')
sdoc.paragraph(__FMT_DET2 % (' ', par_str, birth_str, str(fam+1)))
counter=''
name = ''
count += 1
def remarks(msg_list,sdoc):
if msg_list :
sdoc.paragraph("")
sdoc.header1(_("Remarks"))
sdoc.paragraph("")
sdoc.paragraph(_("The following problems where encountered:"))
for msg in msg_list :
sdoc.paragraph(msg)
sdoc.paragraph("")
sdoc.paragraph("")
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
register_quick_report(
name = 'all_relations',
category = CATEGORY_QR_PERSON,
run_func = run,
translated_name = _("Relation to Home Person"),
status = _("Stable"),
description= _("Display all relationships between person and home person."),
author_name="B. Malengier",
author_email="benny.malengier@gramps-project.org"
)