Endnotes improvment, see issue 4997 & 4998.

svn: r17809
This commit is contained in:
Peter Landgren 2011-06-19 11:47:22 +00:00
parent 8d71cee996
commit 4750ab4816
9 changed files with 83 additions and 152 deletions

View File

@ -203,16 +203,6 @@ class TextDoc(object):
"""
raise NotImplementedError
def write_endnotes_ref(self, text, style_name, links=False):
"""
Writes the note's text and take care of paragraphs,
@param text: text to write.
@param style_name: style to be used.
@param links: make URLs in the text clickable (if supported)
"""
raise NotImplementedError
def write_styled_note(self, styledtext, format, style_name,
contains_html=False, links=False):
"""

View File

@ -26,8 +26,9 @@
Provide utilities for printing endnotes in text reports.
"""
from gen.plug.docgen import FontStyle, ParagraphStyle, FONT_SANS_SERIF
from gen.lib import NoteType
from gen.lib import NoteType, SourceRef
from gen.ggettext import gettext as _
from Utils import confidence
def add_endnote_styles(style_sheet):
"""
@ -41,32 +42,38 @@ def add_endnote_styles(style_sheet):
para = ParagraphStyle()
para.set_font(font)
para.set_header_level(2)
para.set_top_margin(0.25)
para.set_bottom_margin(0.25)
para.set_top_margin(0.2)
para.set_bottom_margin(0.2)
para.set_description(_('The style used for the generation header.'))
style_sheet.add_paragraph_style("Endnotes-Header", para)
para = ParagraphStyle()
para.set(first_indent=-0.75, lmargin=.75)
para.set_top_margin(0.25)
para.set_bottom_margin(0.25)
para.set_top_margin(0.2)
para.set_bottom_margin(0.0)
para.set_description(_('The basic style used for the endnotes source display.'))
style_sheet.add_paragraph_style("Endnotes-Source", para)
para = ParagraphStyle()
para.set(lmargin=.75)
para.set_top_margin(0.2)
para.set_bottom_margin(0.0)
para.set_description(_('The basic style used for the endnotes notes display.'))
style_sheet.add_paragraph_style("Endnotes-Source-Notes", para)
para = ParagraphStyle()
para.set(first_indent=-0.9, lmargin=1.9)
# para.set(lmargin=1.5)
para.set_top_margin(0.25)
para.set_bottom_margin(0.25)
para.set_top_margin(0.2)
para.set_bottom_margin(0.0)
para.set_description(_('The basic style used for the endnotes reference display.'))
style_sheet.add_paragraph_style("Endnotes-Ref", para)
para = ParagraphStyle()
para.set(lmargin=1.5)
para.set_top_margin(0.25)
para.set_bottom_margin(0.25)
para.set_description(_('The basic style used for the endnotes notes display.'))
style_sheet.add_paragraph_style("Endnotes-Notes", para)
para.set(lmargin=1.9)
para.set_top_margin(0.2)
para.set_bottom_margin(0.0)
para.set_description(_('The basic style used for the endnotes reference notes display.'))
style_sheet.add_paragraph_style("Endnotes-Ref-Notes", para)
def cite_source(bibliography, obj):
"""
@ -121,52 +128,19 @@ def write_endnotes(bibliography, database, doc, printnotes=False, links=False):
first = True
doc.start_paragraph('Endnotes-Source', "%d." % cindex)
src_txt = _format_source_text(source)
doc.write_text(src_txt, links=links)
doc.write_text(_format_source_text(source), links=links)
doc.end_paragraph()
ref_list = citation.get_ref_list()
if ref_list:
first = True
reflines = ""
for key, ref in ref_list:
datepresent = False
date = ref.get_date_object()
if date is not None and not date.is_empty():
datepresent = True
if datepresent:
if ref.get_page():
txt = "%s: %s - %s" % (key, ref.get_page(), str(date))
else:
txt = "%s: %s" % (key, str(date))
else:
txt = "%s: %s" % (key, ref.get_page())
if first:
reflines += txt
first = False
else:
reflines += ('\n%s' % txt)
doc.write_endnotes_ref(reflines,'Endnotes-Ref', links=links)
if printnotes:
note_list = source.get_note_list()
ind = 1
for notehandle in note_list:
note = database.get_note_from_handle(notehandle)
doc.start_paragraph('Endnotes-Notes')
doc.write_text(_('Note %(ind)d - Type: %(type)s') % {
'ind': ind,
'type': str(note.get_type())})
doc.end_paragraph()
doc.write_styled_note(note.get_styledtext(),
note.get_format(),'Endnotes-Notes',
contains_html= note.get_type() \
== NoteType.HTML_CODE,
links=links)
ind += 1
_print_notes(source, database, doc, 'Endnotes-Source-Notes', links)
for key, ref in citation.get_ref_list():
doc.start_paragraph('Endnotes-Ref', "%s:" % key)
doc.write_text(_format_ref_text(ref, key), links=links)
doc.end_paragraph()
if printnotes:
_print_notes(ref, database, doc, 'Endnotes-Ref-Notes', links)
def _format_source_text(source):
if not source: return ""
@ -192,3 +166,36 @@ def _format_source_text(source):
src_txt += "(%s)" % source.get_abbreviation()
return src_txt
def _format_ref_text(ref, key):
if not ref: return ""
ref_txt = ""
datepresent = False
date = ref.get_date_object()
if date is not None and not date.is_empty():
datepresent = True
if datepresent:
if ref.get_page():
ref_txt = "%s - %s" % (ref.get_page(), str(date))
else:
ref_txt = str(date)
else:
ref_txt = ref.get_page()
# Print only confidence level if it is not Normal
if ref.get_confidence_level() != SourceRef.CONF_NORMAL:
ref_txt += " [" + confidence[ref.get_confidence_level()] + "]"
return ref_txt
def _print_notes(obj, db, doc, style, links):
note_list = obj.get_note_list()
ind = 1
for notehandle in note_list:
note = db.get_note_from_handle(notehandle)
contains_html = note.get_type() == NoteType.HTML_CODE
doc.write_styled_note(note.get_styledtext(), note.get_format(), style,
contains_html=contains_html, links=links)
ind += 1

View File

@ -257,7 +257,7 @@ class AsciiDoc(BaseDoc,TextDoc):
this_text = reformat_para(self.text,regular_indent,right,fmt,
right_pad,first_indent)
else:
this_text = self.text
this_text = ' '*(regular_indent+first_indent) + self.text
if self.__note_format:
# don't add an extra LF before the_pad if preformatted notes.
@ -404,15 +404,6 @@ class AsciiDoc(BaseDoc,TextDoc):
self.write_text(line)
self.end_paragraph()
def write_endnotes_ref(self, text, style_name, links=False):
"""
Overwrite base method for lines of endnotes references
"""
for line in text.split('\n'):
self.start_paragraph(style_name)
self.write_text(line)
self.end_paragraph()
#--------------------------------------------------------------------
#
# Writes text.

View File

@ -449,22 +449,6 @@ class HtmlDoc(BaseDoc, TextDoc):
"""
self.__reduce_list()
def write_endnotes_ref(self, text, style_name, links=False):
"""
Overwrite base method for lines of endnotes references
"""
self.htmllist += [Html('div', id='grampsstylednote')]
for line in text.split('\n'):
# more basic method we convert all to a monospace character
self.htmllist += [Html('pre', class_=style_name,
style = 'font-family: courier, monospace',
indent=None, inline=True)]
self.write_text(line)
#end pre element
self.__reduce_list()
#end div element
self.__reduce_list()
def write_styled_note(self, styledtext, format, style_name,
contains_html=False, links=False):
"""

View File

@ -644,14 +644,3 @@ class LaTeXDoc(BaseDoc, TextDoc):
self._backend.write("\\newline\n")
self.end_paragraph()
self._backend.write("\n\\vspace*{0.5cm} \n\\end{minipage}\n\n")
def write_endnotes_ref(self, text, style_name, links=False):
"""
Overwrite base method for lines of endnotes references
"""
self._backend.write("\\begin{minipage}{{0.8\\linewidth}}\n")
for line in text.split('\n'):
self.start_paragraph(style_name)
self.write_text(line)
self.end_paragraph()
self._backend.write("\n\\vspace*{0.5cm} \n\end{minipage}\n\n")

View File

@ -1498,28 +1498,6 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
)
self.new_cell = 1
def write_endnotes_ref(self, text, style_name, links=False):
"""
Overwrite base method for lines of endnotes references
"""
for line in text.split('\n'):
text = escape(line, _esc_map)
# Replace multiple spaces: have to go from the largest number down
for n in range(text.count(' '), 1, -1):
text = text.replace(' '*n, ' <text:s text:c="%d"/>' % (n-1) )
if links == True:
text = re.sub(URL_PATTERN, _CLICKABLE, text)
self.start_paragraph(style_name)
# self.cntnt.write('<text:span text:style-name="GRAMPS-preformat">')
self.cntnt.write(
'<text:span text:style-name="Standard">' +
text +
'</text:span>'
)
self.end_paragraph()
def write_styled_note(self, styledtext, format, style_name,
contains_html=False, links=False):
"""

