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
|
2010-05-01 09:42:42 +05:30
|
|
|
# Copyright (C) 2010 Jakim Friant
|
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-03-11 22:14:45 +05:30
|
|
|
from gen.display.name import displayer as _nd
|
2009-08-14 12:44:25 +05:30
|
|
|
from Errors import ReportError
|
2010-05-01 09:42:42 +05:30
|
|
|
from gen.plug.report import Report
|
|
|
|
from gen.plug.report import utils as ReportUtils
|
|
|
|
from gui.plug.report import 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
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PrintSimple
|
|
|
|
# Simple numbering system
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2010-03-11 22:14:45 +05:30
|
|
|
class PrintSimple():
|
|
|
|
def number(self, level):
|
|
|
|
return "%d." % level
|
2010-03-09 07:13:26 +05:30
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PrintVlliers
|
|
|
|
# de_Villiers_Pama numbering system
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2010-03-12 02:52:34 +05:30
|
|
|
class PrintVilliers():
|
2010-03-09 07:13:26 +05:30
|
|
|
def __init__(self):
|
|
|
|
self.pama = 'abcdefghijklmnopqrstuvwxyz'
|
|
|
|
self.num = {0:1}
|
|
|
|
|
2010-03-11 22:14:45 +05:30
|
|
|
def number(self, level):
|
|
|
|
to_return = self.pama[level-1]
|
2010-03-09 07:50:13 +05:30
|
|
|
if level > 1:
|
2010-03-11 22:14:45 +05:30
|
|
|
to_return += str(self.num[level-1])
|
|
|
|
to_return += "."
|
2010-03-09 07:13:26 +05:30
|
|
|
|
|
|
|
self.num[level] = 1
|
|
|
|
self.num[level-1] = self.num[level-1] + 1
|
|
|
|
|
2010-03-11 22:14:45 +05:30
|
|
|
return to_return
|
|
|
|
|
2010-03-09 07:13:26 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# class PrintMeurgey
|
|
|
|
# Meurgey_de_Tupigny numbering system
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2010-03-11 22:14:45 +05:30
|
|
|
class PrintMeurgey():
|
2010-03-09 07:13:26 +05:30
|
|
|
def __init__(self):
|
|
|
|
self.childnum = [""]
|
|
|
|
|
2010-03-11 22:14:45 +05:30
|
|
|
def number(self, level):
|
2010-03-09 07:13:26 +05:30
|
|
|
if level == 1:
|
|
|
|
dash = ""
|
|
|
|
else:
|
|
|
|
dash = "-"
|
|
|
|
if len(self.childnum) < level:
|
|
|
|
self.childnum.append(1)
|
2010-03-11 22:14:45 +05:30
|
|
|
|
|
|
|
to_return = ReportUtils.roman(level) + dash + \
|
|
|
|
str(self.childnum[level-1]) + "."
|
2010-03-09 07:13:26 +05:30
|
|
|
|
|
|
|
if level > 1:
|
|
|
|
self.childnum[level-1] += 1
|
2010-03-11 22:14:45 +05:30
|
|
|
|
|
|
|
return to_return
|
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Printinfo
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class Printinfo():
|
|
|
|
"""
|
|
|
|
A base class used to help make the individual numbering system classes.
|
|
|
|
This class must first be initialized with set_class_vars
|
|
|
|
"""
|
|
|
|
def __init__(self, doc, database, numbering, showmarriage):
|
|
|
|
#classes
|
|
|
|
self.doc = doc
|
|
|
|
self.database = database
|
|
|
|
self.numbering = numbering
|
|
|
|
#variables
|
|
|
|
self.showmarriage = showmarriage
|
|
|
|
|
|
|
|
def __date_place(self,event):
|
|
|
|
if event:
|
|
|
|
date = DateHandler.get_date(event)
|
|
|
|
place_handle = event.get_place_handle()
|
|
|
|
if place_handle:
|
|
|
|
place = self.database.get_place_from_handle(
|
|
|
|
place_handle).get_title()
|
|
|
|
return("%(event_abbrev)s %(date)s - %(place)s" % {
|
|
|
|
'event_abbrev': event.type.get_abbreviation(),
|
|
|
|
'date' : date,
|
|
|
|
'place' : place,
|
|
|
|
})
|
|
|
|
else:
|
|
|
|
return("%(event_abbrev)s %(date)s" % {
|
|
|
|
'event_abbrev': event.type.get_abbreviation(),
|
|
|
|
'date' : date
|
|
|
|
})
|
|
|
|
return ""
|
|
|
|
|
|
|
|
def dump_string(self, person, family=None):
|
|
|
|
string = self.__date_place(get_birth_or_fallback(self.database, \
|
|
|
|
person))
|
|
|
|
|
|
|
|
tmp = self.__date_place(get_death_or_fallback(self.database, person))
|
|
|
|
if string and tmp:
|
|
|
|
string += ", "
|
|
|
|
string += tmp
|
|
|
|
|
|
|
|
if string:
|
|
|
|
string = " (" + string + ")"
|
|
|
|
|
|
|
|
if family is not None:
|
|
|
|
tmp = self.__date_place(ReportUtils.find_marriage(self.database,
|
|
|
|
family))
|
|
|
|
if tmp:
|
2010-03-12 02:52:34 +05:30
|
|
|
string += ", " + tmp
|
2010-03-11 22:14:45 +05:30
|
|
|
|
|
|
|
self.doc.write_text(string)
|
|
|
|
|
|
|
|
def print_person(self, level, person):
|
|
|
|
display_num = self.numbering.number(level)
|
|
|
|
self.doc.start_paragraph("DR-Level%d" % min(level, 32), display_num)
|
2010-03-09 07:13:26 +05:30
|
|
|
mark = ReportUtils.get_person_mark(self.database, person)
|
2010-03-11 22:14:45 +05:30
|
|
|
self.doc.write_text(_nd.display(person), mark)
|
|
|
|
self.dump_string(person)
|
2010-03-09 07:13:26 +05:30
|
|
|
self.doc.end_paragraph()
|
2010-03-11 22:14:45 +05:30
|
|
|
|
|
|
|
def print_spouse(self, level, spouse_handle, family_handle):
|
|
|
|
#Currently print_spouses is the same for all numbering systems.
|
|
|
|
if spouse_handle:
|
|
|
|
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 = _nd.display(spouse)
|
|
|
|
self.doc.write_text(_("sp. %(spouse)s") % {'spouse':name}, mark)
|
|
|
|
if self.showmarriage:
|
|
|
|
self.dump_string(spouse, family_handle)
|
|
|
|
else:
|
|
|
|
self.dump_string(spouse)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
2010-03-09 07:13:26 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# 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-11 22:14:45 +05:30
|
|
|
self.objPrint.print_spouse(level, spouse_handle, family)
|
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)
|
|
|
|
|
2010-03-11 22:14:45 +05:30
|
|
|
|
2010-03-09 07:13:26 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# 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()
|
|
|
|
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
|
2010-03-11 22:14:45 +05:30
|
|
|
numbering = menu.get_option_by_name('numbering').get_value()
|
|
|
|
if numbering == "Simple":
|
|
|
|
obj = PrintSimple()
|
|
|
|
elif numbering == "de Villiers/Pama":
|
2010-03-12 02:52:34 +05:30
|
|
|
obj = PrintVilliers()
|
2010-03-11 22:14:45 +05:30
|
|
|
elif numbering == "Meurgey de Tupigny":
|
|
|
|
obj = PrintMeurgey()
|
|
|
|
else:
|
|
|
|
raise AttributeError("no such numbering: '%s'" % self.numbering)
|
|
|
|
|
|
|
|
self.objPrint = Printinfo(self.doc, database, obj,
|
|
|
|
menu.get_option_by_name('marrs').get_value())
|
2010-03-09 07:13:26 +05:30
|
|
|
|
|
|
|
|
|
|
|
def write_report(self):
|
|
|
|
self.doc.start_paragraph("DR-Title")
|
2010-03-11 22:14:45 +05:30
|
|
|
name = _nd.display(self.center_person)
|
2010-03-09 07:13:26 +05:30
|
|
|
title = _("Descendants of %s") % name
|
|
|
|
mark = IndexMark(title, INDEX_TYPE_TOC, 1)
|
|
|
|
self.doc.write_text(title, mark)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
2010-03-11 22:14:45 +05:30
|
|
|
recurse = RecurseDown(self.max_generations, self.database, self.objPrint)
|
2010-03-09 07:13:26 +05:30
|
|
|
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-12 02:52:34 +05:30
|
|
|
marrs = BooleanOption(_('Show marriage info'), False)
|
|
|
|
marrs.set_help(_("Whether to show marriage information in the report."))
|
2010-03-11 22:14:45 +05:30
|
|
|
menu.add_option(category_name, "marrs", marrs)
|
2010-03-09 07:13:26 +05:30
|
|
|
|
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)
|