From e8f9c8422ae18c2bdbe5db2a476207c1876c51f7 Mon Sep 17 00:00:00 2001 From: Gerald Britton Date: Fri, 21 Jan 2011 14:30:14 +0000 Subject: [PATCH] Tweaks to graphical tree reports svn: r16422 --- src/plugins/drawreport/AncestorTree.py | 79 ++++++----- src/plugins/drawreport/DescendTree.py | 189 ++++++++++++++----------- src/plugins/lib/libtreebase.py | 9 +- 3 files changed, 150 insertions(+), 127 deletions(-) diff --git a/src/plugins/drawreport/AncestorTree.py b/src/plugins/drawreport/AncestorTree.py index 31903cfdd..0f223e956 100644 --- a/src/plugins/drawreport/AncestorTree.py +++ b/src/plugins/drawreport/AncestorTree.py @@ -35,11 +35,9 @@ def log2(val): """ Calculate the log base 2 of a value. """ - return int(math.log10(val)/math.log10(2)) + return int(math.log(val, 2)) -def X_INDEX(level): - """ calculate the row that this person is in """ - return log2(level) +X_INDEX = log2 from gen.ggettext import sgettext as _ @@ -96,7 +94,7 @@ class AncestorBoxBase(BoxBase): #Calculate which row in the column of people. tmp_y = self.level[1] - (2**x_level) #Calculate which row in the table (yes table) of people. - delta = int((2**max_gen)/(2**(x_level))) + delta = (2**max_gen) // (2**(x_level)) return int((delta/2) + (tmp_y*delta)) class PersonBox(AncestorBoxBase): @@ -117,11 +115,11 @@ class FamilyBox(AncestorBoxBase): def y_index(self, max_gen): """ Calculate the column or generation that this person is in. """ - x_level = self.level[0] -1 + x_level = self.level[0] - 1 #Calculate which row in the column of people. tmp_y = self.level[1] - (2**x_level) #Calculate which row in the table (yes table) of people. - delta = int((2**max_gen)/(2**(x_level))) + delta = (2**max_gen) // (2**(x_level)) return int((delta/2) + (tmp_y*delta)) @@ -252,8 +250,8 @@ class MakeAncestorTree(object): myself = PersonBox(index) - myself.text = \ - self.calc_items.calc_person(index, indi_handle, fams_handle) + myself.text = self.calc_items.calc_person( + index, indi_handle, fams_handle) self.canvas.add_box(myself) @@ -266,8 +264,8 @@ class MakeAncestorTree(object): myself = FamilyBox(index) #calculate the text. - myself.text = \ - self.calc_items.calc_marrage(indi_handle, fams_handle) + myself.text = self.calc_items.calc_marrage(indi_handle, fams_handle) + self.canvas.add_box(myself) @@ -277,9 +275,9 @@ class MakeAncestorTree(object): return line = Line(person) - if father is not None: + if father: line.add_to(father) - if mother is not None: + if mother: line.add_to(mother) self.canvas.add_line(line) @@ -295,13 +293,14 @@ class MakeAncestorTree(object): return None person = self.database.get_person_from_handle(person_handle) - if person is None: + if not person: return self.__fill(index, None, - min(self.fill_out, self.max_generations-X_INDEX(index)-1)) + min(self.fill_out, self.max_generations-X_INDEX(index)-1) + ) parents_handle = person.get_main_parents_family_handle() father = marrbox = mother = None - if parents_handle is not None: + if parents_handle: #note depth first family = self.database.get_family_from_handle(parents_handle) father = self.recurse(family.get_father_handle(), parents_handle, @@ -318,7 +317,8 @@ class MakeAncestorTree(object): self.add_line(mybox, father, mother) else: mybox = self.__fill(index, person_handle, - min(self.fill_out, self.max_generations-X_INDEX(index)-1)) + min(self.fill_out, self.max_generations-X_INDEX(index)-1) + ) #father = self.__fill(index *2, self.fill_out) #mybox = self.add_person_box(index, person_handle, family_handle) #if self.fill_out and self.inlc_marr and (log2(index) + 2) < @@ -368,7 +368,8 @@ class MakeAncestorTree(object): cur_gen += 1 else: #found our father. add him - __BOXES[cur_gen] = self.add_person_box(__INDEX[cur_gen], None, None) + __BOXES[cur_gen] = self.add_person_box( + __INDEX[cur_gen], None, None) ########################### #Step 1.5. Dad has already been made. @@ -376,8 +377,8 @@ class MakeAncestorTree(object): ########################### #Step 2. add our kid - __BOXES[cur_gen-1] = \ - self.add_person_box(__INDEX[cur_gen-1], + __BOXES[cur_gen-1] = self.add_person_box( + __INDEX[cur_gen-1], person_handle if cur_gen == 1 else None, None) @@ -402,7 +403,8 @@ class MakeAncestorTree(object): else: ########################### #Step 3. Now we can make Mom - __BOXES[cur_gen] = self.add_person_box(__INDEX[cur_gen], None, None) + __BOXES[cur_gen] = self.add_person_box( + __INDEX[cur_gen], None, None) ########################### #Step 4. Father and Mother are done but only 1/2 line @@ -465,7 +467,7 @@ class RLTransform(): """ put the box in it's correct spot """ #1. cm_x box.x_cm = self.rept_opts.littleoffset - box.x_cm += (box.level[0] * \ + box.x_cm += (box.level[0] * (self.rept_opts.col_width + self.rept_opts.max_box_width)) #2. cm_y box.y_cm = self.__next_y(box) * self.rept_opts.max_box_height @@ -490,7 +492,7 @@ class RLTransform(): #------------------------------------------------------------------------ class MakeReport(): - def __init__(self, dbase, doc, canvas, \ + def __init__(self, dbase, doc, canvas, font_normal, inlc_marr, compress_tree): self.database = dbase @@ -579,10 +581,7 @@ class GUIConnect(): """ Return a class that holds the proper title based off of the GUI options """ title_type = self.get_val('report_title') - if title_type == 0: - return TitleN(doc) - else: - return TitleA(doc) + return TitleA(doc) if title_type else TitleN(doc) #------------------------------------------------------------------------ # @@ -634,8 +633,8 @@ class AncestorTree2(Report): #Title title = self.connect.title_class(self.doc) center = self.database.get_person_from_gramps_id( - self.connect.get_val('pid') - ) + self.connect.get_val('pid') + ) title.calc_title(center) self.canvas.add_title(title) @@ -687,11 +686,9 @@ class AncestorTree2(Report): colsperpage = self.doc.get_usable_width() colsperpage += self.doc.report_opts.col_width - colsperpage = int(colsperpage / (self.doc.report_opts.max_box_width + - self.doc.report_opts.col_width)) - if colsperpage == 0: #Is the page really that small? - colsperpage = 1 - + colsperpage = int(colsperpage / (self.doc.report_opts.max_box_width + + self.doc.report_opts.col_width)) + colsperpage = colsperpage or 1 ##################### #Vars @@ -841,8 +838,10 @@ class AncestorTree2Options(MenuReportOptions): category_name = _("Secondary") dispMom = TextOption(_("Secondary\nDisplay Format"), - ["$n","%s $b" % _BORN,"%s $m" %_MARR,"%s $d" \ - %_DIED] ) + ["$n","%s $b" % _BORN, + "%s $m" %_MARR, + "%s $d" %_DIED] + ) dispMom.set_help(_("Display format for the output box.")) menu.add_option(category_name, "disp_sec", dispMom) @@ -923,9 +922,11 @@ class AncestorTree2Options(MenuReportOptions): if max_gen > 1: item_list.append([1, _("One Generation of empty boxes " "for unknown ancestors") ]) - for itr in range(2, max_gen): - item_list.append([itr, str(itr) + _(" Generations of empty boxes " - "for unknown ancestors") ]) + + item_list.extend([itr, str(itr) + + _(" Generations of empty boxes for unknown ancestors")] + for itr in range(2, max_gen) + ) self.fillout.set_items(item_list) if old_val+2 > len(item_list): diff --git a/src/plugins/drawreport/DescendTree.py b/src/plugins/drawreport/DescendTree.py index 1f5140c1b..cff18e3d3 100644 --- a/src/plugins/drawreport/DescendTree.py +++ b/src/plugins/drawreport/DescendTree.py @@ -159,43 +159,46 @@ class DescendantTitleBase(TitleBox): def descendant_print(self, person_list, person_list2 = []): """ calculate the Descendant title Person_list will always be passed - If in the Family reports and there are two familys, person_list2 + If in the Family reports and there are two families, person_list2 will be used. """ names = self._get_names(person_list) - if person_list2 != []: - names2 = self._get_names(person_list2) if person_list2: - if len(person_list) + len(person_list2) == 3: - if len(person_list) == 1: + names2 = self._get_names(person_list2) + if len(names) + len(names2) == 3: + if len(names) == 1: title = _("Descendant Chart for %(person)s and " "%(father1)s, %(mother1)s") % \ - {'person': names[0], \ - 'father1': names2[0], \ + {'person': names[0], + 'father1': names2[0], 'mother1': names2[1], - } - else: + } + else: # Should be 2 items in names list title = _("Descendant Chart for %(person)s, %(father1)s " "and %(mother1)s") % \ - {'father1': names[0], \ - 'mother1': names[1], \ - 'person': names2[0] } - else: #if not person_list2: + {'father1': names[0], + 'mother1': names[1], + 'person': names2[0], + } + else: # Should be 2 items in both names and names2 lists title = _("Descendant Chart for %(father1)s, %(father2)s " "and %(mother1)s, %(mother2)s") % \ - {'father1': names[0], \ - 'mother1': names[1], \ - 'father2': names2[0], \ - 'mother2': names2[1] } - else: + {'father1': names[0], + 'mother1': names[1], + 'father2': names2[0], + 'mother2': names2[1], + } + else: # No person_list2: Just one family if len(names) == 1: title = _("Descendant Chart for %(person)s") % \ - {'person': names[0] } - elif len(names) == 2: + {'person': names[0]} + else: # Should be two items in names list title = _("Descendant Chart for %(father)s and %(mother)s") % \ - {'father': names[0], 'mother': names[1] } + {'father': names[0], + 'mother': names[1], + } return title def get_parents(self, family_id): @@ -373,7 +376,7 @@ class RecurseDown: self.database = dbase self.canvas = canvas - self.famalies_seen = [] + self.famalies_seen = set() self.cols = [] self.__last_direct = [] @@ -509,7 +512,7 @@ class RecurseDown: for family_handle in family_handles: if family_handle not in self.famalies_seen: - self.famalies_seen.append(family_handle) + self.famalies_seen.add(family_handle) family = self.database.get_family_from_handle(family_handle) @@ -535,17 +538,19 @@ class RecurseDown: mykids = [kid.ref for kid in family.get_child_ref_list()] + def _child_recurse(who): + self.recurse(child_ref, x_level+1, 0, who) for child_ref in mykids: if self.inlc_marr and self.max_spouses > 0: - self.recurse(child_ref, x_level+1, 0, marr) + _child_recurse(marr) elif spouse: - self.recurse(child_ref, x_level+1, 0, spouse) + _child_recurse(spouse) else: - self.recurse(child_ref, x_level+1, 0, myself) + _child_recurse(myself) first = 0 - if self.max_spouses > s_level and spouse_handle and \ - self.famalies_seen.count(spouse_handle): + if self.max_spouses > s_level and \ + spouse_handle in self.famalies_seen: #spouse_handle = ReportUtils.find_spouse(person,family) self.recurse(spouse_handle, x_level, s_level+1, spouse) @@ -561,21 +566,23 @@ class RecurseDown: self.bold_now = 2 if father_h == None: - father_b = self.add_person_box( (level, 0), None, None, father2) + father_b = self.add_person_box( + (level, 0), None, None, father2) else: - father_b = self.add_person_box( (level, 0), father_h, - family_h, father2) + father_b = self.add_person_box( + (level, 0), father_h, family_h, father2) if self.inlc_marr: - family_b = self.add_marriage_box( (level, 1), father_h, - family_h, father_b) - self.famalies_seen.append(family_h) + family_b = self.add_marriage_box( + (level, 1), father_h, family_h, father_b) + self.famalies_seen.add(family_h) if mother_h: - mother_b = self.add_person_box( (level, 0), mother_h, - family_h, father_b) + mother_b = self.add_person_box( + (level, 0), mother_h, family_h, father_b) else: - mother_b = self.add_person_box( (level, 0), None, None, father_b) + mother_b = self.add_person_box( + (level, 0), None, None, father_b) #child_refs = [] #for child_ref in family.get_child_ref_list(): @@ -633,7 +640,7 @@ class RecurseDown: show = self.has_children(person_handle) #if self.max_spouses == 0 and not self.has_children(person_handle): - # self.famalies_seen.append(person_handle) + # self.famalies_seen.add(person_handle) # show = False if show: @@ -677,7 +684,7 @@ class MakePersonTree(RecurseDown): ####################### #don't do center person's parents family. if family2_h: - self.famalies_seen.append(family2_h) + self.famalies_seen.add(family2_h) ####################### #Center person's Fathers OTHER wives @@ -763,7 +770,7 @@ class MakeFamilyTree(RecurseDown): ####################### #don't do my fathers parents family. will be done later if family2_h: - self.famalies_seen.append(family2_h) + self.famalies_seen.add(family2_h) ####################### #my father mothers OTHER husbands @@ -781,10 +788,10 @@ class MakeFamilyTree(RecurseDown): ####################### #don't do my parents family in recurse. will be done later - self.famalies_seen.append(family1_h) + self.famalies_seen.add(family1_h) ##If dad has no other children from other marriages. remove him if self.max_spouses == 0 and not self.has_children(father1_h): - self.famalies_seen.append(father1_h) + self.famalies_seen.add(father1_h) ####################### #my fathers parents! @@ -801,7 +808,7 @@ class MakeFamilyTree(RecurseDown): #this parent again IF s/he has children show = self.has_children(father1_h) if not show: - self.famalies_seen.append(father1_h) + self.famalies_seen.add(father1_h) father2_id = self.add_family( 0, family2, None ) @@ -881,17 +888,17 @@ class MakeFamilyTree(RecurseDown): ####################### #don't do my parents family. - self.famalies_seen = [family1_h] + self.famalies_seen = set([family1_h] ) ##If mom has no other children from other marriages. remove her if self.max_spouses == 0 and not self.has_children(mother1_h): - self.famalies_seen.append(mother1_h) + self.famalies_seen.add(mother1_h) if mother1_h: myfams = mother1.get_family_handle_list() if len(myfams) < 2: #If mom didn't have any other families, don't even do her #she is already here with dad and will be added later - self.famalies_seen.append(mother1_h) + self.famalies_seen.add(mother1_h) ####################### #my mother other spouses (if no parents) @@ -1166,14 +1173,14 @@ class MakeReport(object): #remove column 0 and move everyone back one level self.cols.pop(0) for box in self.canvas.boxes: - box.level = (box.level[0]-1, box.level[1]) + box.level = (box.level[0] - 1, box.level[1]) #go ahead and set it now. width = self.canvas.doc.report_opts.max_box_width for box in self.canvas.boxes: box.width = width - box.x_cm box.x_cm += self.canvas.doc.report_opts.littleoffset - box.x_cm += (box.level[0] * \ + box.x_cm += (box.level[0] * (self.canvas.doc.report_opts.col_width + self.canvas.doc.report_opts.max_box_width)) @@ -1246,8 +1253,7 @@ class GuiConnect(): if box.boxstr == "CG2-fam-box": #((((( workinglines = display_marr - elif box.level[1] > 0 or (box.level[0] == 0 and - box.father is not None): + elif box.level[1] > 0 or (box.level[0] == 0 and box.father): workinglines = display_spou else: workinglines = display @@ -1345,9 +1351,8 @@ class Descend2Tree(Report): colsperpage += self.doc.report_opts.col_width tmp = self.doc.report_opts.max_box_width tmp += self.doc.report_opts.col_width - colsperpage = int( colsperpage / tmp ) - if colsperpage == 0: #Is the page really that small? - colsperpage = 1 + colsperpage = int(colsperpage / tmp) + colsperpage = colsperpage or 1 ##################### #Vars @@ -1465,10 +1470,12 @@ class Descend2TreeOptions(MenuReportOptions): menu.add_option(category_name, "pid", self.__pid) self.showparents = BooleanOption( - _('Start with the parent(s) of the selected first'), True) + _('Start with the parent(s) of the selected first'), + True) self.showparents.set_help( _("Will show the parents, brother and sisters of the " - "selected person.")) + "selected person.") + ) menu.add_option(category_name, "show_gparents", self.showparents) max_gen = NumberOption(_("Generations"), 2, 1, 50) @@ -1492,8 +1499,10 @@ class Descend2TreeOptions(MenuReportOptions): menu.add_option(category_name, "dispf", disp) bold = BooleanOption(_('Bold direct descendants'), True) - bold.set_help(_("Whether to bold those people that are direct " - "(not step or half) descendants.")) + bold.set_help( + _("Whether to bold those people that are direct " + "(not step or half) descendants.") + ) menu.add_option(category_name, "bolddirect", bold) #Will add when libsubstkeyword supports it. @@ -1506,8 +1515,9 @@ class Descend2TreeOptions(MenuReportOptions): category_name = _("Secondary") - diffspouse = BooleanOption(_('Use seperate display format for ' - 'spouses'), True) + diffspouse = BooleanOption( + _("Use seperate display format for spouses"), + True) diffspouse.set_help(_("Whether spouses can have a different format.")) menu.add_option(category_name, "diffspouse", diffspouse) @@ -1521,8 +1531,9 @@ class Descend2TreeOptions(MenuReportOptions): menu.add_option(category_name, "sdispf", sdisp) incmarr = BooleanOption(_('Include Marriage information'), True) - incmarr.set_help(_("Whether to include marriage information in the " - "report.")) + incmarr.set_help( + _("Whether to include marriage information in the report.") + ) menu.add_option(category_name, "incmarr", incmarr) marrdisp = StringOption(_("Marriage\nDisplay Format"), "%s $m" % _MARR) @@ -1531,8 +1542,9 @@ class Descend2TreeOptions(MenuReportOptions): category_name = _("Replace") - repldisp = TextOption(_("Replace Display Format:\n'Replace this'/'" - "with this'"), []) + repldisp = TextOption( + _("Replace Display Format:\n'Replace this'/' with this'"), + []) repldisp.set_help(_("i.e.\nUnited States of America/U.S.A")) menu.add_option(category_name, "replacelist", repldisp) @@ -1542,14 +1554,17 @@ class Descend2TreeOptions(MenuReportOptions): self.scale.add_item( 0, "Do not scale report") self.scale.add_item( 1, "Scale report to fit page width only") self.scale.add_item( 2, "Scale report to fit the size of the page") - self.scale.set_help(_("Whether to scale the report to fit a " - "specific size")) + self.scale.set_help( + _("Whether to scale the report to fit a specific size") + ) menu.add_option(category_name, "scale_report", self.scale) self.scale.connect('value-changed', self.__check_blank) self.__onepage = BooleanOption(_('One page report'), True) - self.__onepage.set_help(_("Whether to scale the size of the page to " - "the size of the report.")) + self.__onepage.set_help( + _("Whether to scale the size of the page to " + "the size of the report.") + ) menu.add_option(category_name, "onepage", self.__onepage) self.__onepage.connect('value-changed', self.__check_blank) @@ -1574,12 +1589,14 @@ class Descend2TreeOptions(MenuReportOptions): category_name = _("Notes") self.usenote = BooleanOption(_('Include a personal note'), False) - self.usenote.set_help(_("Whether to include a personalized note on " - "the report.")) + self.usenote.set_help( + _("Whether to include a personalized note on the report.") + ) menu.add_option(category_name, "use_note", self.usenote) - self.notedisp = TextOption(_("Note to add\nto the graph\n\n$T " - "inserts today's date"), []) + self.notedisp = TextOption( + _("Note to add\nto the graph\n\n$T inserts today's date"), + []) self.notedisp.set_help(_("Add a personal note")) menu.add_option(category_name, "note_disp", self.notedisp) @@ -1596,13 +1613,18 @@ class Descend2TreeOptions(MenuReportOptions): self.__blank.set_available( off ) def __Title_enum(self): - item_list = [] - item_list.append([0, "Do not print a title" ]) - item_list.append([1, "Descendant Chart for [selected person(s)]" ]) + item_list = [ + [0, "Do not print a title" ], + [1, "Descendant Chart for [selected person(s)]" ], + ] if self.name != _RPT_NAME: - item_list.append([2, "Family Chart for [names of chosen family]" ]) + item_list.append( + [2, "Family Chart for [names of chosen family]" ] + ) if self.showparents.get_value(): - item_list.append([3, "Cousin Chart for [names of children]" ]) + item_list.append( + [3, "Cousin Chart for [names of children]" ] + ) self.title.set_items(item_list) def make_default_style(self, default_style): @@ -1618,8 +1640,9 @@ class Descend2TreeOptions(MenuReportOptions): para_style = ParagraphStyle() para_style.set_font(font) para_style.set_alignment(PARA_ALIGN_CENTER) - para_style.set_description(_('The basic style used for the ' - 'title display.')) + para_style.set_description( + _("The basic style used for the title display.") + ) default_style.add_paragraph_style("CG2-Title", para_style) font = FontStyle() @@ -1627,8 +1650,9 @@ class Descend2TreeOptions(MenuReportOptions): font.set_type_face(FONT_SANS_SERIF) para_style = ParagraphStyle() para_style.set_font(font) - para_style.set_description(_('The basic style used for the ' - 'text display.')) + para_style.set_description( + _('The basic style used for the text display.') + ) default_style.add_paragraph_style("CG2-Normal", para_style) #Set the size of the shadow based on the font size! Much better @@ -1638,8 +1662,9 @@ class Descend2TreeOptions(MenuReportOptions): font.set_bold(True) para_style = ParagraphStyle() para_style.set_font(font) - para_style.set_description(_('The bold style used for the ' - 'text display.')) + para_style.set_description( + _('The bold style used for the text display.') + ) default_style.add_paragraph_style("CG2-Bold", para_style) graph_style = GraphicsStyle() diff --git a/src/plugins/lib/libtreebase.py b/src/plugins/lib/libtreebase.py index 22be2b6dd..f62e7b5b8 100644 --- a/src/plugins/lib/libtreebase.py +++ b/src/plugins/lib/libtreebase.py @@ -609,16 +609,13 @@ class TitleBox(BoxBase): def _get_names(self, persons): """ A helper function that receives a list of persons and returns their names in a list """ - tmp = [] - for person in persons: - tmp.append(name_displayer.display(person)) - return tmp + return [name_displayer.display(person) for person in persons] def display(self): """ display the title box. """ - if self.page.y_page_num != 0 or self.boxstr == "None": + if self.page.y_page_num or self.boxstr == "None": return - if self.text != "": + if self.text: self.doc.center_text(self.boxstr, self.text, self.width/2, self.y_cm)