2007-06-13 09:43:00 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Brian G. Matherly
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2007-10-07 08:49:35 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2007-06-13 09:43:00 +05:30
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# $Id: $
|
|
|
|
|
|
|
|
"""
|
|
|
|
Provide utilities for printing endnotes in text reports.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import BaseDoc
|
2007-10-07 08:49:35 +05:30
|
|
|
from gettext import gettext as _
|
2007-06-13 09:43:00 +05:30
|
|
|
|
|
|
|
def add_endnote_styles(style_sheet):
|
|
|
|
"""
|
|
|
|
Add paragraph styles to a style sheet to be used for displaying endnotes.
|
|
|
|
|
|
|
|
@param style_sheet: Style sheet
|
|
|
|
@type style_sheet: L{Basedoc.StyleSheet}
|
|
|
|
"""
|
|
|
|
font = BaseDoc.FontStyle()
|
2007-10-07 08:49:35 +05:30
|
|
|
font.set(face=BaseDoc.FONT_SANS_SERIF, size=14, italic=1)
|
2007-06-13 09:43:00 +05:30
|
|
|
para = BaseDoc.ParagraphStyle()
|
|
|
|
para.set_font(font)
|
|
|
|
para.set_header_level(2)
|
|
|
|
para.set_top_margin(0.25)
|
|
|
|
para.set_bottom_margin(0.25)
|
|
|
|
para.set_description(_('The style used for the generation header.'))
|
2007-10-07 08:49:35 +05:30
|
|
|
style_sheet.add_paragraph_style("Endnotes-Header", para)
|
2007-06-13 09:43:00 +05:30
|
|
|
|
|
|
|
para = BaseDoc.ParagraphStyle()
|
2007-10-07 08:49:35 +05:30
|
|
|
para.set(first_indent=-0.75, lmargin=.75)
|
2007-06-13 09:43:00 +05:30
|
|
|
para.set_top_margin(0.25)
|
|
|
|
para.set_bottom_margin(0.25)
|
|
|
|
para.set_description(_('The basic style used for the endnotes source display.'))
|
2007-10-07 08:49:35 +05:30
|
|
|
style_sheet.add_paragraph_style("Endnotes-Source", para)
|
2007-06-13 09:43:00 +05:30
|
|
|
|
|
|
|
para = BaseDoc.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 reference display.'))
|
2007-10-07 08:49:35 +05:30
|
|
|
style_sheet.add_paragraph_style("Endnotes-Ref", para)
|
2007-06-13 09:43:00 +05:30
|
|
|
|
2007-10-07 08:49:35 +05:30
|
|
|
def cite_source(bibliography, obj):
|
2007-06-13 09:43:00 +05:30
|
|
|
"""
|
|
|
|
Cite any sources for the object and add them to the bibliography.
|
|
|
|
|
|
|
|
@param bibliography: The bibliography to contain the citations.
|
|
|
|
@type bibliography: L{Bibliography}
|
|
|
|
@param obj: An object with source references.
|
|
|
|
@type obj: L{Relib.SourceBase}
|
|
|
|
"""
|
|
|
|
txt = ""
|
|
|
|
slist = obj.get_source_references()
|
|
|
|
if slist:
|
|
|
|
first = 1
|
|
|
|
for ref in slist:
|
|
|
|
if not first:
|
2007-10-07 08:49:35 +05:30
|
|
|
txt += ', '
|
2007-06-13 09:43:00 +05:30
|
|
|
first = 0
|
2007-10-07 08:49:35 +05:30
|
|
|
(cindex, key) = bibliography.add_reference(ref)
|
2007-06-13 09:43:00 +05:30
|
|
|
txt += "%d" % (cindex + 1)
|
2007-07-23 17:52:03 +05:30
|
|
|
if key != None:
|
|
|
|
txt += key
|
2007-06-13 09:43:00 +05:30
|
|
|
return txt
|
|
|
|
|
2007-10-07 08:49:35 +05:30
|
|
|
def write_endnotes(bibliography, database, doc):
|
2007-06-13 09:43:00 +05:30
|
|
|
"""
|
|
|
|
Write all the entries in the bibliography as endnotes.
|
|
|
|
|
|
|
|
@param bibliography: The bibliography that contains the citations.
|
|
|
|
@type bibliography: L{Bibliography}
|
|
|
|
@param database: The database that the sources come from.
|
|
|
|
@type database: GrampsDbBase
|
|
|
|
@param doc: The document to write the endnotes into.
|
|
|
|
@type doc: L{BaseDoc.TextDoc}
|
|
|
|
"""
|
|
|
|
if bibliography.get_citation_count() == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
doc.start_paragraph('Endnotes-Header')
|
|
|
|
doc.write_text(_('Endnotes'))
|
|
|
|
doc.end_paragraph()
|
|
|
|
|
|
|
|
cindex = 0
|
|
|
|
for citation in bibliography.get_citation_list():
|
|
|
|
cindex += 1
|
|
|
|
source = database.get_source_from_handle(citation.get_source_handle())
|
|
|
|
first = True
|
|
|
|
|
2007-10-07 08:49:35 +05:30
|
|
|
doc.start_paragraph('Endnotes-Source', "%d." % cindex)
|
2007-06-13 09:43:00 +05:30
|
|
|
|
|
|
|
src_txt = _format_source_text(source)
|
|
|
|
|
|
|
|
doc.write_text(src_txt)
|
|
|
|
doc.end_paragraph()
|
|
|
|
|
|
|
|
ref_list = citation.get_ref_list()
|
|
|
|
|
|
|
|
if ref_list:
|
|
|
|
doc.start_paragraph('Endnotes-Ref')
|
|
|
|
|
|
|
|
first = True
|
|
|
|
rindex = 0
|
2007-10-07 08:49:35 +05:30
|
|
|
for key, ref in ref_list:
|
|
|
|
txt = "%s: %s" % (key, ref.get_page())
|
2007-06-13 09:43:00 +05:30
|
|
|
if first:
|
|
|
|
doc.write_text(txt)
|
|
|
|
first = False
|
|
|
|
else:
|
|
|
|
doc.write_text('; %s' % txt)
|
|
|
|
|
|
|
|
rindex += 1
|
|
|
|
doc.end_paragraph()
|
|
|
|
|
|
|
|
def _format_source_text(source):
|
|
|
|
src_txt = ""
|
|
|
|
|
|
|
|
if source.get_author():
|
|
|
|
src_txt += source.get_author()
|
|
|
|
|
|
|
|
if source.get_title():
|
|
|
|
if src_txt:
|
|
|
|
src_txt += ", "
|
|
|
|
src_txt += '"%s"' % source.get_title()
|
|
|
|
|
|
|
|
if source.get_publication_info():
|
|
|
|
if src_txt:
|
|
|
|
src_txt += ", "
|
|
|
|
src_txt += source.get_publication_info()
|
|
|
|
|
|
|
|
if source.get_abbreviation():
|
|
|
|
if src_txt:
|
|
|
|
src_txt += ", "
|
|
|
|
src_txt += "(%s)" % source.get_abbreviation()
|
|
|
|
|
2007-10-07 08:49:35 +05:30
|
|
|
return src_txt
|