2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2005-12-06 12:08:09 +05:30
|
|
|
# Copyright (C) 2000-2005 Donald N. Allingham
|
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
|
|
|
|
|
|
|
"""
|
|
|
|
The core of the GRAMPS plugin system. This module provides tasks to load
|
|
|
|
plugins from specfied directories, build menus for the different categories,
|
|
|
|
and provide dialog to select and execute plugins.
|
|
|
|
|
|
|
|
Plugins are divided into several categories. This are: reports, tools,
|
2004-05-07 09:28:26 +05:30
|
|
|
importers, exporters, and document generators.
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK libraries
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-11-03 12:05:06 +05:30
|
|
|
import gobject
|
2002-10-20 19:55:16 +05:30
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import traceback
|
|
|
|
import os
|
|
|
|
import sys
|
2005-01-11 09:21:27 +05:30
|
|
|
import re
|
2004-12-22 07:26:37 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import const
|
|
|
|
import Utils
|
2006-03-03 05:40:52 +05:30
|
|
|
import Config
|
2003-01-15 10:55:50 +05:30
|
|
|
import Errors
|
2006-03-10 01:51:32 +05:30
|
|
|
from PluginUtils import Report, Tool
|
2005-01-05 10:32:19 +05:30
|
|
|
import PluginMgr
|
2005-12-06 12:08:09 +05:30
|
|
|
import GrampsDisplay
|
2005-12-26 10:41:37 +05:30
|
|
|
import DisplayState
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
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
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-01-11 09:21:27 +05:30
|
|
|
|
2005-12-26 10:41:37 +05:30
|
|
|
class PluginDialog(DisplayState.ManagedWindow):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Displays the dialog box that allows the user to select the
|
|
|
|
report that is desired."""
|
|
|
|
|
2005-12-26 10:41:37 +05:30
|
|
|
def __init__(self,state, uistate, track, item_list,categories,msg,label=None,
|
2005-12-06 12:08:09 +05:30
|
|
|
button_label=None,tool_tip=None,content=REPORTS):
|
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."""
|
|
|
|
|
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
|
|
|
|
|
|
|
DisplayState.ManagedWindow.__init__(self, uistate, [], None)
|
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
|
|
|
|
2006-03-05 04:23:46 +05:30
|
|
|
self.dialog = gtk.glade.XML(const.plugins_glade,"report","gramps")
|
2002-10-20 19:55:16 +05:30
|
|
|
self.dialog.signal_autoconnect({
|
|
|
|
"on_report_apply_clicked" : self.on_apply_clicked,
|
2004-02-28 09:21:59 +05:30
|
|
|
"destroy_passed_object" : self.close,
|
|
|
|
"on_delete_event" : self.on_delete_event,
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
|
|
|
|
|
|
|
self.tree = self.dialog.get_widget("tree")
|
2005-12-26 10:41:37 +05:30
|
|
|
self.window = self.dialog.get_widget("report")
|
2003-03-06 11:42:51 +05:30
|
|
|
self.title = self.dialog.get_widget("title")
|
|
|
|
|
2005-12-26 10:41:37 +05:30
|
|
|
Utils.set_titles(self.window, self.title, msg )
|
2003-03-06 11:42:51 +05:30
|
|
|
|
2002-11-03 12:05:06 +05:30
|
|
|
self.store = gtk.TreeStore(gobject.TYPE_STRING)
|
|
|
|
self.selection = self.tree.get_selection()
|
|
|
|
self.selection.connect('changed', self.on_node_selected)
|
|
|
|
col = gtk.TreeViewColumn('',gtk.CellRendererText(),text=0)
|
|
|
|
self.tree.append_column(col)
|
|
|
|
self.tree.set_model(self.store)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.description = self.dialog.get_widget("description")
|
2003-09-30 09:49:35 +05:30
|
|
|
if label:
|
|
|
|
self.description.set_text(label)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.status = self.dialog.get_widget("report_status")
|
2003-03-05 11:31:31 +05:30
|
|
|
|
|
|
|
Utils.set_title_label(self.dialog,msg)
|
|
|
|
|
2003-02-08 22:58:41 +05:30
|
|
|
self.author_name = self.dialog.get_widget("author_name")
|
|
|
|
self.author_email = self.dialog.get_widget("author_email")
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2003-02-08 22:58:41 +05:30
|
|
|
self.statbox = self.dialog.get_widget("statbox")
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-10-14 07:52:14 +05:30
|
|
|
self.apply_button = self.dialog.get_widget("apply")
|
|
|
|
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:
|
2003-12-10 09:01:38 +05:30
|
|
|
try:
|
2004-05-03 09:17:29 +05:30
|
|
|
tt = gtk.tooltips_data_get(self.apply_button)
|
2003-12-10 09:01:38 +05:30
|
|
|
if tt:
|
|
|
|
tt[0].set_tip(self.apply_button,tool_tip)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2003-10-14 07:52:14 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
self.item = None
|
|
|
|
self.build_plugin_tree(item_list,categories)
|
2005-12-26 10:41:37 +05:30
|
|
|
self.window.show()
|
2004-02-28 09:21:59 +05:30
|
|
|
|
|
|
|
def on_delete_event(self,obj,b):
|
2005-12-26 10:41:37 +05:30
|
|
|
pass
|
2004-02-28 09:21:59 +05:30
|
|
|
|
|
|
|
def close(self,ok=0):
|
2005-12-26 10:41:37 +05:30
|
|
|
self.window.destroy()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
def on_apply_clicked(self,obj):
|
|
|
|
"""Execute the selected report"""
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
(item_class,options_class,title,category,name) = self.item
|
|
|
|
if self.content == REPORTS:
|
2005-12-29 04:28:26 +05:30
|
|
|
Report.report(self.state.db,self.state.active,
|
2005-12-06 12:08:09 +05:30
|
|
|
item_class,options_class,title,name,category)
|
|
|
|
else:
|
2005-12-29 04:28:26 +05:30
|
|
|
Tool.gui_tool(self.state.db,self.state.active,
|
2005-12-06 12:08:09 +05:30
|
|
|
item_class,options_class,title,name,category,
|
2005-12-29 04:28:26 +05:30
|
|
|
self.state.db.request_rebuild,self.parent)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-11-03 12:05:06 +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"""
|
|
|
|
|
2004-08-20 17:41:56 +05:30
|
|
|
store,node = self.selection.get_selected()
|
|
|
|
if node:
|
|
|
|
path = store.get_path(node)
|
|
|
|
if not node or not self.imap.has_key(path):
|
2003-02-08 22:58:41 +05:30
|
|
|
self.statbox.hide()
|
2002-11-03 12:05:06 +05:30
|
|
|
return
|
2003-02-08 22:58:41 +05:30
|
|
|
self.statbox.show()
|
2002-11-03 12:05:06 +05:30
|
|
|
data = self.imap[path]
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
(report_class,options_class,title,category,name,
|
|
|
|
doc,status,author,email,unsupported) = data
|
2002-10-20 19:55:16 +05:30
|
|
|
self.description.set_text(doc)
|
2005-12-06 12:08:09 +05:30
|
|
|
if unsupported:
|
|
|
|
status = UNSUPPORTED
|
2003-02-08 22:58:41 +05:30
|
|
|
self.status.set_text(status)
|
2004-05-12 09:28:14 +05:30
|
|
|
self.title.set_text('<span weight="bold" size="larger">%s</span>' % title)
|
|
|
|
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)
|
2005-12-06 12:08:09 +05:30
|
|
|
self.item = (report_class,options_class,title,category,name)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
def build_plugin_tree(self,item_list,categories):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Populates a GtkTree with each menu item assocated with a entry
|
|
|
|
in the lists. The list must consist of a tuples with the following
|
|
|
|
format:
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
(item_class,options_class,title,category,name,
|
|
|
|
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 = []
|
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]:
|
|
|
|
category = UNSUPPORTED
|
|
|
|
else:
|
|
|
|
category = categories[plugin[3]]
|
|
|
|
if item_hash.has_key(category):
|
|
|
|
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.
|
2005-12-06 12:08:09 +05:30
|
|
|
key_list = [ item for item in item_hash.keys() if item != UNSUPPORTED]
|
2002-10-20 19:55:16 +05:30
|
|
|
key_list.sort()
|
2002-11-03 12:05:06 +05:30
|
|
|
key_list.reverse()
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
prev = None
|
2005-12-06 12:08:09 +05:30
|
|
|
if item_hash.has_key(UNSUPPORTED):
|
|
|
|
key = UNSUPPORTED
|
2002-10-20 19:55:16 +05:30
|
|
|
data = item_hash[key]
|
2002-11-03 12:05:06 +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
|
2005-12-06 12:08:09 +05:30
|
|
|
data.sort(lambda x,y: cmp(x[2],y[2]))
|
2002-10-20 19:55:16 +05:30
|
|
|
for item in data:
|
2002-11-03 12:05:06 +05:30
|
|
|
next = self.store.insert_after(node,next)
|
|
|
|
ilist.append((next,item))
|
2005-12-06 12:08:09 +05:30
|
|
|
self.store.set(next,0,item[2])
|
2004-12-23 09:18:23 +05:30
|
|
|
for key in key_list:
|
|
|
|
data = item_hash[key]
|
|
|
|
node = self.store.insert_after(None,prev)
|
|
|
|
self.store.set(node,0,key)
|
|
|
|
next = None
|
|
|
|
data.sort(lambda x,y: cmp(x[2],y[2]))
|
|
|
|
for item in data:
|
|
|
|
next = self.store.insert_after(node,next)
|
|
|
|
ilist.append((next,item))
|
|
|
|
self.store.set(next,0,item[2])
|
|
|
|
for next,tab in ilist:
|
|
|
|
path = self.store.get_path(next)
|
|
|
|
self.imap[path] = tab
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ReportPlugins interface class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class ReportPlugins(PluginDialog):
|
|
|
|
"""Displays the dialog box that allows the user to select the
|
|
|
|
report that is desired."""
|
|
|
|
|
2005-12-26 10:41:37 +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."""
|
2005-01-05 10:32:19 +05:30
|
|
|
PluginDialog.__init__(
|
2005-12-26 10:41:37 +05:30
|
|
|
self,
|
|
|
|
dbstate,
|
|
|
|
uistate,
|
|
|
|
track,
|
2005-12-06 12:08:09 +05:30
|
|
|
PluginMgr.report_list,
|
|
|
|
Report.standalone_categories,
|
|
|
|
_("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"),
|
|
|
|
REPORTS)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ToolPlugins interface class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class ToolPlugins(PluginDialog):
|
|
|
|
"""Displays the dialog box that allows the user to select the tool
|
|
|
|
that is desired."""
|
|
|
|
|
2005-12-29 04:28:26 +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."""
|
|
|
|
|
2005-01-05 10:32:19 +05:30
|
|
|
PluginDialog.__init__(
|
|
|
|
self,
|
2005-12-29 04:28:26 +05:30
|
|
|
dbstate,
|
|
|
|
uistate,
|
|
|
|
track,
|
2005-01-05 10:32:19 +05:30
|
|
|
PluginMgr.tool_list,
|
2005-12-06 12:08:09 +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"),
|
|
|
|
TOOLS)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# PluginStatus
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-01-11 09:21:27 +05:30
|
|
|
|
2005-12-29 04:28:26 +05:30
|
|
|
class PluginStatus(DisplayState.ManagedWindow):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Displays a dialog showing the status of loaded plugins"""
|
|
|
|
|
2005-12-29 04:28:26 +05:30
|
|
|
def __init__(self,state,uistate,track):
|
2004-11-20 10:16:47 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
import cStringIO
|
2005-12-29 04:28:26 +05:30
|
|
|
DisplayState.ManagedWindow.__init__(self, uistate, [], None)
|
2006-03-01 10:38:11 +05:30
|
|
|
|
2005-12-29 04:28:26 +05:30
|
|
|
self.state = state
|
|
|
|
self.uistate = uistate
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-08-17 07:44:33 +05:30
|
|
|
self.glade = gtk.glade.XML(const.pluginsFile,"plugstat","gramps")
|
2005-12-26 10:41:37 +05:30
|
|
|
self.window = self.glade.get_widget("plugstat")
|
|
|
|
self.window.set_title("%s - GRAMPS" % _('Plugin status'))
|
2002-10-20 19:55:16 +05:30
|
|
|
window = self.glade.get_widget("text")
|
2004-11-20 10:16:47 +05:30
|
|
|
self.pop_button = self.glade.get_widget("pop_button")
|
2006-03-03 05:40:52 +05:30
|
|
|
self.pop_button.set_active(Config.get_pop_plugin_status())
|
2004-11-20 10:16:47 +05:30
|
|
|
self.pop_button.connect('toggled',
|
2006-03-03 05:40:52 +05:30
|
|
|
lambda obj: Config.save_pop_plugin_status(self.pop_button.get_active()))
|
|
|
|
Config.client.notify_add("/apps/gramps/behavior/pop-plugin-status",
|
2004-11-20 10:16:47 +05:30
|
|
|
self.pop_button_update)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.glade.signal_autoconnect({
|
2004-11-20 10:16:47 +05:30
|
|
|
'on_close_clicked' : self.close,
|
|
|
|
'on_help_clicked' : self.help,
|
|
|
|
'on_plugstat_delete_event' : self.on_delete,
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
|
|
|
|
|
|
|
info = cStringIO.StringIO()
|
2003-03-07 07:51:18 +05:30
|
|
|
|
2005-01-05 10:32:19 +05:30
|
|
|
if len(PluginMgr.expect_list) + len(PluginMgr.failmsg_list) == 0:
|
2003-03-07 07:51:18 +05:30
|
|
|
window.get_buffer().set_text(_('All modules were successfully loaded.'))
|
|
|
|
else:
|
|
|
|
info.write(_("The following modules could not be loaded:"))
|
|
|
|
info.write("\n\n")
|
|
|
|
|
2005-01-05 10:32:19 +05:30
|
|
|
for (filename,msg) in PluginMgr.expect_list:
|
2004-08-20 17:41:56 +05:30
|
|
|
info.write("%s: %s\n\n" % (filename,msg))
|
2003-03-07 07:51:18 +05:30
|
|
|
|
2005-01-05 10:32:19 +05:30
|
|
|
for (filename,msgs) in PluginMgr.failmsg_list:
|
2003-03-07 07:51:18 +05:30
|
|
|
error = str(msgs[0])
|
|
|
|
if error[0:11] == "exceptions.":
|
|
|
|
error = error[11:]
|
2004-08-20 17:41:56 +05:30
|
|
|
info.write("%s: %s\n" % (filename,error) )
|
2003-03-07 07:51:18 +05:30
|
|
|
traceback.print_exception(msgs[0],msgs[1],msgs[2],None,info)
|
|
|
|
info.write('\n')
|
|
|
|
info.seek(0)
|
|
|
|
window.get_buffer().set_text(info.read())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-11-20 10:16:47 +05:30
|
|
|
def on_delete(self,obj1,obj2):
|
2005-12-29 04:28:26 +05:30
|
|
|
pass
|
2004-11-20 10:16:47 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def close(self,obj):
|
2005-12-26 10:41:37 +05:30
|
|
|
self.window.destroy()
|
2004-11-20 10:16:47 +05:30
|
|
|
|
|
|
|
def help(self,obj):
|
|
|
|
"""Display the GRAMPS manual"""
|
2005-12-06 12:08:09 +05:30
|
|
|
GrampsDisplay.help('gramps-getting-started')
|
2004-11-20 10:16:47 +05:30
|
|
|
|
|
|
|
def pop_button_update(self, client,cnxn_id,entry,data):
|
2006-03-03 05:40:52 +05:30
|
|
|
self.pop_button.set_active(Config.get_pop_plugin_status())
|
2004-11-20 10:16:47 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Building pulldown menus
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-06 12:08:09 +05:30
|
|
|
def build_tools_menu(top_menu,callback):
|
|
|
|
build_plugin_menu(PluginMgr.tool_list,
|
|
|
|
Tool.tool_categories,
|
|
|
|
Tool.gui_tool,
|
|
|
|
top_menu,callback)
|
|
|
|
|
|
|
|
def build_report_menu(top_menu,callback):
|
|
|
|
build_plugin_menu(PluginMgr.report_list,
|
|
|
|
Report.standalone_categories,
|
|
|
|
Report.report,
|
|
|
|
top_menu,callback)
|
|
|
|
|
|
|
|
def build_plugin_menu(item_list,categories,func,top_menu,callback):
|
|
|
|
menu = gtk.Menu()
|
|
|
|
menu.show()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-08-20 17:41:56 +05:30
|
|
|
hash_data = {}
|
2005-12-06 12:08:09 +05:30
|
|
|
for item in item_list:
|
|
|
|
if item[9]:
|
|
|
|
category = UNSUPPORTED
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2005-12-06 12:08:09 +05:30
|
|
|
category = categories[item[3]]
|
|
|
|
if hash_data.has_key(category):
|
|
|
|
hash_data[category].append(
|
|
|
|
(item[0],item[1],item[2],item[4],item[3]))
|
|
|
|
else:
|
|
|
|
hash_data[category] = [
|
|
|
|
(item[0],item[1],item[2],item[4],item[3])]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# Sort categories, skipping the unsupported
|
|
|
|
catlist = [item for item in hash_data.keys() if item != UNSUPPORTED]
|
2002-10-20 19:55:16 +05:30
|
|
|
catlist.sort()
|
|
|
|
for key in catlist:
|
|
|
|
entry = gtk.MenuItem(key)
|
|
|
|
entry.show()
|
2005-12-06 12:08:09 +05:30
|
|
|
menu.append(entry)
|
2002-10-20 19:55:16 +05:30
|
|
|
submenu = gtk.Menu()
|
|
|
|
submenu.show()
|
|
|
|
entry.set_submenu(submenu)
|
2004-08-20 17:41:56 +05:30
|
|
|
lst = hash_data[key]
|
2005-12-06 12:08:09 +05:30
|
|
|
lst.sort(by_menu_name)
|
2004-08-20 17:41:56 +05:30
|
|
|
for name in lst:
|
2005-12-06 12:08:09 +05:30
|
|
|
subentry = gtk.MenuItem("%s..." % name[2])
|
2002-10-20 19:55:16 +05:30
|
|
|
subentry.show()
|
2005-12-06 12:08:09 +05:30
|
|
|
subentry.connect("activate",callback,func,
|
|
|
|
name[0],name[1],name[2],name[3],name[4])
|
2002-10-20 19:55:16 +05:30
|
|
|
submenu.append(subentry)
|
2004-12-22 07:26:37 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# If there are any unsupported items we add separator
|
|
|
|
# and the unsupported category at the end of the menu
|
|
|
|
if hash_data.has_key(UNSUPPORTED):
|
|
|
|
entry = gtk.MenuItem(None)
|
|
|
|
entry.show()
|
|
|
|
menu.append(entry)
|
|
|
|
key = UNSUPPORTED
|
2004-12-22 07:26:37 +05:30
|
|
|
entry = gtk.MenuItem(key)
|
|
|
|
entry.show()
|
2005-12-06 12:08:09 +05:30
|
|
|
menu.append(entry)
|
2004-12-22 07:26:37 +05:30
|
|
|
submenu = gtk.Menu()
|
|
|
|
submenu.show()
|
|
|
|
entry.set_submenu(submenu)
|
|
|
|
lst = hash_data[key]
|
2005-12-06 12:08:09 +05:30
|
|
|
lst.sort(by_menu_name)
|
2004-12-22 07:26:37 +05:30
|
|
|
for name in lst:
|
2004-12-22 10:25:12 +05:30
|
|
|
subentry = gtk.MenuItem("%s..." % name[2])
|
2004-12-22 07:26:37 +05:30
|
|
|
subentry.show()
|
2005-12-06 12:08:09 +05:30
|
|
|
subentry.connect("activate",callback,func,
|
|
|
|
name[0],name[1],name[2],name[3],name[4])
|
2004-12-22 07:26:37 +05:30
|
|
|
submenu.append(subentry)
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
top_menu.set_submenu(menu)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
def by_menu_name(a,b):
|
|
|
|
return cmp(a[2],b[2])
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2005-01-11 09:21:27 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2005-12-06 12:08:09 +05:30
|
|
|
# Reload plugins
|
2005-01-11 09:21:27 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-06 12:08:09 +05:30
|
|
|
class Reload(Tool.Tool):
|
|
|
|
def __init__(self,db,person,options_class,name,callback=None,parent=None):
|
|
|
|
Tool.Tool.__init__(self,db,person,options_class,name)
|
|
|
|
|
|
|
|
"""
|
|
|
|
Treated as a callback, causes all plugins to get reloaded.
|
|
|
|
This is useful when writing and debugging a plugin.
|
|
|
|
"""
|
2005-01-11 09:21:27 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
pymod = re.compile(r"^(.*)\.py$")
|
|
|
|
|
|
|
|
oldfailmsg = PluginMgr.failmsg_list[:]
|
|
|
|
PluginMgr.failmsg_list = []
|
|
|
|
|
|
|
|
# attempt to reload all plugins that have succeeded in the past
|
|
|
|
for plugin in PluginMgr._success_list:
|
|
|
|
filename = os.path.basename(plugin.__file__)
|
|
|
|
filename = filename.replace('pyc','py')
|
|
|
|
filename = filename.replace('pyo','py')
|
|
|
|
try:
|
|
|
|
reload(plugin)
|
|
|
|
except:
|
|
|
|
PluginMgr.failmsg_list.append((filename,sys.exc_info()))
|
2005-01-11 09:21:27 +05:30
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# Remove previously good plugins that are now bad
|
|
|
|
# from the registered lists
|
|
|
|
(PluginMgr.export_list,
|
|
|
|
PluginMgr.import_list,
|
|
|
|
PluginMgr.tool_list,
|
|
|
|
PluginMgr.cli_tool_list,
|
|
|
|
PluginMgr.report_list,
|
|
|
|
PluginMgr.bkitems_list,
|
|
|
|
PluginMgr.cl_list,
|
|
|
|
PluginMgr.textdoc_list,
|
|
|
|
PluginMgr.bookdoc_list,
|
|
|
|
PluginMgr.drawdoc_list) = PluginMgr.purge_failed(
|
|
|
|
PluginMgr.failmsg_list,
|
|
|
|
PluginMgr.export_list,
|
|
|
|
PluginMgr.import_list,
|
|
|
|
PluginMgr.tool_list,
|
|
|
|
PluginMgr.cli_tool_list,
|
|
|
|
PluginMgr.report_list,
|
|
|
|
PluginMgr.bkitems_list,
|
|
|
|
PluginMgr.cl_list,
|
|
|
|
PluginMgr.textdoc_list,
|
|
|
|
PluginMgr.bookdoc_list,
|
|
|
|
PluginMgr.drawdoc_list)
|
|
|
|
|
|
|
|
# attempt to load the plugins that have failed in the past
|
|
|
|
for (filename,message) in oldfailmsg:
|
2005-01-11 09:21:27 +05:30
|
|
|
name = os.path.split(filename)
|
|
|
|
match = pymod.match(name[1])
|
|
|
|
if not match:
|
|
|
|
continue
|
|
|
|
PluginMgr.attempt_list.append(filename)
|
|
|
|
plugin = match.groups()[0]
|
|
|
|
try:
|
2005-12-06 12:08:09 +05:30
|
|
|
# For some strange reason second importing of a failed plugin
|
|
|
|
# results in success. Then reload reveals the actual error.
|
|
|
|
# Looks like a bug in Python.
|
2005-01-11 09:21:27 +05:30
|
|
|
a = __import__(plugin)
|
2005-12-06 12:08:09 +05:30
|
|
|
reload(a)
|
|
|
|
PluginMgr._success_list.append(a)
|
2005-01-11 09:21:27 +05:30
|
|
|
except:
|
|
|
|
PluginMgr.failmsg_list.append((filename,sys.exc_info()))
|
|
|
|
|
2005-12-06 12:08:09 +05:30
|
|
|
# attempt to load any new files found
|
|
|
|
for directory in PluginMgr.loaddir_list:
|
|
|
|
for filename in os.listdir(directory):
|
|
|
|
name = os.path.split(filename)
|
|
|
|
match = pymod.match(name[1])
|
|
|
|
if not match:
|
|
|
|
continue
|
|
|
|
if filename in PluginMgr.attempt_list:
|
|
|
|
continue
|
|
|
|
PluginMgr.attempt_list.append(filename)
|
|
|
|
plugin = match.groups()[0]
|
|
|
|
try:
|
|
|
|
a = __import__(plugin)
|
|
|
|
if a not in PluginMgr._success_list:
|
|
|
|
PluginMgr._success_list.append(a)
|
|
|
|
except:
|
|
|
|
PluginMgr.failmsg_list.append((filename,sys.exc_info()))
|
|
|
|
|
2006-03-03 05:40:52 +05:30
|
|
|
if Config.get_pop_plugin_status() and len(PluginMgr.failmsg_list):
|
2005-12-06 12:08:09 +05:30
|
|
|
PluginStatus()
|
|
|
|
else:
|
|
|
|
global status_up
|
|
|
|
if status_up:
|
|
|
|
status_up.close(None)
|
|
|
|
status_up = None
|
|
|
|
|
|
|
|
# Re-generate tool and report menus
|
|
|
|
parent.build_plugin_menus(rebuild=True)
|
|
|
|
|
|
|
|
class ReloadOptions(Tool.ToolOptions):
|
|
|
|
"""
|
|
|
|
Defines options and provides handling interface.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self,name,person_id=None):
|
|
|
|
Tool.ToolOptions.__init__(self,name,person_id)
|
2005-01-11 09:21:27 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register the plugin reloading tool
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
if __debug__:
|
|
|
|
PluginMgr.register_tool(
|
|
|
|
name = 'reload',
|
|
|
|
category = Tool.TOOL_DEBUG,
|
|
|
|
tool_class = Reload,
|
|
|
|
options_class = ReloadOptions,
|
|
|
|
modes = Tool.MODE_GUI,
|
|
|
|
translated_name = _("Reload plugins"),
|
|
|
|
description=_("Attempt to reload plugins. "
|
|
|
|
"Note: This tool itself is not reloaded!"),
|
|
|
|
)
|