2001-05-13 07:26:57 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2000 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
|
|
|
|
#
|
|
|
|
|
2001-06-06 04:45:43 +05:30
|
|
|
import string
|
|
|
|
import os
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Try to abstract SAX1 from SAX2
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2001-06-28 20:53:16 +05:30
|
|
|
try:
|
2002-03-06 05:46:58 +05:30
|
|
|
from xml.sax import make_parser,handler,SAXParseException
|
2001-06-28 20:53:16 +05:30
|
|
|
except:
|
2002-03-06 05:46:58 +05:30
|
|
|
from _xmlplus.sax import make_parser,handler,SAXParseException
|
2001-06-06 04:45:43 +05:30
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
FONT_SANS_SERIF = 0
|
|
|
|
FONT_SERIF = 1
|
|
|
|
|
|
|
|
PAPER_PORTRAIT = 0
|
|
|
|
PAPER_LANDSCAPE = 1
|
|
|
|
|
|
|
|
PARA_ALIGN_CENTER = 0
|
|
|
|
PARA_ALIGN_LEFT = 1
|
|
|
|
PARA_ALIGN_RIGHT = 2
|
|
|
|
PARA_ALIGN_JUSTIFY= 3
|
|
|
|
|
2001-06-06 04:45:43 +05:30
|
|
|
def cnv2color(text):
|
|
|
|
c0 = string.atoi(text[1:3],16)
|
|
|
|
c1 = string.atoi(text[3:5],16)
|
|
|
|
c2 = string.atoi(text[5:7],16)
|
|
|
|
return (c0,c1,c2)
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class PaperStyle:
|
|
|
|
def __init__(self,name,height,width):
|
|
|
|
self.name = name
|
|
|
|
self.orientation = PAPER_PORTRAIT
|
|
|
|
self.height = height
|
|
|
|
self.width = width
|
|
|
|
|
|
|
|
def get_name(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
def get_orientation(self):
|
|
|
|
return self.orientation
|
|
|
|
|
|
|
|
def set_orientation(self,val):
|
|
|
|
self.orientation = val
|
|
|
|
|
|
|
|
def get_height(self):
|
|
|
|
return self.height
|
|
|
|
|
|
|
|
def get_width(self):
|
|
|
|
return self.width
|
|
|
|
|
2001-12-19 14:35:53 +05:30
|
|
|
def get_height_inches(self):
|
|
|
|
return self.height / 2.54
|
|
|
|
|
|
|
|
def get_width_inches(self):
|
|
|
|
return self.width / 2.54
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class FontStyle:
|
|
|
|
def __init__(self, style=None):
|
|
|
|
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
|
|
|
|
self.color = (0,0,0)
|
|
|
|
self.under = 0
|
|
|
|
|
2001-06-06 04:45:43 +05:30
|
|
|
def set(self,face=None,size=None,italic=None,bold=None,underline=None,color=None):
|
|
|
|
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)
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
def set_italic(self,val):
|
|
|
|
"0 disables italics, 1 enables italics"
|
|
|
|
self.italic = val
|
|
|
|
|
|
|
|
def get_italic(self):
|
|
|
|
"1 indicates use italics"
|
|
|
|
return self.italic
|
|
|
|
|
|
|
|
def set_bold(self,val):
|
|
|
|
"0 disables bold face, 1 enables bold face"
|
|
|
|
self.bold = val
|
|
|
|
|
|
|
|
def get_bold(self):
|
|
|
|
"1 indicates use bold face"
|
|
|
|
return self.bold
|
|
|
|
|
|
|
|
def set_color(self,val):
|
|
|
|
"sets the color using an RGB color tuple"
|
|
|
|
self.color = val
|
|
|
|
|
|
|
|
def get_color(self):
|
|
|
|
"Returns an RGB color tuple"
|
|
|
|
return self.color
|
|
|
|
|
|
|
|
def set_size(self,val):
|
|
|
|
"sets font size in points"
|
|
|
|
self.size = val
|
|
|
|
|
|
|
|
def get_size(self):
|
|
|
|
"returns font size in points"
|
|
|
|
return self.size
|
|
|
|
|
|
|
|
def set_type_face(self,val):
|
|
|
|
"sets the font face type"
|
|
|
|
self.face = val
|
|
|
|
|
|
|
|
def get_type_face(self):
|
|
|
|
"returns the font face type"
|
|
|
|
return self.face
|
|
|
|
|
|
|
|
def set_underline(self,val):
|
|
|
|
"1 enables underlining"
|
|
|
|
self.under = val
|
|
|
|
|
|
|
|
def get_underline(self):
|
|
|
|
"1 indicates underlining"
|
|
|
|
return self.under
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class TableStyle:
|
|
|
|
def __init__(self,obj=None):
|
|
|
|
if obj:
|
|
|
|
self.width = obj.width
|
|
|
|
self.columns = obj.columns
|
|
|
|
self.colwid = obj.colwid[:]
|
|
|
|
else:
|
|
|
|
self.width = 0
|
|
|
|
self.columns = 0
|
2001-10-29 04:58:38 +05:30
|
|
|
self.colwid = [ 0 ] * 100
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
def set_width(self,width):
|
|
|
|
self.width = width
|
|
|
|
|
|
|
|
def get_width(self):
|
|
|
|
return self.width
|
|
|
|
|
|
|
|
def set_columns(self,columns):
|
|
|
|
self.columns = columns
|
|
|
|
|
|
|
|
def get_columns(self):
|
|
|
|
return self.columns
|
|
|
|
|
2001-06-20 02:18:35 +05:30
|
|
|
def set_column_widths(self, list):
|
|
|
|
self.columns = len(list)
|
|
|
|
for i in range(self.columns):
|
|
|
|
self.colwid[i] = list[i]
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
def set_column_width(self,index,width):
|
|
|
|
self.colwid[index] = width
|
|
|
|
|
|
|
|
def get_column_width(self,index):
|
|
|
|
return self.colwid[index]
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class TableCellStyle:
|
|
|
|
def __init__(self,obj=None):
|
|
|
|
if obj:
|
|
|
|
self.rborder = obj.rborder
|
|
|
|
self.lborder = obj.lborder
|
|
|
|
self.tborder = obj.tborder
|
|
|
|
self.bborder = obj.bborder
|
|
|
|
self.padding = obj.padding
|
2002-02-20 03:01:18 +05:30
|
|
|
self.longlist = obj.longlist
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
|
|
|
self.rborder = 0
|
|
|
|
self.lborder = 0
|
|
|
|
self.tborder = 0
|
|
|
|
self.bborder = 0
|
|
|
|
self.padding = 0
|
2002-02-20 03:01:18 +05:30
|
|
|
self.longlist = 0
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
def set_padding(self,val):
|
|
|
|
self.padding = val
|
|
|
|
|
|
|
|
def set_right_border(self,val):
|
|
|
|
self.rborder = val
|
|
|
|
|
|
|
|
def set_left_border(self,val):
|
|
|
|
self.lborder = val
|
|
|
|
|
|
|
|
def set_top_border(self,val):
|
|
|
|
self.tborder = val
|
|
|
|
|
|
|
|
def set_bottom_border(self,val):
|
|
|
|
self.bborder = val
|
|
|
|
|
2002-02-20 03:01:18 +05:30
|
|
|
def set_longlist(self,val):
|
|
|
|
self.longlist = val
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
def get_padding(self):
|
|
|
|
return self.padding
|
|
|
|
|
|
|
|
def get_right_border(self):
|
|
|
|
return self.rborder
|
|
|
|
|
|
|
|
def get_left_border(self):
|
|
|
|
return self.lborder
|
|
|
|
|
|
|
|
def get_top_border(self):
|
|
|
|
return self.tborder
|
|
|
|
|
|
|
|
def get_bottom_border(self):
|
|
|
|
return self.bborder
|
|
|
|
|
2002-02-20 03:01:18 +05:30
|
|
|
def get_longlist(self):
|
|
|
|
return self.longlist
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class ParagraphStyle:
|
|
|
|
def __init__(self,p=None):
|
|
|
|
if p:
|
|
|
|
self.font = FontStyle(p.font)
|
|
|
|
self.rmargin = p.rmargin
|
|
|
|
self.lmargin = p.lmargin
|
|
|
|
self.first_indent = p.first_indent
|
|
|
|
self.align = p.align
|
|
|
|
self.level = p.level
|
|
|
|
self.top_border = p.top_border
|
|
|
|
self.bottom_border = p.bottom_border
|
|
|
|
self.right_border = p.right_border
|
|
|
|
self.left_border = p.left_border
|
|
|
|
self.pad = p.pad
|
2001-05-18 04:42:07 +05:30
|
|
|
self.bgcolor = p.bgcolor
|
2001-05-13 07:26:57 +05:30
|
|
|
else:
|
|
|
|
self.font = FontStyle()
|
|
|
|
self.rmargin = 0
|
|
|
|
self.lmargin = 0
|
|
|
|
self.first_indent = 0
|
|
|
|
self.align = PARA_ALIGN_LEFT
|
|
|
|
self.level = 0
|
|
|
|
self.top_border = 0
|
|
|
|
self.bottom_border = 0
|
|
|
|
self.right_border = 0
|
|
|
|
self.left_border = 0
|
|
|
|
self.pad = 0
|
2001-05-18 04:42:07 +05:30
|
|
|
self.bgcolor = (255,255,255)
|
2001-05-13 07:26:57 +05:30
|
|
|
|
2001-06-06 04:45:43 +05:30
|
|
|
def set(self,rmargin=None,lmargin=None,first_indent=None,align=None,\
|
|
|
|
tborder=None,bborder=None,rborder=None,lborder=None,pad=None,
|
2001-06-20 04:07:42 +05:30
|
|
|
bgcolor=None,font=None):
|
|
|
|
if font != None:
|
|
|
|
self.font = FontStyle(font)
|
2001-06-06 04:45:43 +05:30
|
|
|
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)
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
def set_header_level(self,level):
|
|
|
|
self.level = level
|
|
|
|
|
|
|
|
def get_header_level(self):
|
|
|
|
return self.level
|
|
|
|
|
|
|
|
def set_font(self,font):
|
|
|
|
self.font = FontStyle(font)
|
|
|
|
|
|
|
|
def get_font(self):
|
2001-06-06 04:45:43 +05:30
|
|
|
return self.font
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
def set_padding(self,val):
|
|
|
|
self.pad = val
|
|
|
|
|
|
|
|
def get_padding(self):
|
|
|
|
return self.pad
|
|
|
|
|
|
|
|
def set_top_border(self,val):
|
|
|
|
self.top_border = val
|
|
|
|
|
|
|
|
def get_top_border(self):
|
|
|
|
return self.top_border
|
|
|
|
|
|
|
|
def set_bottom_border(self,val):
|
|
|
|
self.bottom_border = val
|
|
|
|
|
|
|
|
def get_bottom_border(self):
|
|
|
|
return self.bottom_border
|
|
|
|
|
|
|
|
def set_left_border(self,val):
|
|
|
|
self.left_border = val
|
|
|
|
|
2001-05-18 04:42:07 +05:30
|
|
|
def get_background_color(self):
|
|
|
|
return self.bgcolor
|
|
|
|
|
|
|
|
def set_background_color(self,color):
|
|
|
|
self.bgcolor = color
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
def get_left_border(self):
|
|
|
|
return self.left_border
|
|
|
|
|
|
|
|
def set_right_border(self,val):
|
|
|
|
self.right_border = val
|
|
|
|
|
|
|
|
def get_right_border(self):
|
|
|
|
return self.right_border
|
|
|
|
|
|
|
|
def set_alignment(self,align):
|
|
|
|
self.align = align
|
|
|
|
|
|
|
|
def get_alignment(self):
|
|
|
|
return self.align
|
|
|
|
|
2001-12-21 11:34:24 +05:30
|
|
|
def get_alignment_text(self):
|
|
|
|
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"
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
def set_left_margin(self,value):
|
|
|
|
"sets the left paragraph margin in centimeters"
|
|
|
|
self.lmargin = value
|
|
|
|
|
|
|
|
def set_right_margin(self,value):
|
|
|
|
"sets the right paragraph margin in centimeters"
|
|
|
|
self.rmargin = value
|
|
|
|
|
|
|
|
def set_first_indent(self,value):
|
|
|
|
"sets the first indent margin in centimeters"
|
|
|
|
self.first_indent = value
|
|
|
|
|
|
|
|
def get_left_margin(self):
|
|
|
|
"returns the left margin in centimeters"
|
|
|
|
return self.lmargin
|
|
|
|
|
|
|
|
def get_right_margin(self):
|
|
|
|
"returns the right margin in centimeters"
|
|
|
|
return self.rmargin
|
|
|
|
|
|
|
|
def get_first_indent(self):
|
|
|
|
"returns the first indent margin in centimeters"
|
|
|
|
return self.first_indent
|
|
|
|
|
2001-06-06 04:45:43 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class StyleSheetList:
|
2001-11-01 22:26:17 +05:30
|
|
|
def __init__(self,file,defstyle):
|
|
|
|
self.map = { "default" : defstyle }
|
2001-06-06 04:45:43 +05:30
|
|
|
self.file = os.path.expanduser("~/.gramps/" + file)
|
|
|
|
self.parse()
|
|
|
|
|
2001-06-16 08:54:44 +05:30
|
|
|
def delete_style_sheet(self,name):
|
|
|
|
del self.map[name]
|
|
|
|
|
2001-12-19 14:35:53 +05:30
|
|
|
def get_style_sheet_map(self):
|
|
|
|
return self.map
|
|
|
|
|
2001-06-06 04:45:43 +05:30
|
|
|
def get_style_sheet(self,name):
|
|
|
|
return self.map[name]
|
|
|
|
|
|
|
|
def get_style_names(self):
|
|
|
|
return self.map.keys()
|
|
|
|
|
|
|
|
def set_style_sheet(self,name,style):
|
|
|
|
if name != "default":
|
|
|
|
self.map[name] = style
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
f = open(self.file,"w")
|
|
|
|
f.write("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n")
|
|
|
|
f.write('<stylelist>\n')
|
|
|
|
for name in self.map.keys():
|
|
|
|
if name == "default":
|
|
|
|
continue
|
|
|
|
sheet = self.map[name]
|
|
|
|
f.write('<sheet name="%s">\n' % name)
|
|
|
|
for p_name in sheet.get_names():
|
|
|
|
p = sheet.get_style(p_name)
|
|
|
|
f.write('<style name="%s">\n' % p_name)
|
|
|
|
font = p.get_font()
|
|
|
|
f.write('<font face="%d" ' % font.get_type_face())
|
|
|
|
f.write('size="%d" ' % font.get_size())
|
|
|
|
f.write('italic="%d" ' % font.get_italic())
|
|
|
|
f.write('bold="%d" ' % font.get_bold())
|
2001-06-15 00:41:08 +05:30
|
|
|
f.write('underline="%d" ' % font.get_underline())
|
2001-06-06 04:45:43 +05:30
|
|
|
f.write('color="#%02x%02x%02x"/>\n' % font.get_color())
|
2001-06-07 19:19:00 +05:30
|
|
|
f.write('<para ')
|
2001-06-14 22:42:56 +05:30
|
|
|
rm = float(p.get_right_margin())
|
|
|
|
lm = float(p.get_left_margin())
|
|
|
|
fi = float(p.get_first_indent())
|
2002-01-06 01:25:03 +05:30
|
|
|
f.write('rmargin="%.3f" ' % rm)
|
|
|
|
f.write('lmargin="%.3f" ' % lm)
|
|
|
|
f.write('first="%.3f" ' % fi)
|
|
|
|
f.write('pad="%.3f" ' % p.get_padding())
|
2001-06-06 04:45:43 +05:30
|
|
|
f.write('bgcolor="#%02x%02x%02x" ' % p.get_background_color())
|
2001-06-08 03:32:09 +05:30
|
|
|
f.write('level="%d" ' % p.get_header_level())
|
2001-06-06 04:45:43 +05:30
|
|
|
f.write('align="%d" ' % p.get_alignment())
|
|
|
|
f.write('tborder="%d" ' % p.get_top_border())
|
|
|
|
f.write('lborder="%d" ' % p.get_left_border())
|
|
|
|
f.write('rborder="%d" ' % p.get_right_border())
|
|
|
|
f.write('bborder="%d"/>\n' % p.get_bottom_border())
|
|
|
|
f.write('</style>\n')
|
|
|
|
f.write('</sheet>\n')
|
|
|
|
f.write('</stylelist>\n')
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
def parse(self):
|
|
|
|
try:
|
2001-11-24 21:09:02 +05:30
|
|
|
parser = make_parser()
|
|
|
|
parser.setContentHandler(SheetParser(self))
|
|
|
|
parser.parse(self.file)
|
2002-03-06 05:46:58 +05:30
|
|
|
except (IOError,OSError,SAXParseException):
|
2002-02-14 08:04:52 +05:30
|
|
|
pass
|
2001-06-06 04:45:43 +05:30
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class StyleSheet:
|
|
|
|
def __init__(self,obj=None):
|
|
|
|
self.style_list = {}
|
|
|
|
if obj != None:
|
|
|
|
for style_name in obj.style_list.keys():
|
|
|
|
style = obj.style_list[style_name]
|
|
|
|
self.style_list[style_name] = ParagraphStyle(style)
|
|
|
|
|
|
|
|
def clear(self):
|
|
|
|
self.style_list = {}
|
|
|
|
|
|
|
|
def add_style(self,name,style):
|
|
|
|
self.style_list[name] = ParagraphStyle(style)
|
|
|
|
|
|
|
|
def get_names(self):
|
|
|
|
return self.style_list.keys()
|
|
|
|
|
|
|
|
def get_styles(self):
|
|
|
|
return self.style_list
|
|
|
|
|
|
|
|
def get_style(self,name):
|
|
|
|
return self.style_list[name]
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2001-06-22 04:44:01 +05:30
|
|
|
class SheetParser(handler.ContentHandler):
|
2001-06-06 04:45:43 +05:30
|
|
|
def __init__(self,sheetlist):
|
2001-06-22 04:44:01 +05:30
|
|
|
handler.ContentHandler.__init__(self)
|
2001-06-06 04:45:43 +05:30
|
|
|
self.sheetlist = sheetlist
|
|
|
|
self.f = None
|
|
|
|
self.p = None
|
|
|
|
self.s = None
|
|
|
|
self.sname = None
|
|
|
|
self.pname = None
|
|
|
|
|
|
|
|
def setDocumentLocator(self,locator):
|
|
|
|
self.locator = locator
|
|
|
|
|
|
|
|
def startElement(self,tag,attrs):
|
|
|
|
if tag == "sheet":
|
2001-11-01 22:26:17 +05:30
|
|
|
self.s = StyleSheet(self.sheetlist.map["default"])
|
2001-06-06 04:45:43 +05:30
|
|
|
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":
|
2002-01-06 01:25:03 +05:30
|
|
|
self.p.set_right_margin(float(attrs['rmargin']))
|
|
|
|
self.p.set_left_margin(float(attrs['lmargin']))
|
|
|
|
self.p.set_first_indent(float(attrs['first']))
|
|
|
|
self.p.set_padding(float(attrs['pad']))
|
2001-06-06 04:45:43 +05:30
|
|
|
self.p.set_alignment(int(attrs['align']))
|
|
|
|
self.p.set_right_border(int(attrs['rborder']))
|
2001-06-08 03:32:09 +05:30
|
|
|
self.p.set_header_level(int(attrs['level']))
|
2001-06-06 04:45:43 +05:30
|
|
|
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']
|
|
|
|
|
|
|
|
def endElement(self,tag):
|
|
|
|
if tag == "style":
|
|
|
|
self.p.set_font(self.f)
|
|
|
|
self.s.add_style(self.pname,self.p)
|
|
|
|
elif tag == "sheet":
|
|
|
|
self.sheetlist.set_style_sheet(self.sname,self.s)
|
|
|
|
|
2001-06-28 20:53:16 +05:30
|
|
|
def characters(self, data):
|
|
|
|
pass
|
2001-06-06 04:45:43 +05:30
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
#------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
class TextDoc:
|
2002-01-29 06:14:15 +05:30
|
|
|
def __init__(self,styles,type,template,orientation=PAPER_PORTRAIT):
|
2001-05-13 07:26:57 +05:30
|
|
|
self.orientation = orientation
|
2002-01-29 06:14:15 +05:30
|
|
|
self.template = template
|
2001-05-13 07:26:57 +05:30
|
|
|
if orientation == PAPER_PORTRAIT:
|
|
|
|
self.width = type.get_width()
|
|
|
|
self.height = type.get_height()
|
|
|
|
else:
|
|
|
|
self.width = type.get_height()
|
|
|
|
self.height = type.get_width()
|
2001-05-19 08:28:18 +05:30
|
|
|
self.paper = type
|
2001-05-13 07:26:57 +05:30
|
|
|
self.tmargin = 2.54
|
|
|
|
self.bmargin = 2.54
|
|
|
|
self.lmargin = 2.54
|
|
|
|
self.rmargin = 2.54
|
2001-06-20 02:18:35 +05:30
|
|
|
self.title = ""
|
2002-04-21 20:23:28 +05:30
|
|
|
self.owner = ''
|
2001-05-13 07:26:57 +05:30
|
|
|
|
|
|
|
self.font = FontStyle()
|
2001-06-06 04:45:43 +05:30
|
|
|
self.style_list = styles.get_styles()
|
2001-05-13 07:26:57 +05:30
|
|
|
self.table_styles = {}
|
|
|
|
self.cell_styles = {}
|
|
|
|
self.name = ""
|
2001-05-18 04:42:07 +05:30
|
|
|
self.photo_list = []
|
2001-05-13 07:26:57 +05:30
|
|
|
|
2002-04-21 20:23:28 +05:30
|
|
|
def set_owner(self,owner):
|
|
|
|
self.owner = owner
|
|
|
|
|
2001-11-14 05:04:29 +05:30
|
|
|
def add_photo(self,name,align,w_cm,h_cm):
|
|
|
|
"""adds a photo of the specified width (in centimeters)"""
|
2001-05-18 04:42:07 +05:30
|
|
|
pass
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
def get_usable_width(self):
|
|
|
|
return self.width - (self.rmargin + self.lmargin)
|
|
|
|
|
|
|
|
def get_usable_height(self):
|
|
|
|
return self.height - (self.tmargin + self.bmargin)
|
|
|
|
|
|
|
|
def creator(self,name):
|
|
|
|
self.name = name
|
|
|
|
|
2001-06-20 02:18:35 +05:30
|
|
|
def set_title(self,name):
|
|
|
|
self.title = name
|
|
|
|
|
2001-05-13 07:26:57 +05:30
|
|
|
def add_table_style(self,name,style):
|
|
|
|
self.table_styles[name] = TableStyle(style)
|
|
|
|
|
|
|
|
def add_cell_style(self,name,style):
|
|
|
|
self.cell_styles[name] = TableCellStyle(style)
|
|
|
|
|
|
|
|
def open(self,filename):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
pass
|
|
|
|
|
2001-05-21 07:36:08 +05:30
|
|
|
def page_break(self):
|
2001-05-13 07:26:57 +05:30
|
|
|
pass
|
|
|
|
|
2001-05-21 07:36:08 +05:30
|
|
|
def start_bold(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def end_bold(self):
|
2001-05-13 07:26:57 +05:30
|
|
|
pass
|
|
|
|
|
2001-06-09 00:30:10 +05:30
|
|
|
def start_paragraph(self,style_name,leader=None):
|
2001-05-13 07:26:57 +05:30
|
|
|
pass
|
|
|
|
|
|
|
|
def end_paragraph(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def start_table(self,name,style_name):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def end_table(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def start_row(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def end_row(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def start_cell(self,style_name,span=1):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def end_cell(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def horizontal_line(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def write_text(self,text):
|
|
|
|
pass
|
2001-06-06 04:45:43 +05:30
|
|
|
|