02707: Add markup notes to html output

part 1: remove template from html output


svn: r12631
This commit is contained in:
Benny Malengier 2009-06-06 09:49:40 +00:00
parent aa499dfec7
commit 542b1e404d
18 changed files with 402 additions and 589 deletions

View File

@ -295,11 +295,13 @@ src/plugins/import/ImportProGen.py
src/plugins/import/ImportVCard.py
# plugins/lib directory
src/plugins/lib/libhtml.py
src/plugins/lib/libcairodoc.py
src/plugins/lib/libholiday.py
src/plugins/lib/libmapservice.py
src/plugins/lib/libgrampsxml.py
src/plugins/lib/libholiday.py
src/plugins/lib/libhtml.py
src/plugins/lib/libhtmlbackend.py
src/plugins/lib/libhtmlconst.py
src/plugins/lib/libmapservice.py
# plugins/mapservices directory
src/plugins/mapservices/eniroswedenmap.py
@ -448,7 +450,6 @@ src/ReportBase/_Report.py
src/ReportBase/_ReportUtils.py
src/ReportBase/_StyleComboBox.py
src/ReportBase/_StyleEditor.py
src/ReportBase/_TemplateParser.py
src/ReportBase/_TextReportDialog.py
# gen

View File

@ -19,7 +19,6 @@ pkgdata_PYTHON = \
_ReportUtils.py\
_StyleComboBox.py\
_StyleEditor.py\
_TemplateParser.py\
_TextReportDialog.py\
_WebReportDialog.py

View File

@ -328,7 +328,6 @@ class CommandLineReport(object):
self.option_class.handler.set_paper(self.paper)
self.orien = self.options_dict['papero']
self.template_name = self.options_dict['template']
if self.category in (CATEGORY_TEXT, CATEGORY_DRAW):
default_style = StyleSheet()

View File

@ -69,3 +69,22 @@ CATEGORY_QR_PLACE = 4
CATEGORY_QR_REPOSITORY = 5
CATEGORY_QR_NOTE = 6
CATEGORY_QR_DATE = 7
#Common data for html reports
## TODO: move to a system where css files are registered
# This information defines the list of styles in the Web reports
# options dialog as well as the location of the corresponding
# stylesheets in src/data.
CSS_FILES = [
# First is used as default selection.
[_("Basic-Ash"), 'Web_Basic-Ash.css'],
[_("Basic-Cypress"), 'Web_Basic-Cypress.css'],
[_("Basic-Lilac"), 'Web_Basic-Lilac.css'],
[_("Basic-Peach"), 'Web_Basic-Peach.css'],
[_("Basic-Spruce"), 'Web_Basic-Spruce.css'],
[_("Mainz"), 'Web_Mainz.css'],
[_("Nebraska"), 'Web_Nebraska.css'],
[_("Visually Impaired"), 'Web_Visually.css'],
[_("No style sheet"), ''],
]

View File

