From 707cb5be78bf8bc17a80992c572e1e7d40733b94 Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Wed, 1 Aug 2007 05:21:19 +0000 Subject: [PATCH] Add generations and relationships to the End of Line Report svn: r8795 --- ChangeLog | 3 + src/plugins/EndOfLineReport.py | 153 ++++++++++++++++++++++++++++++--- 2 files changed, 146 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5e40e31b5..b29a1843c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2007-08-01 Brian Matherly + * src/plugins/EndOfLineReport.py: Add generations and relationships + 2007-07-31 Jérôme * src/GrampsDbUtils/gedcomexport.glade: use UTF-8 instead of UNICODE diff --git a/src/plugins/EndOfLineReport.py b/src/plugins/EndOfLineReport.py index 172a2e994..93bd65c98 100644 --- a/src/plugins/EndOfLineReport.py +++ b/src/plugins/EndOfLineReport.py @@ -34,7 +34,7 @@ from gettext import gettext as _ # gramps modules # #------------------------------------------------------------------------ -from PluginUtils import register_report +from PluginUtils import register_report, relationship_class from ReportBase import Report, ReportUtils, ReportOptions, \ CATEGORY_TEXT, MODE_GUI, MODE_BKI, MODE_CLI import BaseDoc @@ -74,6 +74,60 @@ class EndOfLineReport(Report): filter.add_rule(Rules.Person.IsAncestorOf([gid,1])) filter.add_rule(Rules.Person.MissingParent([])) self.ind_list = filter.apply(self.database,plist) + + self.relationship = relationship_class(self.database) + + # 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 = {} + self.get_eol(self.person,1,[]) + + def get_eol(self,person,gen,pedigree): + 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) + self.get_eol(father,gen+1,pedigree) + if mother_handle: + mother = self.database.get_person_from_handle(mother_handle) + self.get_eol(mother,gen+1,pedigree) + + 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)] def write_report(self): """ @@ -94,9 +148,16 @@ class EndOfLineReport(Report): self.doc.end_paragraph() self.doc.start_table('EolTable','EOL-Table') - self.write_collumn_header() - for person_handle in self.ind_list: - self.write_person_row(person_handle) + +# self.write_collumn_header() + + 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) + self.write_relationship_row(person_handle) + for pedigree in self.eol_map[generation][person_handle]: + self.write_pedigree_row(pedigree) self.doc.end_table() def write_collumn_header(self): @@ -125,6 +186,18 @@ class EndOfLineReport(Report): self.doc.end_row() + def write_generation_row(self,generation): + """ + Write out a row in the table showing the generation. + """ + self.doc.start_row() + self.doc.start_cell('EOL_GenerationCell',4) + 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() + def write_person_row(self,person_handle): """ Write a row in the table with information about the given person. @@ -144,10 +217,9 @@ class EndOfLineReport(Report): self.doc.start_cell('EOL-TableCell') self.doc.start_paragraph('EOL-Normal') birth_ref = person.get_birth_ref() - text = "" if birth_ref: event = self.database.get_event_from_handle(birth_ref.ref) - text += DateHandler.get_date( event ) + text = DateHandler.get_date( event ) place_handle = event.get_place_handle() place = ReportUtils.place_name(self.database,place_handle) @@ -165,7 +237,7 @@ class EndOfLineReport(Report): death_ref = person.get_death_ref() if death_ref: event = self.database.get_event_from_handle(death_ref.ref) - text += DateHandler.get_date( event ) + text = DateHandler.get_date( event ) place_handle = event.get_place_handle() place = ReportUtils.place_name(self.database,place_handle) @@ -179,6 +251,46 @@ class EndOfLineReport(Report): self.doc.end_cell() self.doc.end_row() + + def write_relationship_row(self,person_handle): + """ + Write a row in the table with with the person's relationship. + """ + ancestor = self.database.get_person_from_handle(person_handle) + (rel_string,common) = self.relationship.get_relationship( + self.person,ancestor) + + text = _("%(person)s is the %(relationship)s of %(active_person)s.") % { + 'person' : name_displayer.display(ancestor), + 'relationship' : rel_string, + 'active_person' : name_displayer.display(self.person) } + + self.doc.start_row() + self.doc.start_cell('EOL-TableCell') + self.doc.end_cell() + self.doc.start_cell('EOL-TableCell',3) + self.doc.start_paragraph('EOL-Pedigree') + self.doc.write_text(text) + self.doc.end_paragraph() + self.doc.end_cell() + self.doc.end_row() + + def write_pedigree_row(self,pedigree): + """ + Write a row in the table with with the person's relationship. + + 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() + self.doc.start_cell('EOL-TableCell',3) + self.doc.start_paragraph('EOL-Pedigree') + self.doc.write_text(text) + self.doc.end_paragraph() + self.doc.end_cell() + self.doc.end_row() class EndOfLineOptions(ReportOptions): """ @@ -217,11 +329,20 @@ class EndOfLineOptions(ReportOptions): font.set_size(10) p = BaseDoc.ParagraphStyle() p.set_font(font) - p.set_top_margin(ReportUtils.pt2cm(3)) - p.set_bottom_margin(ReportUtils.pt2cm(3)) + p.set_top_margin(ReportUtils.pt2cm(6)) + p.set_bottom_margin(ReportUtils.pt2cm(6)) p.set_description(_('The basic style used for the text display.')) default_style.add_paragraph_style("EOL-Normal",p) + font = BaseDoc.FontStyle() + font.set_size(12) + font.set_italic(True) + p = BaseDoc.ParagraphStyle() + p.set_font(font) + p.set_top_margin(ReportUtils.pt2cm(3)) + p.set_description(_('The basic style used for generation headings.')) + default_style.add_paragraph_style("EOL-Generation",p) + font = BaseDoc.FontStyle() font.set_size(12) font.set_bold(True) @@ -232,10 +353,22 @@ class EndOfLineOptions(ReportOptions): p.set_description(_('The basic style used for table headings.')) default_style.add_paragraph_style("EOL-Normal-Bold",p) + font = BaseDoc.FontStyle() + font.set_size(8) + p = BaseDoc.ParagraphStyle() + p.set_font(font) + p.set_top_margin(0) + p.set_bottom_margin(ReportUtils.pt2cm(3)) + p.set_description(_('The basic style used for the text display.')) + default_style.add_paragraph_style("EOL-Pedigree",p) + #Table Styles cell = BaseDoc.TableCellStyle() - cell.set_padding(0.2) default_style.add_cell_style('EOL-TableCell',cell) + + cell = BaseDoc.TableCellStyle() + cell.set_bottom_border(1) + default_style.add_cell_style('EOL_GenerationCell',cell) table = BaseDoc.TableStyle() table.set_width(100)