2007-09-30 10:26:56 +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-09-30 10:26:56 +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
|
|
|
|
#
|
2008-01-23 11:11:46 +05:30
|
|
|
# $Id$
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
Generate an hourglass graph using the GraphViz generator.
|
2008-01-29 02:52:06 +05:30
|
|
|
/Reports/GraphViz/Hourglass Graph...
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
2008-01-13 09:56:47 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
from gettext import gettext as _
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-01-06 02:12:05 +05:30
|
|
|
from PluginUtils import register_report, NumberOption, PersonOption
|
2007-11-29 20:32:40 +05:30
|
|
|
from ReportBase import Report, ReportUtils, MenuReportOptions, \
|
|
|
|
MODE_GUI, MODE_CLI, CATEGORY_GRAPHVIZ
|
2007-09-30 10:26:56 +05:30
|
|
|
from BasicUtils import name_displayer
|
|
|
|
import DateHandler
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# AncestorChart
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class HourGlassReport(Report):
|
2008-01-13 09:56:47 +05:30
|
|
|
"""
|
|
|
|
An hourglass report displays ancestors and descendants of a center person.
|
|
|
|
"""
|
|
|
|
def __init__(self, database, person, options_class):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
|
|
|
Creates HourGlass object that produces the report.
|
|
|
|
"""
|
2008-01-13 09:56:47 +05:30
|
|
|
Report.__init__(self, database, person, options_class)
|
|
|
|
self.__db = database
|
2008-01-23 11:11:46 +05:30
|
|
|
|
|
|
|
menu = options_class.menu
|
|
|
|
self.max_descend = menu.get_option_by_name('maxdescend').get_value()
|
|
|
|
self.max_ascend = menu.get_option_by_name('maxascend').get_value()
|
|
|
|
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-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
def write_report(self):
|
2008-01-13 09:56:47 +05:30
|
|
|
"""
|
|
|
|
Generate the report.
|
|
|
|
"""
|
2008-01-06 02:12:05 +05:30
|
|
|
self.add_person(self.center_person)
|
2008-01-13 09:56:47 +05:30
|
|
|
self.traverse_up(self.center_person, 1)
|
|
|
|
self.traverse_down(self.center_person, 1)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
2008-01-13 09:56:47 +05:30
|
|
|
def traverse_down(self, person, gen):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
|
|
|
Resursively find the descendants of the given person.
|
|
|
|
"""
|
|
|
|
if gen > self.max_descend:
|
|
|
|
return
|
|
|
|
for family_handle in person.get_family_handle_list():
|
2008-01-13 09:56:47 +05:30
|
|
|
family = self.__db.get_family_from_handle(family_handle)
|
2007-09-30 10:26:56 +05:30
|
|
|
self.add_family(family)
|
|
|
|
self.doc.add_link( person.get_gramps_id(), family.get_gramps_id() )
|
|
|
|
for child_ref in family.get_child_ref_list():
|
|
|
|
child_handle = child_ref.get_reference_handle()
|
2008-01-13 09:56:47 +05:30
|
|
|
child = self.__db.get_person_from_handle(child_handle)
|
2007-09-30 10:26:56 +05:30
|
|
|
self.add_person(child)
|
2008-01-13 09:56:47 +05:30
|
|
|
self.doc.add_link(family.get_gramps_id(), child.get_gramps_id())
|
|
|
|
self.traverse_down(child, gen+1)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
2008-01-13 09:56:47 +05:30
|
|
|
def traverse_up(self, person, gen):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
|
|
|
Resursively find the ancestors of the given person.
|
|
|
|
"""
|
|
|
|
if gen > self.max_ascend:
|
|
|
|
return
|
|
|
|
family_handle = person.get_main_parents_family_handle()
|
|
|
|
if family_handle:
|
2008-01-13 09:56:47 +05:30
|
|
|
family = self.__db.get_family_from_handle(family_handle)
|
2007-09-30 10:26:56 +05:30
|
|
|
family_id = family.get_gramps_id()
|
|
|
|
self.add_family(family)
|
|
|
|
self.doc.add_link( family_id, person.get_gramps_id() )
|
|
|
|
father_handle = family.get_father_handle()
|
|
|
|
if father_handle:
|
2008-01-13 09:56:47 +05:30
|
|
|
father = self.__db.get_person_from_handle(father_handle)
|
2007-09-30 10:26:56 +05:30
|
|
|
self.add_person(father)
|
|
|
|
self.doc.add_link( father.get_gramps_id(), family_id )
|
2008-01-13 09:56:47 +05:30
|
|
|
self.traverse_up(father, gen+1)
|
2007-09-30 10:26:56 +05:30
|
|
|
mother_handle = family.get_mother_handle()
|
|
|
|
if mother_handle:
|
2008-01-13 09:56:47 +05:30
|
|
|
mother = self.__db.get_person_from_handle( mother_handle )
|
2007-09-30 10:26:56 +05:30
|
|
|
self.add_person( mother )
|
|
|
|
self.doc.add_link( mother.get_gramps_id(), family_id )
|
|
|
|
self.traverse_up( mother, gen+1 )
|
|
|
|
|
2008-01-13 09:56:47 +05:30
|
|
|
def add_person(self, person):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
|
|
|
Add a person to the Graph. The node id will be the person's gramps id.
|
|
|
|
"""
|
|
|
|
p_id = person.get_gramps_id()
|
|
|
|
name = name_displayer.display_formal(person)
|
|
|
|
|
2008-01-13 09:56:47 +05:30
|
|
|
birth_evt = ReportUtils.get_birth_or_fallback(self.__db, person)
|
2007-09-30 10:26:56 +05:30
|
|
|
if birth_evt:
|
|
|
|
birth = DateHandler.get_date(birth_evt)
|
|
|
|
else:
|
|
|
|
birth = ""
|
|
|
|
|
2008-01-13 09:56:47 +05:30
|
|
|
death_evt = ReportUtils.get_death_or_fallback(self.__db, person)
|
2007-09-30 10:26:56 +05:30
|
|
|
if death_evt:
|
|
|
|
death = DateHandler.get_date(death_evt)
|
|
|
|
else:
|
|
|
|
death = ""
|
|
|
|
|
2008-01-13 09:56:47 +05:30
|
|
|
label = "%s \\n(%s - %s)" % (name, birth, death)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
gender = person.get_gender()
|
|
|
|
if gender == person.MALE:
|
|
|
|
color = 'lightblue'
|
|
|
|
elif gender == person.FEMALE:
|
|
|
|
color = 'lightpink'
|
|
|
|
else:
|
|
|
|
color = 'lightgray'
|
|
|
|
|
2008-01-13 09:56:47 +05:30
|
|
|
self.doc.add_node(p_id, label, "box", "", "filled", color)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
2008-01-13 09:56:47 +05:30
|
|
|
def add_family(self, family):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
|
|
|
Add a family to the Graph. The node id will be the family's gramps id.
|
|
|
|
"""
|
|
|
|
family_id = family.get_gramps_id()
|
|
|
|
label = ""
|
2008-01-13 09:56:47 +05:30
|
|
|
marriage = ReportUtils.find_marriage(self.__db, family)
|
2007-09-30 10:26:56 +05:30
|
|
|
if marriage:
|
|
|
|
label = DateHandler.get_date(marriage)
|
2008-01-13 09:56:47 +05:30
|
|
|
self.doc.add_node(family_id, label, "ellipse", "",
|
|
|
|
"filled", "lightyellow")
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# HourGlassOptions
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2007-11-29 05:03:40 +05:30
|
|
|
class HourGlassOptions(MenuReportOptions):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
|
|
|
Defines options for the HourGlass report.
|
|
|
|
"""
|
2008-01-24 18:20:33 +05:30
|
|
|
def __init__(self, name, dbase):
|
|
|
|
MenuReportOptions.__init__(self, name, dbase)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
2008-01-24 18:20:33 +05:30
|
|
|
def add_menu_options(self, menu):
|
2008-01-13 09:56:47 +05:30
|
|
|
"""
|
|
|
|
Create all the menu options for this report.
|
|
|
|
"""
|
2007-09-30 10:26:56 +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)
|
|
|
|
|
2008-01-13 09:56:47 +05:30
|
|
|
max_gen = NumberOption(_('Max Descendant Generations'), 10, 1, 15)
|
2007-09-30 10:26:56 +05:30
|
|
|
max_gen.set_help(_("The number of generations of descendants to " \
|
|
|
|
"include in the report"))
|
2008-01-13 09:56:47 +05:30
|
|
|
menu.add_option(category_name, "maxdescend", max_gen)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
2008-01-13 09:56:47 +05:30
|
|
|
max_gen = NumberOption(_('Max Ancestor Generations'), 10, 1, 15)
|
2007-09-30 10:26:56 +05:30
|
|
|
max_gen.set_help(_("The number of generations of ancestors to " \
|
|
|
|
"include in the report"))
|
2008-01-13 09:56:47 +05:30
|
|
|
menu.add_option(category_name, "maxascend", max_gen)
|
2007-09-30 10:26:56 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
register_report(
|
|
|
|
name = 'hourglass_graph',
|
|
|
|
category = CATEGORY_GRAPHVIZ,
|
|
|
|
report_class = HourGlassReport,
|
|
|
|
options_class = HourGlassOptions,
|
|
|
|
modes = MODE_GUI | MODE_CLI,
|
2008-01-29 02:52:06 +05:30
|
|
|
translated_name = _("Hourglass Graph..."),
|
2007-09-30 10:26:56 +05:30
|
|
|
status = _("Stable"),
|
|
|
|
author_name = "Brian G. Matherly",
|
|
|
|
author_email = "brian@gramps-project.org",
|
|
|
|
description = _("Produces an hourglass graph")
|
|
|
|
)
|