@ -42,8 +42,7 @@ import gtk
#-------------------------------------------------------------------------
import const
from _ReportDialog import ReportDialog
from _FileEntry import FileEntry
from _TemplateParser import _template_map, _default_template, _user_template
from _Constants import CSS_FILES
from _PaperMenu import PaperFrame
#-------------------------------------------------------------------------
@ -62,7 +61,7 @@ class DocReportDialog(ReportDialog):
for a basic *stand-alone* report."""
self.style_name = "default"
self.page_html_added = False
self.firstpage_added = False
ReportDialog.__init__(self, dbstate, uistate, option_class,
name, trans_name)
@ -90,7 +89,11 @@ class DocReportDialog(ReportDialog):
"""
pstyle = self.paper_frame.get_paper_style()
self.doc = self.format(self.selected_style, pstyle, self.template_name)
self.doc = self.format(self.selected_style, pstyle)
if not self.format_menu.get_active_plugin().get_paper_used():
#set css filename
self.doc.set_css_filename(const.DATA_DIR + os.sep +
self.css_filename)
self.options.set_document(self.doc)
@ -102,7 +105,7 @@ class DocReportDialog(ReportDialog):
formats for the report. It adjust the various dialog sections
to reflect the appropriate values for the currently selected
file format. For example, a HTML document doesn't need any
paper size/orientation options, but it does need a template
paper size/orientation options, but it does need a css
file. Those chances are made here."""
docgen_plugin = obj.get_active_plugin()
if docgen_plugin.get_extension():
@ -113,7 +116,7 @@ class DocReportDialog(ReportDialog):
# Is this to be a printed report or an electronic report
# (i.e. a set of web pages)
if self.page_html_added:
if self.firstpage_added:
self.notebook.remove_page(0)
if docgen_plugin.get_paper_used():
self.paper_label = gtk.Label('<b>%s</b>'%_("Paper Options"))
@ -125,6 +128,7 @@ class DocReportDialog(ReportDialog):
self.html_label.set_use_markup(True)
self.notebook.insert_page(self.html_table, self.html_label, 0)
self.html_table.show_all()
self.firstpage_added = True
ext_val = docgen_plugin.get_extension()
if ext_val:
@ -142,7 +146,6 @@ class DocReportDialog(ReportDialog):
if self.style_button:
self.style_button.set_sensitive(docgen_plugin.get_style_support())
self.style_menu.set_sensitive(docgen_plugin.get_style_support())
self.page_html_added = True
def setup_format_frame(self):
"""Set up the format frame of the dialog. This function
@ -182,70 +185,34 @@ class DocReportDialog(ReportDialog):
self.setup_html_frame()
ReportDialog.setup_report_options_frame(self)
def html_file_enable(self, obj):
active = obj.get_active()
text = unicode(obj.get_model()[active][0])
if text in _template_map:
if _template_map[text]:
self.html_fileentry.set_sensitive(0)
else:
self.html_fileentry.set_sensitive(1)
else:
self.html_fileentry.set_sensitive(0)
def setup_html_frame(self):
"""Set up the html frame of the dialog. This sole purpose of
this function is to grab a pointer for later use in the parse
html frame function."""
self.html_table = gtk.Table(3, 3)
self.html_table = gtk.Table(3,3)
self.html_table.set_col_spacings(12)
self.html_table.set_row_spacings(6)
self.html_table.set_border_width(0)
label = gtk.Label("%s:" % _("Template"))
label.set_alignment(0.0, 0.5)
label = gtk.Label("%s:" % _("CSS file"))
label.set_alignment(0.0,0.5)
self.html_table.attach(label, 1, 2, 1, 2, gtk.SHRINK|gtk.FILL,
yoptions=gtk.SHRINK)
self.template_combo = gtk.combo_box_new_text()
tlist = sorted(_template_map)
self.css_combo = gtk.combo_box_new_text()
template_name = self.options.handler.get_template_name()
self.template_combo.append_text(_default_template)
css_filename = self.options.handler.get_css_filename()
active_index = 0
for template_index, template in enumerate(sorted(_template_map)):
if template != _user_template:
self.template_combo.append_text(template)
if _template_map[template] == os.path.basename(template_name):
active_index = template_index
self.template_combo.append_text(_user_template)
index = 0
for style in CSS_FILES:
self.css_combo.append_text(style[0])
if css_filename == style[1]:
active_index = index
index += 1
self.template_combo.connect('changed', self.html_file_enable)
self.html_table.attach(self.template_combo, 2, 3, 1, 2,
yoptions=gtk.SHRINK)
label = gtk.Label("%s:" % _("User Template"))
label.set_alignment(0.0, 0.5)
self.html_table.attach(label, 1, 2, 2, 3, gtk.SHRINK|gtk.FILL,
yoptions=gtk.SHRINK)
self.html_fileentry = FileEntry("HTML_Template",
_("Choose File"))
if template_name and not active_index:
active_index = template_index
user_template = template_name
self.html_fileentry.set_sensitive(True)
else:
user_template = ''
self.html_fileentry.set_sensitive(False)
if os.path.isfile(user_template):
self.html_fileentry.set_filename(user_template)
self.html_table.attach(self.html_fileentry, 2, 3, 2, 3,
yoptions=gtk.SHRINK)
self.template_combo.set_active(active_index)
self.html_table.attach(self.css_combo,2,3,1,2, yoptions=gtk.SHRINK)
self.css_combo.set_active(active_index)
def parse_format_frame(self):
"""Parse the format frame of the dialog. Save the user
@ -254,7 +221,7 @@ class DocReportDialog(ReportDialog):
self.format = docgen_plugin.get_basedoc()
format_name = docgen_plugin.get_extension()
self.options.handler.set_format_name(format_name)
def parse_html_frame(self):
"""Parse the html frame of the dialog. Save the user selected
html template name for later use. Note that this routine
@ -262,19 +229,8 @@ class DocReportDialog(ReportDialog):
displayed on the screen. The subclass will know whether this
entry was enabled. This is for simplicity of programming."""
model = self.template_combo.get_model()
text = unicode(model[self.template_combo.get_active()][0])
if text in _template_map:
if text == _user_template:
self.template_name = self.html_fileentry.get_full_path(0)
else:
self.template_name = "%s%s%s" % (const.TEMPLATE_DIR,
os.path.sep,
_template_map[text])
else:
self.template_name = ""
self.options.handler.set_template_name(self.template_name)
self.css_filename = CSS_FILES[self.css_combo.get_active()][1]
self.options.handler.set_css_filename(self.css_filename)
def on_ok_clicked(self, obj):
"""The user is satisfied with the dialog choices. Validate

View File