View File

@ -447,21 +447,6 @@ class RTFDoc(BaseDoc,TextDoc):
self.write_text('\n')
self.end_paragraph()
def write_endnotes_ref(self,text,style_name,links=False):
"""
Overwrite base method for lines of endnotes references
"""
for line in text.split('\n'):
self.start_paragraph(style_name)
self.write_text(line)
if self.in_table:
# Add LF when in table as in indiv_complete report
self.write_text('\n')
self.end_paragraph()
# Write an empty para after all ref lines for each source
self.start_paragraph(style_name)
self.end_paragraph()
#--------------------------------------------------------------------
#
# Writes text. If braces are not currently open, open them. Loop

View File

@ -1293,18 +1293,9 @@ class CairoDoc(BaseDoc, TextDoc, DrawDoc):
def end_cell(self):
self._active_element = self._active_element.get_parent()
def write_endnotes_ref(self, text, style_name):
"""
Overwrite base method for lines of endnotes references
"""
for line in text.split('\n\n'):
self.start_paragraph(style_name)
self.write_text(line)
self.end_paragraph()
def write_styled_note(self, styledtext, format, style_name,
contains_html=False):
contains_html=False, links=False):
"""
Convenience function to write a styledtext to the cairo doc.
styledtext : assumed a StyledText object to write
@ -1358,7 +1349,7 @@ class CairoDoc(BaseDoc, TextDoc, DrawDoc):
text = self._backend.ESCAPE_FUNC()(text)
self._active_element.add_text(text)
def write_text(self, text, mark=None):
def write_text(self, text, mark=None, links=False):
"""Write a normal piece of text according to the
present style
@param text: text to write.

