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-01-06 02:12:05 +05:30
|
|
|
from PluginUtils import register_report, PersonOption
|
2007-12-30 11:11:16 +05:30
|
|
|
from ReportBase import Report, ReportUtils, MenuReportOptions, \
|
2007-07-30 09:02:19 +05:30
|
|
|
CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI
|
|
|
|
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:
|
|
|
|
# elements are an array of names that link the person handle
|
|
|
|
# to the person or interest
|
|
|
|
# eol_map[generation][person_handle][pedigree_index][person_name_index]
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
"""
|
2007-08-01 10:51:19 +05:30
|
|
|
name = name_displayer.display(person)
|
|
|
|
pedigree = pedigree + [name]
|
|
|
|
person_is_eol = False
|
|
|
|
families = person.get_parent_family_handle_list()
|
|
|
|
|
|
|
|
if not families:
|
|
|
|
person_is_eol = True
|
|
|
|
|
|
|
|
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)
|
2008-01-23 11:11:46 +05:30
|
|
|
self.get_eol(father, gen+1, pedigree)
|
2007-08-01 10:51:19 +05:30
|
|
|
if mother_handle:
|
|
|
|
mother = self.database.get_person_from_handle(mother_handle)
|
2008-01-23 11:11:46 +05:30
|
|
|
self.get_eol(mother, gen+1, pedigree)
|
2007-08-01 10:51:19 +05:30
|
|
|
|
|
|
|
if not father_handle or not mother_handle:
|
|
|
|
person_is_eol = True
|
|
|
|
|
|
|
|
if person_is_eol:
|
|
|
|
# This person is the end of a line
|
|
|
|
person_handle = person.get_handle()
|
|
|
|
if not self.eol_map.has_key(gen):
|
|
|
|
self.eol_map[gen] = {}
|
|
|
|
if not self.eol_map[gen].has_key(person_handle):
|
|
|
|
self.eol_map[gen][person_handle] = []
|
|
|
|
self.eol_map[gen][person_handle].append( list(pedigree) )
|
|
|
|
|
|
|
|
# Remove this person from the pedigree
|
|
|
|
pedigree = pedigree[1:len(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')
|
2007-08-01 10:51:19 +05:30
|
|
|
|
|
|
|
for generation in self.eol_map.keys():
|
|
|
|
self.write_generation_row(generation)
|
|
|
|
for person_handle in self.eol_map[generation].keys():
|
|
|
|
self.write_person_row(person_handle)
|
|
|
|
for pedigree in self.eol_map[generation][person_handle]:
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
text = " -- ".join(pedigree)
|
|
|
|
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
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
register_report(
|
|
|
|
name = 'endofline_report',
|
|
|
|
category = CATEGORY_TEXT,
|
|
|
|
report_class = EndOfLineReport,
|
|
|
|
options_class = EndOfLineOptions,
|
|
|
|
modes = MODE_GUI | MODE_BKI | 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
|
|
|
)
|