gramps/src/plugins/FanChart.py

329 lines
11 KiB
Python
Raw Normal View History

#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2003-2006 Donald N. Allingham
#
# 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$
#------------------------------------------------------------------------
#
# python modules
#
#------------------------------------------------------------------------
from gettext import gettext as _
#------------------------------------------------------------------------
#
# gnome/gtk
#
#------------------------------------------------------------------------
import gtk
#------------------------------------------------------------------------
#
# gramps modules
#
#------------------------------------------------------------------------
import BaseDoc
from PluginUtils import Report, ReportOptions, ReportUtils, register_report
from SubstKeywords import SubstKeywords
pt2cm = ReportUtils.pt2cm
#------------------------------------------------------------------------
#
# FanChart
#
#------------------------------------------------------------------------
class FanChart(Report.Report):
def __init__(self,database,person,options_class):
"""
Creates the FanChart object that produces the report.
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.
display -
"""
Report.Report.__init__(self,database,person,options_class)
self.height = 0
self.lines = 0
self.display = "%n"
self.map = [None] * 32
self.text= {}
self.box_width = 0
def define_graphics_styles(self):
g = BaseDoc.GraphicsStyle()
g.set_paragraph_style('FC-Title')
g.set_line_width(0)
self.doc.add_draw_style("t",g)
g = BaseDoc.GraphicsStyle()
g.set_fill_color((255,212,210))
g.set_paragraph_style('FC-Normal')
self.doc.add_draw_style("FC-c1",g)
g = BaseDoc.GraphicsStyle()
g.set_fill_color((255,212,210))
g.set_paragraph_style('FC-Normal')
g.set_line_width(0)
self.doc.add_draw_style("FC-c1n",g)
g = BaseDoc.GraphicsStyle()
g.set_fill_color((251,204,158))
g.set_paragraph_style('FC-Normal')
self.doc.add_draw_style("FC-c2",g)
g = BaseDoc.GraphicsStyle()
g.set_fill_color((251,204,158))
g.set_paragraph_style('FC-Normal')
g.set_line_width(0)
self.doc.add_draw_style("FC-c2n",g)
g = BaseDoc.GraphicsStyle()
g.set_fill_color((255,255,111))
g.set_paragraph_style('FC-Normal')
self.doc.add_draw_style("FC-c3",g)
g = BaseDoc.GraphicsStyle()
g.set_fill_color((255,255,111))
g.set_paragraph_style('FC-Normal')
g.set_line_width(0)
self.doc.add_draw_style("FC-c3n",g)
g = BaseDoc.GraphicsStyle()
g.set_fill_color((158,255,158))
g.set_paragraph_style('FC-Normal')
self.doc.add_draw_style("FC-c4",g)
g = BaseDoc.GraphicsStyle()
g.set_fill_color((158,255,158))
g.set_paragraph_style('FC-Normal')
g.set_line_width(0)
self.doc.add_draw_style("FC-c4n",g)
g = BaseDoc.GraphicsStyle()
g.set_fill_color((156,205,255))
g.set_paragraph_style('FC-Normal')
self.doc.add_draw_style("FC-c5",g)
g = BaseDoc.GraphicsStyle()
g.set_fill_color((156,205,255))
g.set_paragraph_style('FC-Normal')
g.set_line_width(0)
self.doc.add_draw_style("FC-c5n",g)
def apply_filter(self,person_handle,index):
"""traverse the ancestors recursively until either the end
of a line is found, or until we reach the maximum number of
generations that we want to deal with"""
if (not person_handle) or (index >= 32):
return
self.map[index-1] = person_handle
self.text[index-1] = []
subst = SubstKeywords(self.database,person_handle)
for line in self.display:
self.text[index-1].append(subst.replace(line))
self.font = self.doc.style_list["FC-Normal"].get_font()
for line in self.text[index-1]:
* src/WriteGedcom.py (get_option_box): Make filters inclusive. * src/plugins/merge.glade: Switch button order to comply with HIG. * src/mergedata.glade: Switch button order to comply with HIG. * src/plugins/RelGraph.py (get_default_basename): Add function. * src/plugins/AncestorReport.py (write_report): Translate string properly. * src/EventEdit.py (update_event): Use transtable. * src/EditPerson.py (on_event_add_clicked, on_edit_birth_clicked, on_edit_death_clicked, on_event_update_clicked): Pass TransTable to the event editor. * src/Marriage.py (on_add_clicked, on_event_update_clicked): Pass TransTable to the event editor. * src/plugins/FtmStyleAncestors.py, src/plugins/FtmStyleDescendants.py: Remove extra space between vars in "%(.*_place)s %(.*_notes)s" * src/plugins/verify.glade: Translate button label. * src/plugins/IndivSummary.py: Proper handling of translation. * src/docgen/OpenOfficeDoc.py (pt2cm): Add function; (draw_text): Convert points to cm for the box width; Use self.string_width() method. * src/BaseDoc.py (string_width): Add a method to compute width. * src/docgen/LPRDoc.py (string_width): Override method. * src/docgen/PdfDoc.py: Use self.string_width() method. * src/docgen/SvgDrawDoc.py: Use self.string_width() method. * src/plugins/AncestorChart2.py: Use self.doc.string_width() method. * src/plugins/AncestorChart.py: Use self.doc.string_width() method. * src/plugins/DesGraph.py: Use self.doc.string_width() method. * src/plugins/FanChart.py: Use self.doc.string_width() method. * src/plugins/TimeLine.py: Use self.doc.string_width() method. * src/plugins/eval.glade: HIG compliance. svn: r3453
2004-08-21 02:56:51 +05:30
self.box_width = max(self.box_width,self.doc.string_width(self.font,line))
self.lines = max(self.lines,len(self.text[index-1]))
person = self.database.get_person_from_handle(person_handle)
family_handle = person.get_main_parents_family_handle()
if family_handle:
* PeopleModel.py: simplify model interface * EditPerson.py: get_family_from_handle fixes * EditSource.py: get_family_from_handle fixes * GraphLayout.py: get_family_from_handle fixes * ImageSelect.py: get_family_from_handle fixes * MediaView.py: get_family_from_handle fixes * MergeData.py: get_family_from_handle fixes * PlaceView.py: get_family_from_handle fixes * ReadXML.py: get_family_from_handle fixes * RelLib.py: get_family_from_handle fixes * Relationship.py: get_family_from_handle fixes * SelectChild.py: get_family_from_handle fixes * SourceView.py: get_family_from_handle fixes * SubstKeywords.py: get_family_from_handle fixes * WriteXML.py: get_family_from_handle fixes * gramps_main.py: get_family_from_handle fixes * plugins/AncestorChart.py: get_family_from_handle fixes * plugins/AncestorChart2.py: get_family_from_handle fixes * plugins/AncestorReport.py: get_family_from_handle fixes * plugins/Ancestors.py: get_family_from_handle fixes * plugins/Check.py: get_family_from_handle fixes * plugins/CountAncestors.py: get_family_from_handle fixes * plugins/Desbrowser.py: get_family_from_handle fixes * plugins/DescendReport.py: get_family_from_handle fixes * plugins/DetAncestralReport.py: get_family_from_handle fixes * plugins/DetDescendantReport.py: get_family_from_handle fixes * plugins/FamilyGroup.py: get_family_from_handle fixes * plugins/FanChart.py: get_family_from_handle fixes * plugins/FtmStyleAncestors.py: get_family_from_handle fixes * plugins/FtmStyleDescendants.py: get_family_from_handle fixes * plugins/GraphViz.py: get_family_from_handle fixes * plugins/IndivComplete.py: get_family_from_handle fixes * plugins/IndivSummary.py: get_family_from_handle fixes * plugins/Merge.py: get_family_from_handle fixes * plugins/RelGraph.py: get_family_from_handle fixes * plugins/Verify.py: get_family_from_handle fixes * plugins/WebPage.py: get_family_from_handle fixes * plugins/WriteCD.py: get_family_from_handle fixes * plugins/WritePkg.py: get_family_from_handle fixes * plugins/rel_de.py: get_family_from_handle fixes * plugins/rel_hu.py: get_family_from_handle fixes * plugins/rel_ru.py: get_family_from_handle fixes svn: r3443
2004-08-20 03:05:16 +05:30
family = self.database.get_family_from_handle(family_handle)
self.apply_filter(family.get_father_handle(),index*2)
self.apply_filter(family.get_mother_handle(),(index*2)+1)
def write_report(self):
self.apply_filter(self.start_person.get_handle(),1)
block_size = self.doc.get_usable_width()/14.0
size = min(self.doc.get_usable_width(),self.doc.get_usable_height()*2.0)/2.0
y = self.doc.get_usable_height()
max_lines = int(size/block_size)
center = (self.doc.get_usable_width()/2.0)
self.doc.start_page()
n = self.start_person.get_primary_name().get_regular_name()
self.doc.center_text('t', _('Five Generation Fan Chart for %s') % n, center, 0)
self.circle_5(center,y,block_size)
self.circle_4(center,y,block_size)
self.circle_3(center,y,block_size)
self.circle_2(center,y,block_size)
self.circle_1(center,y,block_size)
self.doc.end_page()
def get_info(self,person_handle):
person = self.database.get_person_from_handle(person_handle)
pn = person.get_primary_name()
birth_ref = person.get_birth_ref()
if birth_ref:
birth = self.database.get_event_from_handle(birth_ref.ref)
b = birth.get_date_object().get_year()
if b == 0:
b = ""
else:
b = ""
death_ref = person.get_death_ref()
if death_ref:
death = self.database.get_event_from_handle(death_ref.ref)
d = death.get_date_object().get_year()
if d == 0:
d = ""
else:
d = ""
if b or d:
val = "%s - %s" % (str(b),str(d))
else:
val = ""
return [ pn.get_first_name(), pn.get_surname(), val ]
def circle_1(self,center,y,size):
(xc,yc) = self.doc.draw_wedge("FC-c1", center, y, size, 180, 360)
self.doc.rotate_text("FC-c1n", self.get_info(self.map[0]), xc, yc ,0)
def circle_2(self,center,y,size):
(xc,yc) = self.doc.draw_wedge("FC-c2", center, y, size*2, 180, 270, size)
if self.map[1]:
self.doc.rotate_text("FC-c2n", self.get_info(self.map[1]), xc, yc, -45)
(xc,yc) = self.doc.draw_wedge("FC-c2", center, y, size*2, 270, 360, size)
if self.map[2]:
self.doc.rotate_text("FC-c2n", self.get_info(self.map[2]), xc,yc ,45)
def circle_3(self,center,y,size):
delta = 45
sangle = -67.5
for index in range(3,7):
start = 180+(index-3)*45
stop = start+45
(xc,yc) = self.doc.draw_wedge("FC-c3", center, y, size*3, start, stop, size*2)
if self.map[index]:
self.doc.rotate_text("FC-c3n", self.get_info(self.map[index]),
xc,yc ,sangle)
sangle += 45
def circle_4(self,center,y,size):
delta = 22.5
sangle = -78.75 + 90
for i in range(0,8):
start_angle = 180 + (i * delta)
end_angle = 180 + ((i+1) * delta)
(xc,yc) = self.doc.draw_wedge("FC-c4", center, y, size*5, start_angle,
end_angle, size*3)
if i == 4:
sangle += 180
if self.map[i+7]:
self.doc.rotate_text("FC-c4n", self.get_info(self.map[i+7]),
xc,yc ,sangle)
sangle += 22.5
def circle_5(self,center,y,size):
delta = 11.25
sangle = -84.625 + 90
for i in range(0,16):
start_angle = 180 + (i * delta)
end_angle = 180 + ((i+1) * delta)
(xc,yc) = self.doc.draw_wedge("FC-c5", center, y, size*7, start_angle,
end_angle, size*5)
if i == 8:
sangle += 180
if self.map[i+15]:
self.doc.rotate_text("FC-c5n", self.get_info(self.map[i+15]),
xc,yc ,sangle)
sangle += 11.25
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
class FanChartOptions(ReportOptions.ReportOptions):
"""
Defines options and provides handling interface.
"""
def __init__(self,name,person_id=None):
ReportOptions.ReportOptions.__init__(self,name,person_id)
def make_default_style(self,default_style):
"""Make the default output style for the Fan Chart report."""
f = BaseDoc.FontStyle()
f.set_size(8)
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
p = BaseDoc.ParagraphStyle()
p.set_font(f)
p.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
p.set_description(_('The basic style used for the text display.'))
default_style.add_style("FC-Normal",p)
f = BaseDoc.FontStyle()
f.set_size(20)
f.set_bold(1)
f.set_type_face(BaseDoc.FONT_SANS_SERIF)
p = BaseDoc.ParagraphStyle()
p.set_font(f)
p.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
p.set_description(_('The style used for the title.'))
default_style.add_style("FC-Title",p)
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
register_report(
name = 'fan_chart',
2005-12-06 12:08:09 +05:30
category = Report.CATEGORY_DRAW,
report_class = FanChart,
options_class = FanChartOptions,
modes = Report.MODE_GUI | Report.MODE_BKI | Report.MODE_CLI,
translated_name = _("Fan Chart"),
2005-12-06 12:08:09 +05:30
status = _("Stable"),
author_name = "Donald N. Allingham",
2005-12-06 12:08:09 +05:30
author_email = "don@gramps-project.org",
description = _("Produces a five generation fan chart")
)