From ecbde74066477df1975944f6239afb04d3980c1d Mon Sep 17 00:00:00 2001 From: Brian Matherly Date: Thu, 6 May 2010 03:40:30 +0000 Subject: [PATCH] Repair duplicated file contents resulting from 0003796 (Make export available when no GUI available). svn: r15332 --- src/cli/plug/__init__.py | 978 ------ src/gen/plug/_options.py | 954 ------ src/gen/plug/report/__init__.py | 68 - src/gen/plug/report/_bibliography.py | 486 --- src/gen/plug/report/_constants.py | 152 - src/gen/plug/report/_options.py | 1643 ---------- src/gen/plug/report/_paper.py | 228 -- src/gen/plug/report/_reportbase.py | 126 - src/gen/plug/report/endnotes.py | 360 -- src/gen/plug/report/utils.py | 582 ---- src/gui/plug/__init__.py | 100 - src/gui/plug/_dialogs.py | 636 ---- src/gui/plug/_guioptions.py | 3078 ------------------ src/gui/plug/report/__init__.py | 70 - src/gui/plug/report/_docreportdialog.py | 524 --- src/gui/plug/report/_drawreportdialog.py | 216 -- src/gui/plug/report/_fileentry.py | 204 -- src/gui/plug/report/_graphvizreportdialog.py | 2388 -------------- src/gui/plug/report/_options.py | 122 - src/gui/plug/report/_papermenu.py | 614 ---- src/gui/plug/report/_reportdialog.py | 1298 -------- src/gui/plug/report/_stylecombobox.py | 174 - src/gui/plug/report/_styleeditor.py | 758 ----- src/gui/plug/report/_textreportdialog.py | 218 -- src/gui/plug/report/_webreportdialog.py | 116 - src/gui/plug/tool.py | 622 ---- 26 files changed, 16715 deletions(-) diff --git a/src/cli/plug/__init__.py b/src/cli/plug/__init__.py index df43f2be7..dfc57e3f9 100644 --- a/src/cli/plug/__init__.py +++ b/src/cli/plug/__init__.py @@ -487,981 +487,3 @@ def run_report(db, name, **options_str_dict): options_str_dict) return clr return clr -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2001-2007 Donald N. Allingham -# Copyright (C) 2008 Lukasz Rymarczyk -# Copyright (C) 2008 Raphael Ackermann -# Copyright (C) 2008 Brian G. Matherly -# Copyright (C) 2010 Jakim Friant -# -# 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 -# -# -# cli.plug.__init__ -# -# $Id$ - - -#------------------------------------------------------------------------- -# -# Python modules -# -#------------------------------------------------------------------------- -from gen.ggettext import gettext as _ -import traceback -import os -import sys - -import logging -log = logging.getLogger(".") - -#------------------------------------------------------------------------- -# -# Gramps modules -# -#------------------------------------------------------------------------- -import Utils -from gen.plug import BasePluginManager -from gen.plug.docgen import (StyleSheet, StyleSheetList, PaperStyle, - PAPER_PORTRAIT, PAPER_LANDSCAPE) -from gen.plug.menu import (FamilyOption, PersonOption, NoteOption, - MediaOption, PersonListOption, NumberOption, - BooleanOption, DestinationOption, StringOption, - TextOption, EnumeratedListOption) -from gen.display.name import displayer as name_displayer -from Errors import ReportError -from gen.plug.report import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK, - CATEGORY_GRAPHVIZ, CATEGORY_CODE) -from gen.plug.report._paper import paper_sizes -import const -import DbState -from cli.grampscli import CLIManager - -#------------------------------------------------------------------------ -# -# Private Functions -# -#------------------------------------------------------------------------ -def _validate_options(options, dbase): - """ - Validate all options by making sure that their values are consistent with - the database. - - menu: The Menu class - dbase: the database the options will be applied to - """ - if not hasattr(options, "menu"): - print 'no menu' - return - menu = options.menu - - for name in menu.get_all_option_names(): - option = menu.get_option_by_name(name) - - if isinstance(option, PersonOption): - pid = option.get_value() - person = dbase.get_person_from_gramps_id(pid) - if not person: - person = dbase.get_default_person() - if not person: - phandle = dbase.iter_person_handles().next() - person = dbase.get_person_from_handle(phandle) - if not person: - print "ERROR: Please specify a person" - if person: - option.set_value(person.get_gramps_id()) - - elif isinstance(option, FamilyOption): - fid = option.get_value() - family = dbase.get_family_from_gramps_id(fid) - if not family: - person = dbase.get_default_person() - family_list = [] - family_handle = None - if person: - family_list = person.get_family_handle_list() - if family_list: - family_handle = family_list[0] - else: - family_handle = dbase.iter_family_handles().next() - if family_handle: - family = dbase.get_family_from_handle(family_handle) - option.set_value(family.get_gramps_id()) - else: - print "ERROR: Please specify a family" - -#------------------------------------------------------------------------ -# -# Command-line report -# -#------------------------------------------------------------------------ -class CommandLineReport(object): - """ - Provide a way to generate report from the command line. - """ - - def __init__(self, database, name, category, option_class, options_str_dict, - noopt=False): - - pmgr = BasePluginManager.get_instance() - self.__textdoc_plugins = [] - self.__drawdoc_plugins = [] - self.__bookdoc_plugins = [] - for plugin in pmgr.get_docgen_plugins(): - if plugin.get_text_support() and plugin.get_extension(): - self.__textdoc_plugins.append(plugin) - if plugin.get_draw_support() and plugin.get_extension(): - self.__drawdoc_plugins.append(plugin) - if plugin.get_text_support() and \ - plugin.get_draw_support() and \ - plugin.get_extension(): - self.__bookdoc_plugins.append(plugin) - - self.database = database - self.category = category - self.format = None - self.option_class = option_class(name, database) - self.option_class.load_previous_values() - _validate_options(self.option_class, database) - self.show = options_str_dict.pop('show', None) - self.options_str_dict = options_str_dict - self.init_standard_options(noopt) - self.init_report_options() - self.parse_options() - self.show_options() - - def init_standard_options(self, noopt): - """ - Initialize the options that are hard-coded into the report system. - """ - self.options_dict = { - 'of' : self.option_class.handler.module_name, - 'off' : self.option_class.handler.get_format_name(), - 'style' : \ - self.option_class.handler.get_default_stylesheet_name(), - 'papers' : self.option_class.handler.get_paper_name(), - 'papero' : self.option_class.handler.get_orientation(), - 'css' : self.option_class.handler.get_css_filename(), - } - - self.options_help = { - 'of' : ["=filename", "Output file name. MANDATORY", ""], - 'off' : ["=format", "Output file format.", []], - 'style' : ["=name", "Style name.", ""], - 'papers' : ["=name", "Paper size name.", ""], - 'papero' : ["=num", "Paper orientation number.", ""], - 'css' : ["=css filename", "CSS filename to use, html format" - " only", ""], - } - - if noopt: - return - - self.options_help['of'][2] = os.path.join(const.USER_HOME, - "whatever_name") - - if self.category == CATEGORY_TEXT: - for plugin in self.__textdoc_plugins: - self.options_help['off'][2].append( - plugin.get_extension() + "\t" + plugin.get_description() ) - elif self.category == CATEGORY_DRAW: - for plugin in self.__drawdoc_plugins: - self.options_help['off'][2].append( - plugin.get_extension() + "\t" + plugin.get_description() ) - elif self.category == CATEGORY_BOOK: - for plugin in self.__bookdoc_plugins: - self.options_help['off'][2].append( - plugin.get_extension() + "\t" + plugin.get_description() ) - else: - self.options_help['off'][2] = "NA" - - self.options_help['papers'][2] = \ - [ paper.get_name() for paper in paper_sizes - if paper.get_name() != _("Custom Size") ] - - self.options_help['papero'][2] = [ - "%d\tPortrait" % PAPER_PORTRAIT, - "%d\tLandscape" % PAPER_LANDSCAPE ] - - self.options_help['css'][2] = os.path.join(const.USER_HOME, - "whatever_name.css") - - if self.category in (CATEGORY_TEXT, CATEGORY_DRAW): - default_style = StyleSheet() - self.option_class.make_default_style(default_style) - - # Read all style sheets available for this item - style_file = self.option_class.handler.get_stylesheet_savefile() - self.style_list = StyleSheetList(style_file, default_style) - - self.options_help['style'][2] = self.style_list.get_style_names() - - def init_report_options(self): - """ - Initialize the options that are defined by each report. - """ - if not hasattr(self.option_class, "menu"): - return - menu = self.option_class.menu - for name in menu.get_all_option_names(): - option = menu.get_option_by_name(name) - self.options_dict[name] = option.get_value() - self.options_help[name] = [ "", option.get_help() ] - - if isinstance(option, PersonOption): - id_list = [] - for person_handle in self.database.get_person_handles(): - person = self.database.get_person_from_handle(person_handle) - id_list.append("%s\t%s" % ( - person.get_gramps_id(), - name_displayer.display(person))) - self.options_help[name].append(id_list) - elif isinstance(option, FamilyOption): - id_list = [] - for family in self.database.iter_families(): - mname = "" - fname = "" - mhandle = family.get_mother_handle() - if mhandle: - mother = self.database.get_person_from_handle(mhandle) - if mother: - mname = name_displayer.display(mother) - fhandle = family.get_father_handle() - if fhandle: - father = self.database.get_person_from_handle(fhandle) - if father: - fname = name_displayer.display(father) - text = "%s:\t%s, %s" % \ - (family.get_gramps_id(), fname, mname) - id_list.append(text) - self.options_help[name].append(id_list) - elif isinstance(option, NoteOption): - id_list = [] - for nhandle in self.database.get_note_handles(): - note = self.database.get_note_from_handle(nhandle) - id_list.append(note.get_gramps_id()) - self.options_help[name].append(id_list) - elif isinstance(option, MediaOption): - id_list = [] - for mhandle in self.database.get_media_object_handles(): - mobject = self.database.get_object_from_handle(mhandle) - id_list.append(mobject.get_gramps_id()) - self.options_help[name].append(id_list) - elif isinstance(option, PersonListOption): - self.options_help[name].append("") - elif isinstance(option, NumberOption): - self.options_help[name].append("A number") - elif isinstance(option, BooleanOption): - self.options_help[name].append(["0\tno", "1\tyes"]) - elif isinstance(option, DestinationOption): - self.options_help[name].append("A file system path") - elif isinstance(option, StringOption): - self.options_help[name].append("Any text") - elif isinstance(option, TextOption): - self.options_help[name].append("Any text") - elif isinstance(option, EnumeratedListOption): - ilist = [] - for (value, description) in option.get_items(): - ilist.append("%s\t%s" % (value, description)) - self.options_help[name].append(ilist) - else: - print "Unknown option: ", option - - def parse_options(self): - """ - Load the options that the user has entered. - """ - if not hasattr(self.option_class, "menu"): - return - menu = self.option_class.menu - menu_opt_names = menu.get_all_option_names() - for opt in self.options_str_dict: - if opt in self.options_dict: - converter = Utils.get_type_converter(self.options_dict[opt]) - self.options_dict[opt] = converter(self.options_str_dict[opt]) - self.option_class.handler.options_dict[opt] = \ - self.options_dict[opt] - - if opt in menu_opt_names: - option = menu.get_option_by_name(opt) - option.set_value(self.options_dict[opt]) - - else: - print "Ignoring unknown option: %s" % opt - - self.option_class.handler.output = self.options_dict['of'] - - self.css_filename = None - if self.category == CATEGORY_TEXT: - for plugin in self.__textdoc_plugins: - if plugin.get_extension() == self.options_dict['off']: - self.format = plugin.get_basedoc() - self.css_filename = self.options_dict['css'] - if self.format is None: - # Pick the first one as the default. - self.format = self.__textdoc_plugins[0].get_basedoc() - elif self.category == CATEGORY_DRAW: - for plugin in self.__drawdoc_plugins: - if plugin.get_extension() == self.options_dict['off']: - self.format = plugin.get_basedoc() - if self.format is None: - # Pick the first one as the default. - self.format = self.__drawdoc_plugins[0].get_basedoc() - elif self.category == CATEGORY_BOOK: - for plugin in self.__bookdoc_plugins: - if plugin.get_extension() == self.options_dict['off']: - self.format = plugin.get_basedoc() - if self.format is None: - # Pick the first one as the default. - self.format = self.__bookdoc_plugins[0].get_basedoc() - else: - self.format = None - - for paper in paper_sizes: - if paper.get_name() == self.options_dict['papers']: - self.paper = paper - self.option_class.handler.set_paper(self.paper) - - self.orien = self.options_dict['papero'] - - if self.category in (CATEGORY_TEXT, CATEGORY_DRAW): - default_style = StyleSheet() - self.option_class.make_default_style(default_style) - - # Read all style sheets available for this item - style_file = self.option_class.handler.get_stylesheet_savefile() - self.style_list = StyleSheetList(style_file, default_style) - - # Get the selected stylesheet - style_name = self.option_class.handler.get_default_stylesheet_name() - self.selected_style = self.style_list.get_style_sheet(style_name) - - def show_options(self): - """ - Print available options on the CLI. - """ - if not self.show: - return - elif self.show == 'all': - print " Available options:" - for key in self.options_dict: - if key in self.options_help: - opt = self.options_help[key] - # Make the output nicer to read, assume that tab has 8 spaces - tabs = '\t' if len(key) < 10 else '\t'*2 - print " %s%s%s (%s)" % (key, tabs, opt[1], opt[0]) - else: - print " %s" % key - print " Use 'show=option' to see description and acceptable values" - elif self.show in self.options_help: - opt = self.options_help[self.show] - tabs = '\t' if len(self.show) < 10 else '\t'*2 - print ' %s%s%s%s' % (self.show, tabs, opt[0], opt[1]) - print " Available values are:" - vals = opt[2] - if isinstance(vals, (list, tuple)): - for val in vals: - print " %s" % val - else: - print " %s" % opt[2] - - else: - #there was a show option given, but the option is invalid - print ("option %s not valid. Use 'show=all' to see all valid " - "options." % self.show) - -#------------------------------------------------------------------------ -# -# Command-line report generic task -# -#------------------------------------------------------------------------ -def cl_report(database, name, category, report_class, options_class, - options_str_dict): - - err_msg = _("Failed to write report. ") - clr = CommandLineReport(database, name, category, options_class, - options_str_dict) - - # Exit here if show option was given - if clr.show: - return - - # write report - try: - if category in [CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK, \ - CATEGORY_GRAPHVIZ]: - clr.option_class.handler.doc = clr.format( - clr.selected_style, - PaperStyle(clr.paper,clr.orien)) - if clr.css_filename is not None and hasattr(clr.option_class.handler.doc, 'set_css_filename'): - clr.option_class.handler.doc.set_css_filename(clr.css_filename) - MyReport = report_class(database, clr.option_class) - MyReport.doc.init() - MyReport.begin_report() - MyReport.write_report() - MyReport.end_report() - return clr - except ReportError, msg: - (m1, m2) = msg.messages() - print err_msg - print m1 - except: - if len(log.handlers) > 0: - log.error(err_msg, exc_info=True) - else: - print >> sys.stderr, err_msg - ## Something seems to eat the exception above. - ## Hack to re-get the exception: - try: - raise - except: - traceback.print_exc() - -def run_report(db, name, **options_str_dict): - """ - Given a database, run a given report. - - db is a Db database - - name is the name of a report - - options_str_dict is the same kind of options - given at the command line. For example: - - >>> run_report(db, "ancestor_report", off="txt", - of="ancestor-007.txt", pid="I37") - - returns CommandLineReport (clr) if successfully runs the report, - None otherwise. - - You can see: - options and values used in clr.option_class.options_dict - filename in clr.option_class.get_output() - """ - dbstate = DbState.DbState() - climanager = CLIManager(dbstate, False) # don't load db - climanager.do_reg_plugins() - pmgr = BasePluginManager.get_instance() - cl_list = pmgr.get_reg_reports() - clr = None - for pdata in cl_list: - if name == pdata.id: - mod = pmgr.load_plugin(pdata) - if not mod: - #import of plugin failed - return clr - category = pdata.category - report_class = getattr(mod, pdata.reportclass) - options_class = getattr(mod, pdata.optionclass) - if category in (CATEGORY_BOOK, CATEGORY_CODE): - options_class(db, name, category, - options_str_dict) - else: - clr = cl_report(db, name, category, - report_class, options_class, - options_str_dict) - return clr - return clr -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2001-2007 Donald N. Allingham -# Copyright (C) 2008 Lukasz Rymarczyk -# Copyright (C) 2008 Raphael Ackermann -# Copyright (C) 2008 Brian G. Matherly -# Copyright (C) 2010 Jakim Friant -# -# 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 -# -# -# cli.plug.__init__ -# -# $Id$ - - -#------------------------------------------------------------------------- -# -# Python modules -# -#------------------------------------------------------------------------- -from gen.ggettext import gettext as _ -import traceback -import os -import sys - -import logging -log = logging.getLogger(".") - -#------------------------------------------------------------------------- -# -# Gramps modules -# -#------------------------------------------------------------------------- -import Utils -from gen.plug import BasePluginManager -from gen.plug.docgen import (StyleSheet, StyleSheetList, PaperStyle, - PAPER_PORTRAIT, PAPER_LANDSCAPE) -from gen.plug.menu import (FamilyOption, PersonOption, NoteOption, - MediaOption, PersonListOption, NumberOption, - BooleanOption, DestinationOption, StringOption, - TextOption, EnumeratedListOption) -from gen.display.name import displayer as name_displayer -from Errors import ReportError -from gen.plug.report import (CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK, - CATEGORY_GRAPHVIZ, CATEGORY_CODE) -from gen.plug.report._paper import paper_sizes -import const -import DbState -from cli.grampscli import CLIManager - -#------------------------------------------------------------------------ -# -# Private Functions -# -#------------------------------------------------------------------------ -def _validate_options(options, dbase): - """ - Validate all options by making sure that their values are consistent with - the database. - - menu: The Menu class - dbase: the database the options will be applied to - """ - if not hasattr(options, "menu"): - print 'no menu' - return - menu = options.menu - - for name in menu.get_all_option_names(): - option = menu.get_option_by_name(name) - - if isinstance(option, PersonOption): - pid = option.get_value() - person = dbase.get_person_from_gramps_id(pid) - if not person: - person = dbase.get_default_person() - if not person: - phandle = dbase.iter_person_handles().next() - person = dbase.get_person_from_handle(phandle) - if not person: - print "ERROR: Please specify a person" - if person: - option.set_value(person.get_gramps_id()) - - elif isinstance(option, FamilyOption): - fid = option.get_value() - family = dbase.get_family_from_gramps_id(fid) - if not family: - person = dbase.get_default_person() - family_list = [] - family_handle = None - if person: - family_list = person.get_family_handle_list() - if family_list: - family_handle = family_list[0] - else: - family_handle = dbase.iter_family_handles().next() - if family_handle: - family = dbase.get_family_from_handle(family_handle) - option.set_value(family.get_gramps_id()) - else: - print "ERROR: Please specify a family" - -#------------------------------------------------------------------------ -# -# Command-line report -# -#------------------------------------------------------------------------ -class CommandLineReport(object): - """ - Provide a way to generate report from the command line. - """ - - def __init__(self, database, name, category, option_class, options_str_dict, - noopt=False): - - pmgr = BasePluginManager.get_instance() - self.__textdoc_plugins = [] - self.__drawdoc_plugins = [] - self.__bookdoc_plugins = [] - for plugin in pmgr.get_docgen_plugins(): - if plugin.get_text_support() and plugin.get_extension(): - self.__textdoc_plugins.append(plugin) - if plugin.get_draw_support() and plugin.get_extension(): - self.__drawdoc_plugins.append(plugin) - if plugin.get_text_support() and \ - plugin.get_draw_support() and \ - plugin.get_extension(): - self.__bookdoc_plugins.append(plugin) - - self.database = database - self.category = category - self.format = None - self.option_class = option_class(name, database) - self.option_class.load_previous_values() - _validate_options(self.option_class, database) - self.show = options_str_dict.pop('show', None) - self.options_str_dict = options_str_dict - self.init_standard_options(noopt) - self.init_report_options() - self.parse_options() - self.show_options() - - def init_standard_options(self, noopt): - """ - Initialize the options that are hard-coded into the report system. - """ - self.options_dict = { - 'of' : self.option_class.handler.module_name, - 'off' : self.option_class.handler.get_format_name(), - 'style' : \ - self.option_class.handler.get_default_stylesheet_name(), - 'papers' : self.option_class.handler.get_paper_name(), - 'papero' : self.option_class.handler.get_orientation(), - 'css' : self.option_class.handler.get_css_filename(), - } - - self.options_help = { - 'of' : ["=filename", "Output file name. MANDATORY", ""], - 'off' : ["=format", "Output file format.", []], - 'style' : ["=name", "Style name.", ""], - 'papers' : ["=name", "Paper size name.", ""], - 'papero' : ["=num", "Paper orientation number.", ""], - 'css' : ["=css filename", "CSS filename to use, html format" - " only", ""], - } - - if noopt: - return - - self.options_help['of'][2] = os.path.join(const.USER_HOME, - "whatever_name") - - if self.category == CATEGORY_TEXT: - for plugin in self.__textdoc_plugins: - self.options_help['off'][2].append( - plugin.get_extension() + "\t" + plugin.get_description() ) - elif self.category == CATEGORY_DRAW: - for plugin in self.__drawdoc_plugins: - self.options_help['off'][2].append( - plugin.get_extension() + "\t" + plugin.get_description() ) - elif self.category == CATEGORY_BOOK: - for plugin in self.__bookdoc_plugins: - self.options_help['off'][2].append( - plugin.get_extension() + "\t" + plugin.get_description() ) - else: - self.options_help['off'][2] = "NA" - - self.options_help['papers'][2] = \ - [ paper.get_name() for paper in paper_sizes - if paper.get_name() != _("Custom Size") ] - - self.options_help['papero'][2] = [ - "%d\tPortrait" % PAPER_PORTRAIT, - "%d\tLandscape" % PAPER_LANDSCAPE ] - - self.options_help['css'][2] = os.path.join(const.USER_HOME, - "whatever_name.css") - - if self.category in (CATEGORY_TEXT, CATEGORY_DRAW): - default_style = StyleSheet() - self.option_class.make_default_style(default_style) - - # Read all style sheets available for this item - style_file = self.option_class.handler.get_stylesheet_savefile() - self.style_list = StyleSheetList(style_file, default_style) - - self.options_help['style'][2] = self.style_list.get_style_names() - - def init_report_options(self): - """ - Initialize the options that are defined by each report. - """ - if not hasattr(self.option_class, "menu"): - return - menu = self.option_class.menu - for name in menu.get_all_option_names(): - option = menu.get_option_by_name(name) - self.options_dict[name] = option.get_value() - self.options_help[name] = [ "", option.get_help() ] - - if isinstance(option, PersonOption): - id_list = [] - for person_handle in self.database.get_person_handles(): - person = self.database.get_person_from_handle(person_handle) - id_list.append("%s\t%s" % ( - person.get_gramps_id(), - name_displayer.display(person))) - self.options_help[name].append(id_list) - elif isinstance(option, FamilyOption): - id_list = [] - for family in self.database.iter_families(): - mname = "" - fname = "" - mhandle = family.get_mother_handle() - if mhandle: - mother = self.database.get_person_from_handle(mhandle) - if mother: - mname = name_displayer.display(mother) - fhandle = family.get_father_handle() - if fhandle: - father = self.database.get_person_from_handle(fhandle) - if father: - fname = name_displayer.display(father) - text = "%s:\t%s, %s" % \ - (family.get_gramps_id(), fname, mname) - id_list.append(text) - self.options_help[name].append(id_list) - elif isinstance(option, NoteOption): - id_list = [] - for nhandle in self.database.get_note_handles(): - note = self.database.get_note_from_handle(nhandle) - id_list.append(note.get_gramps_id()) - self.options_help[name].append(id_list) - elif isinstance(option, MediaOption): - id_list = [] - for mhandle in self.database.get_media_object_handles(): - mobject = self.database.get_object_from_handle(mhandle) - id_list.append(mobject.get_gramps_id()) - self.options_help[name].append(id_list) - elif isinstance(option, PersonListOption): - self.options_help[name].append("") - elif isinstance(option, NumberOption): - self.options_help[name].append("A number") - elif isinstance(option, BooleanOption): - self.options_help[name].append(["0\tno", "1\tyes"]) - elif isinstance(option, DestinationOption): - self.options_help[name].append("A file system path") - elif isinstance(option, StringOption): - self.options_help[name].append("Any text") - elif isinstance(option, TextOption): - self.options_help[name].append("Any text") - elif isinstance(option, EnumeratedListOption): - ilist = [] - for (value, description) in option.get_items(): - ilist.append("%s\t%s" % (value, description)) - self.options_help[name].append(ilist) - else: - print "Unknown option: ", option - - def parse_options(self): - """ - Load the options that the user has entered. - """ - if not hasattr(self.option_class, "menu"): - return - menu = self.option_class.menu - menu_opt_names = menu.get_all_option_names() - for opt in self.options_str_dict: - if opt in self.options_dict: - converter = Utils.get_type_converter(self.options_dict[opt]) - self.options_dict[opt] = converter(self.options_str_dict[opt]) - self.option_class.handler.options_dict[opt] = \ - self.options_dict[opt] - - if opt in menu_opt_names: - option = menu.get_option_by_name(opt) - option.set_value(self.options_dict[opt]) - - else: - print "Ignoring unknown option: %s" % opt - - self.option_class.handler.output = self.options_dict['of'] - - self.css_filename = None - if self.category == CATEGORY_TEXT: - for plugin in self.__textdoc_plugins: - if plugin.get_extension() == self.options_dict['off']: - self.format = plugin.get_basedoc() - self.css_filename = self.options_dict['css'] - if self.format is None: - # Pick the first one as the default. - self.format = self.__textdoc_plugins[0].get_basedoc() - elif self.category == CATEGORY_DRAW: - for plugin in self.__drawdoc_plugins: - if plugin.get_extension() == self.options_dict['off']: - self.format = plugin.get_basedoc() - if self.format is None: - # Pick the first one as the default. - self.format = self.__drawdoc_plugins[0].get_basedoc() - elif self.category == CATEGORY_BOOK: - for plugin in self.__bookdoc_plugins: - if plugin.get_extension() == self.options_dict['off']: - self.format = plugin.get_basedoc() - if self.format is None: - # Pick the first one as the default. - self.format = self.__bookdoc_plugins[0].get_basedoc() - else: - self.format = None - - for paper in paper_sizes: - if paper.get_name() == self.options_dict['papers']: - self.paper = paper - self.option_class.handler.set_paper(self.paper) - - self.orien = self.options_dict['papero'] - - if self.category in (CATEGORY_TEXT, CATEGORY_DRAW): - default_style = StyleSheet() - self.option_class.make_default_style(default_style) - - # Read all style sheets available for this item - style_file = self.option_class.handler.get_stylesheet_savefile() - self.style_list = StyleSheetList(style_file, default_style) - - # Get the selected stylesheet - style_name = self.option_class.handler.get_default_stylesheet_name() - self.selected_style = self.style_list.get_style_sheet(style_name) - - def show_options(self): - """ - Print available options on the CLI. - """ - if not self.show: - return - elif self.show == 'all': - print " Available options:" - for key in self.options_dict: - if key in self.options_help: - opt = self.options_help[key] - # Make the output nicer to read, assume that tab has 8 spaces - tabs = '\t' if len(key) < 10 else '\t'*2 - print " %s%s%s (%s)" % (key, tabs, opt[1], opt[0]) - else: - print " %s" % key - print " Use 'show=option' to see description and acceptable values" - elif self.show in self.options_help: - opt = self.options_help[self.show] - tabs = '\t' if len(self.show) < 10 else '\t'*2 - print ' %s%s%s%s' % (self.show, tabs, opt[0], opt[1]) - print " Available values are:" - vals = opt[2] - if isinstance(vals, (list, tuple)): - for val in vals: - print " %s" % val - else: - print " %s" % opt[2] - - else: - #there was a show option given, but the option is invalid - print ("option %s not valid. Use 'show=all' to see all valid " - "options." % self.show) - -#------------------------------------------------------------------------ -# -# Command-line report generic task -# -#------------------------------------------------------------------------ -def cl_report(database, name, category, report_class, options_class, - options_str_dict): - - err_msg = _("Failed to write report. ") - clr = CommandLineReport(database, name, category, options_class, - options_str_dict) - - # Exit here if show option was given - if clr.show: - return - - # write report - try: - if category in [CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_BOOK, \ - CATEGORY_GRAPHVIZ]: - clr.option_class.handler.doc = clr.format( - clr.selected_style, - PaperStyle(clr.paper,clr.orien)) - if clr.css_filename is not None and hasattr(clr.option_class.handler.doc, 'set_css_filename'): - clr.option_class.handler.doc.set_css_filename(clr.css_filename) - MyReport = report_class(database, clr.option_class) - MyReport.doc.init() - MyReport.begin_report() - MyReport.write_report() - MyReport.end_report() - return clr - except ReportError, msg: - (m1, m2) = msg.messages() - print err_msg - print m1 - except: - if len(log.handlers) > 0: - log.error(err_msg, exc_info=True) - else: - print >> sys.stderr, err_msg - ## Something seems to eat the exception above. - ## Hack to re-get the exception: - try: - raise - except: - traceback.print_exc() - -def run_report(db, name, **options_str_dict): - """ - Given a database, run a given report. - - db is a Db database - - name is the name of a report - - options_str_dict is the same kind of options - given at the command line. For example: - - >>> run_report(db, "ancestor_report", off="txt", - of="ancestor-007.txt", pid="I37") - - returns CommandLineReport (clr) if successfully runs the report, - None otherwise. - - You can see: - options and values used in clr.option_class.options_dict - filename in clr.option_class.get_output() - """ - dbstate = DbState.DbState() - climanager = CLIManager(dbstate, False) # don't load db - climanager.do_reg_plugins() - pmgr = BasePluginManager.get_instance() - cl_list = pmgr.get_reg_reports() - clr = None - for pdata in cl_list: - if name == pdata.id: - mod = pmgr.load_plugin(pdata) - if not mod: - #import of plugin failed - return clr - category = pdata.category - report_class = getattr(mod, pdata.reportclass) - options_class = getattr(mod, pdata.optionclass) - if category in (CATEGORY_BOOK, CATEGORY_CODE): - options_class(db, name, category, - options_str_dict) - else: - clr = cl_report(db, name, category, - report_class, options_class, - options_str_dict) - return clr - return clr diff --git a/src/gen/plug/_options.py b/src/gen/plug/_options.py index 495e026a2..eedd9e1de 100644 --- a/src/gen/plug/_options.py +++ b/src/gen/plug/_options.py @@ -475,957 +475,3 @@ class Options(object): in the add_user_options() method above. """ pass -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2004-2005 Donald N. Allingham -# Copyright (C) 2010 Jakim Friant -# -# 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:_Options.py 9912 2008-01-22 09:17:46Z acraphae $ - -# Written by Alex Roitman - -""" -General option handling, including saving and parsing. -""" - -#------------------------------------------------------------------------- -# -# Standard Python modules -# -#------------------------------------------------------------------------- -import os - -#------------------------------------------------------------------------- -# -# SAX interface -# -#------------------------------------------------------------------------- -try: - from xml.sax import make_parser, handler,SAXParseException - from xml.sax.saxutils import quoteattr -except: - from _xmlplus.sax import make_parser, handler,SAXParseException - from _xmlplus.sax.saxutils import quoteattr - -#------------------------------------------------------------------------- -# -# gramps modules -# -#------------------------------------------------------------------------- -import Utils - -#------------------------------------------------------------------------- -# -# List of options for a single module -# -#------------------------------------------------------------------------- -class OptionList(object): - """ - Implements a set of options to parse and store for a given module. - """ - - def __init__(self): - self.options = {} - - def set_options(self, options): - """ - Set the whole bunch of options for the OptionList. - @param options: list of options to set. - @type options: list - """ - self.options = options - - def get_options(self): - """ - Return the whole bunch of options for the OptionList. - @returns: list of options - @rtype: list - """ - return self.options - - def set_option(self, name,value): - """ - Set a particular option in the OptionList. - @param name: name of the option to set. - @type name: str - @param value: value of the option to set. - @type str - """ - self.options[name] = value - - def remove_option(self, name): - """ - Remove a particular option from the OptionList. - @param name: name of the option to remove. - @type name: str - """ - if name in self.options: - del self.options[name] - - def get_option(self, name): - """ - Return the value of a particular option in the OptionList. - @param name: name of the option to retrieve - @type name: str - @returns: value associated with the passed option - @rtype: str - """ - return self.options.get(name,None) - -#------------------------------------------------------------------------- -# -# Collection of option lists -# -#------------------------------------------------------------------------- -class OptionListCollection(object): - """ - Implements a collection of option lists. - """ - - def __init__(self,filename): - """ - Create an OptionListCollection instance from the list defined - in the specified file. - @param filename: XML file that contains option definitions - @type filename: str - """ - - self.filename = os.path.expanduser(filename) - self.option_list_map = {} - self.init_common() - self.parse() - - def init_common(self): - pass - - def get_option_list_map(self): - """ - Return the map of module names to option lists. - @returns: Returns the map of module names to option lists. - @rtype: dictionary - """ - return self.option_list_map - - def get_option_list(self, name): - """ - Return the option_list associated with the module name - @param name: name associated with the desired module. - @type name: str - @returns: returns the option list associated with the name, - or None of no such option exists - @rtype: str - """ - return self.option_list_map.get(name,None) - - def get_module_names(self): - """ - Return a list of all the module names in the OptionListCollection - @returns: returns the list of module names - @rtype: list - """ - return self.option_list_map.keys() - - def set_option_list(self, name, option_list): - """ - Add or replaces an option_list in the OptionListCollection. - @param name: name associated with the module to add or replace. - @type name: str - @param option_list: list of options - @type option_list: str - """ - self.option_list_map[name] = option_list - - def write_common(self,f): - """ - Stub function for common options. Overridden by reports. - """ - pass - - def write_module_common(self,f, option_list): - """ - Stub function for common options. Overridden by reports. - """ - pass - - def save(self): - """ - Saves the current OptionListCollection to the associated file. - """ - f = open(self.filename,"w") - f.write("\n") - f.write('\n') - - self.write_common(f) - - for module_name in self.get_module_names(): - option_list = self.get_option_list(module_name) - f.write('\n' % quoteattr(module_name)) - options = option_list.get_options() - for option_name, option_data in options.iteritems(): - if isinstance(option_data, (list, tuple)): - f.write(' \n') - else: - f.write(' \n') - - f.write('\n') - f.close() - - def parse(self): - """ - Loads the OptionList from the associated file, if it exists. - """ - try: - if os.path.isfile(self.filename): - p = make_parser() - p.setContentHandler(OptionParser(self)) - p.parse(self.filename) - except (IOError,OSError,SAXParseException): - pass - -#------------------------------------------------------------------------- -# -# OptionParser -# -#------------------------------------------------------------------------- -class OptionParser(handler.ContentHandler): - """ - SAX parsing class for the OptionListCollection XML file. - """ - - def __init__(self,collection): - """ - Create a OptionParser class that populates the passed collection. - - collection: OptionListCollection to be loaded from the file. - """ - handler.ContentHandler.__init__(self) - self.collection = collection - - self.mname = None - self.option_list = None - self.oname = None - self.o = None - self.an_o = None - self.list_class = OptionList - - def startElement(self,tag,attrs): - """ - Overridden class that handles the start of a XML element - """ - if tag in ("report","module"): - self.mname = attrs['name'] - self.option_list = self.list_class() - self.o = {} - elif tag == "option": - self.oname = attrs['name'] - if attrs.has_key('length'): - self.an_o = [] - else: - self.an_o = attrs['value'] - elif tag == "listitem": - self.an_o.append(attrs['value']) - - def endElement(self,tag): - "Overridden class that handles the end of a XML element" - if tag == "option": - self.o[self.oname] = self.an_o - elif tag in ("report","module"): - self.option_list.set_options(self.o) - self.collection.set_option_list(self.mname,self.option_list) - -#------------------------------------------------------------------------- -# -# Class handling options for plugins -# -#------------------------------------------------------------------------- -class OptionHandler(object): - """ - Implements handling of the options for the plugins. - """ - - def __init__(self,module_name, options_dict,person_id=None): - self.module_name = module_name - self.default_options_dict = options_dict.copy() - self.options_dict = options_dict - - # Retrieve our options from whole collection - self.init_subclass() - self.option_list_collection = self.collection_class(self.filename) - self.init_common() - self.saved_option_list = self.option_list_collection.get_option_list(module_name) - self.person_id = person_id - - # Whatever was found should override the defaults - if self.saved_option_list: - self.set_options() - else: - # If nothing was found, set up the option list - self.saved_option_list = self.list_class() - self.option_list_collection.set_option_list(module_name, - self.saved_option_list) - - def init_subclass(self): - self.collection_class = OptionListCollection - self.list_class = OptionList - self.filename = None - - def init_common(self): - pass - - def set_options(self): - """ - Set options to be used in this plugin according to the passed - options dictionary. - - Dictionary values are all strings, since they were read from XML. - Here we need to convert them to the needed types. We use default - values to determine the type. - """ - # First we set options_dict values based on the saved options - options = self.saved_option_list.get_options() - bad_opts = [] - for option_name, option_data in options.iteritems(): - if option_name not in self.options_dict: - print "Option %s is present in the %s but is not known "\ - "to the module." % (option_name, - self.option_list_collection.filename) - print "Ignoring..." - bad_opts.append(option_name) - continue - try: - converter = Utils.get_type_converter(self.options_dict[option_name]) - self.options_dict[option_name] = converter(option_data) - except ValueError: - pass - except TypeError: - pass - - for option_name in bad_opts: - options.pop(option_name) - - # Then we set common options from whatever was found - self.set_common_options() - - def set_common_options(self): - pass - - def save_options(self): - """ - Saves options to file. - - We need to only store non-default options. Therefore, we remove all - options whose values are the defaults prior to saving. - """ - - # First we save options from options_dict - for option_name, option_data in self.options_dict.iteritems(): - if option_data == self.default_options_dict[option_name]: - self.saved_option_list.remove_option(option_name) - else: - self.saved_option_list.set_option(option_name,self.options_dict[option_name]) - - # Handle common options - self.save_common_options() - - # Finally, save the whole collection into file - self.option_list_collection.save() - - def save_common_options(self): - pass - - def get_person_id(self): - return self.person_id - - def set_person_id(self,val): - self.person_id = val - -#------------------------------------------------------------------------ -# -# Base Options class -# -#------------------------------------------------------------------------ -class Options(object): - - """ - Defines options and provides handling interface. - - This is a base Options class for the modules. All modules, options - classes should derive from it. - """ - - def __init__(self, name,person_id=None): - """ - Initialize the class, performing usual house-keeping tasks. - Subclasses MUST call this in their __init__() method. - - Modules that need custom options need to override this method. - Two dictionaries allow the addition of custom options: - - self.options_dict - This is a dictionary whose keys are option names - and values are the default option values. - - self.options_help - This is a dictionary whose keys are option names - and values are 3- or 4- lists or tuples: - ('=example','Short description',VALUES,DO_PREPEND) - The VALUES is either a single string (in that case - the DO_PREPEND does not matter) or a list/tuple of - strings to list. In that case, if DO_PREPEND evaluates - as True then each string will be preneded with the ordinal - number when help is printed on the command line. - - NOTE: Both dictionaries must have identical keys. - """ - self.name = name - self.person_id = person_id - self.options_dict = {} - self.options_help = {} - self.handler = None - - def load_previous_values(self): - """ - Modifies all options to have the value they were last used as. Call this - function after all options have been added. - """ - self.handler = OptionHandler(self.name,self.options_dict,self.person_id) - - def add_user_options(self,dialog): - """ - Set up UI controls (widgets) for the options specific for this modul. - - This method MUST be overridden by modules that define new options. - The single argument 'dialog' is the Report.ReportDialog instance. - Any attribute of the dialog is available. - - After the widgets are defined, they MUST be added to the dialog - using the following call: - dialog.add_options(LABEL,widget) - - NOTE: To really have any effect besides looking pretty, each widget - set up here must be also parsed in the parse_user_options() - method below. - """ - pass - - def parse_user_options(self,dialog): - """ - Parses UI controls (widgets) for the options specific for this module. - - This method MUST be overridden by modules that define new options. - The single argument 'dialog' is the Report.ReportDialog instance. - Any attribute of the dialog is available. - - After obtaining values from the widgets, they MUST be used to set the - appropriate options_dict values. Otherwise the values will not have - any user-visible effect. - - NOTE: Any widget parsed here MUST be defined and added to the dialog - in the add_user_options() method above. - """ - pass -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2004-2005 Donald N. Allingham -# Copyright (C) 2010 Jakim Friant -# -# 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:_Options.py 9912 2008-01-22 09:17:46Z acraphae $ - -# Written by Alex Roitman - -""" -General option handling, including saving and parsing. -""" - -#------------------------------------------------------------------------- -# -# Standard Python modules -# -#------------------------------------------------------------------------- -import os - -#------------------------------------------------------------------------- -# -# SAX interface -# -#------------------------------------------------------------------------- -try: - from xml.sax import make_parser, handler,SAXParseException - from xml.sax.saxutils import quoteattr -except: - from _xmlplus.sax import make_parser, handler,SAXParseException - from _xmlplus.sax.saxutils import quoteattr - -#------------------------------------------------------------------------- -# -# gramps modules -# -#------------------------------------------------------------------------- -import Utils - -#------------------------------------------------------------------------- -# -# List of options for a single module -# -#------------------------------------------------------------------------- -class OptionList(object): - """ - Implements a set of options to parse and store for a given module. - """ - - def __init__(self): - self.options = {} - - def set_options(self, options): - """ - Set the whole bunch of options for the OptionList. - @param options: list of options to set. - @type options: list - """ - self.options = options - - def get_options(self): - """ - Return the whole bunch of options for the OptionList. - @returns: list of options - @rtype: list - """ - return self.options - - def set_option(self, name,value): - """ - Set a particular option in the OptionList. - @param name: name of the option to set. - @type name: str - @param value: value of the option to set. - @type str - """ - self.options[name] = value - - def remove_option(self, name): - """ - Remove a particular option from the OptionList. - @param name: name of the option to remove. - @type name: str - """ - if name in self.options: - del self.options[name] - - def get_option(self, name): - """ - Return the value of a particular option in the OptionList. - @param name: name of the option to retrieve - @type name: str - @returns: value associated with the passed option - @rtype: str - """ - return self.options.get(name,None) - -#------------------------------------------------------------------------- -# -# Collection of option lists -# -#------------------------------------------------------------------------- -class OptionListCollection(object): - """ - Implements a collection of option lists. - """ - - def __init__(self,filename): - """ - Create an OptionListCollection instance from the list defined - in the specified file. - @param filename: XML file that contains option definitions - @type filename: str - """ - - self.filename = os.path.expanduser(filename) - self.option_list_map = {} - self.init_common() - self.parse() - - def init_common(self): - pass - - def get_option_list_map(self): - """ - Return the map of module names to option lists. - @returns: Returns the map of module names to option lists. - @rtype: dictionary - """ - return self.option_list_map - - def get_option_list(self, name): - """ - Return the option_list associated with the module name - @param name: name associated with the desired module. - @type name: str - @returns: returns the option list associated with the name, - or None of no such option exists - @rtype: str - """ - return self.option_list_map.get(name,None) - - def get_module_names(self): - """ - Return a list of all the module names in the OptionListCollection - @returns: returns the list of module names - @rtype: list - """ - return self.option_list_map.keys() - - def set_option_list(self, name, option_list): - """ - Add or replaces an option_list in the OptionListCollection. - @param name: name associated with the module to add or replace. - @type name: str - @param option_list: list of options - @type option_list: str - """ - self.option_list_map[name] = option_list - - def write_common(self,f): - """ - Stub function for common options. Overridden by reports. - """ - pass - - def write_module_common(self,f, option_list): - """ - Stub function for common options. Overridden by reports. - """ - pass - - def save(self): - """ - Saves the current OptionListCollection to the associated file. - """ - f = open(self.filename,"w") - f.write("\n") - f.write('\n') - - self.write_common(f) - - for module_name in self.get_module_names(): - option_list = self.get_option_list(module_name) - f.write('\n' % quoteattr(module_name)) - options = option_list.get_options() - for option_name, option_data in options.iteritems(): - if isinstance(option_data, (list, tuple)): - f.write(' \n') - else: - f.write(' \n') - - f.write('\n') - f.close() - - def parse(self): - """ - Loads the OptionList from the associated file, if it exists. - """ - try: - if os.path.isfile(self.filename): - p = make_parser() - p.setContentHandler(OptionParser(self)) - p.parse(self.filename) - except (IOError,OSError,SAXParseException): - pass - -#------------------------------------------------------------------------- -# -# OptionParser -# -#------------------------------------------------------------------------- -class OptionParser(handler.ContentHandler): - """ - SAX parsing class for the OptionListCollection XML file. - """ - - def __init__(self,collection): - """ - Create a OptionParser class that populates the passed collection. - - collection: OptionListCollection to be loaded from the file. - """ - handler.ContentHandler.__init__(self) - self.collection = collection - - self.mname = None - self.option_list = None - self.oname = None - self.o = None - self.an_o = None - self.list_class = OptionList - - def startElement(self,tag,attrs): - """ - Overridden class that handles the start of a XML element - """ - if tag in ("report","module"): - self.mname = attrs['name'] - self.option_list = self.list_class() - self.o = {} - elif tag == "option": - self.oname = attrs['name'] - if attrs.has_key('length'): - self.an_o = [] - else: - self.an_o = attrs['value'] - elif tag == "listitem": - self.an_o.append(attrs['value']) - - def endElement(self,tag): - "Overridden class that handles the end of a XML element" - if tag == "option": - self.o[self.oname] = self.an_o - elif tag in ("report","module"): - self.option_list.set_options(self.o) - self.collection.set_option_list(self.mname,self.option_list) - -#------------------------------------------------------------------------- -# -# Class handling options for plugins -# -#------------------------------------------------------------------------- -class OptionHandler(object): - """ - Implements handling of the options for the plugins. - """ - - def __init__(self,module_name, options_dict,person_id=None): - self.module_name = module_name - self.default_options_dict = options_dict.copy() - self.options_dict = options_dict - - # Retrieve our options from whole collection - self.init_subclass() - self.option_list_collection = self.collection_class(self.filename) - self.init_common() - self.saved_option_list = self.option_list_collection.get_option_list(module_name) - self.person_id = person_id - - # Whatever was found should override the defaults - if self.saved_option_list: - self.set_options() - else: - # If nothing was found, set up the option list - self.saved_option_list = self.list_class() - self.option_list_collection.set_option_list(module_name, - self.saved_option_list) - - def init_subclass(self): - self.collection_class = OptionListCollection - self.list_class = OptionList - self.filename = None - - def init_common(self): - pass - - def set_options(self): - """ - Set options to be used in this plugin according to the passed - options dictionary. - - Dictionary values are all strings, since they were read from XML. - Here we need to convert them to the needed types. We use default - values to determine the type. - """ - # First we set options_dict values based on the saved options - options = self.saved_option_list.get_options() - bad_opts = [] - for option_name, option_data in options.iteritems(): - if option_name not in self.options_dict: - print "Option %s is present in the %s but is not known "\ - "to the module." % (option_name, - self.option_list_collection.filename) - print "Ignoring..." - bad_opts.append(option_name) - continue - try: - converter = Utils.get_type_converter(self.options_dict[option_name]) - self.options_dict[option_name] = converter(option_data) - except ValueError: - pass - except TypeError: - pass - - for option_name in bad_opts: - options.pop(option_name) - - # Then we set common options from whatever was found - self.set_common_options() - - def set_common_options(self): - pass - - def save_options(self): - """ - Saves options to file. - - We need to only store non-default options. Therefore, we remove all - options whose values are the defaults prior to saving. - """ - - # First we save options from options_dict - for option_name, option_data in self.options_dict.iteritems(): - if option_data == self.default_options_dict[option_name]: - self.saved_option_list.remove_option(option_name) - else: - self.saved_option_list.set_option(option_name,self.options_dict[option_name]) - - # Handle common options - self.save_common_options() - - # Finally, save the whole collection into file - self.option_list_collection.save() - - def save_common_options(self): - pass - - def get_person_id(self): - return self.person_id - - def set_person_id(self,val): - self.person_id = val - -#------------------------------------------------------------------------ -# -# Base Options class -# -#------------------------------------------------------------------------ -class Options(object): - - """ - Defines options and provides handling interface. - - This is a base Options class for the modules. All modules, options - classes should derive from it. - """ - - def __init__(self, name,person_id=None): - """ - Initialize the class, performing usual house-keeping tasks. - Subclasses MUST call this in their __init__() method. - - Modules that need custom options need to override this method. - Two dictionaries allow the addition of custom options: - - self.options_dict - This is a dictionary whose keys are option names - and values are the default option values. - - self.options_help - This is a dictionary whose keys are option names - and values are 3- or 4- lists or tuples: - ('=example','Short description',VALUES,DO_PREPEND) - The VALUES is either a single string (in that case - the DO_PREPEND does not matter) or a list/tuple of - strings to list. In that case, if DO_PREPEND evaluates - as True then each string will be preneded with the ordinal - number when help is printed on the command line. - - NOTE: Both dictionaries must have identical keys. - """ - self.name = name - self.person_id = person_id - self.options_dict = {} - self.options_help = {} - self.handler = None - - def load_previous_values(self): - """ - Modifies all options to have the value they were last used as. Call this - function after all options have been added. - """ - self.handler = OptionHandler(self.name,self.options_dict,self.person_id) - - def add_user_options(self,dialog): - """ - Set up UI controls (widgets) for the options specific for this modul. - - This method MUST be overridden by modules that define new options. - The single argument 'dialog' is the Report.ReportDialog instance. - Any attribute of the dialog is available. - - After the widgets are defined, they MUST be added to the dialog - using the following call: - dialog.add_options(LABEL,widget) - - NOTE: To really have any effect besides looking pretty, each widget - set up here must be also parsed in the parse_user_options() - method below. - """ - pass - - def parse_user_options(self,dialog): - """ - Parses UI controls (widgets) for the options specific for this module. - - This method MUST be overridden by modules that define new options. - The single argument 'dialog' is the Report.ReportDialog instance. - Any attribute of the dialog is available. - - After obtaining values from the widgets, they MUST be used to set the - appropriate options_dict values. Otherwise the values will not have - any user-visible effect. - - NOTE: Any widget parsed here MUST be defined and added to the dialog - in the add_user_options() method above. - """ - pass diff --git a/src/gen/plug/report/__init__.py b/src/gen/plug/report/__init__.py index dd05749cc..5404f74df 100644 --- a/src/gen/plug/report/__init__.py +++ b/src/gen/plug/report/__init__.py @@ -32,71 +32,3 @@ from _reportbase import Report from _bibliography import Bibliography, Citation -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2001 David R. Hampton -# Copyright (C) 2001-2006 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly -# Copyright (C) 2010 Jakim Friant -# -# 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 -# - -# gen.plug.report.__init__ -# -# $Id: __init__.py 12360 2009-03-19 02:32:16Z pez4brian $ - -"Report Generation Framework" - -from _constants import * -from _reportbase import Report - -from _bibliography import Bibliography, Citation - -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2001 David R. Hampton -# Copyright (C) 2001-2006 Donald N. Allingham -# Copyright (C) 2007 Brian G. Matherly -# Copyright (C) 2010 Jakim Friant -# -# 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 -# - -# gen.plug.report.__init__ -# -# $Id: __init__.py 12360 2009-03-19 02:32:16Z pez4brian $ - -"Report Generation Framework" - -from _constants import * -from _reportbase import Report - -from _bibliography import Bibliography, Citation - diff --git a/src/gen/plug/report/_bibliography.py b/src/gen/plug/report/_bibliography.py index 6bf37aecb..121cc2b72 100644 --- a/src/gen/plug/report/_bibliography.py +++ b/src/gen/plug/report/_bibliography.py @@ -241,489 +241,3 @@ class Bibliography(object): return False # Can't find anything different. They must be equal. return True -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2007 Brian G. Matherly -# Copyright (C) 2010 Jakim Friant -# -# 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: _Bibliography.py 13191 2009-09-10 18:49:48Z gbritton $ - -""" -Contain and organize bibliographic information. -""" -import string -import math -from gen.lib import SourceRef - -class Citation(object): - """ - Store information about a citation and all of its references. - """ - def __init__(self): - """ - Initialize members. - """ - self.__src_handle = None - self.__ref_list = [] - - def get_source_handle(self): - """ - Provide the handle to the source that this citation is for. - - @return: Source Handle - @rtype: handle - """ - return self.__src_handle - - def set_source_handle(self, handle): - """ - Set the handle for the source that this citation is for. - - @param handle: Source Handle - @type handle: handle - """ - self.__src_handle = handle - - def get_ref_list(self): - """ - List all the references to this citation. - - @return: a list of references - @rtype: list of L{gen.lib.srcref} objects - """ - return self.__ref_list - - def add_reference(self, source_ref): - """ - Add a reference to this citation. If a similar reference exists, don't - add another one. - - @param source_ref: Source Reference - @type source_ref: L{gen.lib.srcref} - @return: The key of the added reference among all the references. - @rtype: char - """ - letter_count = len(string.ascii_lowercase) - ref_count = len(self.__ref_list) - x_ref_count = ref_count - # Return "a" for ref_count = 0, otherwise log(0) does not work - if ref_count == 0: - self.__ref_list.append(("a", source_ref)) - return "a" - last_letter = string.ascii_lowercase[ ref_count % letter_count ] - key = "" - # Calculate prek number of digits. - number_of_letters = int(math.log(float(ref_count), float(letter_count)))+1 - # Exclude index for number_of_letters-1 - for n in range(1, number_of_letters-1): - ref_count -= pow(letter_count, n) - # Adjust number_of_letters for new index - number_of_letters = int(math.log(float(ref_count), float(letter_count))) +1 - for n in range(1, number_of_letters): - x_ref_count -= pow(letter_count, n) - for letter in range(1, number_of_letters): - index = x_ref_count / pow(letter_count, letter) % letter_count - key += string.ascii_lowercase[ index ] - key = key + last_letter - self.__ref_list.append((key, source_ref)) - return key - -class Bibliography(object): - """ - Store and organize multiple citations into a bibliography. - """ - MODE_DATE = 2**0 - MODE_PAGE = 2**1 - MODE_CONF = 2**2 - MODE_NOTE = 2**3 - MODE_ALL = MODE_DATE | MODE_PAGE | MODE_CONF | MODE_NOTE - - def __init__(self, mode=MODE_ALL): - """ - A bibliography will store citations (sources) and references to those - citations (source refs). Duplicate entries will not be added. To change - what is considered duplicate, you can tell the bibliography what source - ref information you are interested in by passing in the mode. - - Possible modes include: - MODE_DATE - MODE_PAGE - MODE_CONF - MODE_NOTE - MODE_ALL - - If you only care about pages, set "mode=MODE_PAGE". - If you only care about dates and pages, set "mode=MODE_DATE|MODE_PAGE". - If you care about everything, set "mode=MODE_ALL". - """ - self.__citation_list = [] - self.mode = mode - - def add_reference(self, source_ref): - """ - Add a reference to a source to this bibliography. If the source already - exists, don't add it again. If a similar reference exists, don't - add another one. - - @param source_ref: Source Reference - @type source_ref: L{gen.lib.srcref} - @return: A tuple containing the index of the source among all the - sources and the key of the reference among all the references. If - there is no reference information, the second element will be None. - @rtype: (int,char) or (int,None) - """ - source_handle = source_ref.get_reference_handle() - cindex = 0 - rkey = "" - citation = None - citation_found = False - for citation in self.__citation_list: - if citation.get_source_handle() == source_handle: - citation_found = True - break - cindex += 1 - - if not citation_found: - citation = Citation() - citation.set_source_handle(source_handle) - cindex = len(self.__citation_list) - self.__citation_list.append(citation) - - if self.__sref_has_info(source_ref): - for key, ref in citation.get_ref_list(): - if self.__srefs_are_equal(ref, source_ref): - # if a reference like this already exists, don't add - # another one - return (cindex, key) - rkey = citation.add_reference(source_ref) - - return (cindex, rkey) - - def get_citation_count(self): - """ - Report the number of citations in this bibliography. - - @return: number of citations - @rtype: int - """ - return len(self.__citation_list) - - def get_citation_list(self): - """ - Return a list containing all the citations in this bibliography. - - @return: citation list - @rtype: list of L{Citation} objects - """ - return self.__citation_list - - def __sref_has_info(self, source_ref): - """ - Determine if this source_ref has any useful information based on the - current mode. - """ - if ( self.mode & self.MODE_PAGE ) == self.MODE_PAGE: - if source_ref.get_page() != "": - return True - if ( self.mode & self.MODE_DATE ) == self.MODE_DATE: - date = source_ref.get_date_object() - if date is not None and not date.is_empty(): - return True - if ( self.mode & self.MODE_CONF ) == self.MODE_CONF: - confidence = source_ref.get_confidence_level() - if confidence is not None and confidence != SourceRef.CONF_NORMAL: - return True - if ( self.mode & self.MODE_NOTE ) == self.MODE_NOTE: - if len(source_ref.get_note_list()) != 0: - return True - # Can't find anything interesting. - return False - - def __srefs_are_equal(self, source_ref1, source_ref2): - """ - Determine if two source references are equal based on the - current mode. - """ - if self.mode == self.MODE_ALL: - return source_ref1.is_equal(source_ref2) - if ( self.mode & self.MODE_PAGE ) == self.MODE_PAGE: - if source_ref1.get_page() != source_ref2.get_page(): - return False - if ( self.mode & self.MODE_DATE ) == self.MODE_DATE: - date1 = source_ref1.get_date_object() - date2 = source_ref2.get_date_object() - if date1.is_equal(date2): - return False - if ( self.mode & self.MODE_CONF ) == self.MODE_CONF: - conf1 = source_ref1.get_confidence_level() - conf2 = source_ref2.get_confidence_level() - if conf1 != conf2: - return False - if ( self.mode & self.MODE_NOTE ) == self.MODE_NOTE: - nl1 = source_ref1.get_note_list() - nl2 = source_ref2.get_note_list() - if len(nl1) != len(nl2): - return False - for notehandle in nl1: - if notehandle not in nl2: - return False - # Can't find anything different. They must be equal. - return True -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2007 Brian G. Matherly -# Copyright (C) 2010 Jakim Friant -# -# 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: _Bibliography.py 13191 2009-09-10 18:49:48Z gbritton $ - -""" -Contain and organize bibliographic information. -""" -import string -import math -from gen.lib import SourceRef - -class Citation(object): - """ - Store information about a citation and all of its references. - """ - def __init__(self): - """ - Initialize members. - """ - self.__src_handle = None - self.__ref_list = [] - - def get_source_handle(self): - """ - Provide the handle to the source that this citation is for. - - @return: Source Handle - @rtype: handle - """ - return self.__src_handle - - def set_source_handle(self, handle): - """ - Set the handle for the source that this citation is for. - - @param handle: Source Handle - @type handle: handle - """ - self.__src_handle = handle - - def get_ref_list(self): - """ - List all the references to this citation. - - @return: a list of references - @rtype: list of L{gen.lib.srcref} objects - """ - return self.__ref_list - - def add_reference(self, source_ref): - """ - Add a reference to this citation. If a similar reference exists, don't - add another one. - - @param source_ref: Source Reference - @type source_ref: L{gen.lib.srcref} - @return: The key of the added reference among all the references. - @rtype: char - """ - letter_count = len(string.ascii_lowercase) - ref_count = len(self.__ref_list) - x_ref_count = ref_count - # Return "a" for ref_count = 0, otherwise log(0) does not work - if ref_count == 0: - self.__ref_list.append(("a", source_ref)) - return "a" - last_letter = string.ascii_lowercase[ ref_count % letter_count ] - key = "" - # Calculate prek number of digits. - number_of_letters = int(math.log(float(ref_count), float(letter_count)))+1 - # Exclude index for number_of_letters-1 - for n in range(1, number_of_letters-1): - ref_count -= pow(letter_count, n) - # Adjust number_of_letters for new index - number_of_letters = int(math.log(float(ref_count), float(letter_count))) +1 - for n in range(1, number_of_letters): - x_ref_count -= pow(letter_count, n) - for letter in range(1, number_of_letters): - index = x_ref_count / pow(letter_count, letter) % letter_count - key += string.ascii_lowercase[ index ] - key = key + last_letter - self.__ref_list.append((key, source_ref)) - return key - -class Bibliography(object): - """ - Store and organize multiple citations into a bibliography. - """ - MODE_DATE = 2**0 - MODE_PAGE = 2**1 - MODE_CONF = 2**2 - MODE_NOTE = 2**3 - MODE_ALL = MODE_DATE | MODE_PAGE | MODE_CONF | MODE_NOTE - - def __init__(self, mode=MODE_ALL): - """ - A bibliography will store citations (sources) and references to those - citations (source refs). Duplicate entries will not be added. To change - what is considered duplicate, you can tell the bibliography what source - ref information you are interested in by passing in the mode. - - Possible modes include: - MODE_DATE - MODE_PAGE - MODE_CONF - MODE_NOTE - MODE_ALL - - If you only care about pages, set "mode=MODE_PAGE". - If you only care about dates and pages, set "mode=MODE_DATE|MODE_PAGE". - If you care about everything, set "mode=MODE_ALL". - """ - self.__citation_list = [] - self.mode = mode - - def add_reference(self, source_ref): - """ - Add a reference to a source to this bibliography. If the source already - exists, don't add it again. If a similar reference exists, don't - add another one. - - @param source_ref: Source Reference - @type source_ref: L{gen.lib.srcref} - @return: A tuple containing the index of the source among all the - sources and the key of the reference among all the references. If - there is no reference information, the second element will be None. - @rtype: (int,char) or (int,None) - """ - source_handle = source_ref.get_reference_handle() - cindex = 0 - rkey = "" - citation = None - citation_found = False - for citation in self.__citation_list: - if citation.get_source_handle() == source_handle: - citation_found = True - break - cindex += 1 - - if not citation_found: - citation = Citation() - citation.set_source_handle(source_handle) - cindex = len(self.__citation_list) - self.__citation_list.append(citation) - - if self.__sref_has_info(source_ref): - for key, ref in citation.get_ref_list(): - if self.__srefs_are_equal(ref, source_ref): - # if a reference like this already exists, don't add - # another one - return (cindex, key) - rkey = citation.add_reference(source_ref) - - return (cindex, rkey) - - def get_citation_count(self): - """ - Report the number of citations in this bibliography. - - @return: number of citations - @rtype: int - """ - return len(self.__citation_list) - - def get_citation_list(self): - """ - Return a list containing all the citations in this bibliography. - - @return: citation list - @rtype: list of L{Citation} objects - """ - return self.__citation_list - - def __sref_has_info(self, source_ref): - """ - Determine if this source_ref has any useful information based on the - current mode. - """ - if ( self.mode & self.MODE_PAGE ) == self.MODE_PAGE: - if source_ref.get_page() != "": - return True - if ( self.mode & self.MODE_DATE ) == self.MODE_DATE: - date = source_ref.get_date_object() - if date is not None and not date.is_empty(): - return True - if ( self.mode & self.MODE_CONF ) == self.MODE_CONF: - confidence = source_ref.get_confidence_level() - if confidence is not None and confidence != SourceRef.CONF_NORMAL: - return True - if ( self.mode & self.MODE_NOTE ) == self.MODE_NOTE: - if len(source_ref.get_note_list()) != 0: - return True - # Can't find anything interesting. - return False - - def __srefs_are_equal(self, source_ref1, source_ref2): - """ - Determine if two source references are equal based on the - current mode. - """ - if self.mode == self.MODE_ALL: - return source_ref1.is_equal(source_ref2) - if ( self.mode & self.MODE_PAGE ) == self.MODE_PAGE: - if source_ref1.get_page() != source_ref2.get_page(): - return False - if ( self.mode & self.MODE_DATE ) == self.MODE_DATE: - date1 = source_ref1.get_date_object() - date2 = source_ref2.get_date_object() - if date1.is_equal(date2): - return False - if ( self.mode & self.MODE_CONF ) == self.MODE_CONF: - conf1 = source_ref1.get_confidence_level() - conf2 = source_ref2.get_confidence_level() - if conf1 != conf2: - return False - if ( self.mode & self.MODE_NOTE ) == self.MODE_NOTE: - nl1 = source_ref1.get_note_list() - nl2 = source_ref2.get_note_list() - if len(nl1) != len(nl2): - return False - for notehandle in nl1: - if notehandle not in nl2: - return False - # Can't find anything different. They must be equal. - return True diff --git a/src/gen/plug/report/_constants.py b/src/gen/plug/report/_constants.py index 40e041777..3fd29d664 100644 --- a/src/gen/plug/report/_constants.py +++ b/src/gen/plug/report/_constants.py @@ -61,158 +61,6 @@ book_categories = { # 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-Blue"), 'Web_Basic-Blue.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"), ''], - ] -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2001-2006 Donald N. Allingham -# Copyright (C) 2010 Rob G. Healey -# Copyright (C) 2010 Jakim Friant -# -# 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: _Constants.py 15146 2010-04-15 14:37:18Z robhealey1 $ - -"Report Generation Framework" - -#------------------------------------------------------------------------- -# -# standard python modules -# -#------------------------------------------------------------------------- -from gen.ggettext import gettext as _ - -#------------------------------------------------------------------------- -# -# Constants -# -#------------------------------------------------------------------------- - -# Report categories -from gen.plug import CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_CODE, CATEGORY_WEB,\ - CATEGORY_BOOK, CATEGORY_GRAPHVIZ - -standalone_categories = { - CATEGORY_TEXT : _("Text Reports"), - CATEGORY_DRAW : _("Graphical Reports"), - CATEGORY_CODE : _("Code Generators"), - CATEGORY_WEB : _("Web Pages"), - CATEGORY_BOOK : _("Books"), - CATEGORY_GRAPHVIZ : _("Graphs"), -} - -book_categories = { - CATEGORY_TEXT : _("Text"), - CATEGORY_DRAW : _("Graphics"), -} - -#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-Blue"), 'Web_Basic-Blue.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"), ''], - ] -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2001-2006 Donald N. Allingham -# Copyright (C) 2010 Rob G. Healey -# Copyright (C) 2010 Jakim Friant -# -# 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: _Constants.py 15146 2010-04-15 14:37:18Z robhealey1 $ - -"Report Generation Framework" - -#------------------------------------------------------------------------- -# -# standard python modules -# -#------------------------------------------------------------------------- -from gen.ggettext import gettext as _ - -#------------------------------------------------------------------------- -# -# Constants -# -#------------------------------------------------------------------------- - -# Report categories -from gen.plug import CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_CODE, CATEGORY_WEB,\ - CATEGORY_BOOK, CATEGORY_GRAPHVIZ - -standalone_categories = { - CATEGORY_TEXT : _("Text Reports"), - CATEGORY_DRAW : _("Graphical Reports"), - CATEGORY_CODE : _("Code Generators"), - CATEGORY_WEB : _("Web Pages"), - CATEGORY_BOOK : _("Books"), - CATEGORY_GRAPHVIZ : _("Graphs"), -} - -book_categories = { - CATEGORY_TEXT : _("Text"), - CATEGORY_DRAW : _("Graphics"), -} - -#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'], diff --git a/src/gen/plug/report/_options.py b/src/gen/plug/report/_options.py index 80c8ea4bd..c9da00ad8 100644 --- a/src/gen/plug/report/_options.py +++ b/src/gen/plug/report/_options.py @@ -818,1646 +818,3 @@ class MenuReportOptions(GuiMenuOptions, ReportOptions): menu_option = self.menu.get_option_by_name(optname) if menu_option: menu_option.set_value(self.options_dict[optname]) - -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2004-2007 Donald N. Allingham -# Copyright (C) 2008 Gary Burton -# Copyright (C) 2010 Jakim Friant -# -# 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: _ReportOptions.py 13346 2009-10-08 01:12:51Z dsblank $ - -# Written by Alex Roitman - -""" -Report option handling, including saving and parsing. -""" - -#------------------------------------------------------------------------- -# -# Standard Python modules -# -#------------------------------------------------------------------------- -import os -import copy -from xml.sax.saxutils import escape - -def escxml(d): - return escape(d, { '"' : '"' } ) - -#------------------------------------------------------------------------- -# -# SAX interface -# -#------------------------------------------------------------------------- -try: - from xml.sax import make_parser, SAXParseException -except: - from _xmlplus.sax import make_parser, SAXParseException - -#------------------------------------------------------------------------- -# -# gramps modules -# -#------------------------------------------------------------------------- -import const -import config -from gen.plug.docgen import PAPER_PORTRAIT -from gen.plug import _options -from gui.plug import GuiMenuOptions - -#------------------------------------------------------------------------- -# -# List of options for a single report -# -#------------------------------------------------------------------------- -class OptionList(_options.OptionList): - """ - Implements a set of options to parse and store for a given report. - """ - - def __init__(self): - _options.OptionList.__init__(self) - self.style_name = None - self.paper_metric = None - self.paper_name = None - self.orientation = None - self.custom_paper_size = [29.7, 21.0] - self.margins = [2.54, 2.54, 2.54, 2.54] - self.format_name = None - self.css_filename = None - - def set_style_name(self, style_name): - """ - Set the style name for the OptionList. - @param style_name: name of the style to set. - @type style_name: str - """ - self.style_name = style_name - - def get_style_name(self): - """ - Return the style name of the OptionList. - @returns: string representing the style name - @rtype: str - """ - return self.style_name - - def set_paper_metric(self, paper_metric): - """ - Set the paper metric for the OptionList. - @param paper_metric: whether to use metric. - @type paper_name: boolean - """ - self.paper_metric = paper_metric - - def get_paper_metric(self): - """ - Return the paper metric of the OptionList. - @returns: returns whether to use metric - @rtype: boolean - """ - return self.paper_metric - - def set_paper_name(self, paper_name): - """ - Set the paper name for the OptionList. - @param paper_name: name of the paper to set. - @type paper_name: str - """ - self.paper_name = paper_name - - def get_paper_name(self): - """ - Return the paper name of the OptionList. - @returns: returns the paper name - @rtype: str - """ - return self.paper_name - - def set_orientation(self, orientation): - """ - Set the orientation for the OptionList. - @param orientation: orientation to set. Possible values are - PAPER_LANDSCAPE or PAPER_PORTRAIT - @type orientation: int - """ - self.orientation = orientation - - def get_orientation(self): - """ - Return the orientation for the OptionList. - @returns: returns the selected orientation. Valid values are - PAPER_LANDSCAPE or PAPER_PORTRAIT - @rtype: int - """ - return self.orientation - - def set_custom_paper_size(self, paper_size): - """ - Set the custom paper size for the OptionList. - @param paper_size: paper size to set in cm. - @type paper_size: [float, float] - """ - self.custom_paper_size = paper_size - - def get_custom_paper_size(self): - """ - Return the custom paper size for the OptionList. - @returns: returns the custom paper size in cm - @rtype: [float, float] - """ - return self.custom_paper_size - - def set_margins(self, margins): - """ - Set the margins for the OptionList. - @param margins: margins to set. Possible values are floats in cm - @type margins: [float, float, float, float] - """ - self.margins = copy.copy(margins) - - def get_margins(self): - """ - Return the margins for the OptionList. - @returns margins: returns the margins, floats in cm - @rtype margins: [float, float, float, float] - """ - return copy.copy(self.margins) - - def set_margin(self, pos, value): - """ - Set a margin for the OptionList. - @param pos: Position of margin [left, right, top, bottom] - @param value: floating point in cm - @type pos: int - @type value: float - """ - self.margins[pos] = value - - def get_margin(self, pos): - """ - Return a margin for the OptionList. - @param pos: Position of margin [left, right, top, bottom] - @type pos: int - @returns: float cm of margin - @rtype: float - """ - return self.margins[pos] - - 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.css_filename = css_filename - - def get_css_filename(self): - """ - Return the template name of the OptionList. - @returns: template name - @rtype: str - """ - return self.css_filename - - def set_format_name(self, format_name): - """ - Set the format name for the OptionList. - @param format_name: name of the format to set. - @type format_name: str - """ - self.format_name = format_name - - def get_format_name(self): - """ - Return the format name of the OptionList. - @returns: returns the format name - @rtype: str - """ - return self.format_name - -#------------------------------------------------------------------------- -# -# Collection of option lists -# -#------------------------------------------------------------------------- -class OptionListCollection(_options.OptionListCollection): - """ - Implements a collection of option lists. - """ - def __init__(self, filename): - _options.OptionListCollection.__init__(self, filename) - - def init_common(self): - # Default values for common options - self.default_style_name = "default" - self.default_paper_metric = config.get('preferences.paper-metric') - self.default_paper_name = config.get('preferences.paper-preference') - 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' - - self.last_paper_metric = self.default_paper_metric - self.last_paper_name = self.default_paper_name - 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_css_filename = self.default_css_filename - self.last_format_name = self.default_format_name - self.option_list_map = {} - - def set_last_paper_metric(self, paper_metric): - """ - Set the last paper metric used for the any report in this collection. - @param paper_metric: whether to use metric. - @type paper_name: boolean - """ - self.last_paper_metric = paper_metric - - def get_last_paper_metric(self): - """ - Return the last paper metric used for the any report in this collection. - @returns: returns whether or not to use metric - @rtype: boolean - """ - return self.last_paper_metric - - def set_last_paper_name(self, paper_name): - """ - Set the last paper name used for the any report in this collection. - @param paper_name: name of the paper to set. - @type paper_name: str - """ - self.last_paper_name = paper_name - - def get_last_paper_name(self): - """ - Return the last paper name used for the any report in this collection. - @returns: returns the name of the paper - @rtype: str - """ - return self.last_paper_name - - def set_last_orientation(self, orientation): - """ - Set the last orientation used for the any report in this collection. - @param orientation: orientation to set. - @type orientation: int - """ - self.last_orientation = orientation - - def get_last_orientation(self): - """ - Return the last orientation used for the any report in this - collection. - @returns: last orientation used - @rtype: int - """ - return self.last_orientation - - def set_last_custom_paper_size(self, custom_paper_size): - """ - Set the last custom paper size used for the any report in this collection. - @param custom_paper_size: size to set in cm (width, height) - @type margins: [float, float] - """ - self.last_custom_paper_size = copy.copy(custom_paper_size) - - def get_last_custom_paper_size(self): - """ - Return the last custom paper size used for the any report in this - collection. - @returns: list of last custom paper size used in cm (width, height) - @rtype: [float, float] - """ - return copy.copy(self.last_custom_paper_size) - - def set_last_margins(self, margins): - """ - Set the last margins used for the any report in this collection. - @param margins: margins to set in cm (left, right, top, bottom) - @type margins: [float, float, float, float] - """ - self.last_margins = copy.copy(margins) - - def get_last_margins(self): - """ - Return the last margins used for the any report in this - collection. - @returns: list of last margins used in cm (left, right, top, bottom) - @rtype: [float, float, float, float] - """ - return copy.copy(self.last_margins) - - def set_last_margin(self, pos, value): - """ - Set the last margin used for the any report in this collection. - @param pos: pos to set (0-4) (left, right, top, bottom) - @type pos: int - @param value: value to set the margin to in cm - @type value: float - """ - self.last_margins[pos] = value - - def get_last_margin(self, pos): - """ - Return the last margins used for the any report in this - collection. - @param pos: position in margins list - @type pos: int - @returns: last margin used in pos - @rtype: float - """ - return self.last_margins[pos] - - def set_last_css_filename(self, css_filename): - """ - Set the last css used for the any report in this collection. - - 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_css_filename - - def set_last_format_name(self, format_name): - """ - Set the last format used for the any report in this collection. - - format_name: name of the format to set. - """ - self.last_format_name = format_name - - def get_last_format_name(self): - """ - Return the last format used for the any report in this collection. - """ - return self.last_format_name - - def write_common(self, f): - f.write('\n') - if self.get_last_paper_metric() != self.default_paper_metric: - f.write(' \n' % self.get_last_paper_metric() ) - if self.get_last_custom_paper_size() != self.default_custom_paper_size: - size = self.get_last_custom_paper_size() - 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_css_filename() != self.default_css_filename: - f.write(' \n' % escxml(self.get_last_css_filename()) ) - if self.get_last_format_name() != self.default_format_name: - f.write(' \n' % escxml(self.get_last_format_name()) ) - if self.get_last_orientation() != self.default_orientation: - f.write(' \n' % self.get_last_orientation() ) - f.write('\n') - - def write_module_common(self, f, option_list): - if option_list.get_style_name() \ - and option_list.get_style_name() != self.default_style_name: - f.write('