#
# 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
#
import os
import tempfile
import string
import re
import intl
import utils
_ = intl.gettext
from TextDoc import *
import const
_top = [
'\n',
'\n',
'
\n',
'\n',
'\n',
'\n',
'\n',
'\n',
'\n',
'\n'
]
_bottom = [
'\n',
'\n',
'\n'
]
class HtmlDoc(TextDoc):
def __init__(self,styles,template):
TextDoc.__init__(self,styles,PaperStyle("",0,0),None)
self.f = None
self.filename = None
self.template = template
self.top = []
self.bottom = []
def open(self,filename):
start = re.compile(r"")
stop = re.compile(r"")
top_add = 1
bottom_add = 0
if self.template and self.template != "":
try:
templateFile = open(self.template,"r")
for line in templateFile.readlines():
if top_add == 1:
self.top.append(line)
match = start.search(line)
if match:
top_add = 0
elif bottom_add == 0:
match = stop.search(line)
if match != None:
bottom_add = 1
self.bottom.append(line)
else:
self.bottom.append(line)
templateFile.close()
if top_add == 1:
mymsg = _("The marker '' was not in the template")
gnome.ui.GnomeErrorDialog(mymsg)
except IOError,msg:
import gnome.ui
mymsg = _("Could not open %s\nUsing the default template") % \
self.template
mymsg = "%s\n%s" % (mymsg,msg)
gnome.ui.GnomeWarningDialog(mymsg)
self.bottom = _bottom
self.top = _top
except:
import gnome.ui
mymsg = _("Could not open %s\nUsing the default template") % \
self.template
gnome.ui.GnomeWarningDialog(mymsg)
self.bottom = _bottom
self.top = _top
else:
self.bottom = _bottom
self.top = _top
if filename[-5:] == ".html" or filename[-4:0] == ".htm":
self.filename = filename
else:
self.filename = filename + ".html"
self.f = open(self.filename,"w")
for line in self.top:
self.f.write(line)
self.f.write('\n')
def close(self):
for line in self.bottom:
self.f.write(line)
self.f.close()
def start_table(self,name,style):
self.tbl = self.table_styles[style]
self.f.write('\n')
def end_table(self):
self.f.write('
\n')
def start_row(self):
self.col = 0
self.f.write('\n')
def end_row(self):
self.f.write('
\n')
def start_cell(self,style_name,span=1):
self.empty = 1
self.f.write(' 1:
self.f.write(' colspan="' + str(span) + '"')
else:
self.f.write(' width="')
self.f.write(str(self.tbl.get_column_width(self.col)))
self.f.write('%"')
self.f.write(' class="')
self.f.write(style_name)
self.f.write('">')
self.col = self.col + 1
def end_cell(self):
self.f.write(' | \n')
def start_paragraph(self,style_name,leader=None):
self.f.write('')
if leader != None:
self.f.write(leader)
self.f.write(' ')
def end_paragraph(self):
if self.empty == 1:
self.f.write(' ')
self.empty = 0
self.f.write('
\n')
def write_text(self,text):
if text != "":
self.empty = 0
text = string.replace(text,'\n','
')
self.f.write(text)