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-01-06 02:12:05 +05:30
|
|
|
# Copyright (C) 2007-2008 Brian G. Matherly
|
2009-04-10 21:50:41 +05:30
|
|
|
# Copyright (C) 2009 Gary Burton
|
2010-03-09 07:13:26 +05:30
|
|
|
# Copyright (C) 2010 Craig J. Anderson
|
|
|
|
|
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-04-26 09:47:01 +05:30
|
|
|
# $Id$
|
|
|
|
|
2009-08-09 22:39:32 +05:30
|
|
|
"""
|
2009-08-14 12:44:25 +05:30
|
|
|
Reports/Text Reports/Descendant Report.
|
2009-08-09 22:39:32 +05:30
|
|
|
"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2009-05-31 20:29:56 +05:30
|
|
|
from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle,
|
2009-08-14 12:44:25 +05:30
|
|
|
FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER)
|
2010-03-09 07:13:26 +05:30
|
|
|
from gen.plug.menu import NumberOption, PersonOption, BooleanOption, EnumeratedListOption
|
2010-01-14 09:38:04 +05:30
|
|
|
from gen.display.name import displayer as name_displayer
|
2009-08-14 12:44:25 +05:30
|
|
|
from Errors import ReportError
|
2009-10-24 19:23:20 +05:30
|
|
|
from ReportBase import Report, ReportUtils, MenuReportOptions
|
2006-03-31 09:25:06 +05:30
|
|
|
import DateHandler
|
2009-08-14 12:44:25 +05:30
|
|
|
import Sort
|
2009-12-21 11:28:55 +05:30
|
|
|
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2010-03-09 07:13:26 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2010-03-09 07:13:26 +05:30
|
|
|
# Printinfo
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2010-03-09 07:13:26 +05:30
|
|
|
class Printinfo():
|
|
|
|
"""
|
|
|
|
A base class used to help make the individual numbering system classes.
|
|
|
|
This class must first be initialized with set_class_vars
|
|
|
|
"""
|
|
|
|
doc = None
|
|
|
|
database = None
|
|
|
|
|
|
|
|
def set_class_vars(self, doc, database, showspouse):
|
|
|
|
Printinfo.doc = doc
|
|
|
|
Printinfo.database = database
|
|
|
|
Printinfo.showspouse = showspouse
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def dump_dates(self, person):
|
2010-03-09 07:13:26 +05:30
|
|
|
birth = get_birth_or_fallback(Printinfo.database, person)
|
|
|
|
death = get_death_or_fallback(Printinfo.database, person)
|
2004-04-26 09:47:01 +05:30
|
|
|
|
2006-03-31 09:25:06 +05:30
|
|
|
if birth or death:
|
2010-03-09 07:13:26 +05:30
|
|
|
Printinfo.doc.write_text(' (')
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2009-04-10 21:50:41 +05:30
|
|
|
if birth:
|
|
|
|
birth_date = DateHandler.get_date(birth)
|
|
|
|
bplace_handle = birth.get_place_handle()
|
|
|
|
if bplace_handle:
|
2010-03-09 07:13:26 +05:30
|
|
|
birth_place = Printinfo.database.get_place_from_handle(
|
2009-04-10 21:50:41 +05:30
|
|
|
bplace_handle).get_title()
|
2010-03-09 07:13:26 +05:30
|
|
|
Printinfo.doc.write_text("%(event_abbrev)s %(birth_date)s - %(place)s" % {
|
2009-12-24 01:05:18 +05:30
|
|
|
'event_abbrev': birth.type.get_abbreviation(),
|
2009-04-10 21:50:41 +05:30
|
|
|
'birth_date' : birth_date,
|
|
|
|
'place' : birth_place,
|
|
|
|
})
|
|
|
|
else:
|
2010-03-09 07:13:26 +05:30
|
|
|
Printinfo.doc.write_text("%(event_abbrev)s %(birth_date)s" % {
|
2009-12-24 01:05:18 +05:30
|
|
|
'event_abbrev': birth.type.get_abbreviation(),
|
2009-04-10 21:50:41 +05:30
|
|
|
'birth_date' : birth_date
|
|
|
|
})
|
|
|
|
|
|
|
|
if death:
|
|
|
|
death_date = DateHandler.get_date(death)
|
|
|
|
dplace_handle = death.get_place_handle()
|
2006-03-31 09:25:06 +05:30
|
|
|
if birth:
|
2010-03-09 07:13:26 +05:30
|
|
|
Printinfo.doc.write_text(', ')
|
2009-04-10 21:50:41 +05:30
|
|
|
if dplace_handle:
|
2010-03-09 07:13:26 +05:30
|
|
|
death_place = Printinfo.database.get_place_from_handle(
|
2009-04-10 21:50:41 +05:30
|
|
|
dplace_handle).get_title()
|
2010-03-09 07:13:26 +05:30
|
|
|
Printinfo.doc.write_text("%(event_abbrev)s %(death_date)s - %(place)s" % {
|
2009-12-24 01:05:18 +05:30
|
|
|
'event_abbrev': death.type.get_abbreviation(),
|
2009-04-10 21:50:41 +05:30
|
|
|
'death_date' : death_date,
|
|
|
|
'place' : death_place,
|
|
|
|
})
|
|
|
|
else:
|
2010-03-09 07:13:26 +05:30
|
|
|
Printinfo.doc.write_text("%(event_abbrev)s %(death_date)s" % {
|
2009-12-24 01:05:18 +05:30
|
|
|
'event_abbrev': death.type.get_abbreviation(),
|
2009-04-10 21:50:41 +05:30
|
|
|
'death_date' : death_date
|
|
|
|
})
|
|
|
|
|
2009-10-07 18:43:58 +05:30
|
|
|
if birth or death:
|
2010-03-09 07:13:26 +05:30
|
|
|
Printinfo.doc.write_text(')')
|
|
|
|
|
|
|
|
def print_person(level, person):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def print_spouse(self, level, spouse_handle):
|
|
|
|
#Currently print_spouses is the same for all numbering systems.
|
|
|
|
if spouse_handle and Printinfo.showspouse:
|
|
|
|
spouse = self.database.get_person_from_handle(spouse_handle)
|
|
|
|
mark = ReportUtils.get_person_mark(self.database, spouse)
|
|
|
|
self.doc.start_paragraph("DR-Spouse%d" % min(level, 32))
|
|
|
|
name = name_displayer.display(spouse)
|
|
|
|
self.doc.write_text(_("sp. %(spouse)s") % {'spouse':name}, mark)
|
|
|
|
self.dump_dates(spouse)
|
|
|
|
self.doc.end_paragraph()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
|
2010-03-09 07:13:26 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PrintSimple
|
|
|
|
# Simple numbering system
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class PrintSimple(Printinfo):
|
|
|
|
def print_person(self, level, person):
|
2009-08-14 12:44:25 +05:30
|
|
|
self.doc.start_paragraph("DR-Level%d" % min(level, 32), "%d." % level)
|
|
|
|
mark = ReportUtils.get_person_mark(self.database, person)
|
|
|
|
self.doc.write_text(name_displayer.display(person), mark)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.dump_dates(person)
|
|
|
|
self.doc.end_paragraph()
|
2010-03-09 07:13:26 +05:30
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PrintVlliers
|
|
|
|
# de_Villiers_Pama numbering system
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class PrintVlliers(Printinfo):
|
|
|
|
def __init__(self):
|
|
|
|
self.pama = 'abcdefghijklmnopqrstuvwxyz'
|
|
|
|
self.num = {0:1}
|
|
|
|
|
|
|
|
def print_person(self, level, person):
|
|
|
|
self.doc.start_paragraph("DR-Level%d" % min(level, 32),
|
|
|
|
self.pama[level-1] +
|
|
|
|
str(self.num[level-1]) + ".")
|
|
|
|
mark = ReportUtils.get_person_mark(self.database, person)
|
|
|
|
self.doc.write_text(name_displayer.display(person), mark)
|
|
|
|
self.dump_dates(person)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.num[level] = 1
|
|
|
|
self.num[level-1] = self.num[level-1] + 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# class PrintMeurgey
|
|
|
|
# Meurgey_de_Tupigny numbering system
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class PrintMeurgey(Printinfo):
|
|
|
|
def __init__(self):
|
|
|
|
self.childnum = [""]
|
|
|
|
|
|
|
|
def print_person(self, level, person):
|
|
|
|
if level == 1:
|
|
|
|
dash = ""
|
|
|
|
else:
|
|
|
|
dash = "-"
|
|
|
|
if len(self.childnum) < level:
|
|
|
|
self.childnum.append(1)
|
|
|
|
|
|
|
|
self.doc.start_paragraph("DR-Level%d" % min(level, 32),
|
|
|
|
ReportUtils.roman(level)
|
|
|
|
+ dash + str(self.childnum[level-1]) + ".")
|
|
|
|
if level > 1:
|
|
|
|
self.childnum[level-1] += 1
|
|
|
|
mark = ReportUtils.get_person_mark(self.database, person)
|
|
|
|
self.doc.write_text(name_displayer.display(person), mark)
|
|
|
|
self.dump_dates(person)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# RecurseDown
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class RecurseDown():
|
|
|
|
"""
|
|
|
|
A simple object to recurse from a person down through their descendants
|
|
|
|
|
|
|
|
The arguments are:
|
|
|
|
|
|
|
|
max_generations: The max number of generations
|
|
|
|
database: The database object
|
|
|
|
objPrint: A Printinfo derived class that prints person
|
|
|
|
information on the report
|
|
|
|
"""
|
|
|
|
def __init__(self, max_generations, database, objPrint):
|
|
|
|
self.max_generations = max_generations
|
|
|
|
self.database = database
|
|
|
|
self.objPrint = objPrint
|
|
|
|
|
|
|
|
def recurse(self, level, person):
|
|
|
|
|
|
|
|
self.objPrint.print_person(level, person)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-07-28 07:59:07 +05:30
|
|
|
for family_handle in person.get_family_handle_list():
|
2004-08-20 03:05:16 +05:30
|
|
|
family = self.database.get_family_from_handle(family_handle)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2009-08-14 12:44:25 +05:30
|
|
|
spouse_handle = ReportUtils.find_spouse(person, family)
|
2010-03-09 07:13:26 +05:30
|
|
|
self.objPrint.print_spouse(level, spouse_handle)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2009-10-12 23:03:07 +05:30
|
|
|
if level >= self.max_generations:
|
|
|
|
continue
|
|
|
|
|
2006-04-17 09:39:00 +05:30
|
|
|
childlist = family.get_child_ref_list()[:]
|
|
|
|
for child_ref in childlist:
|
|
|
|
child = self.database.get_person_from_handle(child_ref.ref)
|
2010-03-09 07:13:26 +05:30
|
|
|
self.recurse(level+1, child)
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# DescendantReport
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class DescendantReport(Report):
|
|
|
|
|
|
|
|
def __init__(self, database, options_class):
|
|
|
|
"""
|
|
|
|
Create the DescendantReport object that produces the report.
|
|
|
|
|
|
|
|
The arguments are:
|
|
|
|
|
|
|
|
database - the GRAMPS database instance
|
|
|
|
options_class - instance of the Options class for this report
|
|
|
|
|
|
|
|
This report needs the following parameters (class variables)
|
|
|
|
that come in the options class.
|
|
|
|
|
|
|
|
gen - Maximum number of generations to include.
|
|
|
|
"""
|
|
|
|
|
|
|
|
Report.__init__(self, database, options_class)
|
|
|
|
|
|
|
|
menu = options_class.menu
|
|
|
|
self.max_generations = menu.get_option_by_name('gen').get_value()
|
|
|
|
self.numbering = menu.get_option_by_name('numbering').get_value()
|
|
|
|
pid = menu.get_option_by_name('pid').get_value()
|
|
|
|
self.center_person = database.get_person_from_gramps_id(pid)
|
|
|
|
if (self.center_person == None) :
|
|
|
|
raise ReportError(_("Person %s is not in the Database") % pid )
|
|
|
|
|
|
|
|
sort = Sort.Sort(self.database)
|
|
|
|
self.by_birthdate = sort.by_birthdate
|
|
|
|
|
|
|
|
#Initialize the Printinfo class
|
|
|
|
p = Printinfo()
|
|
|
|
p.set_class_vars(self.doc, database,
|
|
|
|
menu.get_option_by_name('shows').get_value())
|
|
|
|
|
|
|
|
|
|
|
|
def write_report(self):
|
|
|
|
self.doc.start_paragraph("DR-Title")
|
|
|
|
name = name_displayer.display(self.center_person)
|
|
|
|
title = _("Descendants of %s") % name
|
|
|
|
mark = IndexMark(title, INDEX_TYPE_TOC, 1)
|
|
|
|
self.doc.write_text(title, mark)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
if self.numbering == "Simple":
|
|
|
|
obj = PrintSimple()
|
|
|
|
elif self.numbering == "de Villiers/Pama":
|
|
|
|
obj = PrintVlliers()
|
|
|
|
elif self.numbering == "Meurgey de Tupigny":
|
|
|
|
obj = PrintMeurgey()
|
|
|
|
else:
|
|
|
|
raise AttributeError("no such numbering: '%s'" % self.numbering)
|
|
|
|
|
|
|
|
recurse = RecurseDown(self.max_generations, self.database, obj)
|
|
|
|
recurse.recurse(1, self.center_person)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2007-12-27 23:58:16 +05:30
|
|
|
# AncestorOptions
|
2003-07-06 03:17:41 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2007-12-27 23:58:16 +05:30
|
|
|
class DescendantOptions(MenuReportOptions):
|
2003-07-11 08:59:33 +05:30
|
|
|
|
2004-12-23 07:18:00 +05:30
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
2003-07-06 03:17:41 +05:30
|
|
|
|
2008-01-24 18:20:33 +05:30
|
|
|
def __init__(self, name, dbase):
|
|
|
|
MenuReportOptions.__init__(self, name, dbase)
|
2007-03-27 17:20:26 +05:30
|
|
|
|
2008-01-24 18:20:33 +05:30
|
|
|
def add_menu_options(self, menu):
|
2007-12-27 23:58:16 +05:30
|
|
|
category_name = _("Report Options")
|
|
|
|
|
2008-01-18 11:09:50 +05:30
|
|
|
pid = PersonOption(_("Center Person"))
|
|
|
|
pid.set_help(_("The center person for the report"))
|
|
|
|
menu.add_option(category_name, "pid", pid)
|
|
|
|
|
2010-03-09 07:13:26 +05:30
|
|
|
numbering = EnumeratedListOption(_("Numbering system"), "Simple")
|
|
|
|
numbering.set_items([
|
|
|
|
("Simple", _("Simple numbering")),
|
|
|
|
("de Villiers/Pama", _("de Villiers/Pama numbering")),
|
|
|
|
("Meurgey de Tupigny", _("Meurgey de Tupigny numbering"))])
|
|
|
|
numbering.set_help(_("The numbering system to be used"))
|
|
|
|
menu.add_option(category_name, "numbering", numbering)
|
|
|
|
|
2009-08-14 12:44:25 +05:30
|
|
|
gen = NumberOption(_("Generations"), 10, 1, 15)
|
2007-12-27 23:58:16 +05:30
|
|
|
gen.set_help(_("The number of generations to include in the report"))
|
2009-08-14 12:44:25 +05:30
|
|
|
menu.add_option(category_name, "gen", gen)
|
2003-07-07 22:27:27 +05:30
|
|
|
|
2010-03-09 07:13:26 +05:30
|
|
|
shows = BooleanOption(_('Show Sp_ouses'), True)
|
|
|
|
shows.set_help(_("Whether to show spouses in the report."))
|
|
|
|
menu.add_option(category_name, "shows", shows)
|
|
|
|
|
2009-08-14 12:44:25 +05:30
|
|
|
def make_default_style(self, default_style):
|
2004-12-23 07:18:00 +05:30
|
|
|
"""Make the default output style for the Descendant Report."""
|
2009-06-11 18:31:27 +05:30
|
|
|
f = FontStyle()
|
2005-12-06 12:08:09 +05:30
|
|
|
f.set_size(12)
|
2009-06-11 18:31:27 +05:30
|
|
|
f.set_type_face(FONT_SANS_SERIF)
|
2004-12-23 07:18:00 +05:30
|
|
|
f.set_bold(1)
|
2009-06-11 18:31:27 +05:30
|
|
|
p = ParagraphStyle()
|
2004-12-23 07:18:00 +05:30
|
|
|
p.set_header_level(1)
|
2005-12-06 12:08:09 +05:30
|
|
|
p.set_bottom_border(1)
|
|
|
|
p.set_top_margin(ReportUtils.pt2cm(3))
|
|
|
|
p.set_bottom_margin(ReportUtils.pt2cm(3))
|
2003-07-06 03:17:41 +05:30
|
|
|
p.set_font(f)
|
2009-06-11 18:31:27 +05:30
|
|
|
p.set_alignment(PARA_ALIGN_CENTER)
|
2004-12-23 07:18:00 +05:30
|
|
|
p.set_description(_("The style used for the title of the page."))
|
2009-08-14 12:44:25 +05:30
|
|
|
default_style.add_paragraph_style("DR-Title", p)
|
2004-12-23 07:18:00 +05:30
|
|
|
|
2009-06-11 18:31:27 +05:30
|
|
|
f = FontStyle()
|
2005-12-06 12:08:09 +05:30
|
|
|
f.set_size(10)
|
2009-08-14 12:44:25 +05:30
|
|
|
for i in range(1, 33):
|
2009-06-11 18:31:27 +05:30
|
|
|
p = ParagraphStyle()
|
2004-12-23 07:18:00 +05:30
|
|
|
p.set_font(f)
|
2005-12-06 12:08:09 +05:30
|
|
|
p.set_top_margin(ReportUtils.pt2cm(f.get_size()*0.125))
|
|
|
|
p.set_bottom_margin(ReportUtils.pt2cm(f.get_size()*0.125))
|
|
|
|
p.set_first_indent(-0.5)
|
2009-08-14 12:44:25 +05:30
|
|
|
p.set_left_margin(min(10.0, float(i-0.5)))
|
2006-03-01 01:24:35 +05:30
|
|
|
p.set_description(_("The style used for the "
|
|
|
|
"level %d display.") % i)
|
2009-08-14 12:44:25 +05:30
|
|
|
default_style.add_paragraph_style("DR-Level%d" % min(i, 32), p)
|
2003-07-06 03:17:41 +05:30
|
|
|
|
2009-06-11 18:31:27 +05:30
|
|
|
p = ParagraphStyle()
|
2005-12-06 12:08:09 +05:30
|
|
|
p.set_font(f)
|
|
|
|
p.set_top_margin(ReportUtils.pt2cm(f.get_size()*0.125))
|
|
|
|
p.set_bottom_margin(ReportUtils.pt2cm(f.get_size()*0.125))
|
2009-08-14 12:44:25 +05:30
|
|
|
p.set_left_margin(min(10.0, float(i-0.5)))
|
2006-03-01 01:24:35 +05:30
|
|
|
p.set_description(_("The style used for the "
|
|
|
|
"spouse level %d display.") % i)
|
2009-08-14 12:44:25 +05:30
|
|
|
default_style.add_paragraph_style("DR-Spouse%d" % min(i, 32), p)
|