View File

@ -165,7 +165,9 @@ class IndivCompleteReport(Report):
Report.__init__(self, database, options_class)
menu = options_class.menu
self.use_pagebreak = menu.get_option_by_name('pageben').get_value()
self.use_srcs = menu.get_option_by_name('cites').get_value()
self.use_srcs_notes = menu.get_option_by_name('incsrcnotes').get_value()
self.sort = menu.get_option_by_name('sort').get_value()
@ -624,7 +626,10 @@ class IndivCompleteReport(Report):
self.write_addresses()
self.write_note()
if self.use_srcs:
Endnotes.write_endnotes(self.bibli, self.database, self.doc)
if self.use_pagebreak:
self.doc.page_break()
Endnotes.write_endnotes(self.bibli, self.database, self.doc,
printnotes=self.use_srcs_notes)
#------------------------------------------------------------------------
#
@ -662,11 +667,22 @@ class IndivCompleteOptions(MenuReportOptions):
sort = BooleanOption(_("List events chronologically"), True)
sort.set_help(_("Whether to sort events into chronological order."))
menu.add_option(category_name, "sort", sort)
pageben = BooleanOption(_("Page break before end notes"),False)
pageben.set_help(
_("Whether to start a new page before the end notes."))
menu.add_option(category_name, "pageben", pageben)
cites = BooleanOption(_("Include Source Information"), True)
cites.set_help(_("Whether to cite sources."))
menu.add_option(category_name, "cites", cites)
incsrcnotes = BooleanOption(_("Include sources notes"), False)
incsrcnotes.set_help(_("Whether to include source notes in the "
"Endnotes section. Only works if Include sources is selected."))
menu.add_option(category_name, "incsrcnotes", incsrcnotes)
################################
category_name = SECTION_CATEGORY
################################