Clean up descendant tree - PEP8, naming, etc.
svn: r13603
This commit is contained in:
parent
d7b4ca2d9c
commit
9b1392c912
@ -26,7 +26,7 @@
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from BasicUtils import name_displayer
|
||||
@ -38,14 +38,6 @@ from ReportBase import Report, MenuReportOptions, ReportUtils
|
||||
from SubstKeywords import SubstKeywords
|
||||
from TransUtils import sgettext as _
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
pt2cm = ReportUtils.pt2cm
|
||||
cm2pt = ReportUtils.cm2pt
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# Constants
|
||||
@ -104,20 +96,20 @@ class GenChart(object):
|
||||
self.sparray[col_x, row_y] = value
|
||||
|
||||
def dimensions(self):
|
||||
"""
|
||||
Returns the dimensions of the chart.
|
||||
"""
|
||||
return (self.max_y+1, self.max_x+1)
|
||||
|
||||
def not_blank(self, line):
|
||||
for i in line:
|
||||
if i and isinstance(i, tuple):
|
||||
return 1
|
||||
return 0
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# DescendTree
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
class DescendTree(Report):
|
||||
"""
|
||||
Report class that generates a descendant tree.
|
||||
"""
|
||||
|
||||
def __init__(self, database, options_class):
|
||||
"""
|
||||
@ -161,6 +153,14 @@ class DescendTree(Report):
|
||||
self.lines = 0
|
||||
self.scale = 1
|
||||
self.box_gap = 0.2
|
||||
self.box_pad_pts = 0
|
||||
self.offset = 0
|
||||
self.page_label_x_offset = 0
|
||||
self.page_label_y_offset = 0
|
||||
self.usable_height = 0
|
||||
self.usable_width = 0
|
||||
self.generations_per_page = 0
|
||||
self.delta = 0
|
||||
|
||||
self.genchart = GenChart(32)
|
||||
|
||||
@ -195,7 +195,7 @@ class DescendTree(Report):
|
||||
subst = SubstKeywords(self.database, person_handle)
|
||||
self.text[(col_x, row_y)] = subst.replace_and_clean(self.display)
|
||||
for line in self.text[(col_x, row_y)]:
|
||||
this_box_width = self.doc.string_width(font, line) + 2*em
|
||||
this_box_width = self.doc.string_width(font, line) + (2 * em)
|
||||
self.box_width = max(self.box_width, this_box_width)
|
||||
|
||||
self.lines = max(self.lines, len(self.text[(col_x, row_y)]))
|
||||
@ -205,7 +205,7 @@ class DescendTree(Report):
|
||||
of a line is found, or until we reach the maximum number of
|
||||
generations that we want to deal with"""
|
||||
|
||||
if col_x/2 >= self.max_generations:
|
||||
if (col_x / 2) >= self.max_generations:
|
||||
return 0
|
||||
|
||||
person = self.database.get_person_from_handle(person_handle)
|
||||
@ -233,6 +233,9 @@ class DescendTree(Report):
|
||||
|
||||
|
||||
def add_lines(self):
|
||||
"""
|
||||
Add the lines that connect the boxes in the chart.
|
||||
"""
|
||||
(maxy, maxx) = self.genchart.dimensions()
|
||||
|
||||
for y in range(0, maxy + 1):
|
||||
@ -269,14 +272,16 @@ class DescendTree(Report):
|
||||
|
||||
|
||||
def write_report(self):
|
||||
|
||||
"""
|
||||
Write the report to the document.
|
||||
"""
|
||||
(maxy, maxx) = self.genchart.dimensions()
|
||||
if maxx <> 1:
|
||||
if maxx != 1:
|
||||
maxx = (maxx - 1) * 2
|
||||
else:
|
||||
#no descendants
|
||||
maxx = 1
|
||||
maxh = int((self.uh-0.75)/(self.box_height*1.25))
|
||||
maxh = int((self.usable_height - 0.75) / (self.box_height * 1.25))
|
||||
|
||||
if self.force_fit:
|
||||
self.print_page(0, maxx, 0, maxy, 0, 0)
|
||||
@ -287,7 +292,7 @@ class DescendTree(Report):
|
||||
startx = 0
|
||||
colx = 0
|
||||
while startx < maxx:
|
||||
stopx = min(maxx, startx+self.generations_per_page*2)
|
||||
stopx = min(maxx, startx + (self.generations_per_page * 2))
|
||||
stopy = min(maxy, starty + maxh)
|
||||
self.print_page(startx, stopx, starty, stopy, colx, coly)
|
||||
colx += 1
|
||||
@ -309,7 +314,7 @@ class DescendTree(Report):
|
||||
if self.title and self.force_fit:
|
||||
pstyle = style_sheet.get_paragraph_style("DC2-Title")
|
||||
tfont = pstyle.get_font()
|
||||
self.offset = pt2cm(1.25 * tfont.get_size())
|
||||
self.offset = ReportUtils.pt2cm(1.25 * tfont.get_size())
|
||||
|
||||
gstyle = style_sheet.get_draw_style("DC2-box")
|
||||
shadow_height = gstyle.get_shadow_space()
|
||||
@ -317,29 +322,35 @@ class DescendTree(Report):
|
||||
# Make space for the page number labels at the bottom.
|
||||
p = style_sheet.get_paragraph_style("DC2-Normal")
|
||||
font = p.get_font()
|
||||
lheight = pt2cm(1.2*font.get_size())
|
||||
lwidth = pt2cm(1.1*self.doc.string_width(font,"(00,00)"))
|
||||
lheight = ReportUtils.pt2cm(1.2 * font.get_size())
|
||||
lwidth = ReportUtils.pt2cm(1.1 *
|
||||
self.doc.string_width(font, "(00,00)"))
|
||||
self.page_label_x_offset = self.doc.get_usable_width() - lwidth
|
||||
self.page_label_y_offset = self.doc.get_usable_height() - lheight
|
||||
|
||||
self.offset = pt2cm(1.25 * font.get_size())
|
||||
self.offset = ReportUtils.pt2cm(1.25 * font.get_size())
|
||||
shadow_height = 0
|
||||
self.uh = self.doc.get_usable_height() - self.offset - shadow_height
|
||||
uw = self.doc.get_usable_width() - pt2cm(self.box_pad_pts)
|
||||
self.usable_height = self.doc.get_usable_height() \
|
||||
- self.offset \
|
||||
- shadow_height
|
||||
self.usable_width = self.doc.get_usable_width() \
|
||||
- ReportUtils.pt2cm(self.box_pad_pts)
|
||||
|
||||
calc_width = pt2cm(self.box_width + self.box_pad_pts) + self.box_gap
|
||||
self.box_width = pt2cm(self.box_width)
|
||||
calc_width = ReportUtils.pt2cm(self.box_width + self.box_pad_pts) \
|
||||
+ self.box_gap
|
||||
self.box_width = ReportUtils.pt2cm(self.box_width)
|
||||
pstyle = style_sheet.get_paragraph_style("DC2-Normal")
|
||||
font = pstyle.get_font()
|
||||
self.box_height = self.lines*pt2cm(1.25*font.get_size())
|
||||
self.box_height = self.lines*ReportUtils.pt2cm(1.25 * font.get_size())
|
||||
|
||||
self.scale = 1
|
||||
|
||||
if self.force_fit:
|
||||
(maxy, maxx) = self.genchart.dimensions()
|
||||
|
||||
bw = (calc_width/(uw/(maxx+1)))
|
||||
bh = (self.box_height*(1.25)+self.box_gap)/(self.uh/maxy)
|
||||
bw = (calc_width / (self.usable_width / (maxx + 1)))
|
||||
bh = ((self.box_height * 1.25) + self.box_gap) \
|
||||
/ (self.usable_height / maxy)
|
||||
|
||||
self.scale = max(bw / 2, bh)
|
||||
self.box_width /= self.scale
|
||||
@ -347,18 +358,17 @@ class DescendTree(Report):
|
||||
self.box_pad_pts /= self.scale
|
||||
self.box_gap /= self.scale
|
||||
|
||||
# maxh = int((self.uh)/(self.box_height+self.box_gap))
|
||||
maxw = int(uw/calc_width)
|
||||
|
||||
# build array of x indices
|
||||
maxw = int(self.usable_width / calc_width)
|
||||
|
||||
self.generations_per_page = maxw
|
||||
|
||||
self.delta = pt2cm(self.box_pad_pts) + self.box_width + self.box_gap
|
||||
self.delta = ReportUtils.pt2cm(self.box_pad_pts) \
|
||||
+ self.box_width \
|
||||
+ self.box_gap
|
||||
if not self.force_fit:
|
||||
calc_width = self.box_width + pt2cm(self.box_pad_pts)
|
||||
remain = self.doc.get_usable_width() - \
|
||||
((self.generations_per_page)*calc_width)
|
||||
calc_width = self.box_width + ReportUtils.pt2cm(self.box_pad_pts)
|
||||
remain = self.doc.get_usable_width() \
|
||||
- (self.generations_per_page * calc_width)
|
||||
self.delta += remain / float(self.generations_per_page)
|
||||
|
||||
def scale_styles(self):
|
||||
@ -367,16 +377,17 @@ class DescendTree(Report):
|
||||
"""
|
||||
style_sheet = self.doc.get_style_sheet()
|
||||
|
||||
g = style_sheet.get_draw_style("DC2-box")
|
||||
g.set_shadow(g.get_shadow(),g.get_shadow_space()/self.scale)
|
||||
g.set_line_width(g.get_line_width()/self.scale)
|
||||
style_sheet.add_draw_style("DC2-box",g)
|
||||
box_style = style_sheet.get_draw_style("DC2-box")
|
||||
box_style.set_shadow(box_style.get_shadow(),
|
||||
box_style.get_shadow_space() / self.scale)
|
||||
box_style.set_line_width(box_style.get_line_width() / self.scale)
|
||||
style_sheet.add_draw_style("DC2-box", box_style)
|
||||
|
||||
p = style_sheet.get_paragraph_style("DC2-Normal")
|
||||
font = p.get_font()
|
||||
para_style = style_sheet.get_paragraph_style("DC2-Normal")
|
||||
font = para_style.get_font()
|
||||
font.set_size(font.get_size() / self.scale)
|
||||
p.set_font(font)
|
||||
style_sheet.add_paragraph_style("DC2-Normal", p)
|
||||
para_style.set_font(font)
|
||||
style_sheet.add_paragraph_style("DC2-Normal", para_style)
|
||||
|
||||
self.doc.set_style_sheet(style_sheet)
|
||||
|
||||
@ -388,8 +399,10 @@ class DescendTree(Report):
|
||||
if self.genchart.get_xy(x, y) != 0:
|
||||
blank = False
|
||||
break
|
||||
if not blank: break
|
||||
if blank: return
|
||||
if not blank:
|
||||
break
|
||||
if blank:
|
||||
return
|
||||
|
||||
self.doc.start_page()
|
||||
if self.title and self.force_fit:
|
||||
@ -404,7 +417,7 @@ class DescendTree(Report):
|
||||
if isinstance(value, basestring):
|
||||
text = '\n'.join(self.text[(x, y)])
|
||||
xbegin = phys_x * self.delta
|
||||
yend = phys_y*bh+self.offset
|
||||
yend = (phys_y * bh) + self.offset
|
||||
self.doc.draw_box("DC2-box",
|
||||
text,
|
||||
xbegin,
|
||||
@ -413,20 +426,33 @@ class DescendTree(Report):
|
||||
self.box_height)
|
||||
elif value == _LINE_HORIZONTAL:
|
||||
xbegin = phys_x * self.delta
|
||||
ystart = (phys_y*bh + self.box_height/2.0) + self.offset
|
||||
ystart = ((phys_y * bh) + self.box_height / 2.0) \
|
||||
+ self.offset
|
||||
xstart = xbegin + self.box_width
|
||||
xstop = (phys_x + 1) * self.delta
|
||||
self.doc.draw_line('DC2-line', xstart, ystart, xstop,
|
||||
ystart)
|
||||
elif value == _LINE_VERTICAL:
|
||||
ystart = ((phys_y-1)*bh + self.box_height/2.0) + self.offset
|
||||
ystop = (phys_y*bh + self.box_height/2.0) + self.offset
|
||||
xlast = (phys_x*self.delta) + self.box_width + self.box_gap
|
||||
ystart = ((phys_y - 1) * bh) \
|
||||
+ (self.box_height / 2.0) \
|
||||
+ self.offset
|
||||
ystop = (phys_y * bh) \
|
||||
+ (self.box_height / 2.0) \
|
||||
+ self.offset
|
||||
xlast = (phys_x * self.delta) \
|
||||
+ self.box_width \
|
||||
+ self.box_gap
|
||||
self.doc.draw_line('DC2-line', xlast, ystart, xlast, ystop)
|
||||
elif value == _LINE_ANGLE:
|
||||
ystart = ((phys_y-1)*bh + self.box_height/2.0) + self.offset
|
||||
ystop = (phys_y*bh + self.box_height/2.0) + self.offset
|
||||
xlast = (phys_x*self.delta) + self.box_width + self.box_gap
|
||||
ystart = ((phys_y - 1) * bh) \
|
||||
+ (self.box_height / 2.0) \
|
||||
+ self.offset
|
||||
ystop = (phys_y * bh) \
|
||||
+ (self.box_height / 2.0) \
|
||||
+ self.offset
|
||||
xlast = (phys_x * self.delta) \
|
||||
+ self.box_width \
|
||||
+ self.box_gap
|
||||
xnext = (phys_x + 1) * self.delta
|
||||
self.doc.draw_line('DC2-line', xlast, ystart, xlast, ystop)
|
||||
self.doc.draw_line('DC2-line', xlast, ystop, xnext, ystop)
|
||||
@ -490,36 +516,36 @@ class DescendTreeOptions(MenuReportOptions):
|
||||
def make_default_style(self, default_style):
|
||||
"""Make the default output style for the Ancestor Tree."""
|
||||
## Paragraph Styles:
|
||||
f = FontStyle()
|
||||
f.set_size(9)
|
||||
f.set_type_face(FONT_SANS_SERIF)
|
||||
p = ParagraphStyle()
|
||||
p.set_font(f)
|
||||
p.set_description(_('The basic style used for the text display.'))
|
||||
default_style.add_paragraph_style("DC2-Normal", p)
|
||||
font = FontStyle()
|
||||
font.set_size(9)
|
||||
font.set_type_face(FONT_SANS_SERIF)
|
||||
p_style = ParagraphStyle()
|
||||
p_style.set_font(font)
|
||||
p_style.set_description(_('The basic style used for the text display.'))
|
||||
default_style.add_paragraph_style("DC2-Normal", p_style)
|
||||
|
||||
f = FontStyle()
|
||||
f.set_size(16)
|
||||
f.set_type_face(FONT_SANS_SERIF)
|
||||
p = ParagraphStyle()
|
||||
p.set_font(f)
|
||||
p.set_alignment(PARA_ALIGN_CENTER)
|
||||
p.set_description(_('The basic style used for the title display.'))
|
||||
default_style.add_paragraph_style("DC2-Title", p)
|
||||
font = FontStyle()
|
||||
font.set_size(16)
|
||||
font.set_type_face(FONT_SANS_SERIF)
|
||||
p_style = ParagraphStyle()
|
||||
p_style.set_font(font)
|
||||
p_style.set_alignment(PARA_ALIGN_CENTER)
|
||||
p_style.set_description(_('The basic style used for the title display.'))
|
||||
default_style.add_paragraph_style("DC2-Title", p_style)
|
||||
|
||||
## Draw styles
|
||||
g = GraphicsStyle()
|
||||
g.set_paragraph_style("DC2-Normal")
|
||||
g.set_shadow(1, 0.2)
|
||||
g.set_fill_color((255, 255, 255))
|
||||
default_style.add_draw_style("DC2-box", g)
|
||||
g_style = GraphicsStyle()
|
||||
g_style.set_paragraph_style("DC2-Normal")
|
||||
g_style.set_shadow(1, 0.2)
|
||||
g_style.set_fill_color((255, 255, 255))
|
||||
default_style.add_draw_style("DC2-box", g_style)
|
||||
|
||||
g = GraphicsStyle()
|
||||
g.set_paragraph_style("DC2-Title")
|
||||
g.set_color((0, 0, 0))
|
||||
g.set_fill_color((255, 255, 255))
|
||||
g.set_line_width(0)
|
||||
default_style.add_draw_style("DC2-title", g)
|
||||
g_style = GraphicsStyle()
|
||||
g_style.set_paragraph_style("DC2-Title")
|
||||
g_style.set_color((0, 0, 0))
|
||||
g_style.set_fill_color((255, 255, 255))
|
||||
g_style.set_line_width(0)
|
||||
default_style.add_draw_style("DC2-title", g_style)
|
||||
|
||||
g = GraphicsStyle()
|
||||
default_style.add_draw_style("DC2-line", g)
|
||||
g_style = GraphicsStyle()
|
||||
default_style.add_draw_style("DC2-line", g_style)
|
||||
|
Loading…
x
Reference in New Issue
Block a user