diff --git a/po/POTFILES.in b/po/POTFILES.in index 5649528b4..b338302e4 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -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 diff --git a/src/ReportBase/Makefile.am b/src/ReportBase/Makefile.am index 8f8d47e3e..2ac631c47 100644 --- a/src/ReportBase/Makefile.am +++ b/src/ReportBase/Makefile.am @@ -19,7 +19,6 @@ pkgdata_PYTHON = \ _ReportUtils.py\ _StyleComboBox.py\ _StyleEditor.py\ - _TemplateParser.py\ _TextReportDialog.py\ _WebReportDialog.py diff --git a/src/ReportBase/_CommandLineReport.py b/src/ReportBase/_CommandLineReport.py index 33bf1e935..9bc42e98c 100644 --- a/src/ReportBase/_CommandLineReport.py +++ b/src/ReportBase/_CommandLineReport.py @@ -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() diff --git a/src/ReportBase/_Constants.py b/src/ReportBase/_Constants.py index 47734abfc..1e1fa24dd 100644 --- a/src/ReportBase/_Constants.py +++ b/src/ReportBase/_Constants.py @@ -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"), ''], + ] diff --git a/src/ReportBase/_DocReportDialog.py b/src/ReportBase/_DocReportDialog.py index d4484e465..388f98a0a 100644 --- a/src/ReportBase/_DocReportDialog.py +++ b/src/ReportBase/_DocReportDialog.py @@ -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('%s'%_("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 diff --git a/src/ReportBase/_ReportDialog.py b/src/ReportBase/_ReportDialog.py index 895254b6d..60c888aed 100644 --- a/src/ReportBase/_ReportDialog.py +++ b/src/ReportBase/_ReportDialog.py @@ -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 diff --git a/src/ReportBase/_ReportOptions.py b/src/ReportBase/_ReportOptions.py index 90ee4e800..d8337b405 100644 --- a/src/ReportBase/_ReportOptions.py +++ b/src/ReportBase/_ReportOptions.py @@ -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(' \n' % (size[0], size[1]) ) if self.get_last_paper_name() != self.default_paper_name: f.write(' \n' % escxml(self.get_last_paper_name()) ) - if self.get_last_template_name() != self.default_template_name: - f.write('