Enhance source endnotes in some text reports.
svn: r8541
This commit is contained in:
157
src/ReportBase/_Bibliography.py
Normal file
157
src/ReportBase/_Bibliography.py
Normal file
@@ -0,0 +1,157 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# 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: $
|
||||
|
||||
"""
|
||||
Contain and organize bibliographic information.
|
||||
"""
|
||||
|
||||
class Citation:
|
||||
"""
|
||||
Store information about a citation and all of its references.
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
Initialize members.
|
||||
"""
|
||||
self.__src_handle = None
|
||||
self.__ref_list = []
|
||||
|
||||
def get_source_handle(self):
|
||||
"""
|
||||
Provide the handle to the source that this citation is for.
|
||||
|
||||
@return: Source Handle
|
||||
@rtype: handle
|
||||
"""
|
||||
return self.__src_handle
|
||||
|
||||
def set_source_handle(self,handle):
|
||||
"""
|
||||
Set the handle for the source that this citation is for.
|
||||
|
||||
@param handle: Source Handle
|
||||
@type handle: handle
|
||||
"""
|
||||
self.__src_handle = handle
|
||||
|
||||
def get_ref_list(self):
|
||||
"""
|
||||
List all the references to this citation.
|
||||
|
||||
@return: a list of references
|
||||
@rtype: list of L{Relib.SourceRef} objects
|
||||
"""
|
||||
return self.__ref_list
|
||||
|
||||
def add_reference(self, source_ref):
|
||||
"""
|
||||
Add a reference to this citation. If a similar reference exists, don't
|
||||
add another one.
|
||||
|
||||
@param source_ref: Source Reference
|
||||
@type source_ref: L{Relib.SourceRef}
|
||||
@return: The index of the added reference among all the references.
|
||||
@rtype: int
|
||||
"""
|
||||
index = 0
|
||||
for ref in self.__ref_list:
|
||||
if _srefs_are_equal(ref,source_ref):
|
||||
# if a reference like this already exists, don't add another one
|
||||
return index
|
||||
index += 1
|
||||
|
||||
self.__ref_list.append(source_ref)
|
||||
return index
|
||||
|
||||
class Bibliography:
|
||||
"""
|
||||
Store and organize multiple citations into a bibliography.
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
Initialize members.
|
||||
"""
|
||||
self.__citation_list = []
|
||||
|
||||
def add_reference(self, source_ref):
|
||||
"""
|
||||
Add a reference to a source to this bibliography. If the source already
|
||||
exists, don't add it again. If a similar reference exists, don't
|
||||
add another one.
|
||||
|
||||
@param source_ref: Source Reference
|
||||
@type source_ref: L{Relib.SourceRef}
|
||||
@return: A tuple containing the index of the source among all the
|
||||
sources and the index of the reference among all the references. If
|
||||
there is no reference information, the second element will be None.
|
||||
@rtype: (int,int) or (int,None)
|
||||
"""
|
||||
source_handle = source_ref.get_reference_handle()
|
||||
cindex = 0
|
||||
rindex = None
|
||||
citation = None
|
||||
citation_found = False
|
||||
for citation in self.__citation_list:
|
||||
if citation.get_source_handle() == source_handle:
|
||||
citation_found = True
|
||||
break
|
||||
cindex += 1
|
||||
|
||||
if not citation_found:
|
||||
citation = Citation()
|
||||
citation.set_source_handle(source_handle)
|
||||
cindex = len(self.__citation_list)
|
||||
self.__citation_list.append(citation)
|
||||
|
||||
if _sref_has_info(source_ref):
|
||||
rindex = citation.add_reference(source_ref)
|
||||
|
||||
return (cindex,rindex)
|
||||
|
||||
def get_citation_count(self):
|
||||
"""
|
||||
Report the number of citations in this bibliography.
|
||||
|
||||
@return: number of citations
|
||||
@rtype: int
|
||||
"""
|
||||
return len(self.__citation_list)
|
||||
|
||||
def get_citation_list(self):
|
||||
"""
|
||||
Return a list containing all the citations in this bibliography.
|
||||
|
||||
@return: citation list
|
||||
@rtype: list of L{Citation} objects
|
||||
"""
|
||||
return self.__citation_list
|
||||
|
||||
def _sref_has_info(source_ref):
|
||||
if source_ref.get_page() == "":
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def _srefs_are_equal(source_ref1,source_ref2):
|
||||
if source_ref1.get_page() == source_ref2.get_page():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
155
src/ReportBase/_Endnotes.py
Normal file
155
src/ReportBase/_Endnotes.py
Normal file
@@ -0,0 +1,155 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# 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 string
|
||||
import BaseDoc
|
||||
|
||||
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()
|
||||
font.set(face=BaseDoc.FONT_SANS_SERIF,size=14,italic=1)
|
||||
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.'))
|
||||
style_sheet.add_paragraph_style("Endnotes-Header",para)
|
||||
|
||||
para = BaseDoc.ParagraphStyle()
|
||||
para.set(first_indent=-0.75,lmargin=.75)
|
||||
para.set_top_margin(0.25)
|
||||
para.set_bottom_margin(0.25)
|
||||
para.set_description(_('The basic style used for the endnotes source display.'))
|
||||
style_sheet.add_paragraph_style("Endnotes-Source",para)
|
||||
|
||||
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.'))
|
||||
style_sheet.add_paragraph_style("Endnotes-Ref",para)
|
||||
|
||||
def cite_source(bibliography,obj):
|
||||
"""
|
||||
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:
|
||||
txt += '<super>'
|
||||
first = 1
|
||||
for ref in slist:
|
||||
if not first:
|
||||
txt += ','
|
||||
first = 0
|
||||
(cindex,rindex) = bibliography.add_reference(ref)
|
||||
txt += "%d" % (cindex + 1)
|
||||
if rindex != None:
|
||||
txt += "%s" % string.lowercase[rindex]
|
||||
txt += '</super>'
|
||||
return txt
|
||||
|
||||
def write_endnotes(bibliography,database,doc):
|
||||
"""
|
||||
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
|
||||
|
||||
doc.start_paragraph('Endnotes-Source',"%d." % cindex)
|
||||
|
||||
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
|
||||
for ref in ref_list:
|
||||
txt = "%s: %s" % (string.lowercase[rindex],ref.get_page())
|
||||
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()
|
||||
|
||||
return src_txt
|
||||
@@ -34,7 +34,6 @@ A collection of utilities to aid in the generation of reports.
|
||||
import time
|
||||
import os
|
||||
from gettext import gettext as _
|
||||
import cStringIO
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@@ -2434,35 +2433,6 @@ def get_address_str(addr):
|
||||
str = "%s, %s" % (str,info)
|
||||
return str
|
||||
|
||||
def get_endnotes(sref_map,obj):
|
||||
if not obj:
|
||||
return ""
|
||||
|
||||
slist = obj.get_source_references()
|
||||
|
||||
if not slist:
|
||||
return ""
|
||||
|
||||
msg = cStringIO.StringIO()
|
||||
first = 1
|
||||
for ref in slist:
|
||||
if not first:
|
||||
msg.write(',')
|
||||
first = 0
|
||||
ref_base = ref.get_reference_handle()
|
||||
the_key = 0
|
||||
for key in sref_map.keys():
|
||||
if ref_base == sref_map[key].get_reference_handle():
|
||||
the_key = key
|
||||
break
|
||||
if not the_key:
|
||||
the_key = len(sref_map) + 1
|
||||
sref_map[the_key] = ref
|
||||
msg.write("%d" % the_key)
|
||||
str = msg.getvalue()
|
||||
msg.close()
|
||||
return str
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# People Filters
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2001 David R. Hampton
|
||||
# Copyright (C) 2001-2006 Donald N. Allingham
|
||||
# Copyright (C) 2001 David R. Hampton
|
||||
# Copyright (C) 2001-2006 Donald N. Allingham
|
||||
# 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
|
||||
@@ -38,4 +39,7 @@ from _TextReportDialog import TextReportDialog
|
||||
from _ReportOptions import ReportOptions
|
||||
import _ReportUtils as ReportUtils
|
||||
|
||||
from _Bibliography import Bibliography, Citation
|
||||
import _Endnotes as Endnotes
|
||||
|
||||
from _PrintTools import run_print_dialog, get_print_dialog_app
|
||||
|
||||
Reference in New Issue
Block a user