@ -85,7 +85,7 @@ class ReportDialog(ManagedWindow.ManagedWindow):
for a basic *stand-alone* report."""
self.style_name = "default"
self.page_html_added = False
self.firstpage_added = False
self.raw_name = name
self.dbstate = dbstate
self.db = dbstate.db

View File

@ -76,8 +76,8 @@ class OptionList(_Options.OptionList):
self.orientation = None
self.custom_paper_size = [29.7, 21.0]
self.margins = [2.54, 2.54, 2.54, 2.54]
self.template_name = None
self.format_name = None
self.css_filename = None
def set_style_name(self, style_name):
"""
@ -197,21 +197,21 @@ class OptionList(_Options.OptionList):
"""
return self.margins[pos]
def set_template_name(self, template_name):
def set_css_filename(self, css_filename):
"""
Set the template name for the OptionList.
@param template_name: name of the template to set.
@type template_name: str
"""
self.template_name = template_name
self.css_filename = css_filename
def get_template_name(self):
def get_css_filename(self):
"""
Return the template name of the OptionList.
@returns: template name
@rtype: str
"""
return self.template_name
return self.css_filename
def set_format_name(self, format_name):
"""
@ -246,8 +246,8 @@ class OptionListCollection(_Options.OptionListCollection):
self.default_style_name = "default"
self.default_paper_metric = Config.get(Config.PAPER_METRIC)
self.default_paper_name = Config.get(Config.PAPER_PREFERENCE)
self.default_template_name = ""
self.default_orientation = PAPER_PORTRAIT
self.default_css_filename = ""
self.default_custom_paper_size = [29.7, 21.0]
self.default_margins = [2.54, 2.54, 2.54, 2.54]
self.default_format_name = 'print'
@ -257,7 +257,7 @@ class OptionListCollection(_Options.OptionListCollection):
self.last_orientation = self.default_orientation
self.last_custom_paper_size = copy.copy(self.default_custom_paper_size)
self.last_margins = copy.copy(self.default_margins)
self.last_template_name = self.default_template_name
self.last_css_filename = self.default_css_filename
self.last_format_name = self.default_format_name
self.option_list_map = {}
@ -365,19 +365,19 @@ class OptionListCollection(_Options.OptionListCollection):
"""
return self.last_margins[pos]
def set_last_template_name(self, template_name):
def set_last_css_filename(self, css_filename):
"""
Set the last template used for the any report in this collection.
template_name: name of the style to set.
"""
self.last_template_name = template_name
Set the last css used for the any report in this collection.
def get_last_template_name(self):
css_filename: name of the style to set.
"""
self.last_css_name = css_filename
def get_last_css_filename(self):
"""
Return the last template used for the any report in this collection.
"""
return self.last_template_name
return self.last_css_filename
def set_last_format_name(self, format_name):
"""
@ -402,8 +402,8 @@ class OptionListCollection(_Options.OptionListCollection):
f.write(' <size value="%f %f"/>\n' % (size[0], size[1]) )
if self.get_last_paper_name() != self.default_paper_name:
f.write(' <paper name="%s"/>\n' % escxml(self.get_last_paper_name()) )
if self.get_last_template_name() != self.default_template_name:
f.write(' <template name="%s"/>\n' % escxml(self.get_last_template_name()) )
if self.get_last_css_filename() != self.default_css_filename:
f.write(' <css name="%s"/>\n' % escxml(self.get_last_css_filename()) )
if self.get_last_format_name() != self.default_format_name:
f.write(' <format name="%s"/>\n' % escxml(self.get_last_format_name()) )
if self.get_last_orientation() != self.default_orientation:
@ -424,9 +424,9 @@ class OptionListCollection(_Options.OptionListCollection):
if option_list.get_paper_name() \
and option_list.get_paper_name() != self.default_paper_name:
f.write(' <paper name="%s"/>\n' % escxml(option_list.get_paper_name()) )
if option_list.get_template_name() \
and option_list.get_template_name() != self.default_template_name:
f.write(' <template name="%s"/>\n' % escxml(option_list.get_template_name()) )
if option_list.get_css_filename() \
and option_list.get_css_filename() != self.default_css_filename:
f.write(' <css name="%s"/>\n' % escxml(option_list.get_css_filename()))
if option_list.get_format_name() \
and option_list.get_format_name() != self.default_format_name:
f.write(' <format name="%s"/>\n' % escxml(option_list.get_format_name()) )
@ -487,11 +487,11 @@ class OptionParser(_Options.OptionParser):
self.collection.set_last_paper_name(attrs['name'])
else:
self.option_list.set_paper_name(attrs['name'])
elif tag == "template":
elif tag == "css":
if self.common:
self.collection.set_last_template_name(attrs['name'])
self.collection.set_last_css_filename(attrs['name'])
else:
self.option_list.set_template_name(attrs['name'])
self.option_list.set_css_filename(attrs['name'])
elif tag == "format":
if self.common:
self.collection.set_last_format_name(attrs['name'])
@ -587,8 +587,8 @@ class OptionHandler(_Options.OptionHandler):
self.paper_name = self.option_list_collection.get_last_paper_name()
self.orientation = self.option_list_collection.get_last_orientation()
self.custom_paper_size = self.option_list_collection.get_last_custom_paper_size()
self.css_filename = self.option_list_collection.get_last_css_filename()
self.margins = self.option_list_collection.get_last_margins()
self.template_name = self.option_list_collection.get_last_template_name()
self.format_name = self.option_list_collection.get_last_format_name()
def set_common_options(self):
@ -600,8 +600,8 @@ class OptionHandler(_Options.OptionHandler):
self.custom_paper_size = self.saved_option_list.get_custom_paper_size()
if self.saved_option_list.get_margins():
self.margins = self.saved_option_list.get_margins()
if self.saved_option_list.get_template_name():
self.template_name = self.saved_option_list.get_template_name()
if self.saved_option_list.get_css_filename():
self.css_filename = self.saved_option_list.get_css_filename()
if self.saved_option_list.get_paper_metric():
self.paper_metric = self.saved_option_list.get_paper_metric()
if self.saved_option_list.get_paper_name():
@ -615,9 +615,9 @@ class OptionHandler(_Options.OptionHandler):
self.saved_option_list.set_orientation(self.orientation)
self.saved_option_list.set_custom_paper_size(self.custom_paper_size)
self.saved_option_list.set_margins(self.margins)
self.saved_option_list.set_template_name(self.template_name)
self.saved_option_list.set_paper_metric(self.paper_metric)
self.saved_option_list.set_paper_name(self.paper_name)
self.saved_option_list.set_css_filename(self.css_filename)
self.saved_option_list.set_format_name(self.format_name)
self.option_list_collection.set_option_list(self.module_name,
self.saved_option_list)
@ -626,9 +626,9 @@ class OptionHandler(_Options.OptionHandler):
self.option_list_collection.set_last_orientation(self.orientation)
self.option_list_collection.set_last_custom_paper_size(self.custom_paper_size)
self.option_list_collection.set_last_margins(self.margins)
self.option_list_collection.set_last_template_name(self.template_name)
self.option_list_collection.set_last_paper_metric(self.paper_metric)
self.option_list_collection.set_last_paper_name(self.paper_name)
self.option_list_collection.set_last_css_filename(self.css_filename)
self.option_list_collection.set_last_format_name(self.format_name)
def get_stylesheet_savefile(self):
@ -672,11 +672,11 @@ class OptionHandler(_Options.OptionHandler):
"""
self.paper = paper
def get_template_name(self):
return self.template_name
def get_css_filename(self):
return self.css_filename
def set_template_name(self, template_name):
self.template_name = template_name
def set_css_filename(self, css_filename):
self.css_filename = css_filename
def get_orientation(self):
return self.orientation

View File

