2003-08-24 02:40:21 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-07-01 00:28:14 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2007-04-23 17:16:26 +05:30
|
|
|
# Copyright (C) 2002 Gary Shao
|
|
|
|
# Copyright (C) 2007 Brian G. Matherly
|
2003-08-24 02:40:21 +05:30
|
|
|
#
|
2005-01-24 22:03:47 +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-11 09:19:44 +05:30
|
|
|
# $Id$
|
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Provides base interface to text based documents. Specific document
|
|
|
|
interfaces should be derived from the core classes.
|
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
2007-01-28 10:38:49 +05:30
|
|
|
from xml.sax.saxutils import escape
|
|
|
|
|
2007-05-20 09:13:38 +05:30
|
|
|
def escxml(string):
|
|
|
|
"""
|
|
|
|
Escapes XML special characters.
|
|
|
|
"""
|
|
|
|
return escape(string, { '"' : '"' } )
|
2003-08-25 08:43:52 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import Utils
|
2004-08-21 02:56:51 +05:30
|
|
|
import FontScale
|
2006-03-30 08:47:33 +05:30
|
|
|
import const
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-03-05 10:15:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# set up logging
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".BaseDoc")
|
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# SAX interface
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
try:
|
2006-04-06 03:00:27 +05:30
|
|
|
from xml.sax import make_parser, handler, SAXParseException
|
2007-05-20 09:13:38 +05:30
|
|
|
except ImportError:
|
2006-04-06 03:00:27 +05:30
|
|
|
from _xmlplus.sax import make_parser, handler, SAXParseException
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
FONT_SANS_SERIF = 0
|
2006-04-08 06:23:44 +05:30
|
|
|
FONT_SERIF = 1
|
|
|
|
FONT_MONOSPACE = 2
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
2003-08-24 02:40:21 +05:30
|
|
|
#
|
|
|
|
# Page orientation
|
|
|
|
#
|
2006-04-08 06:23:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
2003-08-24 02:40:21 +05:30
|
|
|
PAPER_PORTRAIT = 0
|
|
|
|
PAPER_LANDSCAPE = 1
|
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
2003-08-24 02:40:21 +05:30
|
|
|
#
|
|
|
|
# Paragraph alignment
|
|
|
|
#
|
2006-04-08 06:23:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
PARA_ALIGN_CENTER = 0
|
|
|
|
PARA_ALIGN_LEFT = 1
|
|
|
|
PARA_ALIGN_RIGHT = 2
|
|
|
|
PARA_ALIGN_JUSTIFY = 3
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
2003-08-24 02:40:21 +05:30
|
|
|
#
|
|
|
|
# Text vs. Graphics mode
|
|
|
|
#
|
2006-04-08 06:23:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
TEXT_MODE = 0
|
2003-08-24 02:40:21 +05:30
|
|
|
GRAPHICS_MODE = 1
|
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
2003-08-24 02:40:21 +05:30
|
|
|
#
|
|
|
|
# Line style
|
|
|
|
#
|
2006-04-08 06:23:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
SOLID = 0
|
2003-08-24 02:40:21 +05:30
|
|
|
DASHED = 1
|
|
|
|
|
2006-06-03 09:02:26 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IndexMark types
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
INDEX_TYPE_ALP = 0
|
|
|
|
INDEX_TYPE_TOC = 1
|
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# cnv2color
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
def cnv2color(text):
|
|
|
|
"""
|
|
|
|
converts a hex value in the form of #XXXXXX into a tuple of integers
|
|
|
|
representing the RGB values
|
|
|
|
"""
|
2006-04-08 06:23:44 +05:30
|
|
|
return (int(text[1:3], 16), int(text[3:5], 16), int(text[5:7], 16))
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2007-02-19 09:43:41 +05:30
|
|
|
# PaperSize
|
2003-08-24 02:40:21 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
2007-02-19 09:43:41 +05:30
|
|
|
class PaperSize:
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Defines the dimensions of a sheet of paper. All dimensions are in
|
|
|
|
centimeters.
|
|
|
|
"""
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, name, height, width):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Creates a new paper style with.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param name: name of the new style
|
|
|
|
@param height: page height in centimeters
|
|
|
|
@param width: page width in centimeters
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.name = name
|
|
|
|
self.height = height
|
|
|
|
self.width = width
|
|
|
|
|
|
|
|
def get_name(self):
|
|
|
|
"Returns the name of the paper style"
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def get_height(self):
|
|
|
|
"Returns the page height in cm"
|
|
|
|
return self.height
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_height(self, height):
|
2003-08-24 02:40:21 +05:30
|
|
|
"Sets the page height in cm"
|
|
|
|
self.height = height
|
|
|
|
|
|
|
|
def get_width(self):
|
|
|
|
"Returns the page width in cm"
|
|
|
|
return self.width
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_width(self, width):
|
2003-08-24 02:40:21 +05:30
|
|
|
"Sets the page width in cm"
|
|
|
|
self.width = width
|
|
|
|
|
|
|
|
def get_height_inches(self):
|
|
|
|
"Returns the page height in inches"
|
|
|
|
return self.height / 2.54
|
|
|
|
|
|
|
|
def get_width_inches(self):
|
|
|
|
"Returns the page width in inches"
|
|
|
|
return self.width / 2.54
|
|
|
|
|
2007-02-25 02:45:21 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PaperStyle
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class PaperStyle:
|
2007-09-16 16:26:01 +05:30
|
|
|
"""Define the various options for a sheet of paper.
|
2007-02-25 02:45:21 +05:30
|
|
|
"""
|
2007-09-16 16:26:01 +05:30
|
|
|
def __init__(self, size, orientation,
|
|
|
|
lmargin=2.54, rmargin=2.54, tmargin=2.54, bmargin=2.54):
|
|
|
|
"""Create a new paper style.
|
2007-02-25 02:45:21 +05:30
|
|
|
|
|
|
|
@param size: size of the new style
|
|
|
|
@type size: PaperSize
|
|
|
|
@param orientation: page orientation
|
|
|
|
@type orientation: PAPER_PORTRAIT or PAPER_LANDSCAPE
|
|
|
|
|
2007-09-16 16:26:01 +05:30
|
|
|
"""
|
2007-02-25 02:45:21 +05:30
|
|
|
self.__orientation = orientation
|
2007-09-16 16:26:01 +05:30
|
|
|
|
2007-02-25 02:45:21 +05:30
|
|
|
if orientation == PAPER_PORTRAIT:
|
2007-09-16 16:26:01 +05:30
|
|
|
self.__size = PaperSize(size.get_name(),
|
|
|
|
size.get_height(),
|
|
|
|
size.get_width())
|
2007-02-25 02:45:21 +05:30
|
|
|
else:
|
2007-09-16 16:26:01 +05:30
|
|
|
self.__size = PaperSize(size.get_name(),
|
|
|
|
size.get_width(),
|
|
|
|
size.get_height())
|
|
|
|
self.__lmargin = lmargin
|
|
|
|
self.__rmargin = rmargin
|
|
|
|
self.__tmargin = tmargin
|
|
|
|
self.__bmargin = bmargin
|
2007-02-25 02:45:21 +05:30
|
|
|
|
|
|
|
def get_size(self):
|
2007-09-16 16:26:01 +05:30
|
|
|
"""Return the size of the paper.
|
2007-05-20 09:13:38 +05:30
|
|
|
|
|
|
|
@returns: object indicating the paper size
|
|
|
|
@rtype: PaperSize
|
2007-09-16 16:26:01 +05:30
|
|
|
|
2007-05-20 09:13:38 +05:30
|
|
|
"""
|
2007-02-25 02:45:21 +05:30
|
|
|
return self.__size
|
|
|
|
|
|
|
|
def get_orientation(self):
|
2007-09-16 16:26:01 +05:30
|
|
|
"""Return the orientation of the page.
|
2007-05-20 09:13:38 +05:30
|
|
|
|
|
|
|
@returns: PAPER_PORTRIAT or PAPER_LANDSCAPE
|
|
|
|
@rtype: int
|
2007-09-16 16:26:01 +05:30
|
|
|
|
2007-05-20 09:13:38 +05:30
|
|
|
"""
|
2007-02-25 02:45:21 +05:30
|
|
|
return self.__orientation
|
|
|
|
|
|
|
|
def get_usable_width(self):
|
2007-09-16 16:26:01 +05:30
|
|
|
"""Return the width of the page area in centimeters.
|
|
|
|
|
|
|
|
The value is the page width less the margins.
|
|
|
|
|
2007-02-25 02:45:21 +05:30
|
|
|
"""
|
|
|
|
return self.__size.get_width() - (self.__rmargin + self.__lmargin)
|
|
|
|
|
|
|
|
def get_usable_height(self):
|
2007-09-16 16:26:01 +05:30
|
|
|
"""Return the height of the page area in centimeters.
|
|
|
|
|
|
|
|
The value is the page height less the margins.
|
|
|
|
|
2007-02-25 02:45:21 +05:30
|
|
|
"""
|
|
|
|
return self.__size.get_height() - (self.__tmargin + self.__bmargin)
|
|
|
|
|
|
|
|
def get_right_margin(self):
|
2007-09-16 16:26:01 +05:30
|
|
|
"""Return the right margin.
|
2007-05-20 09:13:38 +05:30
|
|
|
|
|
|
|
@returns: Right margin in centimeters
|
|
|
|
@rtype: float
|
2007-09-16 16:26:01 +05:30
|
|
|
|
2007-05-20 09:13:38 +05:30
|
|
|
"""
|
2007-02-25 02:45:21 +05:30
|
|
|
return self.__rmargin
|
|
|
|
|
|
|
|
def get_left_margin(self):
|
2007-09-16 16:26:01 +05:30
|
|
|
"""Return the left margin.
|
2007-05-20 09:13:38 +05:30
|
|
|
|
|
|
|
@returns: Left margin in centimeters
|
|
|
|
@rtype: float
|
2007-09-16 16:26:01 +05:30
|
|
|
|
2007-05-20 09:13:38 +05:30
|
|
|
"""
|
2007-02-25 02:45:21 +05:30
|
|
|
return self.__lmargin
|
|
|
|
|
|
|
|
def get_top_margin(self):
|
2007-09-16 16:26:01 +05:30
|
|
|
"""Return the top margin.
|
2007-05-20 09:13:38 +05:30
|
|
|
|
|
|
|
@returns: Top margin in centimeters
|
|
|
|
@rtype: float
|
2007-09-16 16:26:01 +05:30
|
|
|
|
2007-05-20 09:13:38 +05:30
|
|
|
"""
|
2007-02-25 02:45:21 +05:30
|
|
|
return self.__tmargin
|
|
|
|
|
|
|
|
def get_bottom_margin(self):
|
2007-09-16 16:26:01 +05:30
|
|
|
"""Return the bottom margin.
|
2007-05-20 09:13:38 +05:30
|
|
|
|
|
|
|
@returns: Bottom margin in centimeters
|
|
|
|
@rtype: float
|
2007-09-16 16:26:01 +05:30
|
|
|
|
2007-05-20 09:13:38 +05:30
|
|
|
"""
|
2007-02-25 02:45:21 +05:30
|
|
|
return self.__bmargin
|
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# FontStyle
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class FontStyle:
|
|
|
|
"""
|
|
|
|
Defines a font style. Controls the font face, size, color, and
|
|
|
|
attributes. In order to remain generic, the only font faces available
|
|
|
|
are FONT_SERIF and FONT_SANS_SERIF. Document formatters should convert
|
|
|
|
these to the appropriate fonts for the target format.
|
|
|
|
|
|
|
|
The FontStyle represents the desired characteristics. There are no
|
|
|
|
guarentees that the document format generator will be able implement
|
|
|
|
all or any of the characteristics.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, style=None):
|
|
|
|
"""
|
|
|
|
Creates a new FontStyle object, accepting the default values.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param style: if specified, initializes the FontStyle from the passed
|
|
|
|
FontStyle instead of using the defaults.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
if style:
|
|
|
|
self.face = style.face
|
|
|
|
self.size = style.size
|
|
|
|
self.italic = style.italic
|
|
|
|
self.bold = style.bold
|
|
|
|
self.color = style.color
|
|
|
|
self.under = style.under
|
|
|
|
else:
|
|
|
|
self.face = FONT_SERIF
|
|
|
|
self.size = 12
|
|
|
|
self.italic = 0
|
|
|
|
self.bold = 0
|
2006-04-06 03:00:27 +05:30
|
|
|
self.color = (0, 0, 0)
|
2003-08-24 02:40:21 +05:30
|
|
|
self.under = 0
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set(self, face=None, size=None, italic=None, bold=None,
|
|
|
|
underline=None, color=None):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Sets font characteristics.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param face: font type face, either FONT_SERIF or FONT_SANS_SERIF
|
|
|
|
@param size: type face size in points
|
|
|
|
@param italic: True enables italics, False disables italics
|
|
|
|
@param bold: True enables bold face, False disables bold face
|
|
|
|
@param underline: True enables underline, False disables underline
|
|
|
|
@param color: an RGB color representation in the form of three integers
|
|
|
|
in the range of 0-255 represeting the red, green, and blue
|
|
|
|
components of a color.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
if face != None:
|
|
|
|
self.set_type_face(face)
|
|
|
|
if size != None:
|
|
|
|
self.set_size(size)
|
|
|
|
if italic != None:
|
|
|
|
self.set_italic(italic)
|
|
|
|
if bold != None:
|
|
|
|
self.set_bold(bold)
|
|
|
|
if underline != None:
|
|
|
|
self.set_underline(underline)
|
|
|
|
if color != None:
|
|
|
|
self.set_color(color)
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_italic(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"0 disables italics, 1 enables italics"
|
|
|
|
self.italic = val
|
|
|
|
|
|
|
|
def get_italic(self):
|
|
|
|
"1 indicates use italics"
|
|
|
|
return self.italic
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_bold(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"0 disables bold face, 1 enables bold face"
|
|
|
|
self.bold = val
|
|
|
|
|
|
|
|
def get_bold(self):
|
|
|
|
"1 indicates use bold face"
|
|
|
|
return self.bold
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_color(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"sets the color using an RGB color tuple"
|
|
|
|
self.color = val
|
|
|
|
|
|
|
|
def get_color(self):
|
|
|
|
"Returns an RGB color tuple"
|
2005-01-24 22:03:47 +05:30
|
|
|
return self.color
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_size(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"sets font size in points"
|
|
|
|
self.size = val
|
|
|
|
|
|
|
|
def get_size(self):
|
|
|
|
"returns font size in points"
|
|
|
|
return self.size
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_type_face(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"sets the font face type"
|
|
|
|
self.face = val
|
|
|
|
|
|
|
|
def get_type_face(self):
|
|
|
|
"returns the font face type"
|
|
|
|
return self.face
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_underline(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"1 enables underlining"
|
|
|
|
self.under = val
|
|
|
|
|
|
|
|
def get_underline(self):
|
|
|
|
"1 indicates underlining"
|
|
|
|
return self.under
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# TableStyle
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class TableStyle:
|
|
|
|
"""
|
|
|
|
Specifies the style or format of a table. The TableStyle contains the
|
|
|
|
characteristics of table width (in percentage of the full width), the
|
|
|
|
number of columns, and the width of each column as a percentage of the
|
|
|
|
width of the table.
|
|
|
|
"""
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, obj=None):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Creates a new TableStyle object, with the values initialized to
|
|
|
|
empty, with allocating space for up to 100 columns.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param obj: if not None, then the object created gets is attributes
|
|
|
|
from the passed object instead of being initialized to empty.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
if obj:
|
|
|
|
self.width = obj.width
|
|
|
|
self.columns = obj.columns
|
|
|
|
self.colwid = obj.colwid[:]
|
|
|
|
else:
|
|
|
|
self.width = 0
|
|
|
|
self.columns = 0
|
|
|
|
self.colwid = [ 0 ] * 100
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_width(self, width):
|
2004-12-25 00:16:34 +05:30
|
|
|
"""
|
|
|
|
Sets the width of the table in terms of percent of the available
|
|
|
|
width
|
|
|
|
"""
|
2003-08-24 02:40:21 +05:30
|
|
|
self.width = width
|
|
|
|
|
|
|
|
def get_width(self):
|
2004-12-25 00:16:34 +05:30
|
|
|
"""
|
|
|
|
Returns the specified width as a percentage of the available space
|
|
|
|
"""
|
2003-08-24 02:40:21 +05:30
|
|
|
return self.width
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_columns(self, columns):
|
2004-12-25 00:16:34 +05:30
|
|
|
"""
|
|
|
|
Sets the number of columns.
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param columns: number of columns that should be used.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.columns = columns
|
|
|
|
|
|
|
|
def get_columns(self):
|
2004-12-25 00:16:34 +05:30
|
|
|
"""
|
|
|
|
Returns the number of columns
|
|
|
|
"""
|
2003-08-24 02:40:21 +05:30
|
|
|
return self.columns
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_column_widths(self, clist):
|
2004-12-25 00:16:34 +05:30
|
|
|
"""
|
|
|
|
Sets the width of all the columns at once, taking the percentages
|
|
|
|
from the passed list.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2006-04-06 03:00:27 +05:30
|
|
|
self.columns = len(clist)
|
2003-08-24 02:40:21 +05:30
|
|
|
for i in range(self.columns):
|
2006-04-06 03:00:27 +05:30
|
|
|
self.colwid[i] = clist[i]
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_column_width(self, index, width):
|
2004-12-25 00:16:34 +05:30
|
|
|
"""
|
|
|
|
Sets the width of a specified column to the specified width.
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param index: column being set (index starts at 0)
|
|
|
|
@param width: percentage of the table width assigned to the column
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2005-01-24 22:03:47 +05:30
|
|
|
self.colwid[index] = width
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def get_column_width(self, index):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Returns the column width of the specified column as a percentage of
|
|
|
|
the entire table width.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param index: column to return (index starts at 0)
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2005-01-24 22:03:47 +05:30
|
|
|
return self.colwid[index]
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# TableCellStyle
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class TableCellStyle:
|
|
|
|
"""
|
|
|
|
Defines the style of a particular table cell. Characteristics are:
|
|
|
|
right border, left border, top border, bottom border, and padding.
|
|
|
|
"""
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, obj=None):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Creates a new TableCellStyle instance.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param obj: if not None, specifies that the values should be
|
|
|
|
copied from the passed object instead of being initialized to empty.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
if obj:
|
|
|
|
self.rborder = obj.rborder
|
|
|
|
self.lborder = obj.lborder
|
|
|
|
self.tborder = obj.tborder
|
|
|
|
self.bborder = obj.bborder
|
|
|
|
self.padding = obj.padding
|
2005-01-24 22:03:47 +05:30
|
|
|
self.longlist = obj.longlist
|
2003-08-24 02:40:21 +05:30
|
|
|
else:
|
|
|
|
self.rborder = 0
|
|
|
|
self.lborder = 0
|
|
|
|
self.tborder = 0
|
|
|
|
self.bborder = 0
|
|
|
|
self.padding = 0
|
2005-01-24 22:03:47 +05:30
|
|
|
self.longlist = 0
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_padding(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"Returns the cell padding in centimeters"
|
|
|
|
self.padding = val
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_right_border(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Defines if a right border in used
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param val: if True, a right border is used, if False, it is not
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.rborder = val
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_left_border(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Defines if a left border in used
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param val: if True, a left border is used, if False, it is not
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.lborder = val
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_top_border(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Defines if a top border in used
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param val: if True, a top border is used, if False, it is not
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.tborder = val
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_bottom_border(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Defines if a bottom border in used
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param val: if 1, a bottom border is used, if 0, it is not
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.bborder = val
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_longlist(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
self.longlist = val
|
|
|
|
|
|
|
|
def get_padding(self):
|
|
|
|
"Returns the cell padding in centimeters"
|
|
|
|
return self.padding
|
|
|
|
|
|
|
|
def get_right_border(self):
|
|
|
|
"Returns 1 if a right border is requested"
|
|
|
|
return self.rborder
|
|
|
|
|
|
|
|
def get_left_border(self):
|
|
|
|
"Returns 1 if a left border is requested"
|
|
|
|
return self.lborder
|
|
|
|
|
|
|
|
def get_top_border(self):
|
|
|
|
"Returns 1 if a top border is requested"
|
|
|
|
return self.tborder
|
|
|
|
|
|
|
|
def get_bottom_border(self):
|
|
|
|
"Returns 1 if a bottom border is requested"
|
|
|
|
return self.bborder
|
|
|
|
|
|
|
|
def get_longlist(self):
|
|
|
|
return self.longlist
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ParagraphStyle
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class ParagraphStyle:
|
|
|
|
"""
|
|
|
|
Defines the characteristics of a paragraph. The characteristics are:
|
|
|
|
font (a FontStyle instance), right margin, left margin, first indent,
|
2005-12-06 12:08:09 +05:30
|
|
|
top margin, bottom margin, alignment, level, top border, bottom border,
|
|
|
|
right border, left border, padding, and background color.
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
"""
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, source=None):
|
2004-12-25 00:16:34 +05:30
|
|
|
"""
|
|
|
|
@param source: if not None, then the ParagraphStyle is created
|
|
|
|
using the values of the source instead of the default values.
|
|
|
|
"""
|
2003-08-24 02:40:21 +05:30
|
|
|
if source:
|
2007-05-08 10:05:14 +05:30
|
|
|
self.font = FontStyle(source.font)
|
2003-08-24 02:40:21 +05:30
|
|
|
self.rmargin = source.rmargin
|
|
|
|
self.lmargin = source.lmargin
|
|
|
|
self.first_indent = source.first_indent
|
2005-12-06 12:08:09 +05:30
|
|
|
self.tmargin = source.tmargin
|
|
|
|
self.bmargin = source.bmargin
|
2007-05-08 10:05:14 +05:30
|
|
|
self.align = source.align
|
|
|
|
self.level = source.level
|
2005-01-24 22:03:47 +05:30
|
|
|
self.top_border = source.top_border
|
|
|
|
self.bottom_border = source.bottom_border
|
|
|
|
self.right_border = source.right_border
|
|
|
|
self.left_border = source.left_border
|
2003-08-24 02:40:21 +05:30
|
|
|
self.pad = source.pad
|
|
|
|
self.bgcolor = source.bgcolor
|
|
|
|
self.description = source.description
|
2007-05-08 08:26:33 +05:30
|
|
|
self.tabs = source.tabs
|
2003-08-24 02:40:21 +05:30
|
|
|
else:
|
2007-05-08 10:05:14 +05:30
|
|
|
self.font = FontStyle()
|
2003-08-24 02:40:21 +05:30
|
|
|
self.rmargin = 0
|
|
|
|
self.lmargin = 0
|
2005-12-06 12:08:09 +05:30
|
|
|
self.tmargin = 0
|
|
|
|
self.bmargin = 0
|
2003-08-24 02:40:21 +05:30
|
|
|
self.first_indent = 0
|
2007-05-08 10:05:14 +05:30
|
|
|
self.align = PARA_ALIGN_LEFT
|
|
|
|
self.level = 0
|
2005-01-24 22:03:47 +05:30
|
|
|
self.top_border = 0
|
|
|
|
self.bottom_border = 0
|
|
|
|
self.right_border = 0
|
|
|
|
self.left_border = 0
|
2003-08-24 02:40:21 +05:30
|
|
|
self.pad = 0
|
2006-04-08 06:23:44 +05:30
|
|
|
self.bgcolor = (255, 255, 255)
|
2003-08-24 02:40:21 +05:30
|
|
|
self.description = ""
|
2007-05-08 08:26:33 +05:30
|
|
|
self.tabs = []
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_description(self, text):
|
2006-04-08 06:23:44 +05:30
|
|
|
"""
|
|
|
|
Sets the desciption of the paragraph
|
|
|
|
"""
|
2003-08-24 02:40:21 +05:30
|
|
|
self.description = text
|
|
|
|
|
|
|
|
def get_description(self):
|
2006-04-08 06:23:44 +05:30
|
|
|
"""
|
|
|
|
Returns the desciption of the paragraph
|
|
|
|
"""
|
2003-08-24 02:40:21 +05:30
|
|
|
return self.description
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set(self, rmargin=None, lmargin=None, first_indent=None,
|
|
|
|
tmargin=None, bmargin=None, align=None,
|
|
|
|
tborder=None, bborder=None, rborder=None, lborder=None,
|
|
|
|
pad=None, bgcolor=None, font=None):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Allows the values of the object to be set.
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
@param rmargin: right indent in centimeters
|
|
|
|
@param lmargin: left indent in centimeters
|
2004-12-25 00:16:34 +05:30
|
|
|
@param first_indent: first line indent in centimeters
|
2005-12-06 12:08:09 +05:30
|
|
|
@param tmargin: space above paragraph in centimeters
|
|
|
|
@param bmargin: space below paragraph in centimeters
|
|
|
|
@param align: alignment type (PARA_ALIGN_LEFT, PARA_ALIGN_RIGHT, PARA_ALIGN_CENTER, or PARA_ALIGN_JUSTIFY)
|
2004-12-25 00:16:34 +05:30
|
|
|
@param tborder: non zero indicates that a top border should be used
|
|
|
|
@param bborder: non zero indicates that a bottom border should be used
|
|
|
|
@param rborder: non zero indicates that a right border should be used
|
|
|
|
@param lborder: non zero indicates that a left border should be used
|
|
|
|
@param pad: padding in centimeters
|
|
|
|
@param bgcolor: background color of the paragraph as an RGB tuple.
|
|
|
|
@param font: FontStyle instance that defines the font
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
if font != None:
|
|
|
|
self.font = FontStyle(font)
|
|
|
|
if pad != None:
|
|
|
|
self.set_padding(pad)
|
|
|
|
if tborder != None:
|
|
|
|
self.set_top_border(tborder)
|
|
|
|
if bborder != None:
|
|
|
|
self.set_bottom_border(bborder)
|
|
|
|
if rborder != None:
|
|
|
|
self.set_right_border(rborder)
|
|
|
|
if lborder != None:
|
|
|
|
self.set_left_border(lborder)
|
|
|
|
if bgcolor != None:
|
|
|
|
self.set_background_color(bgcolor)
|
|
|
|
if align != None:
|
|
|
|
self.set_alignment(align)
|
|
|
|
if rmargin != None:
|
|
|
|
self.set_right_margin(rmargin)
|
|
|
|
if lmargin != None:
|
|
|
|
self.set_left_margin(lmargin)
|
|
|
|
if first_indent != None:
|
|
|
|
self.set_first_indent(first_indent)
|
2005-12-06 12:08:09 +05:30
|
|
|
if tmargin != None:
|
|
|
|
self.set_top_margin(tmargin)
|
|
|
|
if bmargin != None:
|
|
|
|
self.set_bottom_margin(bmargin)
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_header_level(self, level):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Sets the header level for the paragraph. This is useful for
|
|
|
|
numbered paragraphs. A value of 1 indicates a header level
|
|
|
|
format of X, a value of two implies X.X, etc. A value of zero
|
|
|
|
means no header level.
|
|
|
|
"""
|
|
|
|
self.level = level
|
|
|
|
|
|
|
|
def get_header_level(self):
|
|
|
|
"Returns the header level of the paragraph"
|
|
|
|
return self.level
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_font(self, font):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Sets the font style of the paragraph.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param font: FontStyle object containing the font definition to use.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.font = FontStyle(font)
|
|
|
|
|
|
|
|
def get_font(self):
|
|
|
|
"Returns the FontStyle of the paragraph"
|
|
|
|
return self.font
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_padding(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Sets the paragraph padding in centimeters
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param val: floating point value indicating the padding in centimeters
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.pad = val
|
|
|
|
|
|
|
|
def get_padding(self):
|
|
|
|
"""Returns a the padding of the paragraph"""
|
|
|
|
return self.pad
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_top_border(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Sets the presence or absence of top border.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param val: True indicates a border should be used, False indicates
|
|
|
|
no border.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.top_border = val
|
|
|
|
|
|
|
|
def get_top_border(self):
|
|
|
|
"Returns 1 if a top border is specified"
|
|
|
|
return self.top_border
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_bottom_border(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Sets the presence or absence of bottom border.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param val: True indicates a border should be used, False
|
|
|
|
indicates no border.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.bottom_border = val
|
|
|
|
|
|
|
|
def get_bottom_border(self):
|
|
|
|
"Returns 1 if a bottom border is specified"
|
2005-01-24 22:03:47 +05:30
|
|
|
return self.bottom_border
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_left_border(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Sets the presence or absence of left border.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param val: True indicates a border should be used, False
|
|
|
|
indicates no border.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.left_border = val
|
|
|
|
|
|
|
|
def get_left_border(self):
|
|
|
|
"Returns 1 if a left border is specified"
|
|
|
|
return self.left_border
|
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def set_right_border(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Sets the presence or absence of rigth border.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param val: True indicates a border should be used, False
|
|
|
|
indicates no border.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.right_border = val
|
|
|
|
|
|
|
|
def get_right_border(self):
|
|
|
|
"Returns 1 if a right border is specified"
|
|
|
|
return self.right_border
|
|
|
|
|
|
|
|
def get_background_color(self):
|
|
|
|
"""
|
|
|
|
Returns a tuple indicating the RGB components of the background
|
|
|
|
color
|
|
|
|
"""
|
|
|
|
return self.bgcolor
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_background_color(self, color):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Sets the background color of the paragraph.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param color: tuple representing the RGB components of a color
|
|
|
|
(0,0,0) to (255,255,255)
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.bgcolor = color
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_alignment(self, align):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Sets the paragraph alignment.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param align: PARA_ALIGN_LEFT, PARA_ALIGN_RIGHT, PARA_ALIGN_CENTER,
|
|
|
|
or PARA_ALIGN_JUSTIFY
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.align = align
|
|
|
|
|
|
|
|
def get_alignment(self):
|
|
|
|
"Returns the alignment of the paragraph"
|
|
|
|
return self.align
|
|
|
|
|
|
|
|
def get_alignment_text(self):
|
|
|
|
"""
|
|
|
|
Returns a text string representing the alginment, either 'left',
|
|
|
|
'right', 'center', or 'justify'
|
|
|
|
"""
|
|
|
|
if self.align == PARA_ALIGN_LEFT:
|
|
|
|
return "left"
|
|
|
|
elif self.align == PARA_ALIGN_CENTER:
|
|
|
|
return "center"
|
|
|
|
elif self.align == PARA_ALIGN_RIGHT:
|
|
|
|
return "right"
|
|
|
|
elif self.align == PARA_ALIGN_JUSTIFY:
|
|
|
|
return "justify"
|
|
|
|
return "unknown"
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_left_margin(self, value):
|
2005-12-06 12:08:09 +05:30
|
|
|
"sets the left indent in centimeters"
|
2003-08-24 02:40:21 +05:30
|
|
|
self.lmargin = value
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_right_margin(self, value):
|
2005-12-06 12:08:09 +05:30
|
|
|
"sets the right indent in centimeters"
|
2003-08-24 02:40:21 +05:30
|
|
|
self.rmargin = value
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_first_indent(self, value):
|
2005-12-06 12:08:09 +05:30
|
|
|
"sets the first line indent in centimeters"
|
2003-08-24 02:40:21 +05:30
|
|
|
self.first_indent = value
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_top_margin(self, value):
|
2005-12-06 12:08:09 +05:30
|
|
|
"sets the space above paragraph in centimeters"
|
|
|
|
self.tmargin = value
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_bottom_margin(self, value):
|
2005-12-06 12:08:09 +05:30
|
|
|
"sets the space below paragraph in centimeters"
|
|
|
|
self.bmargin = value
|
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
def get_left_margin(self):
|
2005-12-06 12:08:09 +05:30
|
|
|
"returns the left indent in centimeters"
|
2003-08-24 02:40:21 +05:30
|
|
|
return self.lmargin
|
|
|
|
|
|
|
|
def get_right_margin(self):
|
2005-12-06 12:08:09 +05:30
|
|
|
"returns the right indent in centimeters"
|
2003-08-24 02:40:21 +05:30
|
|
|
return self.rmargin
|
|
|
|
|
|
|
|
def get_first_indent(self):
|
2005-12-06 12:08:09 +05:30
|
|
|
"returns the first line indent in centimeters"
|
2003-08-24 02:40:21 +05:30
|
|
|
return self.first_indent
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
def get_top_margin(self):
|
|
|
|
"returns the space above paragraph in centimeters"
|
|
|
|
return self.tmargin
|
|
|
|
|
|
|
|
def get_bottom_margin(self):
|
|
|
|
"returns the space below paragraph in centimeters"
|
|
|
|
return self.bmargin
|
|
|
|
|
2007-05-08 08:26:33 +05:30
|
|
|
def set_tabs(self, tab_stops):
|
|
|
|
assert(type(tab_stops) == type([]))
|
|
|
|
self.tabs = tab_stops
|
|
|
|
|
|
|
|
def get_tabs(self):
|
|
|
|
return self.tabs
|
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# StyleSheetList
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class StyleSheetList:
|
|
|
|
"""
|
|
|
|
Interface into the user's defined style sheets. Each StyleSheetList
|
|
|
|
has a predefined default style specified by the report. Additional
|
|
|
|
styles are loaded from a specified XML file if it exists.
|
|
|
|
"""
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, filename, defstyle):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Creates a new StyleSheetList from the specified default style and
|
|
|
|
any other styles that may be defined in the specified file.
|
|
|
|
|
|
|
|
file - XML file that contains style definitions
|
|
|
|
defstyle - default style
|
|
|
|
"""
|
|
|
|
defstyle.set_name('default')
|
|
|
|
self.map = { "default" : defstyle }
|
2007-09-08 11:24:02 +05:30
|
|
|
self.file = os.path.join(const.HOME_DIR, filename)
|
2003-08-24 02:40:21 +05:30
|
|
|
self.parse()
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def delete_style_sheet(self, name):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Removes a style from the list. Since each style must have a
|
|
|
|
unique name, the name is used to delete the stylesheet.
|
|
|
|
|
|
|
|
name - Name of the style to delete
|
|
|
|
"""
|
|
|
|
del self.map[name]
|
|
|
|
|
|
|
|
def get_style_sheet_map(self):
|
|
|
|
"""
|
|
|
|
Returns the map of names to styles.
|
|
|
|
"""
|
|
|
|
return self.map
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def get_style_sheet(self, name):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Returns the StyleSheet associated with the name
|
|
|
|
|
|
|
|
name - name associated with the desired StyleSheet.
|
|
|
|
"""
|
|
|
|
return self.map[name]
|
|
|
|
|
|
|
|
def get_style_names(self):
|
|
|
|
"Returns a list of all the style names in the StyleSheetList"
|
|
|
|
return self.map.keys()
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_style_sheet(self, name, style):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Adds or replaces a StyleSheet in the StyleSheetList. The
|
|
|
|
default style may not be replaced.
|
|
|
|
|
|
|
|
name - name assocated with the StyleSheet to add or replace.
|
|
|
|
style - definition of the StyleSheet
|
|
|
|
"""
|
|
|
|
style.set_name(name)
|
|
|
|
if name != "default":
|
|
|
|
self.map[name] = style
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
"""
|
|
|
|
Saves the current StyleSheet definitions to the associated file.
|
|
|
|
"""
|
2006-04-08 06:23:44 +05:30
|
|
|
xml_file = open(self.file,"w")
|
|
|
|
xml_file.write("<?xml version=\"1.0\"?>\n")
|
|
|
|
xml_file.write('<stylelist>\n')
|
2003-08-24 02:40:21 +05:30
|
|
|
for name in self.map.keys():
|
|
|
|
if name == "default":
|
|
|
|
continue
|
|
|
|
sheet = self.map[name]
|
2007-01-28 10:38:49 +05:30
|
|
|
xml_file.write('<sheet name="%s">\n' % escxml(name))
|
2007-04-23 17:16:26 +05:30
|
|
|
for p_name in sheet.get_paragraph_style_names():
|
|
|
|
para = sheet.get_paragraph_style(p_name)
|
2007-01-28 10:38:49 +05:30
|
|
|
xml_file.write('<style name="%s">\n' % escxml(p_name))
|
2006-04-08 06:23:44 +05:30
|
|
|
font = para.get_font()
|
|
|
|
xml_file.write('<font face="%d" ' % font.get_type_face())
|
|
|
|
xml_file.write('size="%d" ' % font.get_size())
|
|
|
|
xml_file.write('italic="%d" ' % font.get_italic())
|
|
|
|
xml_file.write('bold="%d" ' % font.get_bold())
|
|
|
|
xml_file.write('underline="%d" ' % font.get_underline())
|
|
|
|
xml_file.write('color="#%02x%02x%02x"/>\n' % font.get_color())
|
|
|
|
xml_file.write('<para ')
|
|
|
|
rmargin = float(para.get_right_margin())
|
|
|
|
lmargin = float(para.get_left_margin())
|
|
|
|
findent = float(para.get_first_indent())
|
|
|
|
tmargin = float(para.get_top_margin())
|
|
|
|
bmargin = float(para.get_bottom_margin())
|
|
|
|
padding = float(para.get_padding())
|
2007-05-20 09:13:38 +05:30
|
|
|
xml_file.write('description="%s" ' %
|
|
|
|
escxml(para.get_description()))
|
2006-04-08 06:23:44 +05:30
|
|
|
xml_file.write('rmargin="%s" ' % Utils.gformat(rmargin))
|
|
|
|
xml_file.write('lmargin="%s" ' % Utils.gformat(lmargin))
|
|
|
|
xml_file.write('first="%s" ' % Utils.gformat(findent))
|
|
|
|
xml_file.write('tmargin="%s" ' % Utils.gformat(tmargin))
|
|
|
|
xml_file.write('bmargin="%s" ' % Utils.gformat(bmargin))
|
|
|
|
xml_file.write('pad="%s" ' % Utils.gformat(padding))
|
|
|
|
bg_color = para.get_background_color()
|
|
|
|
xml_file.write('bgcolor="#%02x%02x%02x" ' % bg_color)
|
|
|
|
xml_file.write('level="%d" ' % para.get_header_level())
|
|
|
|
xml_file.write('align="%d" ' % para.get_alignment())
|
|
|
|
xml_file.write('tborder="%d" ' % para.get_top_border())
|
|
|
|
xml_file.write('lborder="%d" ' % para.get_left_border())
|
|
|
|
xml_file.write('rborder="%d" ' % para.get_right_border())
|
|
|
|
xml_file.write('bborder="%d"/>\n' % para.get_bottom_border())
|
|
|
|
xml_file.write('</style>\n')
|
|
|
|
xml_file.write('</sheet>\n')
|
|
|
|
xml_file.write('</stylelist>\n')
|
|
|
|
xml_file.close()
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def parse(self):
|
|
|
|
"""
|
|
|
|
Loads the StyleSheets from the associated file, if it exists.
|
|
|
|
"""
|
|
|
|
try:
|
2006-03-31 09:49:06 +05:30
|
|
|
if os.path.isfile(self.file):
|
2006-04-08 06:23:44 +05:30
|
|
|
parser = make_parser()
|
|
|
|
parser.setContentHandler(SheetParser(self))
|
2007-07-01 00:28:14 +05:30
|
|
|
the_file = open(self.file)
|
|
|
|
parser.parse(the_file)
|
|
|
|
the_file.close()
|
2003-08-24 02:40:21 +05:30
|
|
|
except (IOError,OSError,SAXParseException):
|
|
|
|
pass
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# StyleSheet
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class StyleSheet:
|
|
|
|
"""
|
|
|
|
A collection of named paragraph styles.
|
|
|
|
"""
|
|
|
|
|
2006-04-08 06:23:44 +05:30
|
|
|
def __init__(self, obj=None):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Creates a new empty StyleSheet.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param obj: if not None, creates the StyleSheet from the values in
|
|
|
|
obj, instead of creating an empty StyleSheet
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-06-27 10:20:33 +05:30
|
|
|
self.para_styles = {}
|
|
|
|
self.draw_styles = {}
|
|
|
|
self.table_styles = {}
|
|
|
|
self.cell_styles = {}
|
2003-08-24 02:40:21 +05:30
|
|
|
self.name = ""
|
|
|
|
if obj != None:
|
2007-06-27 10:20:33 +05:30
|
|
|
for style_name in obj.para_styles.keys():
|
|
|
|
style = obj.para_styles[style_name]
|
|
|
|
self.para_styles[style_name] = ParagraphStyle(style)
|
|
|
|
for style_name in obj.draw_styles.keys():
|
|
|
|
style = obj.draw_styles[style_name]
|
|
|
|
self.draw_styles[style_name] = GraphicsStyle(style)
|
|
|
|
for style_name in obj.table_styles.keys():
|
|
|
|
style = obj.table_styles[style_name]
|
|
|
|
self.table_styles[style_name] = TableStyle(style)
|
|
|
|
for style_name in obj.cell_styles.keys():
|
|
|
|
style = obj.cell_styles[style_name]
|
|
|
|
self.cell_styles[style_name] = TableCellStyle(style)
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_name(self, name):
|
2006-04-08 06:23:44 +05:30
|
|
|
"""
|
|
|
|
Sets the name of the StyleSheet
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
@param name: The name to be given to the StyleSheet
|
2006-04-08 06:23:44 +05:30
|
|
|
"""
|
2003-08-24 02:40:21 +05:30
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def get_name(self):
|
2006-04-08 06:23:44 +05:30
|
|
|
"""
|
|
|
|
Returns the name of the StyleSheet
|
|
|
|
"""
|
2003-08-24 02:40:21 +05:30
|
|
|
return self.name
|
|
|
|
|
|
|
|
def clear(self):
|
2007-04-23 17:16:26 +05:30
|
|
|
"Removes all styles from the StyleSheet"
|
2007-06-27 10:20:33 +05:30
|
|
|
self.para_styles = {}
|
|
|
|
self.draw_styles = {}
|
|
|
|
self.table_styles = {}
|
|
|
|
self.cell_styles = {}
|
2008-02-10 09:39:09 +05:30
|
|
|
|
|
|
|
def is_empty(self):
|
|
|
|
"Checks if any styles are defined"
|
|
|
|
style_count = len(self.para_styles) + \
|
|
|
|
len(self.draw_styles) + \
|
|
|
|
len(self.table_styles) + \
|
|
|
|
len(self.cell_styles)
|
|
|
|
if style_count > 0:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
def add_paragraph_style(self, name, style):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Adds a paragraph style to the style sheet.
|
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
@param name: The name of the ParagraphStyle
|
|
|
|
@param style: ParagraphStyle instance to be added.
|
|
|
|
"""
|
2007-06-27 10:20:33 +05:30
|
|
|
self.para_styles[name] = ParagraphStyle(style)
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
def get_paragraph_style(self, name):
|
|
|
|
"""
|
|
|
|
Returns the ParagraphStyle associated with the name
|
|
|
|
|
|
|
|
@param name: name of the ParagraphStyle that is wanted
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-06-27 10:20:33 +05:30
|
|
|
return ParagraphStyle(self.para_styles[name])
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
def get_paragraph_style_names(self):
|
2003-08-24 02:40:21 +05:30
|
|
|
"Returns the the list of paragraph names in the StyleSheet"
|
2007-06-27 10:20:33 +05:30
|
|
|
return self.para_styles.keys()
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
def add_draw_style(self, name, style):
|
|
|
|
"""
|
|
|
|
Adds a draw style to the style sheet.
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
@param name: The name of the GraphicsStyle
|
|
|
|
@param style: GraphicsStyle instance to be added.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-06-27 10:20:33 +05:30
|
|
|
self.draw_styles[name] = GraphicsStyle(style)
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
def get_draw_style(self, name):
|
|
|
|
"""
|
|
|
|
Returns the GraphicsStyle associated with the name
|
|
|
|
|
|
|
|
@param name: name of the GraphicsStyle that is wanted
|
|
|
|
"""
|
2007-06-27 10:20:33 +05:30
|
|
|
return GraphicsStyle(self.draw_styles[name])
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
def get_draw_style_names(self):
|
|
|
|
"Returns the the list of draw style names in the StyleSheet"
|
2007-06-27 10:20:33 +05:30
|
|
|
return self.draw_styles.keys()
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
def add_table_style(self, name, style):
|
|
|
|
"""
|
|
|
|
Adds a table style to the style sheet.
|
|
|
|
|
|
|
|
@param name: The name of the TableStyle
|
|
|
|
@param style: TableStyle instance to be added.
|
|
|
|
"""
|
2007-06-27 10:20:33 +05:30
|
|
|
self.table_styles[name] = TableStyle(style)
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
def get_table_style(self, name):
|
|
|
|
"""
|
|
|
|
Returns the TableStyle associated with the name
|
|
|
|
|
|
|
|
@param name: name of the TableStyle that is wanted
|
|
|
|
"""
|
2007-06-27 10:20:33 +05:30
|
|
|
return TableStyle(self.table_styles[name])
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
def get_table_style_names(self):
|
|
|
|
"Returns the the list of table style names in the StyleSheet"
|
2007-06-27 10:20:33 +05:30
|
|
|
return self.table_styles.keys()
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
def add_cell_style(self, name, style):
|
|
|
|
"""
|
|
|
|
Adds a cell style to the style sheet.
|
|
|
|
|
|
|
|
@param name: The name of the TableCellStyle
|
|
|
|
@param style: TableCellStyle instance to be added.
|
|
|
|
"""
|
2007-06-27 10:20:33 +05:30
|
|
|
self.cell_styles[name] = TableCellStyle(style)
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
def get_cell_style(self, name):
|
|
|
|
"""
|
|
|
|
Returns the TableCellStyle associated with the name
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
@param name: name of the TableCellStyle that is wanted
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-06-27 10:20:33 +05:30
|
|
|
return TableCellStyle(self.cell_styles[name])
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
def get_cell_style_names(self):
|
|
|
|
"Returns the the list of cell style names in the StyleSheet"
|
2007-06-27 10:20:33 +05:30
|
|
|
return self.cell_styles.keys()
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# SheetParser
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class SheetParser(handler.ContentHandler):
|
|
|
|
"""
|
|
|
|
SAX parsing class for the StyleSheetList XML file.
|
|
|
|
"""
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, sheetlist):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Creates a SheetParser class that populates the passed StyleSheetList
|
|
|
|
class.
|
|
|
|
|
|
|
|
sheetlist - StyleSheetList instance to be loaded from the file.
|
|
|
|
"""
|
|
|
|
handler.ContentHandler.__init__(self)
|
|
|
|
self.sheetlist = sheetlist
|
|
|
|
self.f = None
|
|
|
|
self.p = None
|
|
|
|
self.s = None
|
|
|
|
self.sname = None
|
|
|
|
self.pname = None
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def startElement(self, tag, attrs):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Overridden class that handles the start of a XML element
|
|
|
|
"""
|
|
|
|
if tag == "sheet":
|
|
|
|
self.s = StyleSheet(self.sheetlist.map["default"])
|
|
|
|
self.sname = attrs['name']
|
|
|
|
elif tag == "font":
|
|
|
|
self.f = FontStyle()
|
|
|
|
self.f.set_type_face(int(attrs['face']))
|
|
|
|
self.f.set_size(int(attrs['size']))
|
|
|
|
self.f.set_italic(int(attrs['italic']))
|
|
|
|
self.f.set_bold(int(attrs['bold']))
|
|
|
|
self.f.set_underline(int(attrs['underline']))
|
|
|
|
self.f.set_color(cnv2color(attrs['color']))
|
|
|
|
elif tag == "para":
|
2007-01-21 09:44:59 +05:30
|
|
|
if attrs.has_key('description'):
|
|
|
|
self.p.set_description(attrs['description'])
|
|
|
|
self.p.set_right_margin(Utils.gfloat(attrs['rmargin']))
|
2003-08-24 02:40:21 +05:30
|
|
|
self.p.set_right_margin(Utils.gfloat(attrs['rmargin']))
|
|
|
|
self.p.set_left_margin(Utils.gfloat(attrs['lmargin']))
|
|
|
|
self.p.set_first_indent(Utils.gfloat(attrs['first']))
|
2005-12-06 12:08:09 +05:30
|
|
|
try:
|
|
|
|
# This is needed to read older style files
|
|
|
|
# lacking tmargin and bmargin
|
|
|
|
self.p.set_top_margin(Utils.gfloat(attrs['tmargin']))
|
|
|
|
self.p.set_bottom_margin(Utils.gfloat(attrs['bmargin']))
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2003-08-24 02:40:21 +05:30
|
|
|
self.p.set_padding(Utils.gfloat(attrs['pad']))
|
|
|
|
self.p.set_alignment(int(attrs['align']))
|
|
|
|
self.p.set_right_border(int(attrs['rborder']))
|
|
|
|
self.p.set_header_level(int(attrs['level']))
|
|
|
|
self.p.set_left_border(int(attrs['lborder']))
|
|
|
|
self.p.set_top_border(int(attrs['tborder']))
|
|
|
|
self.p.set_bottom_border(int(attrs['bborder']))
|
|
|
|
self.p.set_background_color(cnv2color(attrs['bgcolor']))
|
|
|
|
elif tag == "style":
|
|
|
|
self.p = ParagraphStyle()
|
|
|
|
self.pname = attrs['name']
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def endElement(self, tag):
|
2003-08-24 02:40:21 +05:30
|
|
|
"Overridden class that handles the start of a XML element"
|
|
|
|
if tag == "style":
|
|
|
|
self.p.set_font(self.f)
|
2007-04-23 17:16:26 +05:30
|
|
|
self.s.add_paragraph_style(self.pname, self.p)
|
2003-08-24 02:40:21 +05:30
|
|
|
elif tag == "sheet":
|
2006-04-08 06:23:44 +05:30
|
|
|
self.sheetlist.set_style_sheet(self.sname, self.s)
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GraphicsStyle
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class GraphicsStyle:
|
2006-04-08 06:23:44 +05:30
|
|
|
"""
|
|
|
|
Defines the properties of graphics objects, such as line width,
|
|
|
|
color, fill, ect.
|
|
|
|
"""
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, obj=None):
|
2006-04-08 06:23:44 +05:30
|
|
|
"""
|
|
|
|
Initialize the object with default values, unless a source
|
|
|
|
object is specified. In that case, make a copy of the source
|
|
|
|
object.
|
|
|
|
"""
|
2003-08-24 02:40:21 +05:30
|
|
|
if obj:
|
|
|
|
self.para_name = obj.para_name
|
|
|
|
self.shadow = obj.shadow
|
2004-01-08 23:39:18 +05:30
|
|
|
self.shadow_space = obj.shadow_space
|
2005-01-24 22:03:47 +05:30
|
|
|
self.color = obj.color
|
2003-08-24 02:40:21 +05:30
|
|
|
self.fill_color = obj.fill_color
|
|
|
|
self.lwidth = obj.lwidth
|
|
|
|
self.lstyle = obj.lstyle
|
|
|
|
else:
|
|
|
|
self.para_name = ""
|
|
|
|
self.shadow = 0
|
2004-01-08 23:39:18 +05:30
|
|
|
self.shadow_space = 0.2
|
2003-08-24 02:40:21 +05:30
|
|
|
self.lwidth = 0.5
|
2006-04-08 06:23:44 +05:30
|
|
|
self.color = (0, 0, 0)
|
|
|
|
self.fill_color = (255, 255, 255)
|
2003-08-24 02:40:21 +05:30
|
|
|
self.lstyle = SOLID
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_line_width(self, val):
|
2006-04-08 06:23:44 +05:30
|
|
|
"""
|
|
|
|
sets the line width
|
|
|
|
"""
|
2003-08-24 02:40:21 +05:30
|
|
|
self.lwidth = val
|
|
|
|
|
|
|
|
def get_line_width(self):
|
2006-04-08 06:23:44 +05:30
|
|
|
"""
|
|
|
|
Returns the name of the StyleSheet
|
|
|
|
"""
|
2003-08-24 02:40:21 +05:30
|
|
|
return self.lwidth
|
|
|
|
|
|
|
|
def get_line_style(self):
|
|
|
|
return self.lstyle
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_line_style(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
self.lstyle = val
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_paragraph_style(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
self.para_name = val
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_shadow(self, val, space=0.2):
|
2003-08-24 02:40:21 +05:30
|
|
|
self.shadow = val
|
2004-01-08 23:39:18 +05:30
|
|
|
self.shadow_space = space
|
|
|
|
|
|
|
|
def get_shadow_space(self):
|
|
|
|
return self.shadow_space
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_color(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
self.color = val
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_fill_color(self, val):
|
2003-08-24 02:40:21 +05:30
|
|
|
self.fill_color = val
|
|
|
|
|
|
|
|
def get_paragraph_style(self):
|
|
|
|
return self.para_name
|
|
|
|
|
|
|
|
def get_shadow(self):
|
|
|
|
return self.shadow
|
|
|
|
|
|
|
|
def get_color(self):
|
|
|
|
return self.color
|
|
|
|
|
|
|
|
def get_fill_color(self):
|
|
|
|
return self.fill_color
|
|
|
|
|
2006-06-03 09:02:26 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# IndexMark
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class IndexMark:
|
|
|
|
"""
|
|
|
|
Defines a mark to be associated with text for indexing.
|
|
|
|
"""
|
2007-06-27 10:20:33 +05:30
|
|
|
def __init__(self, key="", itype=INDEX_TYPE_ALP, level=1):
|
2006-06-03 09:02:26 +05:30
|
|
|
"""
|
|
|
|
Initialize the object with default values, unless values are specified.
|
|
|
|
"""
|
|
|
|
self.key = key
|
2007-06-27 10:20:33 +05:30
|
|
|
self.type = itype
|
2006-06-04 09:56:28 +05:30
|
|
|
self.level = level
|
2006-06-03 09:02:26 +05:30
|
|
|
|
2003-08-24 02:40:21 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
2003-09-02 06:17:09 +05:30
|
|
|
# BaseDoc
|
2003-08-24 02:40:21 +05:30
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class BaseDoc:
|
|
|
|
"""
|
2007-04-30 07:26:34 +05:30
|
|
|
Base class for document generators. Different output formats,
|
2003-08-24 02:40:21 +05:30
|
|
|
such as OpenOffice, AbiWord, and LaTeX are derived from this base
|
|
|
|
class, providing a common interface to all document generators.
|
|
|
|
"""
|
2007-02-25 02:45:21 +05:30
|
|
|
def __init__(self, styles, paper_style, template):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2003-09-02 06:17:09 +05:30
|
|
|
Creates a BaseDoc instance, which provides a document generation
|
2003-08-24 02:40:21 +05:30
|
|
|
interface. This class should never be instantiated directly, but
|
|
|
|
only through a derived class.
|
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
@param styles: StyleSheet containing the styles used.
|
|
|
|
@param paper_style: PaperStyle instance containing information about
|
2004-12-25 00:16:34 +05:30
|
|
|
the paper. If set to None, then the document is not a page
|
|
|
|
oriented document (e.g. HTML)
|
|
|
|
@param template: Format template for document generators that are
|
|
|
|
not page oriented.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
self.template = template
|
2007-02-25 02:45:21 +05:30
|
|
|
self.paper = paper_style
|
2007-04-23 17:16:26 +05:30
|
|
|
self._style_sheet = styles
|
2007-04-30 07:26:34 +05:30
|
|
|
self._creator = ""
|
2003-08-24 02:40:21 +05:30
|
|
|
self.print_req = 0
|
2005-01-20 09:41:13 +05:30
|
|
|
self.init_called = False
|
2007-12-21 05:48:39 +05:30
|
|
|
self.type = "standard"
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2003-09-13 10:26:04 +05:30
|
|
|
def init(self):
|
2005-01-20 09:41:13 +05:30
|
|
|
self.init_called = True
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def print_requested(self):
|
2003-08-24 02:40:21 +05:30
|
|
|
self.print_req = 1
|
|
|
|
|
2007-04-30 07:26:34 +05:30
|
|
|
def set_creator(self, name):
|
|
|
|
"Sets the owner name"
|
|
|
|
self._creator = name
|
|
|
|
|
|
|
|
def get_creator(self):
|
2003-08-24 02:40:21 +05:30
|
|
|
"Returns the owner name"
|
2007-04-30 07:26:34 +05:30
|
|
|
return self._creator
|
2007-04-23 17:16:26 +05:30
|
|
|
|
|
|
|
def get_style_sheet(self):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-04-23 17:16:26 +05:30
|
|
|
Returns the StyleSheet of the document.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-04-23 17:16:26 +05:30
|
|
|
return StyleSheet(self._style_sheet)
|
|
|
|
|
2007-06-27 10:20:33 +05:30
|
|
|
def set_style_sheet(self, style_sheet):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-04-23 17:16:26 +05:30
|
|
|
Sets the StyleSheet of the document.
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2007-04-23 17:16:26 +05:30
|
|
|
@param style_sheet: The new style sheet for the document
|
|
|
|
@type style_sheet: StyleSheet
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-04-23 17:16:26 +05:30
|
|
|
self._style_sheet = StyleSheet(style_sheet)
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def open(self, filename):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Opens the document.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param filename: path name of the file to create
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def close(self):
|
|
|
|
"Closes the document"
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2007-04-30 07:26:34 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# TextDoc
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class TextDoc:
|
|
|
|
"""
|
|
|
|
Abstract Interface for text document generators. Output formats for
|
|
|
|
text reports must implment this interface to be used by the report
|
|
|
|
system.
|
|
|
|
"""
|
2003-08-25 08:43:52 +05:30
|
|
|
def page_break(self):
|
2003-08-24 02:40:21 +05:30
|
|
|
"Forces a page break, creating a new page"
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def start_bold(self):
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def end_bold(self):
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def start_superscript(self):
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def end_superscript(self):
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def start_paragraph(self, style_name, leader=None):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Starts a new paragraph, using the specified style name.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param style_name: name of the ParagraphStyle to use for the
|
|
|
|
paragraph.
|
|
|
|
@param leader: Leading text for a paragraph. Typically used
|
|
|
|
for numbering.
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def end_paragraph(self):
|
|
|
|
"Ends the current parsgraph"
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def start_table(self, name, style_name):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Starts a new table.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param name: Unique name of the table.
|
|
|
|
@param style_name: TableStyle to use for the new table
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def end_table(self):
|
|
|
|
"Ends the current table"
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def start_row(self):
|
|
|
|
"Starts a new row on the current table"
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def end_row(self):
|
|
|
|
"Ends the current row on the current table"
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def start_cell(self, style_name, span=1):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Starts a new table cell, using the paragraph style specified.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param style_name: TableCellStyle to use for the cell
|
|
|
|
@param span: number of columns to span
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
|
|
|
def end_cell(self):
|
|
|
|
"Ends the current table cell"
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def write_note(self, text, format, style_name):
|
2003-12-11 09:19:44 +05:30
|
|
|
"""
|
|
|
|
Writes the note's text and take care of paragraphs,
|
|
|
|
depending on the format.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param text: text to write.
|
|
|
|
@param format: format to use for writing. True for flowed text,
|
2003-12-11 09:19:44 +05:30
|
|
|
1 for preformatted text.
|
|
|
|
"""
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-12-11 09:19:44 +05:30
|
|
|
|
2006-06-03 09:02:26 +05:30
|
|
|
def write_text(self, text, mark=None):
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
|
|
|
Writes the text in the current paragraph. Should only be used after a
|
|
|
|
start_paragraph and before an end_paragraph.
|
|
|
|
|
2004-12-25 00:16:34 +05:30
|
|
|
@param text: text to write.
|
2006-06-03 09:02:26 +05:30
|
|
|
@param mark: IndexMark to use for indexing (if supported)
|
2003-08-24 02:40:21 +05:30
|
|
|
"""
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def add_media_object(self, name, align, w_cm, h_cm):
|
|
|
|
"""
|
|
|
|
Adds a photo of the specified width (in centimeters)
|
|
|
|
|
|
|
|
@param name: filename of the image to add
|
|
|
|
@param align: alignment of the image. Valid values are 'left',
|
|
|
|
'right', 'center', and 'single'
|
|
|
|
@param w_cm: width in centimeters
|
|
|
|
@param h_cm: height in centimeters
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# DrawDoc
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class DrawDoc:
|
|
|
|
"""
|
|
|
|
Abstract Interface for graphical document generators. Output formats
|
|
|
|
for graphical reports must implment this interface to be used by the
|
|
|
|
report system.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def start_page(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def end_page(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def get_usable_width(self):
|
|
|
|
"""
|
|
|
|
Returns the width of the text area in centimeters. The value is
|
|
|
|
the page width less the margins.
|
|
|
|
"""
|
2007-05-20 09:13:38 +05:30
|
|
|
width = self.paper.get_size().get_width()
|
|
|
|
right = self.paper.get_right_margin()
|
|
|
|
left = self.paper.get_left_margin()
|
|
|
|
return width - (right + left)
|
2007-04-30 07:26:34 +05:30
|
|
|
|
|
|
|
def get_usable_height(self):
|
|
|
|
"""
|
|
|
|
Returns the height of the text area in centimeters. The value is
|
|
|
|
the page height less the margins.
|
|
|
|
"""
|
2007-05-20 09:13:38 +05:30
|
|
|
height = self.paper.get_size().get_height()
|
|
|
|
top = self.paper.get_top_margin()
|
|
|
|
bottom = self.paper.get_bottom_margin()
|
|
|
|
return height - (top + bottom)
|
2007-04-30 07:26:34 +05:30
|
|
|
|
|
|
|
def string_width(self, fontstyle, text):
|
|
|
|
"Determine the width need for text in given font"
|
|
|
|
return FontScale.string_width(fontstyle, text)
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def draw_path(self, style, path):
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2007-02-26 03:23:38 +05:30
|
|
|
def draw_box(self, style, text, x, y, w, h):
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def draw_text(self, style, text, x1, y1):
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def center_text(self, style, text, x1, y1):
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def rotate_text(self, style, text, x, y, angle):
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def draw_line(self, style, x1, y1, x2, y2):
|
2007-04-30 07:26:34 +05:30
|
|
|
raise NotImplementedError
|
2003-08-24 02:40:21 +05:30
|
|
|
|
2007-09-30 10:26:56 +05:30
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GVDoc
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
class GVDoc:
|
|
|
|
"""
|
|
|
|
Abstract Interface for Graphviz document generators. Output formats
|
|
|
|
for Graphviz reports must implment this interface to be used by the
|
|
|
|
report system.
|
|
|
|
"""
|
2007-12-31 13:03:19 +05:30
|
|
|
def add_node(self, id, label, shape="box", fillcolor="white", url="", htmloutput=False):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
|
|
|
Add a node to this graph. Nodes can be different shapes like boxes and
|
|
|
|
circles.
|
|
|
|
|
|
|
|
@param id: A unique identification value for this node.
|
|
|
|
Example: "p55"
|
|
|
|
@type id: string
|
|
|
|
@param label: The text to be displayed in the node.
|
|
|
|
Example: "John Smith"
|
|
|
|
@type label: string
|
|
|
|
@param shape: The shape for the node.
|
|
|
|
Examples: "box", "ellipse", "circle"
|
|
|
|
@type shape: string
|
|
|
|
@param fillcolor: The fill color for the node.
|
|
|
|
Examples: "blue", "lightyellow"
|
|
|
|
@type fillcolor: string
|
|
|
|
@param url: A URL for the node.
|
|
|
|
@type url: string
|
2007-12-31 13:03:19 +05:30
|
|
|
@param htmloutput: Whether the label contains HTML.
|
|
|
|
@type htmloutput: boolean
|
2007-09-30 10:26:56 +05:30
|
|
|
@return: nothing
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
2008-01-02 14:13:19 +05:30
|
|
|
|
2007-12-31 13:03:19 +05:30
|
|
|
def add_link(self, id1, id2, style="", head="", tail="", comment=""):
|
2007-09-30 10:26:56 +05:30
|
|
|
"""
|
|
|
|
Add a link between two nodes.
|
|
|
|
|
|
|
|
@param id1: The unique identifier of the starting node.
|
|
|
|
Example: "p55"
|
|
|
|
@type id1: string
|
|
|
|
@param id2: The unique identifier of the ending node.
|
|
|
|
Example: "p55"
|
|
|
|
@type id2: string
|
2007-12-31 13:03:19 +05:30
|
|
|
@param comment: A text string displayed at the end of the link line.
|
|
|
|
Example: "person C is the son of person A and person B"
|
|
|
|
@type comment: string
|
2007-09-30 10:26:56 +05:30
|
|
|
@return: nothing
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
2008-01-02 14:13:19 +05:30
|
|
|
|
|
|
|
def add_comment(self, comment):
|
|
|
|
"""
|
|
|
|
Add a comment to the source file.
|
|
|
|
|
|
|
|
@param comment: A text string to add as a comment.
|
|
|
|
Example: "Next comes the individuals."
|
|
|
|
@type comment: string
|
|
|
|
@return: nothing
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2007-12-30 11:11:16 +05:30
|
|
|
def start_subgraph(self,id):
|
|
|
|
"""
|
|
|
|
Start a subgraph in this graph.
|
|
|
|
|
|
|
|
@param id: The unique identifier of the subgraph.
|
|
|
|
Example: "p55"
|
|
|
|
@type id1: string
|
|
|
|
@return: nothing
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
2008-01-02 14:13:19 +05:30
|
|
|
|
2007-12-30 11:11:16 +05:30
|
|
|
def end_subgraph(self):
|
|
|
|
"""
|
|
|
|
End a subgraph that was previously started in this graph.
|
|
|
|
|
|
|
|
@return: nothing
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|