1#
2# Gramps - a GTK+/GNOME based genealogy program
3#
4# Copyright (C) 2001  David R. Hampton
5# Copyright (C) 2001-2006  Donald N. Allingham
6# Copyright (C) 2007       Brian G. Matherly
7# Copyright (C) 2010       Jakim Friant
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22#
23
24#-------------------------------------------------------------------------
25#
26# Gramps modules
27#
28#-------------------------------------------------------------------------
29from ...const import GRAMPS_LOCALE as glocale
30from ...utils.grampslocale import GrampsLocale
31from ...display.name import NameDisplay
32from ...config import config
33
34#-------------------------------------------------------------------------
35#
36# Report
37#
38#-------------------------------------------------------------------------
39class Report:
40    """
41    The Report base class.  This is a base class for generating
42    customized reports.  It cannot be used as is, but it can be easily
43    sub-classed to create a functional report generator.
44    """
45
46    def __init__(self, database, options_class, user):
47        self.database = database
48        self.options_class = options_class
49        self._user = user
50
51        self.doc = options_class.get_document()
52
53        creator = database.get_researcher().get_name()
54        self.doc.set_creator(creator)
55
56        output = options_class.get_output()
57        if output:
58            self.standalone = True
59            self.doc.open(options_class.get_output())
60        else:
61            self.standalone = False
62
63    def begin_report(self):
64        pass
65
66    def set_locale(self, language):
67        """
68        Set the translator to one selected with
69        stdoptions.add_localization_option().
70        """
71        from ...datehandler import LANG_TO_DISPLAY, main_locale
72        if language == GrampsLocale.DEFAULT_TRANSLATION_STR: # the UI language
73            locale = glocale
74        elif language in LANG_TO_DISPLAY: # a displayer exists
75            locale = LANG_TO_DISPLAY[main_locale[language]]._locale
76        else: # no displayer
77            locale = GrampsLocale(lang=language)
78        self._ = locale.translation.sgettext
79        self._get_date = locale.get_date
80        self._get_type = locale.get_type
81        self._ldd = locale.date_displayer
82        self.doc.set_rtl_doc(locale.rtl_locale)
83        self._name_display = NameDisplay(locale) # a legacy/historical name
84        self._name_display.set_name_format(self.database.name_formats)
85        fmt_default = config.get('preferences.name-format')
86        self._name_display.set_default_format(fmt_default)
87        self._locale = locale # define it here rather than in every report
88        return locale
89
90    def write_report(self):
91        pass
92
93    def end_report(self):
94        if self.standalone:
95            self.doc.close()
96
97