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
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
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-06-01 10:09:40 +05:30
|
|
|
from PluginUtils import register_report
|
2008-02-18 19:36:41 +05:30
|
|
|
from Utils import media_path_full
|
2006-06-01 10:09:40 +05:30
|
|
|
from ReportBase import Report, ReportOptions, CATEGORY_TEXT, MODE_BKI
|
2003-08-26 09:37:00 +05:30
|
|
|
import BaseDoc
|
2006-05-15 21:23:42 +05:30
|
|
|
from Selectors import selector_factory
|
|
|
|
SelectObject = selector_factory('MediaObject')
|
2008-01-06 16:21:20 +05:30
|
|
|
#import AddMedia
|
2007-09-11 03:44:33 +05:30
|
|
|
import ThumbNails
|
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):
|
2003-06-25 09:08:53 +05:30
|
|
|
|
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
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2008-02-20 10:22:10 +05:30
|
|
|
Report.__init__(self, database, options_class)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
|
|
|
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)
|
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() )
|
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
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2006-06-01 10:09:40 +05:30
|
|
|
class SimpleBookTitleOptions(ReportOptions):
|
2005-01-08 11:24:49 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
2008-02-20 10:22:10 +05:30
|
|
|
def __init__(self, name, dbase):
|
|
|
|
ReportOptions.__init__(self, name, dbase)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
|
|
|
# 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.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...'))
|
2006-11-09 12:25:18 +05:30
|
|
|
select_obj_button.connect('clicked',self.select_obj,dialog)
|
2008-02-19 15:06:50 +05:30
|
|
|
#select_file_button = gtk.Button(_('From file...'))
|
|
|
|
#select_file_button.connect('clicked',self.select_file,dialog)
|
|
|
|
select_table = gtk.Table(1,2)
|
2003-09-10 07:20:26 +05:30
|
|
|
select_table.set_col_spacings(10)
|
|
|
|
select_table.attach(select_obj_button,
|
|
|
|
0,1,0,1,gtk.SHRINK|gtk.FILL,gtk.SHRINK|gtk.FILL)
|
2008-02-19 15:06:50 +05:30
|
|
|
#select_table.attach(select_file_button,
|
|
|
|
# 1,2,0,1,gtk.SHRINK|gtk.FILL,gtk.SHRINK|gtk.FILL)
|
2003-09-10 07:20:26 +05:30
|
|
|
select_table.attach(self.remove_obj_button,
|
2008-02-19 15:06:50 +05:30
|
|
|
1,2,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'])
|
2006-11-09 12:25:18 +05:30
|
|
|
size_frame = gtk.HBox()
|
|
|
|
size_frame.pack_start(self.size,expand=False,fill=False,padding=6)
|
|
|
|
size_frame.pack_start(gtk.Label(_('cm')),
|
|
|
|
expand=False,fill=False,padding=6)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
|
|
|
dialog.add_frame_option(_('Image'),_('Preview'),preview_table)
|
|
|
|
dialog.add_frame_option(_('Image'),_('Select'),select_table)
|
2006-11-09 12:25:18 +05:30
|
|
|
dialog.add_frame_option(_('Image'),_('Size'),size_frame)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def select_obj(self, obj,dialog):
|
2006-11-09 12:25:18 +05:30
|
|
|
s_o = SelectObject(dialog.dbstate,dialog.uistate,dialog.track)
|
2005-01-08 11:24:49 +05:30
|
|
|
the_object = s_o.run()
|
2006-11-09 12:25:18 +05:30
|
|
|
self.setup_object(dialog.db,the_object)
|
2003-09-10 07:20:26 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def select_file(self, obj,dialog):
|
2008-01-06 16:21:20 +05:30
|
|
|
print 'Deprecated use, this must be removed'
|
|
|
|
|
|
|
|
#a_o = AddMedia.AddMediaObject(dialog.dbstate,dialog.uistate,
|
|
|
|
# dialog.track)
|
|
|
|
#a_o.run()
|
|
|
|
#self.setup_object(dialog.db,a_o.object)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
|
|
|
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())
|
2008-02-18 19:36:41 +05:30
|
|
|
icon_image = ThumbNails.get_thumbnail_image(
|
|
|
|
media_path_full(database, 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.'))
|
2007-10-21 09:50:05 +05:30
|
|
|
default_style.add_paragraph_style("SBT-Title",para)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
|
|
|
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.'))
|
2007-10-21 09:50:05 +05:30
|
|
|
default_style.add_paragraph_style("SBT-Subtitle",para)
|
2005-01-08 11:24:49 +05:30
|
|
|
|
|
|
|
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.'))
|
2007-10-21 09:50:05 +05:30
|
|
|
default_style.add_paragraph_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',
|
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,
|
2006-06-01 10:09:40 +05:30
|
|
|
modes = MODE_BKI,
|
2005-01-08 11:24:49 +05:30
|
|
|
translated_name = _("Title Page"),
|
|
|
|
)
|