@ -1,113 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2001-2007 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id:_TemplateParser.py 9912 2008-01-22 09:17:46Z acraphae $
#-----------------------------------------------------------------------
#
# Python modules
#
#-----------------------------------------------------------------------
from gettext import gettext as _
import os
#-----------------------------------------------------------------------
#
# XML modules
#
#-----------------------------------------------------------------------
try:
from xml.sax import make_parser, handler,SAXParseException
except:
from _xmlplus.sax import make_parser, handler,SAXParseException
#-----------------------------------------------------------------------
#
# GRAMPS modules
#
#-----------------------------------------------------------------------
import const
#-----------------------------------------------------------------------
#
# Parser for templates file
#
#-----------------------------------------------------------------------
class TemplateParser(handler.ContentHandler):
"""
Interface to the document template file
"""
def __init__(self,data,fpath):
"""
Create a template parser. The parser loads map of tempate names
to the file containing the tempate.
data - dictionary that holds the name to path mappings
fpath - filename of the XML file
"""
handler.ContentHandler.__init__(self)
self.data = data
self.path = fpath
def setDocumentLocator(self,locator):
"""Set the XML document locator"""
self.locator = locator
def startElement(self,tag,attrs):
"""
Loads the dictionary when an XML tag of 'template' is found. The format
XML tag is <template title=\"name\" file=\"path\">
"""
if tag == "template":
self.data[attrs['title']] = attrs['file']
#-----------------------------------------------------------------------
#
# Initialization
#
#-----------------------------------------------------------------------
_default_template = _("Default Template")
_user_template = _("User Defined Template")
_template_map = {
_user_template : ""
}
try:
template_path = const.TEMPLATE_DIR
xmlfile = os.path.join(template_path, "templates.xml")
if os.path.isfile(xmlfile):
parser = make_parser()
parser.setContentHandler(TemplateParser(_template_map,template_path))
the_file = open(xmlfile)
parser.parse(the_file)
the_file.close()
template_path = const.USER_TEMPLATES
xmlfile = os.path.join(template_path, "templates.xml")
if os.path.isfile(xmlfile):
parser = make_parser()
parser.setContentHandler(TemplateParser(_template_map,template_path))
parser.parse(xmlfile)
except (IOError,OSError,SAXParseException):
pass

View File

@ -111,9 +111,8 @@ TOOL_OPTIONS = os.path.join(HOME_DIR, "tool_options.xml")
ENV_DIR = os.path.join(HOME_DIR, "env")
TEMP_DIR = os.path.join(HOME_DIR, "temp")
THUMB_DIR = os.path.join(HOME_DIR, "thumb")
USER_PLUGINS = os.path.join(HOME_DIR, "plugins")
USER_TEMPLATES = os.path.join(HOME_DIR, "templates")
THUMB_DIR = os.path.join(HOME_DIR, "thumb")
USER_PLUGINS = os.path.join(HOME_DIR, "plugins")
# dirs checked/made for each Gramps session
USER_DIRLIST = (HOME_DIR, ENV_DIR, TEMP_DIR, THUMB_DIR,
USER_PLUGINS, USER_TEMPLATES)
@ -138,7 +137,6 @@ RULE_GLADE = os.path.join(GLADE_DIR, "rule.glade")
PLUGINS_DIR = os.path.join(ROOT_DIR, "plugins")
DATA_DIR = os.path.join(ROOT_DIR, "data")
SYSTEM_FILTERS = os.path.join(DATA_DIR, "system_filters.xml")
TEMPLATE_DIR = os.path.join(DATA_DIR, "templates")
TIP_DATA = os.path.join(DATA_DIR, "tips.xml")
PAPERSIZE = os.path.join(DATA_DIR, "papersize.xml")

View File

@ -335,75 +335,3 @@ class DocBackend(object):
otext += opentag[1]
return otext
def _add_markup_from_styled(self, text, s_tags, split=''):
"""
Input is plain text, output is text with markup added according to the
s_tags which are assumed to be styledtexttags.
When split is given the text will be split over the value given, and
tags applied in such a way that it the text can be safely splitted in
pieces along split
@param text : str, a piece of text
@param s_tags : styledtexttags that must be applied to the text
@param split : str, optional. A string along which the output can
be safely split without breaking the styling.
As adding markup means original text must be escaped, ESCAPE_FUNC is
used
This can be used to convert the text of a styledtext to the format
needed for a document backend
Do not call this method in a report, use the write_markup method
@note: the algorithm is complex as it assumes mixing of tags is not
allowed: eg <b>text<i> here</b> not</i> is assumed invalid
as markup. If the s_tags require such a setup, what is returned
is <b>text</b><i><b> here</b> not</i>
overwrite this method if this complexity is not needed.
"""
FIRST = 0
LAST = 1
tagspos = {}
for s_tag in s_tags:
tag = self.find_tag_by_stag(s_tag)
if tag is not None:
for (start, end) in s_tag.ranges:
if start in tagspos:
tagspos[start] += [(tag, FIRST)]
else:
tagspos[start] = [(tag, FIRST)]
if end in tagspos:
tagspos[end] += [(tag, LAST)]
else:
tagspos[end] = [(tag, LAST)]
start = 0
end = len(text)
keylist = tagspos.keys()
keylist.sort()
keylist = [x for x in keylist if x<=len(text)]
opentags = []
otext = u"" #the output, text with markup
lensplit = len(split)
for pos in keylist:
#write text up to tag
if pos > start:
if split:
#make sure text can split
splitpos = text[start:pos].find(split)
while splitpos <> -1:
otext += self.ESCAPE_FUNC()(text[start:start+splitpos])
#close open tags
for opentag in reversed(opentags):
otext += opentag[1]
#add split text
otext += self.ESCAPE_FUNC()(split)
#open the tags again
for opentag in opentags:
otext += opentag[0]
#obtain new values
start = start + splitpos + lensplit
splitpos = text[start:pos].find(split)
otext += self.ESCAPE_FUNC()(text[start:pos])

