diff --git a/gramps/plugins/textreport/descendreport.py b/gramps/plugins/textreport/descendreport.py index 15d5fa554..2af4e4f62 100644 --- a/gramps/plugins/textreport/descendreport.py +++ b/gramps/plugins/textreport/descendreport.py @@ -51,7 +51,6 @@ from gramps.gen.plug.report import Report from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import MenuReportOptions from gramps.gen.plug.report import stdoptions -from gramps.gen.sort import Sort from gramps.gen.utils.db import (get_birth_or_fallback, get_death_or_fallback, get_marriage_or_fallback, get_divorce_or_fallback) @@ -64,11 +63,14 @@ from gramps.gen.proxy import CacheProxyDb # #------------------------------------------------------------------------ class PrintSimple: + """ Simple numbering system """ + def __init__(self, showdups): self.showdups = showdups self.num = {0:1} def number(self, level): + """ the number of the person """ if self.showdups: # Just show original simple numbering to_return = "%d." % level @@ -91,11 +93,14 @@ class PrintSimple: # #------------------------------------------------------------------------ class PrintVilliers: + """ de_Villiers_Pama numbering system """ + def __init__(self): self.pama = 'abcdefghijklmnopqrstuvwxyz' self.num = {0:1} def number(self, level): + """ the number of the person """ to_return = self.pama[level-1] if level > 1: to_return += str(self.num[level-1]) @@ -114,10 +119,13 @@ class PrintVilliers: # #------------------------------------------------------------------------ class PrintMeurgey: + """ Meurgey_de_Tupigny numbering system """ + def __init__(self): self.childnum = [""] def number(self, level): + """ the number of the person """ if level == 1: dash = "" else: @@ -157,7 +165,8 @@ class Printinfo: self._ = rlocale.translation.sgettext # needed for English self._get_date = rlocale.get_date - def __date_place(self,event): + def __date_place(self, event): + """ return the date and/or place an event happened """ if event: date = self._get_date(event.get_date_object()) place_handle = event.get_place_handle() @@ -177,11 +186,12 @@ class Printinfo: return "" def dump_string(self, person, family=None): + """ generate a descriptive string for a person """ string = self.__date_place( - get_birth_or_fallback(self.database, person) - ) + get_birth_or_fallback(self.database, person)) - tmp = self.__date_place(get_death_or_fallback(self.database, person)) + tmp = self.__date_place( + get_death_or_fallback(self.database, person)) if string and tmp: string += ", " string += tmp @@ -190,20 +200,21 @@ class Printinfo: string = " (" + string + ")" if family and self.showmarriage: - tmp = self.__date_place(get_marriage_or_fallback(self.database, - family)) + tmp = self.__date_place( + get_marriage_or_fallback(self.database, family)) if tmp: string += ", " + tmp if family and self.showdivorce: - tmp = self.__date_place(get_divorce_or_fallback(self.database, - family)) + tmp = self.__date_place( + get_divorce_or_fallback(self.database, family)) if tmp: string += ", " + tmp self.doc.write_text(string) def print_person(self, level, person): + """ print the person """ display_num = self.numbering.number(level) self.doc.start_paragraph("DR-Level%d" % min(level, 32), display_num) mark = ReportUtils.get_person_mark(self.database, person) @@ -213,6 +224,7 @@ class Printinfo: return display_num def print_spouse(self, level, spouse_handle, family_handle): + """ print the spouse """ #Currently print_spouses is the same for all numbering systems. if spouse_handle: spouse = self.database.get_person_from_handle(spouse_handle) @@ -220,25 +232,27 @@ class Printinfo: self.doc.start_paragraph("DR-Spouse%d" % min(level, 32)) name = self._name_display.display(spouse) self.doc.write_text( - self._("sp. %(spouse)s") % {'spouse':name}, mark) + self._("sp. %(spouse)s") % {'spouse':name}, mark) self.dump_string(spouse, family_handle) self.doc.end_paragraph() else: self.doc.start_paragraph("DR-Spouse%d" % min(level, 32)) self.doc.write_text( - self._("sp. %(spouse)s") % {'spouse':self._('Unknown')}) + self._("sp. %(spouse)s") % {'spouse':self._('Unknown')}) self.doc.end_paragraph() def print_reference(self, level, person, display_num): + """ print the reference """ #Person and their family have already been printed so #print reference here if person: mark = ReportUtils.get_person_mark(self.database, person) self.doc.start_paragraph("DR-Spouse%d" % min(level, 32)) name = self._name_display.display(person) - self.doc.write_text( - self._("sp. see %(reference)s : %(spouse)s") % - {'reference':display_num, 'spouse':name}, mark) + self.doc.write_text(self._("sp. see %(reference)s: %(spouse)s" + % {'reference' : display_num, + 'spouse' : name}), + mark) self.doc.end_paragraph() @@ -255,21 +269,23 @@ class RecurseDown: max_generations: The max number of generations database: The database object - objPrint: A Printinfo derived class that prints person + obj_print: A Printinfo derived class that prints person information on the report """ - def __init__(self, max_generations, database, objPrint, showdups, rlocale): + def __init__(self, max_generations, database, + obj_print, showdups, rlocale): self.max_generations = max_generations self.database = database - self.objPrint = objPrint + self.obj_print = obj_print self.showdups = showdups self.person_printed = {} self._ = rlocale.translation.sgettext # needed for English def recurse(self, level, person, curdepth): + """ recurse """ person_handle = person.get_handle() - display_num = self.objPrint.print_person(level, person) + display_num = self.obj_print.print_person(level, person) if curdepth is None: ref_str = display_num @@ -287,10 +303,10 @@ class RecurseDown: if not self.showdups and spouse_handle in self.person_printed: # Just print a reference spouse = self.database.get_person_from_handle(spouse_handle) - self.objPrint.print_reference(level, spouse, - self.person_printed[spouse_handle]) + self.obj_print.print_reference( + level, spouse, self.person_printed[spouse_handle]) else: - self.objPrint.print_spouse(level, spouse_handle, family) + self.obj_print.print_spouse(level, spouse_handle, family) if spouse_handle: spouse_num = self._("%s sp." % (ref_str)) @@ -311,6 +327,7 @@ class RecurseDown: # #------------------------------------------------------------------------ class DescendantReport(Report): + """ Descendant report """ def __init__(self, database, options, user): """ @@ -347,10 +364,8 @@ class DescendantReport(Report): self.max_generations = menu.get_option_by_name('gen').get_value() pid = menu.get_option_by_name('pid').get_value() self.center_person = self.database.get_person_from_gramps_id(pid) - if (self.center_person == None) : - raise ReportError(_("Person %s is not in the Database") % pid ) - - sort = Sort(self.database) + if self.center_person is None: + raise ReportError(_("Person %s is not in the Database") % pid) #Initialize the Printinfo class self._showdups = menu.get_option_by_name('dups').get_value() @@ -362,15 +377,15 @@ class DescendantReport(Report): elif numbering == "Meurgey de Tupigny": obj = PrintMeurgey() else: - raise AttributeError("no such numbering: '%s'" % self.numbering) + raise AttributeError("no such numbering: '%s'" % numbering) marrs = menu.get_option_by_name('marrs').get_value() divs = menu.get_option_by_name('divs').get_value() stdoptions.run_name_format_option(self, menu) - self.objPrint = Printinfo(self.doc, self.database, obj, marrs, divs, - self._name_display, self._locale) + self.obj_print = Printinfo(self.doc, self.database, obj, marrs, divs, + self._name_display, self._locale) def write_report(self): self.doc.start_paragraph("DR-Title") @@ -382,7 +397,7 @@ class DescendantReport(Report): self.doc.end_paragraph() recurse = RecurseDown(self.max_generations, self.database, - self.objPrint, self._showdups, self._locale) + self.obj_print, self._showdups, self._locale) recurse.recurse(1, self.center_person, None) #------------------------------------------------------------------------ @@ -414,9 +429,9 @@ class DescendantOptions(MenuReportOptions): numbering = EnumeratedListOption(_("Numbering system"), "Simple") numbering.set_items([ - ("Simple", _("Simple numbering")), - ("de Villiers/Pama", _("de Villiers/Pama numbering")), - ("Meurgey de Tupigny", _("Meurgey de Tupigny numbering"))]) + ("Simple", _("Simple numbering")), + ("de Villiers/Pama", _("de Villiers/Pama numbering")), + ("Meurgey de Tupigny", _("Meurgey de Tupigny numbering"))]) numbering.set_help(_("The numbering system to be used")) menu.add_option(category_name, "numbering", numbering) @@ -425,7 +440,8 @@ class DescendantOptions(MenuReportOptions): menu.add_option(category_name, "gen", gen) marrs = BooleanOption(_('Show marriage info'), False) - marrs.set_help(_("Whether to show marriage information in the report.")) + marrs.set_help( + _("Whether to show marriage information in the report.")) menu.add_option(category_name, "marrs", marrs) divs = BooleanOption(_('Show divorce info'), False) @@ -441,38 +457,42 @@ class DescendantOptions(MenuReportOptions): def make_default_style(self, default_style): """Make the default output style for the Descendant Report.""" - f = FontStyle() - f.set_size(12) - f.set_type_face(FONT_SANS_SERIF) - f.set_bold(1) - p = ParagraphStyle() - p.set_header_level(1) - p.set_bottom_border(1) - p.set_top_margin(ReportUtils.pt2cm(3)) - p.set_bottom_margin(ReportUtils.pt2cm(3)) - p.set_font(f) - p.set_alignment(PARA_ALIGN_CENTER) - p.set_description(_("The style used for the title of the page.")) - default_style.add_paragraph_style("DR-Title", p) + fstyle = FontStyle() + fstyle.set_size(12) + fstyle.set_type_face(FONT_SANS_SERIF) + fstyle.set_bold(1) + pstyle = ParagraphStyle() + pstyle.set_header_level(1) + pstyle.set_bottom_border(1) + pstyle.set_top_margin(ReportUtils.pt2cm(3)) + pstyle.set_bottom_margin(ReportUtils.pt2cm(3)) + pstyle.set_font(fstyle) + pstyle.set_alignment(PARA_ALIGN_CENTER) + pstyle.set_description(_("The style used for the title of the page.")) + default_style.add_paragraph_style("DR-Title", pstyle) - f = FontStyle() - f.set_size(10) + fstyle = FontStyle() + fstyle.set_size(10) for i in range(1, 33): - p = ParagraphStyle() - p.set_font(f) - p.set_top_margin(ReportUtils.pt2cm(f.get_size()*0.125)) - p.set_bottom_margin(ReportUtils.pt2cm(f.get_size()*0.125)) - p.set_first_indent(-0.5) - p.set_left_margin(min(10.0, float(i-0.5))) - p.set_description(_("The style used for the " - "level %d display.") % i) - default_style.add_paragraph_style("DR-Level%d" % min(i, 32), p) + pstyle = ParagraphStyle() + pstyle.set_font(fstyle) + pstyle.set_top_margin(ReportUtils.pt2cm(fstyle.get_size()*0.125)) + pstyle.set_bottom_margin( + ReportUtils.pt2cm(fstyle.get_size()*0.125)) + pstyle.set_first_indent(-0.5) + pstyle.set_left_margin(min(10.0, float(i-0.5))) + pstyle.set_description( + _("The style used for the level %d display.") % i) + default_style.add_paragraph_style("DR-Level%d" % min(i, 32), + pstyle) - p = ParagraphStyle() - p.set_font(f) - p.set_top_margin(ReportUtils.pt2cm(f.get_size()*0.125)) - p.set_bottom_margin(ReportUtils.pt2cm(f.get_size()*0.125)) - p.set_left_margin(min(10.0, float(i-0.5))) - p.set_description(_("The style used for the " - "spouse level %d display.") % i) - default_style.add_paragraph_style("DR-Spouse%d" % min(i, 32), p) + pstyle = ParagraphStyle() + pstyle.set_font(fstyle) + pstyle.set_top_margin(ReportUtils.pt2cm(fstyle.get_size()*0.125)) + pstyle.set_bottom_margin( + ReportUtils.pt2cm(fstyle.get_size()*0.125)) + pstyle.set_left_margin(min(10.0, float(i-0.5))) + pstyle.set_description( + _("The style used for the spouse level %d display.") % i) + default_style.add_paragraph_style("DR-Spouse%d" % min(i, 32), + pstyle)