2007-05-07 09:33:04 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Donald N. Allingham
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
2011-10-23 08:43:50 +05:30
|
|
|
# Simple/_SimpleDoc.py
|
|
|
|
# $Id$
|
|
|
|
#
|
2007-05-07 09:33:04 +05:30
|
|
|
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Provide a simplified database access interface to the GRAMPS database.
|
2007-05-07 09:33:04 +05:30
|
|
|
"""
|
2009-05-31 20:29:56 +05:30
|
|
|
from gen.plug.docgen import StyleSheet, ParagraphStyle, TableStyle,\
|
|
|
|
TableCellStyle, FONT_SANS_SERIF, PARA_ALIGN_LEFT
|
2007-05-07 09:33:04 +05:30
|
|
|
|
2009-05-21 22:49:50 +05:30
|
|
|
class SimpleDoc(object):
|
2007-05-07 09:33:04 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Provide a simplified database access interface to the GRAMPS database.
|
2007-05-07 09:33:04 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, doc):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Initialize the class with the real document
|
2007-05-07 09:33:04 +05:30
|
|
|
"""
|
|
|
|
self.doc = doc
|
|
|
|
|
|
|
|
def __write(self, format, text):
|
2007-05-21 09:49:59 +05:30
|
|
|
"""
|
|
|
|
Writes a paragraph using the specified format to the BaseDoc
|
|
|
|
"""
|
2007-05-07 09:33:04 +05:30
|
|
|
self.doc.start_paragraph(format)
|
|
|
|
self.doc.write_text(text)
|
|
|
|
self.doc.end_paragraph()
|
|
|
|
|
|
|
|
def title(self, text):
|
|
|
|
"""
|
2007-05-21 09:49:59 +05:30
|
|
|
Writes the Title using the Title paragraph
|
2007-05-07 09:33:04 +05:30
|
|
|
"""
|
|
|
|
self.__write('Title', text)
|
|
|
|
|
|
|
|
def header1(self, text):
|
|
|
|
"""
|
2007-05-21 09:49:59 +05:30
|
|
|
Writes the first level header using the Header1 paragraph
|
2007-05-07 09:33:04 +05:30
|
|
|
"""
|
|
|
|
self.__write('Header1', text)
|
|
|
|
|
|
|
|
def header2(self, text):
|
|
|
|
"""
|
2007-05-21 09:49:59 +05:30
|
|
|
Writes the second level header using the Header2 paragraph
|
2007-05-07 09:33:04 +05:30
|
|
|
"""
|
|
|
|
self.__write('Header2', text)
|
|
|
|
|
|
|
|
def header3(self, text):
|
|
|
|
"""
|
2007-05-21 09:49:59 +05:30
|
|
|
Writes the third level header using the Header3 paragraph
|
2007-05-07 09:33:04 +05:30
|
|
|
"""
|
|
|
|
self.__write('Header3', text)
|
|
|
|
|
|
|
|
def paragraph(self, text):
|
|
|
|
"""
|
2007-05-21 09:49:59 +05:30
|
|
|
Writes a paragraph using the Normal format
|
2007-05-07 09:33:04 +05:30
|
|
|
"""
|
|
|
|
self.__write('Normal', text)
|
|
|
|
|
2009-11-23 07:09:29 +05:30
|
|
|
def make_basic_stylesheet(**kwargs):
|
2007-05-21 09:49:59 +05:30
|
|
|
"""
|
2009-11-23 07:09:29 +05:30
|
|
|
Create the basic style sheet for the SimpleDoc class.
|
|
|
|
|
|
|
|
kwargs - a dictionary of the form:
|
|
|
|
item={method: value, ...}, ...
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
make_basic_stylesheet(Table={"set_width": 90})
|
|
|
|
|
2007-05-21 09:49:59 +05:30
|
|
|
"""
|
2009-05-30 03:55:44 +05:30
|
|
|
sheet = StyleSheet()
|
2007-05-07 09:33:04 +05:30
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
pstyle = ParagraphStyle()
|
2007-05-07 09:33:04 +05:30
|
|
|
fstyle = pstyle.get_font()
|
2009-05-30 03:55:44 +05:30
|
|
|
fstyle.set_type_face(FONT_SANS_SERIF)
|
2007-05-07 09:33:04 +05:30
|
|
|
fstyle.set_size(14)
|
|
|
|
fstyle.set_bold(True)
|
|
|
|
pstyle.set_font(fstyle)
|
2009-05-30 03:55:44 +05:30
|
|
|
pstyle.set_alignment(PARA_ALIGN_LEFT)
|
2009-11-23 07:09:29 +05:30
|
|
|
# Handle args:
|
|
|
|
if "Title" in kwargs:
|
|
|
|
for method in kwargs["Title"]:
|
|
|
|
value = kwargs["Title"][method]
|
|
|
|
if value is not None:
|
|
|
|
getattr(pstyle, method)(value)
|
2007-05-07 09:33:04 +05:30
|
|
|
sheet.add_paragraph_style('Title', pstyle)
|
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
pstyle = ParagraphStyle()
|
2007-05-07 09:33:04 +05:30
|
|
|
fstyle = pstyle.get_font()
|
2009-05-30 03:55:44 +05:30
|
|
|
fstyle.set_type_face(FONT_SANS_SERIF)
|
2007-05-07 09:33:04 +05:30
|
|
|
fstyle.set_size(12)
|
|
|
|
fstyle.set_bold(True)
|
|
|
|
pstyle.set_font(fstyle)
|
2009-05-30 03:55:44 +05:30
|
|
|
pstyle.set_alignment(PARA_ALIGN_LEFT)
|
2007-05-08 08:26:33 +05:30
|
|
|
pstyle.set_tabs([4, 8, 12, 16])
|
2009-11-23 07:09:29 +05:30
|
|
|
# Handle args:
|
|
|
|
if "Header1" in kwargs:
|
|
|
|
for method in kwargs["Header1"]:
|
|
|
|
value = kwargs["Header1"][method]
|
|
|
|
if value is not None:
|
|
|
|
getattr(pstyle, method)(value)
|
2007-05-07 09:33:04 +05:30
|
|
|
sheet.add_paragraph_style('Header1', pstyle)
|
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
pstyle = ParagraphStyle()
|
2007-05-07 09:33:04 +05:30
|
|
|
fstyle = pstyle.get_font()
|
2009-05-30 03:55:44 +05:30
|
|
|
fstyle.set_type_face(FONT_SANS_SERIF)
|
2007-05-07 09:33:04 +05:30
|
|
|
fstyle.set_size(10)
|
|
|
|
fstyle.set_bold(True)
|
|
|
|
pstyle.set_font(fstyle)
|
2009-05-30 03:55:44 +05:30
|
|
|
pstyle.set_alignment(PARA_ALIGN_LEFT)
|
2007-05-08 08:26:33 +05:30
|
|
|
pstyle.set_tabs([4, 8, 12, 16])
|
2009-11-23 07:09:29 +05:30
|
|
|
# Handle args:
|
|
|
|
if "Header2" in kwargs:
|
|
|
|
for method in kwargs["Header2"]:
|
|
|
|
value = kwargs["Header2"][method]
|
|
|
|
if value is not None:
|
|
|
|
getattr(pstyle, method)(value)
|
2007-05-07 09:33:04 +05:30
|
|
|
sheet.add_paragraph_style('Header2', pstyle)
|
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
pstyle = ParagraphStyle()
|
2007-05-07 09:33:04 +05:30
|
|
|
fstyle = pstyle.get_font()
|
2009-05-30 03:55:44 +05:30
|
|
|
fstyle.set_type_face(FONT_SANS_SERIF)
|
2007-05-07 09:33:04 +05:30
|
|
|
fstyle.set_size(10)
|
|
|
|
fstyle.set_bold(True)
|
|
|
|
fstyle.set_italic(True)
|
|
|
|
pstyle.set_font(fstyle)
|
2009-05-30 03:55:44 +05:30
|
|
|
pstyle.set_alignment(PARA_ALIGN_LEFT)
|
2007-05-08 08:26:33 +05:30
|
|
|
pstyle.set_tabs([4, 8, 12, 16])
|
2009-11-23 07:09:29 +05:30
|
|
|
# Handle args:
|
|
|
|
if "Header3" in kwargs:
|
|
|
|
for method in kwargs["Header3"]:
|
|
|
|
value = kwargs["Header3"][method]
|
|
|
|
if value is not None:
|
|
|
|
getattr(pstyle, method)(value)
|
2007-05-07 09:33:04 +05:30
|
|
|
sheet.add_paragraph_style('Header3', pstyle)
|
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
pstyle = ParagraphStyle()
|
2007-05-08 08:26:33 +05:30
|
|
|
pstyle.set_tabs([4, 8, 12, 16])
|
2009-11-23 07:09:29 +05:30
|
|
|
# Handle args:
|
|
|
|
if "Normal" in kwargs:
|
|
|
|
for method in kwargs["Normal"]:
|
|
|
|
value = kwargs["Normal"][method]
|
|
|
|
if value is not None:
|
|
|
|
getattr(pstyle, method)(value)
|
2007-05-08 08:26:33 +05:30
|
|
|
sheet.add_paragraph_style('Normal', pstyle)
|
2007-12-21 05:48:39 +05:30
|
|
|
|
|
|
|
# Styles for tables:
|
2009-05-30 03:55:44 +05:30
|
|
|
tbl = TableStyle()
|
2007-12-21 05:48:39 +05:30
|
|
|
tbl.set_width(100)
|
|
|
|
tbl.set_columns(2)
|
|
|
|
tbl.set_column_width(0,20)
|
|
|
|
tbl.set_column_width(1,80)
|
2009-11-23 07:09:29 +05:30
|
|
|
# Handle args:
|
|
|
|
if "Table" in kwargs:
|
|
|
|
for method in kwargs["Table"]:
|
|
|
|
value = kwargs["Table"][method]
|
|
|
|
if value is not None:
|
|
|
|
getattr(tbl, method)(value)
|
2007-12-21 05:48:39 +05:30
|
|
|
sheet.add_table_style("Table",tbl)
|
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
cell = TableCellStyle()
|
2007-12-21 05:48:39 +05:30
|
|
|
cell.set_top_border(1)
|
|
|
|
cell.set_bottom_border(1)
|
2009-11-23 07:09:29 +05:30
|
|
|
# Handle args:
|
|
|
|
if "TableHead" in kwargs:
|
|
|
|
for method in kwargs["TableHead"]:
|
|
|
|
value = kwargs["TableHead"][method]
|
|
|
|
if value is not None:
|
|
|
|
getattr(cell, method)(value)
|
2007-12-21 05:48:39 +05:30
|
|
|
sheet.add_cell_style("TableHead",cell)
|
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
cell = TableCellStyle()
|
2009-11-23 07:09:29 +05:30
|
|
|
# Handle args:
|
|
|
|
if "TableHeaderCell" in kwargs:
|
|
|
|
for method in kwargs["TableHeaderCell"]:
|
|
|
|
value = kwargs["TableHeaderCell"][method]
|
|
|
|
if value is not None:
|
|
|
|
getattr(cell, method)(value)
|
2009-11-15 04:20:19 +05:30
|
|
|
sheet.add_cell_style("TableHeaderCell",cell)
|
2007-12-21 05:48:39 +05:30
|
|
|
|
2009-05-30 03:55:44 +05:30
|
|
|
cell = TableCellStyle()
|
2007-12-21 05:48:39 +05:30
|
|
|
cell.set_longlist(1)
|
2009-11-23 07:09:29 +05:30
|
|
|
# Handle args:
|
|
|
|
if "TableDataCell" in kwargs:
|
|
|
|
for method in kwargs["TableDataCell"]:
|
|
|
|
value = kwargs["TableDataCell"][method]
|
|
|
|
if value is not None:
|
|
|
|
getattr(cell, method)(value)
|
2009-11-15 04:20:19 +05:30
|
|
|
sheet.add_cell_style("TableDataCell",cell)
|
2007-12-21 05:48:39 +05:30
|
|
|
|
2007-05-07 09:33:04 +05:30
|
|
|
return sheet
|