View File

@ -61,7 +61,7 @@ class BaseDoc(object):
such as OpenOffice, AbiWord, and LaTeX are derived from this base
class, providing a common interface to all document generators.
"""
def __init__(self, styles, paper_style, template):
def __init__(self, styles, paper_style):
"""
Create a BaseDoc instance, which provides a document generation
interface. This class should never be instantiated directly, but
@ -71,10 +71,7 @@ class BaseDoc(object):
@param paper_style: PaperStyle instance containing information about
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.
"""
self.template = template
self.paper = paper_style
self._style_sheet = styles
self._creator = ""

View File

@ -1152,7 +1152,7 @@ class BookReportDialog(DocReportDialog):
def make_document(self):
"""Create a document of the type requested by the user."""
pstyle = self.paper_frame.get_paper_style()
self.doc = self.format(self.selected_style, pstyle, self.template_name)
self.doc = self.format(self.selected_style, pstyle)
self.rptlist = []
for item in self.book.get_item_list():

View File

@ -43,6 +43,7 @@ import tarfile
import const
import Errors
from gen.plug.docgen import BaseDoc, TextDoc, FONT_SANS_SERIF
from libhtmlbackend import HtmlBackend
from QuestionDialog import ErrorDialog, WarningDialog
import Utils
@ -94,10 +95,10 @@ _bottom = [
# HtmlDoc
#
#------------------------------------------------------------------------
class HtmlDoc(BaseDoc,TextDoc):
class HtmlDoc(BaseDoc, TextDoc):
def __init__(self,styles,type,template):
BaseDoc.__init__(self,styles,None,template)
def __init__(self,styles,type):
BaseDoc.__init__(self, styles, None)
self.year = time.localtime(time.time())[0]
self.ext = '.html'
self.meta = ""
@ -105,14 +106,18 @@ class HtmlDoc(BaseDoc,TextDoc):
self.map = None
self.f = None
self.filename = None
self.top = []
self.bottom = []
self.base = ""
self.load_template()
self.build_header()
self.style_declaration = None
self.image_dir = "images"
def set_css_filename(self, css_filename):
"""
Set the css file to use. The path must be included.
Note: DocReportDialog sets this for html doc
"""
self.css_filename = css_filename
def set_extension(self,val):
if val[0] != '.':
val = "." + val
@ -123,87 +128,6 @@ class HtmlDoc(BaseDoc,TextDoc):
def set_keywords(self,keywords):
self.meta = ",".join(keywords)
def load_tpkg(self):
start = re.compile(r"<!--\s*START\s*-->")
stop = re.compile(r"<!--\s*STOP\s*-->")
top_add = 1
bottom_add = 0
archive = tarfile.open(self.template)
self.map = {}
for tarinfo in archive:
self.map[tarinfo.name] = archive.extractfile(tarinfo)
templateFile = self.map['template.html']
while 1:
line = templateFile.readline()
if line == '':
break
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 is not None:
bottom_add = 1
self.bottom.append(line)
else:
self.bottom.append(line)
templateFile.close()
archive.close
if top_add == 1:
mymsg = _("The marker '<!-- START -->' was not in the template")
ErrorDialog(_("Template Error"),mymsg)
def load_html(self):
start = re.compile(r"<!--\s*START\s*-->")
stop = re.compile(r"<!--\s*STOP\s*-->")
top_add = 1
bottom_add = 0
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 is not None:
bottom_add = 1
self.bottom.append(line)
else:
self.bottom.append(line)
templateFile.close()
if top_add == 1:
mymsg = _("The marker '<!-- START -->' was not in the template")
ErrorDialog(_("Template Error"),mymsg)
def load_template(self):
if self.template:
try:
if self.template[-4:] == 'tpkg':
self.load_tpkg()
else:
self.load_html()
except IOError,msg:
mymsg = _("Could not open %s\nUsing the default template") % \
self.template
WarningDialog(mymsg,str(msg))
self.bottom = _bottom
self.top = _top
except:
mymsg = _("Could not open %s\nUsing the default template") % \
self.template
WarningDialog(mymsg)
self.bottom = _bottom
self.top = _top
else:
self.bottom = _bottom
self.top = _top
def process_line(self,line):
l = line.replace('$VERSION',const.VERSION)
@ -226,34 +150,13 @@ class HtmlDoc(BaseDoc,TextDoc):
except:
raise Errors.ReportError(_("Could not create %s") % self.filename)
if self.meta:
match = t_keyword_line_re.match(self.file_header)
if match:
g = match.groups()
line = "%s%s%s" % (g[0],self.meta,g[2])
else:
line = self.file_header
else:
line = self.file_header
self.f.write(line)
if not self.style_declaration:
self.build_style_declaration()
self.f.write(self.style_declaration)
def build_header(self):
self.fix_title("".join(self.top))
def fix_title(self,msg=None):
if msg is None:
match = t_header_line_re.match(self.file_header)
else:
match = t_header_line_re.match(msg)
if match:
m = match.groups()
self.file_header = '%s<TITLE>%s</TITLE>%s\n' % (m[0],m[1],m[2])
else:
self.file_header = "".join(self.top)
self.file_header = self.process_line(self.file_header)
## TODO REMOVE ??
pass
def build_style_declaration(self):
styles = self.get_style_sheet()
@ -330,8 +233,6 @@ class HtmlDoc(BaseDoc,TextDoc):
self.style_declaration = '\n'.join(text)
def close(self):
for line in self.bottom:
self.f.write(self.process_line(line))
self.f.close()
self.write_support_files()

View File

@ -8,9 +8,11 @@ pkgdatadir = $(datadir)/@PACKAGE@/plugins/lib
pkgdata_PYTHON = \
libcairodoc.py\
libgrampsxml.py\
libhtml.py\
libhtmlbackend.py\
libhtmlconst.py\
libholiday.py\
libmapservice.py\
libhtml.py
libmapservice.py
pkgpyexecdir = @pkgpyexecdir@/plugins/lib
pkgpythondir = @pkgpythondir@/plugins/lib

View File

@ -0,0 +1,159 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2009 Benny Malengier
#
# 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
#
# $Id: docbackend.py 12437 2009-04-13 02:11:49Z pez4brian $
"""Html and Html format management for the different reports
"""
#------------------------------------------------------------------------
#
# Python modules
#
#------------------------------------------------------------------------
from xml.sax.saxutils import escape
#-------------------------------------------------------------------------
#
# GTK modules
#
#-------------------------------------------------------------------------
#------------------------------------------------------------------------
#
# Gramps modules
#
#------------------------------------------------------------------------
from gen.plug.docbackend import DocBackend
from libhtml import Html
try:
from gen.plug import PluginManager, Plugin
from gettext import gettext as _
except ImportError:
print 'Plugin manager not imported.'
#------------------------------------------------------------------------
#
# Document Backend class for html pages
#
#------------------------------------------------------------------------
class HtmlBackend(DocBackend):
"""
Implementation for html pages
Contrary to other backends, we do not write to file but to a Html object
instead, writing out the file on close.
"""
STYLETAG_TO_PROPERTY = {
DocBackend.FONTCOLOR : 'font-color:%s;',
DocBackend.HIGHLIGHT : 'background-color:%s;',
DocBackend.FONTFACE : "font-family:'%s';",
DocBackend.FONTSIZE : 'font-size:%spx;',
}
# overwrite base class attributes, they become static var of CairoDoc
SUPPORTED_MARKUP = [
DocBackend.BOLD,
DocBackend.ITALIC,
DocBackend.UNDERLINE,
DocBackend.FONTFACE,
DocBackend.FONTSIZE,
DocBackend.FONTCOLOR,
DocBackend.HIGHLIGHT,
DocBackend.SUPERSCRIPT ]
STYLETAG_MARKUP = {
DocBackend.BOLD : ("<strong>", "</strong>"),
DocBackend.ITALIC : ("<em>", "</em>"),
DocBackend.UNDERLINE : ('<span style="text-decoration:underline;">',
"</span>"),
DocBackend.SUPERSCRIPT : ("<sup>", "</sup>"),
}
ESCAPE_FUNC = lambda x: escape
def __init__(self, filename=None):
"""
@param filename: path name of the file the backend works on
"""
DocBackend.__init__(self, filename)
self.html_page = None
self.html_header = None
self.html_body = None
def _create_xmltag(self, type, value):
"""
overwrites the method in DocBackend
creates the pango xml tags needed for non bool style types
"""
if type not in self.SUPPORTED_MARKUP:
return None
if type == DocBackend.FONTSIZE:
#size is in points
value = str(value)
return ('<span style="%s">' % (self.STYLETAG_TO_PROPERTY[type] %
(value)),
'</span>')
def open(self):
"""
overwrite method, htmlbackend creates a html object that is written on
close
"""
self.html_page, self.html_header, self.html_body = Html.page()
def __write(self, str):
""" a write to the file
"""
DocBackend.write(self, str)
def write(obj):
""" write to the html page. One can pass a html object, or a string
"""
self.html_body += obj
def close(self):
"""
write out the html to the page
"""
DocBackend.open(self)
self._html.write(self.__write)
DocBackend.close(self)
# ------------------------------------------
#
# Register Plugin
#
# -------------------------------------------
try:
PluginManager.get_instance().register_plugin(
Plugin(
name = __name__,
description = _("Manages a HTML file implementing DocBackend."),
module_name = __name__
)
)
except NameError:
print 'Plugin not registered.'

View File

@ -0,0 +1,130 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2007 Johan Gonqvist <johan.gronqvist@gmail.com>
# Copyright (C) 2007 Gary Burton <gary.burton@zen.co.uk>
# Copyright (C) 2007-2009 Stephane Charette <stephanecharette@gmail.com>
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2008 Jason M. Simanek <jason@bohemianalps.com>
# Copyright (C) 2008-2009 Rob G. Healey <robhealey1@gmail.com>
#
# 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
#
# $Id: NarrativeWeb.py 12593 2009-05-30 08:46:12Z robhealey1 $
#------------------------------------------------------------------------
#
# GRAMPS modules
#
#------------------------------------------------------------------------
try:
from gen.plug import PluginManager, Plugin
from gettext import gettext as _
except ImportError:
print 'Plugin manager not imported.'
#------------------------------------------------------------------------
#
# Constants
#
#------------------------------------------------------------------------
_CHARACTER_SETS = [
# First is used as default selection.
# As seen on the internet, ISO-xxx are listed as capital letters
[_('Unicode UTF-8 (recommended)'), 'UTF-8'],
['ISO-8859-1', 'ISO-8859-1' ],
['ISO-8859-2', 'ISO-8859-2' ],
['ISO-8859-3', 'ISO-8859-3' ],
['ISO-8859-4', 'ISO-8859-4' ],
['ISO-8859-5', 'ISO-8859-5' ],
['ISO-8859-6', 'ISO-8859-6' ],
['ISO-8859-7', 'ISO-8859-7' ],
['ISO-8859-8', 'ISO-8859-8' ],
['ISO-8859-9', 'ISO-8859-9' ],
['ISO-8859-10', 'ISO-8859-10' ],
['ISO-8859-13', 'ISO-8859-13' ],
['ISO-8859-14', 'ISO-8859-14' ],
['ISO-8859-15', 'ISO-8859-15' ],
['koi8_r', 'koi8_r', ],
]
_CC = [
'',
'<a rel="license" href="http://creativecommons.org/licenses/by/2.5/">'
'<img alt="Creative Commons License - By attribution" '
'title="Creative Commons License - By attribution" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nd/2.5/">'
'<img alt="Creative Commons License - By attribution, No derivations" '
'title="Creative Commons License - By attribution, No derivations" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">'
'<img alt="Creative Commons License - By attribution, Share-alike" '
'title="Creative Commons License - By attribution, Share-alike" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nc/2.5/">'
'<img alt="Creative Commons License - By attribution, Non-commercial" '
'title="Creative Commons License - By attribution, Non-commercial" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.5/">'
'<img alt="Creative Commons License - By attribution, Non-commercial, No derivations" '
'title="Creative Commons License - By attribution, Non-commercial, No derivations" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/2.5/">'
'<img alt="Creative Commons License - By attribution, Non-commerical, Share-alike" '
'title="Creative Commons License - By attribution, Non-commerical, Share-alike" '
'src="%(gif_fname)s" /></a>'
]
_COPY_OPTIONS = [
_('Standard copyright'),
# This must match _CC
_('Creative Commons - By attribution'),
_('Creative Commons - By attribution, No derivations'),
_('Creative Commons - By attribution, Share-alike'),
_('Creative Commons - By attribution, Non-commercial'),
_('Creative Commons - By attribution, Non-commercial, No derivations'),
_('Creative Commons - By attribution, Non-commercial, Share-alike'),
_('No copyright notice'),
]
# ------------------------------------------
#
# Register Plugin
#
# -------------------------------------------
try:
PluginManager.get_instance().register_plugin(
Plugin(
name = __name__,
description = _("Common constants for html files."),
module_name = __name__
)
)
except NameError:
print 'Plugin not registered.'

View File

@ -84,7 +84,7 @@ from gen.plug.menu import PersonOption, NumberOption, StringOption, \
BooleanOption, EnumeratedListOption, FilterOption, \
NoteOption, MediaOption, DestinationOption
from ReportBase import (Report, ReportUtils, MenuReportOptions, CATEGORY_WEB,
Bibliography)
Bibliography, CSS_FILES )
import Utils
import ThumbNails
import ImgManip
@ -96,6 +96,7 @@ from DateHandler import displayer as _dd
from DateHandler import parser as _dp
from gen.proxy import PrivateProxyDb, LivingProxyDb
from gen.lib.eventroletype import EventRoleType
from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS
#------------------------------------------------------------------------
#
@ -125,88 +126,6 @@ _HGAP = 30
_SHADOW = 5
_XOFFSET = 5
# This information defines the list of styles in the Narrative Web
# options dialog as well as the location of the corresponding SCREEN
# stylesheets.
_CSS_FILES = [
# First is used as default selection.
[_("Basic-Ash"), 'Web_Basic-Ash.css'],
[_("Basic-Cypress"), 'Web_Basic-Cypress.css'],
[_("Basic-Lilac"), 'Web_Basic-Lilac.css'],
[_("Basic-Peach"), 'Web_Basic-Peach.css'],
[_("Basic-Spruce"), 'Web_Basic-Spruce.css'],
[_("Mainz"), 'Web_Mainz.css'],
[_("Nebraska"), 'Web_Nebraska.css'],
[_("Visually Impaired"), 'Web_Visually.css'],
[_("No style sheet"), ''],
]
_CHARACTER_SETS = [
# First is used as default selection.
# As you see these on the internet, they are in full capital letters.
# UTF-8 is specifically identified instead of the entire unicode set.
[_('Unicode UTF-8 (recommended)'), 'UTF-8'],
['ISO-8859-1', 'ISO-8859-1' ],
['ISO-8859-2', 'ISO-8859-2' ],
['ISO-8859-3', 'ISO-8859-3' ],
['ISO-8859-4', 'ISO-8859-4' ],
['ISO-8859-5', 'ISO-8859-5' ],
['ISO-8859-6', 'ISO-8859-6' ],
['ISO-8859-7', 'ISO-8859-7' ],
['ISO-8859-8', 'ISO-8859-8' ],
['ISO-8859-9', 'ISO-8859-9' ],
['ISO-8859-10', 'ISO-8859-10' ],
['ISO-8859-13', 'ISO-8859-13' ],
['ISO-8859-14', 'ISO-8859-14' ],
['ISO-8859-15', 'ISO-8859-15' ],
['koi8_r', 'koi8_r', ],
]
_CC = [
'',
'<a rel="license" href="http://creativecommons.org/licenses/by/2.5/">'
'<img alt="Creative Commons License - By attribution" '
'title="Creative Commons License - By attribution" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nd/2.5/">'
'<img alt="Creative Commons License - By attribution, No derivations" '
'title="Creative Commons License - By attribution, No derivations" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">'
'<img alt="Creative Commons License - By attribution, Share-alike" '
'title="Creative Commons License - By attribution, Share-alike" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nc/2.5/">'
'<img alt="Creative Commons License - By attribution, Non-commercial" '
'title="Creative Commons License - By attribution, Non-commercial" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.5/">'
'<img alt="Creative Commons License - By attribution, Non-commercial, No derivations" '
'title="Creative Commons License - By attribution, Non-commercial, No derivations" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/2.5/">'
'<img alt="Creative Commons License - By attribution, Non-commerical, Share-alike" '
'title="Creative Commons License - By attribution, Non-commerical, Share-alike" '
'src="%(gif_fname)s" /></a>'
]
_COPY_OPTIONS = [
_('Standard copyright'),
_('Creative Commons - By attribution'),
_('Creative Commons - By attribution, No derivations'),
_('Creative Commons - By attribution, Share-alike'),
_('Creative Commons - By attribution, Non-commercial'),
_('Creative Commons - By attribution, Non-commercial, No derivations'),
_('Creative Commons - By attribution, Non-commercial, Share-alike'),
_('No copyright notice'),
]
wrapper = TextWrapper()
wrapper.break_log_words = True
wrapper.width = 20
@ -3571,8 +3490,8 @@ class NavWebOptions(MenuReportOptions):
cright.set_help( _("The copyright to be used for the web files"))
menu.add_option(category_name, "cright", cright)
css = EnumeratedListOption(_('StyleSheet'), _CSS_FILES[0][1])
for style in _CSS_FILES:
css = EnumeratedListOption(_('StyleSheet'), CSS_FILES[0][1])
for style in CSS_FILES:
css.add_item(style[1], style[0])
css.set_help( _('The stylesheet to be used for the web page'))
menu.add_option(category_name, "css", css)

View File

@ -56,7 +56,8 @@ from gen.lib import date, Date, Name, Person, NameType, EventType
import const
from GrampsCfg import get_researcher
from gen.plug import PluginManager
from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_WEB
from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_WEB, \
CSS_FILES
from gen.plug.menu import BooleanOption, NumberOption, StringOption, \
EnumeratedListOption, FilterOption, PersonOption, \
DestinationOption
@ -69,6 +70,7 @@ from BasicUtils import name_displayer as _nd
import libholiday
from libhtml import Html
from libhtmlconst import _CHARACTER_SETS, _CC, _COPY_OPTIONS
#------------------------------------------------------------------------
#
@ -82,90 +84,6 @@ _WEB_EXT = ['.html', '.htm', '.shtml', '.php', '.php3', '.cgi']
_CALENDARSCREEN = 'calendar-screen.css'
_CALENDARPRINT = 'calendar-print.css'
# This information defines the list of styles in the Web calendar
# options dialog as well as the location of the corresponding
# stylesheets.
_CSS_FILES = [
# First is used as default selection.
[_("Basic-Ash"), 'Web_Basic-Ash.css'],
[_("Basic-Cypress"), 'Web_Basic-Cypress.css'],
[_("Basic-Lilac"), 'Web_Basic-Lilac.css'],
[_("Basic-Peach"), 'Web_Basic-Peach.css'],
[_("Basic-Spruce"), 'Web_Basic-Spruce.css'],
[_("Mainz"), 'Web_Mainz.css'],
[_("Nebraska"), 'Web_Nebraska.css'],
[_("Visually Impaired"), 'Web_Visually.css'],
[_("No style sheet"), ''],
]
_CHARACTER_SETS = [
# First is used as default selection.
# As seen on the internet, ISO-xxx are listed as capital letters
[_('Unicode UTF-8 (recommended)'), 'UTF-8'],
['ISO-8859-1', 'ISO-8859-1' ],
['ISO-8859-2', 'ISO-8859-2' ],
['ISO-8859-3', 'ISO-8859-3' ],
['ISO-8859-4', 'ISO-8859-4' ],
['ISO-8859-5', 'ISO-8859-5' ],
['ISO-8859-6', 'ISO-8859-6' ],
['ISO-8859-7', 'ISO-8859-7' ],
['ISO-8859-8', 'ISO-8859-8' ],
['ISO-8859-9', 'ISO-8859-9' ],
['ISO-8859-10', 'ISO-8859-10' ],
['ISO-8859-13', 'ISO-8859-13' ],
['ISO-8859-14', 'ISO-8859-14' ],
['ISO-8859-15', 'ISO-8859-15' ],
['koi8_r', 'koi8_r', ],
]
_CC = [
'',
'<a rel="license" href="http://creativecommons.org/licenses/by/2.5/">'
'<img alt="Creative Commons License - By attribution" '
'title="Creative Commons License - By attribution" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nd/2.5/">'
'<img alt="Creative Commons License - By attribution, No derivations" '
'title="Creative Commons License - By attribution, No derivations" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">'
'<img alt="Creative Commons License - By attribution, Share-alike" '
'title="Creative Commons License - By attribution, Share-alike" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nc/2.5/">'
'<img alt="Creative Commons License - By attribution, Non-commercial" '
'title="Creative Commons License - By attribution, Non-commercial" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/2.5/">'
'<img alt="Creative Commons License - By attribution, Non-commercial, No derivations" '
'title="Creative Commons License - By attribution, Non-commercial, No derivations" '
'src="%(gif_fname)s" /></a>',
'<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/2.5/">'
'<img alt="Creative Commons License - By attribution, Non-commerical, Share-alike" '
'title="Creative Commons License - By attribution, Non-commerical, Share-alike" '
'src="%(gif_fname)s" /></a>'
]
_COPY_OPTIONS = [
_('Standard copyright'),
# This must match _CC
_('Creative Commons - By attribution'),
_('Creative Commons - By attribution, No derivations'),
_('Creative Commons - By attribution, Share-alike'),
_('Creative Commons - By attribution, Non-commercial'),
_('Creative Commons - By attribution, Non-commercial, No derivations'),
_('Creative Commons - By attribution, Non-commercial, Share-alike'),
_('No copyright notice'),
]
#------------------------------------------------------------------------
#
# WebCalReport
@ -1428,8 +1346,8 @@ class WebCalOptions(MenuReportOptions):
cright.set_help( _("The copyright to be used for the web files"))
menu.add_option(category_name, "cright", cright)
css = EnumeratedListOption(_('StyleSheet'), _CSS_FILES[0][1])
for style in _CSS_FILES:
css = EnumeratedListOption(_('StyleSheet'), CSS_FILES[0][1])
for style in CSS_FILES:
css.add_item(style[1], style[0])
css.set_help( _('The Style Sheet to be used for the web page'))
menu.add_option(category_name, "css", css)