2007-07-30 09:02:19 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2008-01-06 02:12:05 +05:30
|
|
|
# Copyright (C) 2007-2008 Brian G. Matherly
|
2007-07-30 09:02:19 +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
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
2008-03-02 04:17:48 +05:30
|
|
|
"""Reports/Text Reports/End of Line Report"""
|
2007-07-30 09:02:19 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-10-02 09:32:10 +05:30
|
|
|
from gen.plug import PluginManager
|
2008-09-27 19:26:17 +05:30
|
|
|
from gen.plug.menu import PersonOption
|
2008-10-02 09:32:10 +05:30
|
|
|
from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_TEXT
|
2007-07-30 09:02:19 +05:30
|
|
|
import BaseDoc
|
|
|
|
from BasicUtils import name_displayer
|
|
|
|
import DateHandler
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# EndOfLineReport
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class EndOfLineReport(Report):
|
|
|
|
|
2008-02-20 10:22:10 +05:30
|
|
|
def __init__(self, database, options_class):
|
2007-07-30 09:02:19 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create the EndOfLineReport object that produces the report.
|
2007-07-30 09:02:19 +05:30
|
|
|
|
|
|
|
The arguments are:
|
|
|
|
|
|
|
|
database - the GRAMPS database instance
|
|
|
|
person - currently selected person
|
|
|
|
options_class - instance of the Options class for this report
|
|
|
|
|
|
|
|
This report needs the following parameters (class variables)
|
|
|
|
that come in the options class.
|
|
|
|
|
|
|
|
"""
|
2008-02-20 10:22:10 +05:30
|
|
|
Report.__init__(self, database, options_class)
|
2007-07-30 09:02:19 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
menu = options_class.menu
|
|
|
|
pid = menu.get_option_by_name('pid').get_value()
|
2008-01-06 02:12:05 +05:30
|
|
|
self.center_person = database.get_person_from_gramps_id(pid)
|
2007-08-01 10:51:19 +05:30
|
|
|
|
|
|
|
# eol_map is a map whose:
|
|
|
|
# keys are the generations of the people
|
|
|
|
# values are a map whose:
|
|
|
|
# keys are person handles
|
|
|
|
# values are an array whose:
|
2008-07-22 10:09:18 +05:30
|
|
|
# elements are an array of ancestor person handles that link
|
|
|
|
# the eol person handle to the person or interest
|
|
|
|
# eol_map[generation][person_handle][pedigree_idx][ancestor_handle_idx]
|
2007-08-01 10:51:19 +05:30
|
|
|
#
|
|
|
|
# There is an array of pedigrees because one person could show up twice
|
|
|
|
# in one generation (descendants marrying). Most people only have one
|
|
|
|
# pedigree.
|
|
|
|
#
|
|
|
|
# eol_map is populated by get_eol() which calls itself recursively.
|
|
|
|
self.eol_map = {}
|
2008-01-23 11:11:46 +05:30
|
|
|
self.get_eol(self.center_person, 1, [])
|
2007-08-01 10:51:19 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def get_eol(self, person, gen, pedigree):
|
|
|
|
"""
|
|
|
|
Recursively find the end of the line for each person
|
|
|
|
"""
|
2008-07-22 10:09:18 +05:30
|
|
|
person_handle = person.get_handle()
|
|
|
|
new_pedigree = list(pedigree) + [person_handle]
|
2007-08-01 10:51:19 +05:30
|
|
|
person_is_eol = False
|
|
|
|
families = person.get_parent_family_handle_list()
|
|
|
|
|
2008-07-22 10:09:18 +05:30
|
|
|
if person_handle in pedigree:
|
|
|
|
# This is a severe error!
|
|
|
|
# It indicates a loop in ancestry: A -> B -> A
|
2007-08-01 10:51:19 +05:30
|
|
|
person_is_eol = True
|
2008-07-22 10:09:18 +05:30
|
|
|
elif not families:
|
|
|
|
person_is_eol = True
|
|
|
|
else:
|
|
|
|
for family_handle in families:
|
|
|
|
family = self.database.get_family_from_handle(family_handle)
|
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
mother_handle = family.get_mother_handle()
|
|
|
|
if father_handle:
|
|
|
|
father = self.database.get_person_from_handle(father_handle)
|
|
|
|
self.get_eol(father, gen+1, new_pedigree)
|
|
|
|
if mother_handle:
|
|
|
|
mother = self.database.get_person_from_handle(mother_handle)
|
|
|
|
self.get_eol(mother, gen+1, new_pedigree)
|
|
|
|
|
|
|
|
if not father_handle or not mother_handle:
|
|
|
|
person_is_eol = True
|
2007-08-01 10:51:19 +05:30
|
|
|
|
|
|
|
if person_is_eol:
|
|
|
|
# This person is the end of a line
|
2008-07-17 23:40:32 +05:30
|
|
|
if gen not in self.eol_map:
|
2007-08-01 10:51:19 +05:30
|
|
|
self.eol_map[gen] = {}
|
2008-07-17 23:40:32 +05:30
|
|
|
if person_handle not in self.eol_map[gen]:
|
2007-08-01 10:51:19 +05:30
|
|
|
self.eol_map[gen][person_handle] = []
|
2008-07-22 10:09:18 +05:30
|
|
|
self.eol_map[gen][person_handle].append( new_pedigree )
|
2007-07-30 09:02:19 +05:30
|
|
|
|
|
|
|
def write_report(self):
|
|
|
|
"""
|
|
|
|
The routine the actually creates the report. At this point, the document
|
|
|
|
is opened and ready for writing.
|
|
|
|
"""
|
2008-01-06 02:12:05 +05:30
|
|
|
pname = name_displayer.display(self.center_person)
|
2007-07-30 09:02:19 +05:30
|
|
|
|
|
|
|
self.doc.start_paragraph("EOL-Title")
|
|
|
|
title = _("End of Line Report for %s") % pname
|
2008-01-23 11:11:46 +05:30
|
|
|
mark = BaseDoc.IndexMark(title, BaseDoc.INDEX_TYPE_TOC, 1)
|
|
|
|
self.doc.write_text(title, mark)
|
2007-07-30 09:02:19 +05:30
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.doc.start_paragraph("EOL-Subtitle")
|
|
|
|
title = _("All the ancestors of %s who are missing a parent") % pname
|
|
|
|
self.doc.write_text(title)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
self.doc.start_table('EolTable','EOL-Table')
|
2009-05-27 02:18:09 +05:30
|
|
|
for generation, handles in self.eol_map.iteritems():
|
2007-08-01 10:51:19 +05:30
|
|
|
self.write_generation_row(generation)
|
2009-05-27 02:18:09 +05:30
|
|
|
for person_handle, pedigrees in handles.iteritems():
|
2007-08-01 10:51:19 +05:30
|
|
|
self.write_person_row(person_handle)
|
2009-05-27 02:18:09 +05:30
|
|
|
for pedigree in pedigrees:
|
2007-08-01 10:51:19 +05:30
|
|
|
self.write_pedigree_row(pedigree)
|
2007-07-30 09:02:19 +05:30
|
|
|
self.doc.end_table()
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def write_generation_row(self, generation):
|
2007-08-01 10:51:19 +05:30
|
|
|
"""
|
|
|
|
Write out a row in the table showing the generation.
|
|
|
|
"""
|
|
|
|
self.doc.start_row()
|
2008-01-23 11:11:46 +05:30
|
|
|
self.doc.start_cell('EOL_GenerationCell', 2)
|
2007-08-01 10:51:19 +05:30
|
|
|
self.doc.start_paragraph('EOL-Generation')
|
|
|
|
self.doc.write_text( _("Generation %d") % generation )
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
self.doc.end_cell()
|
|
|
|
self.doc.end_row()
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def write_person_row(self, person_handle):
|
2007-07-30 09:02:19 +05:30
|
|
|
"""
|
|
|
|
Write a row in the table with information about the given person.
|
|
|
|
"""
|
|
|
|
person = self.database.get_person_from_handle(person_handle)
|
|
|
|
|
|
|
|
name = name_displayer.display(person)
|
|
|
|
mark = ReportUtils.get_person_mark(self.database, person)
|
2007-08-03 09:30:28 +05:30
|
|
|
birth_date = ""
|
2007-07-30 09:02:19 +05:30
|
|
|
birth_ref = person.get_birth_ref()
|
|
|
|
if birth_ref:
|
|
|
|
event = self.database.get_event_from_handle(birth_ref.ref)
|
2007-08-03 09:30:28 +05:30
|
|
|
birth_date = DateHandler.get_date( event )
|
2007-07-30 09:02:19 +05:30
|
|
|
|
2007-08-03 09:30:28 +05:30
|
|
|
death_date = ""
|
2007-07-30 09:02:19 +05:30
|
|
|
death_ref = person.get_death_ref()
|
|
|
|
if death_ref:
|
|
|
|
event = self.database.get_event_from_handle(death_ref.ref)
|
2007-08-03 09:30:28 +05:30
|
|
|
death_date = DateHandler.get_date( event )
|
|
|
|
dates = _(" (%(birth_date)s - %(death_date)s)") % {
|
|
|
|
'birth_date' : birth_date,
|
|
|
|
'death_date' : death_date }
|
2007-08-01 10:51:19 +05:30
|
|
|
|
|
|
|
self.doc.start_row()
|
2008-01-23 11:11:46 +05:30
|
|
|
self.doc.start_cell('EOL-TableCell', 2)
|
2007-08-03 09:30:28 +05:30
|
|
|
self.doc.start_paragraph('EOL-Normal')
|
2008-01-23 11:11:46 +05:30
|
|
|
self.doc.write_text(name, mark)
|
2007-08-03 09:30:28 +05:30
|
|
|
self.doc.write_text(dates)
|
2007-08-01 10:51:19 +05:30
|
|
|
self.doc.end_paragraph()
|
|
|
|
self.doc.end_cell()
|
|
|
|
self.doc.end_row()
|
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def write_pedigree_row(self, pedigree):
|
2007-08-01 10:51:19 +05:30
|
|
|
"""
|
2007-08-03 09:30:28 +05:30
|
|
|
Write a row in the table with with the person's family line.
|
2007-08-01 10:51:19 +05:30
|
|
|
|
|
|
|
pedigree is an array containing the names of the people in the pedigree
|
|
|
|
"""
|
2008-07-22 10:09:18 +05:30
|
|
|
names = []
|
|
|
|
for person_handle in pedigree:
|
|
|
|
person = self.database.get_person_from_handle(person_handle)
|
|
|
|
names.append(name_displayer.display(person))
|
|
|
|
text = " -- ".join(names)
|
2007-08-01 10:51:19 +05:30
|
|
|
self.doc.start_row()
|
|
|
|
self.doc.start_cell('EOL-TableCell')
|
|
|
|
self.doc.end_cell()
|
2007-08-03 09:30:28 +05:30
|
|
|
self.doc.start_cell('EOL-TableCell')
|
2007-08-01 10:51:19 +05:30
|
|
|
self.doc.start_paragraph('EOL-Pedigree')
|
|
|
|
self.doc.write_text(text)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
self.doc.end_cell()
|
|
|
|
self.doc.end_row()
|
2007-07-30 09:02:19 +05:30
|
|
|
|
2007-12-30 11:11:16 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# EndOfLineOptions
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class EndOfLineOptions(MenuReportOptions):
|
2007-07-30 09:02:19 +05:30
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
2008-01-24 18:20:33 +05:30
|
|
|
def __init__(self, name, dbase):
|
|
|
|
MenuReportOptions.__init__(self, name, dbase)
|
2007-12-30 11:11:16 +05:30
|
|
|
|
2008-01-24 18:20:33 +05:30
|
|
|
def add_menu_options(self, menu):
|
2008-01-06 02:12:05 +05:30
|
|
|
"""
|
|
|
|
Add options to the menu for the End of Line report.
|
|
|
|
"""
|
2008-01-18 11:09:50 +05:30
|
|
|
category_name = _("Report Options")
|
|
|
|
|
|
|
|
pid = PersonOption(_("Center Person"))
|
2008-01-06 02:12:05 +05:30
|
|
|
pid.set_help(_("The center person for the report"))
|
2008-01-18 11:09:50 +05:30
|
|
|
menu.add_option(category_name, "pid", pid)
|
2007-07-30 09:02:19 +05:30
|
|
|
|
2008-01-23 11:11:46 +05:30
|
|
|
def make_default_style(self, default_style):
|
2007-07-30 09:02:19 +05:30
|
|
|
"""Make the default output style for the End of Line Report."""
|
|
|
|
# Paragraph Styles
|
|
|
|
f = BaseDoc.FontStyle()
|
|
|
|
f.set_size(16)
|
|
|
|
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
|
|
|
|
f.set_bold(1)
|
|
|
|
p = BaseDoc.ParagraphStyle()
|
|
|
|
p.set_header_level(1)
|
|
|
|
p.set_bottom_border(1)
|
|
|
|
p.set_bottom_margin(ReportUtils.pt2cm(8))
|
|
|
|
p.set_font(f)
|
|
|
|
p.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
|
|
|
|
p.set_description(_("The style used for the title of the page."))
|
2008-01-23 11:11:46 +05:30
|
|
|
default_style.add_paragraph_style("EOL-Title", p)
|
2007-07-30 09:02:19 +05:30
|
|
|
|
|
|
|
font = BaseDoc.FontStyle()
|
2008-01-23 11:11:46 +05:30
|
|
|
font.set(face=BaseDoc.FONT_SANS_SERIF, size=12, italic=1)
|
2007-07-30 09:02:19 +05:30
|
|
|
p = BaseDoc.ParagraphStyle()
|
|
|
|
p.set_bottom_margin(ReportUtils.pt2cm(6))
|
|
|
|
p.set_font(font)
|
|
|
|
p.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
|
|
|
|
p.set_description(_('The style used for the section headers.'))
|
2008-01-23 11:11:46 +05:30
|
|
|
default_style.add_paragraph_style("EOL-Subtitle", p)
|
2007-07-30 09:02:19 +05:30
|
|
|
|
|
|
|
font = BaseDoc.FontStyle()
|
|
|
|
font.set_size(10)
|
|
|
|
p = BaseDoc.ParagraphStyle()
|
|
|
|
p.set_font(font)
|
2007-08-01 10:51:19 +05:30
|
|
|
p.set_top_margin(ReportUtils.pt2cm(6))
|
|
|
|
p.set_bottom_margin(ReportUtils.pt2cm(6))
|
2007-07-30 09:02:19 +05:30
|
|
|
p.set_description(_('The basic style used for the text display.'))
|
2008-01-23 11:11:46 +05:30
|
|
|
default_style.add_paragraph_style("EOL-Normal", p)
|
2007-07-30 09:02:19 +05:30
|
|
|
|
2007-08-01 10:51:19 +05:30
|
|
|
font = BaseDoc.FontStyle()
|
|
|
|
font.set_size(12)
|
|
|
|
font.set_italic(True)
|
|
|
|
p = BaseDoc.ParagraphStyle()
|
|
|
|
p.set_font(font)
|
2007-08-03 09:30:28 +05:30
|
|
|
p.set_top_margin(ReportUtils.pt2cm(6))
|
2007-08-01 10:51:19 +05:30
|
|
|
p.set_description(_('The basic style used for generation headings.'))
|
2008-01-23 11:11:46 +05:30
|
|
|
default_style.add_paragraph_style("EOL-Generation", p)
|
2007-08-01 10:51:19 +05:30
|
|
|
|
|
|
|
font = BaseDoc.FontStyle()
|
|
|
|
font.set_size(8)
|
|
|
|
p = BaseDoc.ParagraphStyle()
|
|
|
|
p.set_font(font)
|
|
|
|
p.set_top_margin(0)
|
2007-08-03 09:30:28 +05:30
|
|
|
p.set_bottom_margin(ReportUtils.pt2cm(6))
|
2007-08-01 10:51:19 +05:30
|
|
|
p.set_description(_('The basic style used for the text display.'))
|
2008-01-23 11:11:46 +05:30
|
|
|
default_style.add_paragraph_style("EOL-Pedigree", p)
|
2007-08-01 10:51:19 +05:30
|
|
|
|
2007-07-30 09:02:19 +05:30
|
|
|
#Table Styles
|
|
|
|
cell = BaseDoc.TableCellStyle()
|
2008-01-23 11:11:46 +05:30
|
|
|
default_style.add_cell_style('EOL-TableCell', cell)
|
2007-08-01 10:51:19 +05:30
|
|
|
|
|
|
|
cell = BaseDoc.TableCellStyle()
|
|
|
|
cell.set_bottom_border(1)
|
2008-01-23 11:11:46 +05:30
|
|
|
default_style.add_cell_style('EOL_GenerationCell', cell)
|
2007-07-30 09:02:19 +05:30
|
|
|
|
|
|
|
table = BaseDoc.TableStyle()
|
|
|
|
table.set_width(100)
|
2007-08-03 09:30:28 +05:30
|
|
|
table.set_columns(2)
|
2008-01-23 11:11:46 +05:30
|
|
|
table.set_column_width(0, 10)
|
|
|
|
table.set_column_width(1, 90)
|
|
|
|
default_style.add_table_style('EOL-Table', table)
|
2007-07-30 09:02:19 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register the plugin
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
pmgr.register_report(
|
2007-07-30 09:02:19 +05:30
|
|
|
name = 'endofline_report',
|
|
|
|
category = CATEGORY_TEXT,
|
|
|
|
report_class = EndOfLineReport,
|
|
|
|
options_class = EndOfLineOptions,
|
2008-10-02 09:32:10 +05:30
|
|
|
modes = PluginManager.REPORT_MODE_GUI | \
|
|
|
|
PluginManager.REPORT_MODE_BKI | \
|
|
|
|
PluginManager.REPORT_MODE_CLI,
|
2008-03-02 04:17:48 +05:30
|
|
|
translated_name = _("End of Line Report"),
|
|
|
|
status = _("Stable"),
|
|
|
|
description = _("Produces a textual end of line report"),
|
|
|
|
author_name = "Brian G. Matherly",
|
|
|
|
author_email = "brian@gramps-project.org"
|
2007-07-30 09:02:19 +05:30
|
|
|
)
|