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

@@ -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