2
# Gramps - a GTK+/GNOME based genealogy program
4
# Copyright (C) 2000-2003 Donald N. Allingham
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
"Text Reports/Ahnentafel Report"
23
#------------------------------------------------------------------------
27
#------------------------------------------------------------------------
31
#------------------------------------------------------------------------
35
#------------------------------------------------------------------------
40
from QuestionDialog import ErrorDialog
41
from gettext import gettext as _
43
#------------------------------------------------------------------------
47
#------------------------------------------------------------------------
48
class AncestorReport(Report.Report):
50
def __init__(self,database,person,max,pgbrk,doc,output,newpage=0):
52
self.database = database
54
self.max_generations = max
57
self.newpage = newpage
65
def filter(self,person,index,generation=1):
66
if person == None or generation >= self.max_generations:
68
self.map[index] = person
70
family = person.getMainParents()
72
self.filter(family.getFather(),index*2,generation+1)
73
self.filter(family.getMother(),(index*2)+1,generation+1)
75
def write_report(self):
80
self.filter(self.start,1)
82
name = self.start.getPrimaryName().getRegularName()
83
self.doc.start_paragraph("AHN-Title")
84
title = _("Ahnentafel Report for %s") % name
85
self.doc.write_text(title)
86
self.doc.end_paragraph()
88
keys = self.map.keys()
93
if generation == 0 or key >= ( 1 << 30):
94
if self.pgbrk and generation > 0:
96
self.doc.start_paragraph("AHN-Generation")
97
t = _("%s Generation") % AncestorReport.gen[generation+1]
98
self.doc.write_text(t)
99
self.doc.end_paragraph()
100
generation = generation + 1
102
self.doc.start_paragraph("AHN-Entry","%s." % str(key))
103
person = self.map[key]
104
name = person.getPrimaryName().getRegularName()
106
self.doc.start_bold()
107
self.doc.write_text(name)
110
self.doc.write_text(" ")
112
self.doc.write_text(". ")
116
birth = person.getBirth()
118
date = birth.getDateObj().get_start_date()
119
place = birth.getPlaceName()
120
if place[-1:] == '.':
122
if date.getDate() != "" or place != "":
123
if date.getDate() != "":
124
if date.getDayValid() and date.getMonthValid():
126
t = _("%s was born on %s in %s. ") % \
127
(name,date.getDate(),place)
129
t = _("%s was born on %s. ") % \
130
(name,date.getDate())
133
t = _("%s was born in the year %s in %s. ") % \
134
(name,date.getDate(),place)
136
t = _("%s was born in the year %s. ") % \
137
(name,date.getDate())
138
self.doc.write_text(t)
140
death = person.getDeath()
142
for event in person.getEventList():
143
if string.lower(event.getName()) == "burial":
147
date = death.getDateObj().get_start_date()
148
place = death.getPlaceName()
149
if place[-1:] == '.':
151
if date.getDate() != "" or place != "":
152
if person.getGender() == RelLib.Person.male:
157
if date.getDate() != "":
158
if date.getDayValid() and date.getMonthValid():
161
t = _("He died on %s in %s") % \
162
(date.getDate(),place)
164
t = _("He died on %s") % date.getDate()
167
t = _("She died on %s in %s") % \
168
(date.getDate(),place)
170
t = _("She died on %s") % date.getDate()
174
t = _("He died in the year %s in %s") % \
175
(date.getDate(),place)
177
t = _("He died in the year %s") % date.getDate()
180
t = _("She died in the year %s in %s") % \
181
(date.getDate(),place)
183
t = _("She died in the year %s") % date.getDate()
185
self.doc.write_text(t)
188
date = buried.getDateObj().get_start_date()
189
place = buried.getPlaceName()
190
if place[-1:] == '.':
192
if date.getDate() != "" or place != "":
193
if date.getDate() != "":
194
if date.getDayValid() and date.getMonthValid():
196
t = _(", and was buried on %s in %s.") % \
197
(date.getDate(),place)
199
t = _(", and was buried on %s.") % \
203
t = _(", and was buried in the year %s in %s.") % \
204
(date.getDate(),place)
206
t = _(", and was buried in the year %s.") % \
209
t = _(" and was buried in %s." % place)
210
self.doc.write_text(t)
212
self.doc.write_text(".")
214
self.doc.end_paragraph()
219
#------------------------------------------------------------------------
223
#------------------------------------------------------------------------
224
class AncestorReportDialog(Report.TextReportDialog):
228
def __init__(self,database,person):
229
Report.TextReportDialog.__init__(self,database,person,self.report_options)
231
#------------------------------------------------------------------------
233
# Customization hooks
235
#------------------------------------------------------------------------
237
"""The window title for this dialog"""
238
return "%s - %s - GRAMPS" % (_("Ahnentafel Report"),_("Text Reports"))
240
def get_header(self, name):
241
"""The header line at the top of the dialog contents"""
242
return _("Ahnentafel Report for %s") % name
244
def get_target_browser_title(self):
245
"""The title of the window created when the 'browse' button is
246
clicked in the 'Save As' frame."""
247
return _("Save Ahnentafel Report")
249
def get_stylesheet_savefile(self):
250
"""Where to save styles for this report."""
251
return "ancestor_report.xml"
253
def make_default_style(self):
254
_make_default_style(self.default_style)
256
def make_report(self):
257
"""Create the object that will produce the Ahnentafel Report.
258
All user dialog has already been handled and the output file
261
MyReport = AncestorReport(self.db, self.person,
262
self.max_gen, self.pg_brk, self.doc, self.target_path)
263
MyReport.write_report()
264
except Errors.ReportError, msg:
265
(m1,m2) = msg.messages()
267
except Errors.FilterError, msg:
268
(m1,m2) = msg.messages()
271
ErrorDialog(_("Could not create %s" % self.target_path),msg)
274
DisplayTrace.DisplayTrace()
276
#------------------------------------------------------------------------
278
# Standalone report function
280
#------------------------------------------------------------------------
281
def report(database,person):
282
AncestorReportDialog(database,person)
285
#------------------------------------------------------------------------
287
# Set up sane defaults for the book_item
289
#------------------------------------------------------------------------
290
_style_file = "ancestor_report.xml"
291
_style_name = "default"
296
_options = ( _person_id, _max_gen, _pg_brk )
298
#------------------------------------------------------------------------
300
# Book Item Options dialog
302
#------------------------------------------------------------------------
303
class AncestorBareReportDialog(Report.BareReportDialog):
305
def __init__(self,database,person,opt,stl):
310
self.person = self.db.getPerson(self.options[0])
313
self.style_name = stl
315
Report.BareReportDialog.__init__(self,database,self.person)
317
self.max_gen = int(self.options[1])
318
self.pg_brk = int(self.options[2])
319
self.new_person = None
321
self.generations_spinbox.set_value(self.max_gen)
322
self.pagebreak_checkbox.set_active(self.pg_brk)
326
#------------------------------------------------------------------------
328
# Customization hooks
330
#------------------------------------------------------------------------
331
def make_default_style(self):
332
_make_default_style(self.default_style)
335
"""The window title for this dialog"""
336
return "%s - GRAMPS Book" % (_("Ahnentafel Report"))
338
def get_header(self, name):
339
"""The header line at the top of the dialog contents"""
340
return _("Ahnentafel Report for GRAMPS Book")
342
def get_stylesheet_savefile(self):
343
"""Where to save styles for this report."""
346
def on_cancel(self, obj):
349
def on_ok_clicked(self, obj):
350
"""The user is satisfied with the dialog choices. Parse all options
351
and close the window."""
354
self.parse_style_frame()
355
self.parse_report_options_frame()
358
self.person = self.new_person
359
self.options = ( self.person.getId(), self.max_gen, self.pg_brk )
360
self.style_name = self.selected_style.get_name()
362
#------------------------------------------------------------------------
364
# Function to write Book Item
366
#------------------------------------------------------------------------
367
def write_book_item(database,person,doc,options,newpage=0):
368
"""Write the Ahnentafel Report using options set.
369
All user dialog has already been handled and the output file opened."""
372
person = database.getPerson(options[0])
373
max_gen = int(options[1])
374
pg_brk = int(options[2])
375
return AncestorReport(database, person, max_gen, pg_brk, doc, None, newpage )
376
except Errors.ReportError, msg:
377
(m1,m2) = msg.messages()
379
except Errors.FilterError, msg:
380
(m1,m2) = msg.messages()
384
DisplayTrace.DisplayTrace()
386
#------------------------------------------------------------------------
390
#------------------------------------------------------------------------
391
def _make_default_style(default_style):
392
"""Make the default output style for the Ahnentafel report."""
393
font = BaseDoc.FontStyle()
394
font.set(face=BaseDoc.FONT_SANS_SERIF,size=16,bold=1)
395
para = BaseDoc.ParagraphStyle()
397
para.set_header_level(1)
399
para.set_description(_('The style used for the title of the page.'))
400
default_style.add_style("AHN-Title",para)
402
font = BaseDoc.FontStyle()
403
font.set(face=BaseDoc.FONT_SANS_SERIF,size=14,italic=1)
404
para = BaseDoc.ParagraphStyle()
406
para.set_header_level(2)
408
para.set_description(_('The style used for the generation header.'))
409
default_style.add_style("AHN-Generation",para)
411
para = BaseDoc.ParagraphStyle()
412
para.set(first_indent=-1.0,lmargin=1.0,pad=0.25)
413
para.set_description(_('The basic style used for the text display.'))
414
default_style.add_style("AHN-Entry",para)
416
#------------------------------------------------------------------------
420
#------------------------------------------------------------------------
459
" (+(+++++111%1%%%%===%1 ",
460
" +______________@_@)&==1 ",
461
" +_::::::::::::::*|#_&&}> ",
462
" &_:::::::::::::::{|#]1~}^ ",
463
" +_::::::::::::::::{|#=|~&4 ",
464
" +_::::]]]]]]]]:::::|{':|~&4 ",
465
" +_::::::::::::::::::{'::|~&4 ",
466
" +_:::::::::::::::::::'*::|~&^ ",
467
" +_:::::::::::::::::::'|*::|~}> ",
468
" 1_::::]]]]]]]]]]]]:::'~|{::|_}% ",
469
" 1_:::::::::::::::::::'..4^'=1+%1 ",
470
" +_::::]]]]]]]]]]]]:::|__])&+%=^% ",
471
" 1_::::::::::::::::::::|#__)&&+'^ ",
472
" 1_::::]]]]]]]]]::::::::|#~_])&%^ ",
473
" 1_::::::::::::::::::::{||#~_])14 ",
474
" 1_::::]]]]]]]]]]]]]]]]]]&}#~_]+4 ",
475
" 1_::::::::::::::::::{{{{||#~~@&4 ",
476
" %_::::]]]]]]]]]]]]]]]])))}(~~~&4 ",
477
" %_:::::::::::::::::{{{{{*|#/~_(4 ",
478
" %_::::]]]]]]]]]]]]]]])))))}2;/}4 ",
479
" %_:::::::::::::::{{{{{***||[#~}4 ",
480
" %_::::]]]]]]]]]])]))))))))}2/;)4 ",
481
" %_::::::::::::::{{{{{**|$$[/2~!4 ",
482
" %_::::]]]]]]]]){{{{******$$[2/}4 ",
483
" %_::::::::::::{{{{****$$$$$[2/!4 ",
484
" =_::::]]]]]]])]))))))))})}}[2/!4 ",
485
" %_:::::::::{{{{{{**|$$$$$$[[2;)4 ",
486
" =_::::]]]])]]))))))))))}}}}[22!4 ",
487
" %_::::::::{{{{{|**|$$[$[[[[[22}4 ",
488
" =_::::]]])])))))))))}}}}}}}222-4 ",
489
" =_:::::{{{{{|{*|$$$$$[[[[22222!4 ",
490
" =_::::)]])))))))))}}}}}}(}(2;2-4 ",
491
" =_:::{{{{{{***|$$$$$[[[[22222;-4 ",
492
" =_:::{])))))))))}}}}}}}(}((2;;<4 ",
493
" >_:{{{{{{**|$$$$$[[[[22222;2;;-4 ",
494
" >_{{{{)))))))}}}}}}}(!(((((;;;-4 ",
495
" >_{{{{|**|*$$$$$[[[[22222;;;;;!4 ",
496
" '_{{{{****$$$$$2[[222222;2;;;;-4 ",
497
" '@{{****$$$$$[[[2[222;;2;;;;;;!4 ",
498
" >]{******$$$[$[2[[2222;;;;;;;;!4 ",
499
" '_****$$$$[$[[[[2222;2;;;;;;;;!4 ",
500
" '@__@@@@@@@33<3<<<<<<-<-!!!!!!!4 ",
501
" 44444444444444444444444444444444 ",
506
#------------------------------------------------------------------------
510
#------------------------------------------------------------------------
511
from Plugins import register_report, register_book_item
515
_("Ahnentafel Report"),
516
category=_("Text Reports"),
518
description= _("Produces a textual ancestral report"),
520
author_name="Donald N. Allingham",
521
author_email="dallingham@users.sourceforge.net"
524
# (name,category,options_dialog,write_book_item,options,style_name,style_file,make_default_style)
526
_("Ahnentafel Report"),
528
AncestorBareReportDialog,