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
|
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
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import os
|
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
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gtk
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
import gtk
|
2003-06-25 09:08:53 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-03-11 06:42:06 +05:30
|
|
|
from PluginUtils import Report, ReportOptions, register_report
|
2003-08-26 09:37:00 +05:30
|
|
|
import BaseDoc
|
2003-09-08 09:14:54 +05:30
|
|
|
import SelectObject
|
2003-09-10 19:08:02 +05:30
|
|
|
import AddMedia
|
2005-01-09 07:48:49 +05:30
|
|
|
import ImgManip
|
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
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class SimpleBookTitle(Report.Report):
|
|
|
|
|
2005-01-08 11:24:49 +05:30
|
|
|
def __init__(self,database,person,options_class):
|
|
|
|
"""
|
|
|
|
Creates 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
|
|
|
|
person - currently selected person
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
|
|
|
Report.Report.__init__(self,database,person,options_class)
|
|
|
|
|
|
|
|
self.title_string = options_class.handler.options_dict['title']
|
|
|
|
self.image_size = options_class.handler.options_dict['imgsize']
|
|
|
|
self.subtitle_string = options_class.handler.options_dict['subtitle']
|
|
|
|
self.footer_string = options_class.handler.options_dict['footer']
|
|
|
|
self.object_id = options_class.handler.options_dict['imgid']
|
|
|
|
|
|
|
|
def write_report(self):
|
2003-06-25 09:08:53 +05:30
|
|
|
|
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)
|
|
|
|
name = 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() )
|
2004-02-21 11:41:59 +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()
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2005-01-08 11:24:49 +05:30
|
|
|
#
|
2003-06-25 09:08:53 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2005-01-08 11:24:49 +05:30
|
|
|
class SimpleBookTitleOptions(ReportOptions.ReportOptions):
|
|
|
|
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self,name,person_id=None):
|
|
|
|
ReportOptions.ReportOptions.__init__(self,name,person_id)
|
|
|
|
|
|
|
|
def set_new_options(self):
|
|
|
|
# Options specific for this report
|
|
|
|
self.options_dict = {
|
|
|
|
'title' : _('Title of the Book'),
|
|
|
|
'subtitle' : _('Subtitle of the Book'),
|
|
|
|
'imgid' : '',
|
|
|
|
'imgsize' : 0.0,
|
|
|
|
'footer' : '',
|
|
|
|
}
|
|
|
|
self.options_help = {
|
|
|
|
'title' : ("=str","Title string for the report",
|
|
|
|
"Whatever String You Wish"),
|
|
|
|
'subtitle' : ("=str","Subtitle string for the report",
|
|
|
|
"Whatever String You Wish"),
|
|
|
|
'footer' : ("=str","Footer string for the report",
|
|
|
|
"Whatever String You Wish"),
|
|
|
|
'imgid' : ("=ID","Gramps ID of the media object to use as an image.",
|
|
|
|
"Valid GRAMPS ID of an image."),
|
|
|
|
'imgsize' : ("=num","Size of the image.",
|
|
|
|
["Floating point value (in cm)",
|
|
|
|
"0 (to fit the page)."],
|
|
|
|
False),
|
|
|
|
}
|
|
|
|
|
|
|
|
def add_user_options(self,dialog):
|
|
|
|
dialog.setup_center_person = dialog.setup_paper_frame
|
|
|
|
dialog.notebook = gtk.Notebook()
|
|
|
|
dialog.notebook.set_border_width(6)
|
|
|
|
dialog.window.vbox.add(dialog.notebook)
|
2003-06-25 09:08:53 +05:30
|
|
|
|
2005-01-08 11:24:49 +05:30
|
|
|
self.title_entry = gtk.Entry()
|
|
|
|
self.title_entry.set_text(self.options_dict['title'])
|
2003-09-08 09:14:54 +05:30
|
|
|
|
2005-01-08 11:24:49 +05:30
|
|
|
self.subtitle_entry = gtk.Entry()
|
|
|
|
self.subtitle_entry.set_text(self.options_dict['subtitle'])
|
2003-09-11 07:10:20 +05:30
|
|
|
|
2005-01-08 11:24:49 +05:30
|
|
|
footer_string = self.options_dict['footer']
|
|
|
|
if not footer_string:
|
2003-07-05 23:55:25 +05:30
|
|
|
dateinfo = time.localtime(time.time())
|
2005-01-09 01:49:06 +05:30
|
|
|
name = dialog.db.get_researcher().get_name()
|
2005-01-08 11:24:49 +05:30
|
|
|
footer_string = _('Copyright %d %s') % (dateinfo[0], name)
|
2003-09-11 07:10:20 +05:30
|
|
|
self.footer_entry = gtk.Entry()
|
2005-01-08 11:24:49 +05:30
|
|
|
self.footer_entry.set_text(footer_string)
|
|
|
|
|
2006-03-17 01:54:27 +05:30
|
|
|
dialog.add_frame_option(_('Text'),_('book|Title'),self.title_entry)
|
2005-01-08 11:24:49 +05:30
|
|
|
dialog.add_frame_option(_('Text'),_('Subtitle'),self.subtitle_entry)
|
|
|
|
dialog.add_frame_option(_('Text'),_('Footer'),self.footer_entry)
|
2003-09-08 09:14:54 +05:30
|
|
|
|
2003-09-10 07:20:26 +05:30
|
|
|
frame = gtk.Frame()
|
|
|
|
frame.set_size_request(96,96)
|
2003-09-08 09:14:54 +05:30
|
|
|
self.preview = gtk.Image()
|
2003-09-10 07:20:26 +05:30
|
|
|
frame.add(self.preview)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
2003-09-10 07:20:26 +05:30
|
|
|
self.obj_title = gtk.Label('')
|
2005-01-08 11:24:49 +05:30
|
|
|
|
2003-09-10 07:20:26 +05:30
|
|
|
self.remove_obj_button = gtk.Button(None,gtk.STOCK_REMOVE)
|
|
|
|
self.remove_obj_button.connect('clicked',self.remove_obj)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
2003-09-10 07:20:26 +05:30
|
|
|
preview_table = gtk.Table(2,1)
|
|
|
|
preview_table.set_row_spacings(10)
|
|
|
|
preview_table.attach(frame,0,1,1,2,gtk.SHRINK|gtk.FILL,gtk.SHRINK|gtk.FILL)
|
|
|
|
preview_table.attach(self.obj_title,0,1,0,1,gtk.SHRINK|gtk.FILL,gtk.SHRINK|gtk.FILL)
|
|
|
|
|
|
|
|
select_obj_button = gtk.Button(_('From gallery...'))
|
2005-01-09 01:49:06 +05:30
|
|
|
select_obj_button.connect('clicked',self.select_obj,dialog.db)
|
2003-09-10 07:20:26 +05:30
|
|
|
select_file_button = gtk.Button(_('From file...'))
|
2005-01-09 01:49:06 +05:30
|
|
|
select_file_button.connect('clicked',self.select_file,dialog.db)
|
2003-09-10 07:20:26 +05:30
|
|
|
select_table = gtk.Table(1,3)
|
|
|
|
select_table.set_col_spacings(10)
|
|
|
|
select_table.attach(select_obj_button,
|
|
|
|
0,1,0,1,gtk.SHRINK|gtk.FILL,gtk.SHRINK|gtk.FILL)
|
|
|
|
select_table.attach(select_file_button,
|
|
|
|
1,2,0,1,gtk.SHRINK|gtk.FILL,gtk.SHRINK|gtk.FILL)
|
|
|
|
select_table.attach(self.remove_obj_button,
|
|
|
|
2,3,0,1,gtk.SHRINK|gtk.FILL,gtk.SHRINK|gtk.FILL)
|
2003-09-11 07:10:20 +05:30
|
|
|
|
2005-01-08 11:24:49 +05:30
|
|
|
self.size = gtk.SpinButton()
|
|
|
|
self.size.set_digits(2)
|
|
|
|
self.size.set_increments(1,2)
|
|
|
|
self.size.set_range(0,20)
|
2005-02-24 05:55:34 +05:30
|
|
|
self.size.set_numeric(True)
|
2005-01-08 11:24:49 +05:30
|
|
|
self.size.set_value(self.options_dict['imgsize'])
|
|
|
|
|
|
|
|
dialog.add_frame_option(_('Image'),_('Preview'),preview_table)
|
|
|
|
dialog.add_frame_option(_('Image'),_('Select'),select_table)
|
|
|
|
dialog.add_frame_option(_('Image'),_('Size'),self.size)
|
|
|
|
|
|
|
|
object_id = self.options_dict['imgid']
|
2005-01-09 01:49:06 +05:30
|
|
|
if object_id and dialog.db.get_object_from_gramps_id(object_id):
|
|
|
|
the_object = dialog.db.get_object_from_gramps_id(object_id)
|
|
|
|
self.setup_object(dialog.db,the_object)
|
2005-01-08 11:24:49 +05:30
|
|
|
else:
|
|
|
|
self.remove_obj_button.set_sensitive(False)
|
|
|
|
self.size.set_sensitive(False)
|
|
|
|
|
|
|
|
def parse_user_options(self,dialog):
|
|
|
|
"""
|
|
|
|
Parses the custom options that we have added.
|
|
|
|
"""
|
|
|
|
self.options_dict['title'] = unicode(self.title_entry.get_text())
|
|
|
|
self.options_dict['subtitle'] = unicode(self.subtitle_entry.get_text())
|
|
|
|
self.options_dict['footer'] = unicode(self.footer_entry.get_text())
|
|
|
|
self.options_dict['imgsize'] = self.size.get_value()
|
2003-06-25 09:08:53 +05:30
|
|
|
|
2003-09-10 07:20:26 +05:30
|
|
|
def remove_obj(self, obj):
|
2005-01-08 11:24:49 +05:30
|
|
|
self.options_dict['imgid'] = ""
|
2003-09-10 07:20:26 +05:30
|
|
|
self.obj_title.set_text('')
|
|
|
|
self.preview.set_from_pixbuf(None)
|
2005-02-24 05:55:34 +05:30
|
|
|
self.remove_obj_button.set_sensitive(False)
|
|
|
|
self.size.set_sensitive(False)
|
2003-09-11 07:10:20 +05:30
|
|
|
|
2005-01-08 11:24:49 +05:30
|
|
|
def select_obj(self,obj,database):
|
|
|
|
s_o = SelectObject.SelectObject(database,_("Select an Object"))
|
|
|
|
the_object = s_o.run()
|
|
|
|
self.setup_object(database,the_object)
|
2003-09-10 07:20:26 +05:30
|
|
|
|
2005-01-08 11:24:49 +05:30
|
|
|
def select_file(self,obj,database):
|
|
|
|
a_o = AddMedia.AddMediaObject(database)
|
|
|
|
the_object = a_o.run()
|
|
|
|
self.setup_object(database,the_object)
|
|
|
|
|
|
|
|
def setup_object(self,database,the_object):
|
|
|
|
if not the_object:
|
2003-09-10 19:08:02 +05:30
|
|
|
return
|
2005-01-08 11:24:49 +05:30
|
|
|
self.options_dict['imgid'] = the_object.get_gramps_id()
|
|
|
|
self.obj_title.set_text(the_object.get_description())
|
2005-12-06 12:08:09 +05:30
|
|
|
icon_image = ImgManip.get_thumbnail_image(the_object.get_path(),
|
|
|
|
the_object.get_mime_type())
|
2005-01-08 11:24:49 +05:30
|
|
|
self.preview.set_from_pixbuf(icon_image)
|
2005-02-24 05:55:34 +05:30
|
|
|
self.remove_obj_button.set_sensitive(True)
|
|
|
|
self.size.set_sensitive(True)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
|
|
|
def make_default_style(self,default_style):
|
|
|
|
"""Make the default output style for the Simple Boot Title report."""
|
|
|
|
font = BaseDoc.FontStyle()
|
|
|
|
font.set(face=BaseDoc.FONT_SANS_SERIF,size=16,bold=1,italic=1)
|
|
|
|
para = BaseDoc.ParagraphStyle()
|
|
|
|
para.set_font(font)
|
|
|
|
para.set_header_level(1)
|
|
|
|
para.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
|
|
|
|
para.set(pad=0.5)
|
|
|
|
para.set_description(_('The style used for the title of the page.'))
|
|
|
|
default_style.add_style("SBT-Title",para)
|
|
|
|
|
|
|
|
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(pad=0.5)
|
|
|
|
para.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
|
|
|
|
para.set_description(_('The style used for the subtitle.'))
|
|
|
|
default_style.add_style("SBT-Subtitle",para)
|
|
|
|
|
|
|
|
font = BaseDoc.FontStyle()
|
|
|
|
font.set(face=BaseDoc.FONT_SANS_SERIF,size=10,italic=1)
|
|
|
|
para = BaseDoc.ParagraphStyle()
|
|
|
|
para.set_font(font)
|
|
|
|
para.set_header_level(2)
|
|
|
|
para.set(pad=0.5)
|
|
|
|
para.set_alignment(BaseDoc.PARA_ALIGN_CENTER)
|
|
|
|
para.set_description(_('The style used for the footer.'))
|
|
|
|
default_style.add_style("SBT-Footer",para)
|
2003-06-25 09:08:53 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2005-01-08 11:24:49 +05:30
|
|
|
register_report(
|
|
|
|
name = 'simple_book_title',
|
2005-12-06 12:08:09 +05:30
|
|
|
category = Report.CATEGORY_TEXT,
|
2005-01-08 11:24:49 +05:30
|
|
|
report_class = SimpleBookTitle,
|
|
|
|
options_class = SimpleBookTitleOptions,
|
|
|
|
modes = Report.MODE_BKI,
|
|
|
|
translated_name = _("Title Page"),
|
|
|
|
)
|