2003-06-25 09:08:53 +05:30
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-03-10 02:19:29 +05:30
|
|
|
# Copyright (C) 2003-2006 Donald N. Allingham
|
2008-04-07 01:22:39 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2003-06-25 09:08:53 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2003-12-17 21:36:36 +05:30
|
|
|
# $Id$
|
|
|
|
|
2003-06-25 09:08:53 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# python modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2005-01-08 11:24:49 +05:30
|
|
|
import time
|
2006-03-17 01:54:27 +05:30
|
|
|
from TransUtils import sgettext as _
|
2005-01-08 11:24:49 +05:30
|
|
|
|
2003-06-25 09:08:53 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-10-02 09:32:10 +05:30
|
|
|
from gen.plug import PluginManager
|
2008-09-27 19:26:17 +05:30
|
|
|
from gen.plug.menu import StringOption, MediaOption, NumberOption
|
2008-02-18 19:36:41 +05:30
|
|
|
from Utils import media_path_full
|
2008-10-02 09:32:10 +05:30
|
|
|
from ReportBase import Report, MenuReportOptions, CATEGORY_TEXT
|
2009-05-31 20:29:56 +05:30
|
|
|
from gen.plug.docgen import (FontStyle, ParagraphStyle,
|
|
|
|
FONT_SANS_SERIF, PARA_ALIGN_CENTER)
|
2003-07-05 23:55:25 +05:30
|
|
|
|
2003-06-25 09:08:53 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2003-07-05 23:55:25 +05:30
|
|
|
# SimpleBookTitle
|
2003-06-25 09:08:53 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-06-01 10:09:40 +05:30
|
|
|
class SimpleBookTitle(Report):
|
2008-04-07 01:22:39 +05:30
|
|
|
""" This report class generates a title page for a book. """
|
2008-02-20 10:22:10 +05:30
|
|
|
def __init__(self, database, options_class):
|
2005-01-08 11:24:49 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create SimpleBookTitle object that produces the report.
|
2003-06-25 09:08:53 +05:30
|
|
|
|
2005-01-08 11:24:49 +05:30
|
|
|
The arguments are:
|
2003-06-25 09:08:53 +05:30
|
|
|
|
2005-01-08 11:24:49 +05:30
|
|
|
database - the GRAMPS database instance
|
|
|
|
options_class - instance of the Options class for this report
|
2003-06-25 09:08:53 +05:30
|
|
|
|
2005-01-08 11:24:49 +05:30
|
|
|
This report needs the following parameters (class variables)
|
|
|
|
that come in the options class.
|
|
|
|
|
|
|
|
title - Title string.
|
|
|
|
subtitle - Subtitle string.
|
|
|
|
imgid - Gramps ID of the media object to use as an image.
|
|
|
|
imgsize - Size for the image.
|
|
|
|
footer - Footer string.
|
|
|
|
"""
|
2008-02-20 10:22:10 +05:30
|
|
|
Report.__init__(self, database, options_class)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
2008-04-07 01:22:39 +05:30
|
|
|
menu = options_class.menu
|
|
|
|
self.title_string = menu.get_option_by_name('title').get_value()
|
|
|
|
self.image_size = menu.get_option_by_name('imgsize').get_value()
|
|
|
|
self.subtitle_string = menu.get_option_by_name('subtitle').get_value()
|
|
|
|
self.footer_string = menu.get_option_by_name('footer').get_value()
|
|
|
|
self.object_id = menu.get_option_by_name('imgid').get_value()
|
2005-01-08 11:24:49 +05:30
|
|
|
|
|
|
|
def write_report(self):
|
2008-04-07 01:22:39 +05:30
|
|
|
""" Generate the contents of the report """
|
2003-07-18 19:13:13 +05:30
|
|
|
self.doc.start_paragraph('SBT-Title')
|
2003-07-05 23:55:25 +05:30
|
|
|
self.doc.write_text(self.title_string)
|
2003-06-25 09:08:53 +05:30
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
2003-09-11 07:10:20 +05:30
|
|
|
self.doc.start_paragraph('SBT-Subtitle')
|
|
|
|
self.doc.write_text(self.subtitle_string)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
2005-01-08 11:24:49 +05:30
|
|
|
if self.object_id:
|
|
|
|
the_object = self.database.get_object_from_gramps_id(self.object_id)
|
2008-02-18 19:36:41 +05:30
|
|
|
name = media_path_full(self.database, the_object.get_path())
|
2003-09-11 07:10:20 +05:30
|
|
|
if self.image_size:
|
|
|
|
image_size = self.image_size
|
|
|
|
else:
|
|
|
|
image_size = min(
|
|
|
|
0.8 * self.doc.get_usable_width(),
|
|
|
|
0.7 * self.doc.get_usable_height() )
|
2008-04-07 01:22:39 +05:30
|
|
|
self.doc.add_media_object(name, 'center', image_size, image_size)
|
2003-09-08 09:14:54 +05:30
|
|
|
|
2003-09-11 07:10:20 +05:30
|
|
|
self.doc.start_paragraph('SBT-Footer')
|
|
|
|
self.doc.write_text(self.footer_string)
|
2003-06-25 09:08:53 +05:30
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2008-04-07 01:22:39 +05:30
|
|
|
# SimpleBookTitleOptions
|
2003-06-25 09:08:53 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-04-07 01:22:39 +05:30
|
|
|
class SimpleBookTitleOptions(MenuReportOptions):
|
2005-01-08 11:24:49 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
2008-04-07 01:22:39 +05:30
|
|
|
|
2008-02-20 10:22:10 +05:30
|
|
|
def __init__(self, name, dbase):
|
2008-04-07 01:22:39 +05:30
|
|
|
self.__db = dbase
|
|
|
|
MenuReportOptions.__init__(self, name, dbase)
|
2003-09-08 09:14:54 +05:30
|
|
|
|
2008-04-07 01:22:39 +05:30
|
|
|
def add_menu_options(self, menu):
|
|
|
|
""" Add the options for this report """
|
|
|
|
category_name = _("Report Options")
|
2003-09-08 09:14:54 +05:30
|
|
|
|
2008-04-07 01:22:39 +05:30
|
|
|
title = StringOption(_('book|Title'), _('Title of the Book') )
|
|
|
|
title.set_help(_("Title string for the book."))
|
|
|
|
menu.add_option(category_name, "title", title)
|
2008-01-06 16:21:20 +05:30
|
|
|
|
2008-04-07 01:22:39 +05:30
|
|
|
subtitle = StringOption(_('Subtitle'), _('Subtitle of the Book') )
|
|
|
|
subtitle.set_help(_("Subtitle string for the book."))
|
|
|
|
menu.add_option(category_name, "subtitle", subtitle)
|
|
|
|
|
|
|
|
dateinfo = time.localtime(time.time())
|
|
|
|
rname = self.__db.get_researcher().get_name()
|
|
|
|
footer_string = _('Copyright %d %s') % (dateinfo[0], rname)
|
|
|
|
footer = StringOption(_('Footer'), footer_string )
|
|
|
|
footer.set_help(_("Footer string for the page."))
|
|
|
|
menu.add_option(category_name, "footer", footer)
|
|
|
|
|
|
|
|
imgid = MediaOption(_('Image'))
|
|
|
|
imgid.set_help( _("Gramps ID of the media object to use as an image."))
|
|
|
|
menu.add_option(category_name, "imgid", imgid)
|
|
|
|
|
|
|
|
imgsize = NumberOption(_('Image Size'), 0, 0, 20, 0.1)
|
|
|
|
imgsize.set_help(_("Size of the image in cm. A value of 0 indicates "
|
|
|
|
"that the image should be fit to the page."))
|
|
|
|
menu.add_option(category_name, "imgsize", imgsize)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
2008-04-07 01:22:39 +05:30
|
|
|
def make_default_style(self, default_style):
|
2005-01-08 11:24:49 +05:30
|
|
|
"""Make the default output style for the Simple Boot Title report."""
|
2009-05-30 03:55:44 +05:30
|
|
|
font = FontStyle()
|
|
|
|
font.set(face=FONT_SANS_SERIF, size=16, bold=1, italic=1)
|
|
|
|
para = ParagraphStyle()
|
2005-01-08 11:24:49 +05:30
|
|
|
para.set_font(font)
|
|
|
|
para.set_header_level(1)
|
2009-05-30 03:55:44 +05:30
|
|
|
para.set_alignment(PARA_ALIGN_CENTER)
|
2005-01-08 11:24:49 +05:30
|
|
|
para.set(pad=0.5)
|
|
|
|
para.set_description(_('The style used for the title of the page.'))
|
2008-04-07 01:22:39 +05:30
|
|
|
default_style.add_paragraph_style("SBT-Title", para)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
font = FontStyle()
|
|
|
|
font.set(face=FONT_SANS_SERIF, size=14, italic=1)
|
|
|
|
para = ParagraphStyle()
|
2005-01-08 11:24:49 +05:30
|
|
|
para.set_font(font)
|
|
|
|
para.set_header_level(2)
|
|
|
|
para.set(pad=0.5)
|
2009-05-30 03:55:44 +05:30
|
|
|
para.set_alignment(PARA_ALIGN_CENTER)
|
2005-01-08 11:24:49 +05:30
|
|
|
para.set_description(_('The style used for the subtitle.'))
|
2008-04-07 01:22:39 +05:30
|
|
|
default_style.add_paragraph_style("SBT-Subtitle", para)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
font = FontStyle()
|
|
|
|
font.set(face=FONT_SANS_SERIF, size=10, italic=1)
|
|
|
|
para = ParagraphStyle()
|
2005-01-08 11:24:49 +05:30
|
|
|
para.set_font(font)
|
|
|
|
para.set_header_level(2)
|
|
|
|
para.set(pad=0.5)
|
2009-05-30 03:55:44 +05:30
|
|
|
para.set_alignment(PARA_ALIGN_CENTER)
|
2005-01-08 11:24:49 +05:30
|
|
|
para.set_description(_('The style used for the footer.'))
|
2008-04-07 01:22:39 +05:30
|
|
|
default_style.add_paragraph_style("SBT-Footer", para)
|
2003-06-25 09:08:53 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2008-04-07 01:22:39 +05:30
|
|
|
# register_report
|
2003-06-25 09:08:53 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2008-05-19 00:54:28 +05:30
|
|
|
pmgr = PluginManager.get_instance()
|
|
|
|
pmgr.register_report(
|
2005-01-08 11:24:49 +05:30
|
|
|
name = 'simple_book_title',
|
2006-06-01 10:09:40 +05:30
|
|
|
category = CATEGORY_TEXT,
|
2005-01-08 11:24:49 +05:30
|
|
|
report_class = SimpleBookTitle,
|
|
|
|
options_class = SimpleBookTitleOptions,
|
2008-10-02 09:32:10 +05:30
|
|
|
modes = PluginManager.REPORT_MODE_BKI,
|
2005-01-08 11:24:49 +05:30
|
|
|
translated_name = _("Title Page"),
|
2008-04-07 01:22:39 +05:30
|
|
|
status = _("Stable"),
|
|
|
|
description = _("Produces a title page for book reports."),
|
|
|
|
author_name = "Brian G. Matherly",
|
|
|
|
author_email = "brian@gramps-project.org"
|
2005-01-08 11:24:49 +05:30
|
|
|
)
|