1#
2# Gramps - a GTK+/GNOME based genealogy program
3#
4# Copyright (C) 2001-2006  Donald N. Allingham
5# Copyright (C) 2010       Jakim Friant
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21
22#-------------------------------------------------------------------------
23#
24# GTK modules
25#
26#-------------------------------------------------------------------------
27from gi.repository import Gtk
28from gi.repository import GObject
29
30#-------------------------------------------------------------------------
31#
32# Gramps modules
33#
34#-------------------------------------------------------------------------
35from gramps.gen.plug.report._constants import CATEGORY_DRAW
36from ._docreportdialog import DocReportDialog
37from ...pluginmanager import GuiPluginManager
38
39#-------------------------------------------------------------------------
40#
41# _DrawFormatComboBox
42#
43#-------------------------------------------------------------------------
44class _DrawFormatComboBox(Gtk.ComboBox):
45    """
46    This class is a combo box that allows the selection of a docgen plugin
47    from all drawdoc plugins.
48    """
49    def __init__(self, active):
50
51        Gtk.ComboBox.__init__(self)
52
53        pmgr = GuiPluginManager.get_instance()
54        self.__drawdoc_plugins = []
55        for plugin in pmgr.get_docgen_plugins():
56            if plugin.get_draw_support():
57                self.__drawdoc_plugins.append(plugin)
58
59        self.store = Gtk.ListStore(GObject.TYPE_STRING)
60        self.set_model(self.store)
61        cell = Gtk.CellRendererText()
62        self.pack_start(cell, True)
63        self.add_attribute(cell, 'text', 0)
64
65        index = 0
66        active_index = 0
67        for plugin in self.__drawdoc_plugins:
68            name = plugin.get_name()
69            self.store.append(row=[name])
70            if plugin.get_extension() == active:
71                active_index = index
72            index += 1
73        self.set_active(active_index)
74
75    def get_active_plugin(self):
76        """
77        Get the plugin represented by the currently active selection.
78        """
79        return self.__drawdoc_plugins[self.get_active()]
80
81#-----------------------------------------------------------------------
82#
83# DrawReportDialog
84#
85#-----------------------------------------------------------------------
86class DrawReportDialog(DocReportDialog):
87    """
88    A class of ReportDialog customized for drawing based reports.
89    """
90    def __init__(self, dbstate, uistate, opt, name, translated_name):
91        """
92        Initialize a dialog to request that the user select options
93        for a basic drawing report.  See the ReportDialog class for
94        more information.
95        """
96        self.format_menu = None
97        self.category = CATEGORY_DRAW
98        DocReportDialog.__init__(self, dbstate, uistate, opt,
99                                 name, translated_name)
100
101    def make_doc_menu(self,active=None):
102        """
103        Build a menu of document types that are appropriate for
104        this drawing report.
105        """
106        self.format_menu = _DrawFormatComboBox( active )
107