2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-04-28 00:49:10 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
2003-10-14 07:52:14 +05:30
|
|
|
# $Id$
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK libraries
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
2006-05-31 06:27:54 +05:30
|
|
|
from ReportBase import report, standalone_categories
|
2006-03-11 06:42:06 +05:30
|
|
|
import _Tool
|
2008-10-02 09:32:10 +05:30
|
|
|
from gen.plug import PluginManager
|
2006-04-01 09:29:42 +05:30
|
|
|
import ManagedWindow
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-05-19 09:44:11 +05:30
|
|
|
_REPORTS = 0
|
|
|
|
_TOOLS = 1
|
|
|
|
_UNSUPPORTED = _("Unsupported")
|
2002-11-03 12:05:06 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PluginDialog interface class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-01 09:29:42 +05:30
|
|
|
class PluginDialog(ManagedWindow.ManagedWindow):
|
2008-05-19 09:44:11 +05:30
|
|
|
"""
|
|
|
|
Displays the dialog box that allows the user to select the
|
|
|
|
plugin that is desired.
|
|
|
|
"""
|
2008-04-01 08:42:08 +05:30
|
|
|
def __init__(self, state, uistate, track, item_list, categories, msg,
|
2008-05-19 09:44:11 +05:30
|
|
|
label=None, button_label=None, tool_tip=None,
|
|
|
|
content=_REPORTS):
|
|
|
|
"""
|
|
|
|
Display the dialog box, and build up the list of available
|
2002-10-20 19:55:16 +05:30
|
|
|
reports. This is used to build the selection tree on the left
|
2008-05-19 09:44:11 +05:30
|
|
|
hand side of the dialog box.
|
|
|
|
"""
|
2005-12-26 10:41:37 +05:30
|
|
|
self.active = state.active
|
2002-11-03 12:05:06 +05:30
|
|
|
self.imap = {}
|
2004-02-28 09:21:59 +05:30
|
|
|
self.msg = msg
|
2005-12-06 12:08:09 +05:30
|
|
|
self.content = content
|
2005-12-26 10:41:37 +05:30
|
|
|
|
2008-05-19 09:44:11 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, track,
|
|
|
|
self.__class__)
|
2006-03-01 10:38:11 +05:30
|
|
|
|
2005-12-26 10:41:37 +05:30
|
|
|
self.state = state
|
|
|
|
self.uistate = uistate
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2009-04-14 01:34:30 +05:30
|
|
|
self.dialog = gtk.Builder()
|
|
|
|
self.dialog.add_from_file(const.PLUGINS_GLADE)
|
|
|
|
self.dialog.connect_signals({
|
2002-10-20 19:55:16 +05:30
|
|
|
"on_report_apply_clicked" : self.on_apply_clicked,
|
2006-04-28 03:02:44 +05:30
|
|
|
"destroy_passed_object" : self.close,
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
|
|
|
|
2009-04-14 01:34:30 +05:30
|
|
|
self.tree = self.dialog.get_object("tree")
|
|
|
|
window = self.dialog.get_object("report")
|
|
|
|
self.title = self.dialog.get_object("title")
|
2003-03-06 11:42:51 +05:30
|
|
|
|
2006-04-28 03:02:44 +05:30
|
|
|
self.set_window(window, self.title, msg )
|
2003-03-06 11:42:51 +05:30
|
|
|
|
2006-07-05 05:08:51 +05:30
|
|
|
self.store = gtk.TreeStore(str)
|
2002-11-03 12:05:06 +05:30
|
|
|
self.selection = self.tree.get_selection()
|
|
|
|
self.selection.connect('changed', self.on_node_selected)
|
2008-04-01 08:42:08 +05:30
|
|
|
col = gtk.TreeViewColumn('', gtk.CellRendererText(), text=0)
|
2002-11-03 12:05:06 +05:30
|
|
|
self.tree.append_column(col)
|
|
|
|
self.tree.set_model(self.store)
|
|
|
|
|
2009-04-14 01:34:30 +05:30
|
|
|
self.description = self.dialog.get_object("description")
|
2003-09-30 09:49:35 +05:30
|
|
|
if label:
|
|
|
|
self.description.set_text(label)
|
2009-04-14 01:34:30 +05:30
|
|
|
self.status = self.dialog.get_object("report_status")
|
2003-03-05 11:31:31 +05:30
|
|
|
|
2009-04-14 01:34:30 +05:30
|
|
|
self.author_name = self.dialog.get_object("author_name")
|
|
|
|
self.author_email = self.dialog.get_object("author_email")
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2009-04-14 01:34:30 +05:30
|
|
|
self.apply_button = self.dialog.get_object("apply")
|
2003-10-14 07:52:14 +05:30
|
|
|
if button_label:
|
|
|
|
self.apply_button.set_label(button_label)
|
|
|
|
else:
|
|
|
|
self.apply_button.set_label(_("_Apply"))
|
2005-02-24 05:55:34 +05:30
|
|
|
self.apply_button.set_use_underline(True)
|
2003-10-14 07:52:14 +05:30
|
|
|
if tool_tip:
|
2009-10-14 00:41:19 +05:30
|
|
|
self.apply_button.set_tooltip_text(tool_tip)
|
2003-10-14 07:52:14 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
self.item = None
|
2008-04-01 08:42:08 +05:30
|
|
|
self.build_plugin_tree(item_list, categories)
|
2006-04-28 03:02:44 +05:30
|
|
|
self.show()
|
2004-02-28 09:21:59 +05:30
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
def rebuild(self):
|
2006-12-21 10:12:37 +05:30
|
|
|
# This method needs to be overridden in the subclass
|
|
|
|
assert False, "This method needs to be overridden in the subclass."
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def build_menu_names(self, obj):
|
2008-04-01 08:42:08 +05:30
|
|
|
return (self.msg, None)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def on_apply_clicked(self, obj):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Execute the selected report"""
|
2006-10-07 00:40:15 +05:30
|
|
|
try:
|
2008-04-01 08:42:08 +05:30
|
|
|
(item_class, options_class, title, category,
|
|
|
|
name, require_active) = self.item
|
2008-05-19 09:44:11 +05:30
|
|
|
if self.content == _REPORTS:
|
2008-04-01 08:42:08 +05:30
|
|
|
report(self.state, self.uistate, self.state.active,
|
|
|
|
item_class, options_class, title, name,
|
|
|
|
category, require_active)
|
2006-10-07 00:40:15 +05:30
|
|
|
else:
|
2008-04-01 08:42:08 +05:30
|
|
|
_Tool.gui_tool(self.state, self.uistate,
|
2008-02-24 19:25:55 +05:30
|
|
|
item_class, options_class,title, name,category,
|
2006-10-07 00:40:15 +05:30
|
|
|
self.state.db.request_rebuild)
|
|
|
|
except TypeError:
|
|
|
|
pass # ignore pressing apply without a plugin being selected
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def on_node_selected(self, obj):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Updates the informational display on the right hand side of
|
|
|
|
the dialog box with the description of the selected report"""
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
store, node = self.selection.get_selected()
|
2004-08-20 17:41:56 +05:30
|
|
|
if node:
|
|
|
|
path = store.get_path(node)
|
2008-07-17 23:40:32 +05:30
|
|
|
if not node or path not in self.imap:
|
2002-11-03 12:05:06 +05:30
|
|
|
return
|
|
|
|
data = self.imap[path]
|
|
|
|
|
2008-04-01 08:42:08 +05:30
|
|
|
(report_class, options_class, title, category, name,
|
2006-06-22 01:09:43 +05:30
|
|
|
doc,status,author,email,unsupported,require_active) = data
|
2002-10-20 19:55:16 +05:30
|
|
|
self.description.set_text(doc)
|
2005-12-06 12:08:09 +05:30
|
|
|
if unsupported:
|
2008-05-19 09:44:11 +05:30
|
|
|
status = _UNSUPPORTED
|
2003-02-08 22:58:41 +05:30
|
|
|
self.status.set_text(status)
|
2006-06-22 01:09:43 +05:30
|
|
|
self.title.set_text('<span weight="bold" size="larger">%s</span>' \
|
|
|
|
% title)
|
2004-05-12 09:28:14 +05:30
|
|
|
self.title.set_use_markup(1)
|
2003-02-08 22:58:41 +05:30
|
|
|
self.author_name.set_text(author)
|
|
|
|
self.author_email.set_text(email)
|
2008-04-01 08:42:08 +05:30
|
|
|
self.item = (report_class, options_class, title, category,
|
|
|
|
name, require_active)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-04-01 08:42:08 +05:30
|
|
|
def build_plugin_tree(self, item_list, categories):
|
2009-08-09 22:39:32 +05:30
|
|
|
"""Populates a GtkTree with each menu item associated with a entry
|
2002-10-20 19:55:16 +05:30
|
|
|
in the lists. The list must consist of a tuples with the following
|
|
|
|
format:
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
(item_class, options_class,title,category, name,
|
2005-12-06 12:08:09 +05:30
|
|
|
doc,status,author,email)
|
|
|
|
|
|
|
|
Items in the same category are grouped under the same submenu.
|
|
|
|
The categories must be dicts from integer to string.
|
|
|
|
"""
|
2002-11-03 12:05:06 +05:30
|
|
|
ilist = []
|
2006-12-20 12:52:19 +05:30
|
|
|
self.store.clear()
|
2003-04-22 21:10:24 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
# build the tree items and group together based on the category name
|
|
|
|
item_hash = {}
|
2005-12-06 12:08:09 +05:30
|
|
|
for plugin in item_list:
|
|
|
|
if plugin[9]:
|
2008-05-19 09:44:11 +05:30
|
|
|
category = _UNSUPPORTED
|
2005-12-06 12:08:09 +05:30
|
|
|
else:
|
|
|
|
category = categories[plugin[3]]
|
2008-07-17 23:40:32 +05:30
|
|
|
if category in item_hash:
|
2005-12-06 12:08:09 +05:30
|
|
|
item_hash[category].append(plugin)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2005-12-06 12:08:09 +05:30
|
|
|
item_hash[category] = [plugin]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
# add a submenu for each category, and populate it with the
|
|
|
|
# GtkTreeItems that are associated with it.
|
2009-05-27 02:18:09 +05:30
|
|
|
key_list = [item for item in item_hash if item != _UNSUPPORTED]
|
|
|
|
key_list.sort(reverse=True)
|
2002-11-03 12:05:06 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
prev = None
|
2008-07-17 23:40:32 +05:30
|
|
|
if _UNSUPPORTED in item_hash:
|
2008-05-19 09:44:11 +05:30
|
|
|
key = _UNSUPPORTED
|
2002-10-20 19:55:16 +05:30
|
|
|
data = item_hash[key]
|
2008-04-01 08:42:08 +05:30
|
|
|
node = self.store.insert_after(None, prev)
|
|
|
|
self.store.set(node, 0, key)
|
2002-10-20 19:55:16 +05:30
|
|
|
next = None
|
2008-04-01 08:42:08 +05:30
|
|
|
data.sort(lambda x, y: cmp(x[2], y[2]))
|
2002-10-20 19:55:16 +05:30
|
|
|
for item in data:
|
2008-02-24 19:25:55 +05:30
|
|
|
next = self.store.insert_after(node, next)
|
2008-04-01 08:42:08 +05:30
|
|
|
ilist.append((next, item))
|
|
|
|
self.store.set(next, 0, item[2])
|
2004-12-23 09:18:23 +05:30
|
|
|
for key in key_list:
|
|
|
|
data = item_hash[key]
|
2008-04-01 08:42:08 +05:30
|
|
|
node = self.store.insert_after(None, prev)
|
|
|
|
self.store.set(node, 0, key)
|
2004-12-23 09:18:23 +05:30
|
|
|
next = None
|
2009-05-27 02:18:09 +05:30
|
|
|
data.sort(key=lambda k:k[2])
|
2004-12-23 09:18:23 +05:30
|
|
|
for item in data:
|
2008-02-24 19:25:55 +05:30
|
|
|
next = self.store.insert_after(node, next)
|
2008-04-01 08:42:08 +05:30
|
|
|
ilist.append((next, item))
|
|
|
|
self.store.set(next, 0, item[2])
|
|
|
|
for next, tab in ilist:
|
2004-12-23 09:18:23 +05:30
|
|
|
path = self.store.get_path(next)
|
|
|
|
self.imap[path] = tab
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2008-05-19 09:44:11 +05:30
|
|
|
# ReportPluginDialog
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-05-19 09:44:11 +05:30
|
|
|
class ReportPluginDialog(PluginDialog):
|
|
|
|
"""
|
|
|
|
Displays the dialog box that allows the user to select the
|
|
|
|
report that is desired.
|
|
|
|
"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2008-04-01 08:42:08 +05:30
|
|
|
def __init__(self, dbstate, uistate, track):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Display the dialog box, and build up the list of available
|
|
|
|
reports. This is used to build the selection tree on the left
|
|
|
|
hand side of the dailog box."""
|
2008-05-19 00:54:28 +05:30
|
|
|
self.__pmgr = PluginManager.get_instance()
|
2006-04-28 03:02:44 +05:30
|
|
|
|
2005-01-05 10:32:19 +05:30
|
|
|
PluginDialog.__init__(
|
2005-12-26 10:41:37 +05:30
|
|
|
self,
|
|
|
|
dbstate,
|
|
|
|
uistate,
|
|
|
|
track,
|
2008-05-19 00:54:28 +05:30
|
|
|
self.__pmgr.get_report_list(),
|
2006-05-31 06:18:07 +05:30
|
|
|
standalone_categories,
|
2005-12-06 12:08:09 +05:30
|
|
|
_("Report Selection"),
|
2005-01-05 10:32:19 +05:30
|
|
|
_("Select a report from those available on the left."),
|
2005-12-06 12:08:09 +05:30
|
|
|
_("_Generate"), _("Generate selected report"),
|
2008-05-19 09:44:11 +05:30
|
|
|
_REPORTS)
|
2008-05-19 00:54:28 +05:30
|
|
|
|
|
|
|
self.__pmgr.connect('plugins-reloaded', self.rebuild)
|
2006-12-20 12:52:19 +05:30
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
def rebuild(self):
|
|
|
|
report_list = self.__pmgr.get_report_list()
|
2008-04-01 08:42:08 +05:30
|
|
|
self.build_plugin_tree(report_list, standalone_categories)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2008-05-19 09:44:11 +05:30
|
|
|
# ToolPluginDialog
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-05-19 09:44:11 +05:30
|
|
|
class ToolPluginDialog(PluginDialog):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Displays the dialog box that allows the user to select the tool
|
|
|
|
that is desired."""
|
|
|
|
|
2008-04-01 08:42:08 +05:30
|
|
|
def __init__(self, dbstate, uistate, track):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Display the dialog box, and build up the list of available
|
|
|
|
reports. This is used to build the selection tree on the left
|
|
|
|
hand side of the dailog box."""
|
2008-05-19 00:54:28 +05:30
|
|
|
self.__pmgr = PluginManager.get_instance()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-05 10:32:19 +05:30
|
|
|
PluginDialog.__init__(
|
|
|
|
self,
|
2005-12-29 04:28:26 +05:30
|
|
|
dbstate,
|
|
|
|
uistate,
|
|
|
|
track,
|
2008-05-19 00:54:28 +05:30
|
|
|
self.__pmgr.get_tool_list(),
|
2006-03-11 06:42:06 +05:30
|
|
|
_Tool.tool_categories,
|
2005-01-05 10:32:19 +05:30
|
|
|
_("Tool Selection"),
|
|
|
|
_("Select a tool from those available on the left."),
|
|
|
|
_("_Run"),
|
2005-12-06 12:08:09 +05:30
|
|
|
_("Run selected tool"),
|
2008-05-19 09:44:11 +05:30
|
|
|
_TOOLS)
|
2006-12-20 12:52:19 +05:30
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
def rebuild(self):
|
|
|
|
tool_list = self.__pmgr.get_tool_list()
|
2008-04-01 08:42:08 +05:30
|
|
|
self.build_plugin_tree(tool_list, _Tool.tool_categories)
|