3292: register plugins, load on need, not on start of GRAMPS - GEPS 014

Improvements: gen.plug only depends on gen, relationship default is moved
to Relationship.py, and config for hidden to a gui.pluginmanager


svn: r13405
This commit is contained in:
Benny Malengier 2009-10-25 13:52:29 +00:00
parent c10da3fec5
commit d25cdc3958
28 changed files with 161 additions and 181 deletions

@ -69,7 +69,7 @@ the format of that file is guessed according to its extension or MIME-type.
.br .br
Formats Formats
available for output are \fBgramps\-xml\fR (guessed if \fIFILE\fR ends with available for export are \fBgramps\-xml\fR (guessed if \fIFILE\fR ends with
\fB.gramps\fR), \fBgedcom\fR (guessed if \fIFILE\fR ends with \fB.ged\fR), or \fB.gramps\fR), \fBgedcom\fR (guessed if \fIFILE\fR ends with \fB.ged\fR), or
any file export available through the GRAMPS plugin system. any file export available through the GRAMPS plugin system.
.br .br

@ -51,7 +51,7 @@ import Errors
import Bookmarks import Bookmarks
import config import config
from QuestionDialog import ErrorDialog from QuestionDialog import ErrorDialog
from gen.plug import PluginManager from gui.pluginmanager import GuiPluginManager
from DdTargets import DdTargets from DdTargets import DdTargets
from Editors import EditPlace, DeletePlaceQuery from Editors import EditPlace, DeletePlaceQuery
from Filters.SideBar import PlaceSidebarFilter from Filters.SideBar import PlaceSidebarFilter
@ -195,7 +195,7 @@ class PlaceView(ListView):
#select the map services to show #select the map services to show
self.mapservicedata = {} self.mapservicedata = {}
servlist = PluginManager.get_instance().get_reg_mapservices() servlist = GuiPluginManager.get_instance().get_reg_mapservices()
for i, pdata in zip(range(len(servlist)), servlist): for i, pdata in zip(range(len(servlist)), servlist):
key = pdata.id.replace(' ', '-') key = pdata.id.replace(' ', '-')
add_menuitem(menu, pdata.name, None, add_menuitem(menu, pdata.name, None,
@ -220,7 +220,6 @@ class PlaceView(ListView):
""" """
return the current label for the menutoolbutton return the current label for the menutoolbutton
""" """
print 'called', self.mapservicedata[self.mapservice].name
return self.mapservicedata[self.mapservice].name return self.mapservicedata[self.mapservice].name
def gotomap(self, obj): def gotomap(self, obj):
@ -250,7 +249,7 @@ class PlaceView(ListView):
places = [(x, None) for x in place_handles] places = [(x, None) for x in place_handles]
#run the mapservice: #run the mapservice:
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
serv = self.mapservicedata[self.mapservice] serv = self.mapservicedata[self.mapservice]
mod = pmgr.load_plugin(serv) mod = pmgr.load_plugin(serv)
if mod: if mod:

@ -56,7 +56,7 @@ import config
from BasicUtils import name_displayer from BasicUtils import name_displayer
import const import const
import ManagedWindow import ManagedWindow
from gen.plug import PluginManager import Relationship
from glade import Glade from glade import Glade
DISABLED = -1 DISABLED = -1
@ -345,8 +345,7 @@ class DisplayState(gen.utils.Callback):
"""method that rebinds the relationship to the current rel calc """method that rebinds the relationship to the current rel calc
Should be called after load or reload of plugins Should be called after load or reload of plugins
""" """
pmgr = PluginManager.get_instance() self.relationship = Relationship.get_relationship_calculator(reinit=True)
self.relationship = pmgr.get_relationship_calculator()
def set_gendepth(self, value): def set_gendepth(self, value):
""" Set the generations we search back for showing relationships """ Set the generations we search back for showing relationships

@ -53,7 +53,7 @@ import gtk
import const import const
import config import config
from gen.plug import PluginManager from gui.pluginmanager import GuiPluginManager
import Utils import Utils
import ManagedWindow import ManagedWindow
@ -132,7 +132,7 @@ class ExportAssistant(gtk.Assistant, ManagedWindow.ManagedWindow) :
self.logo = gtk.gdk.pixbuf_new_from_file(_gramps_png) self.logo = gtk.gdk.pixbuf_new_from_file(_gramps_png)
self.splash = gtk.gdk.pixbuf_new_from_file(_splash_jpg) self.splash = gtk.gdk.pixbuf_new_from_file(_splash_jpg)
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
self.__exporters = pmgr.get_export_plugins() self.__exporters = pmgr.get_export_plugins()
self.__previous_page = -1 self.__previous_page = -1

@ -48,6 +48,7 @@ import gobject
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import Utils import Utils
from gui.utils import ProgressMeter from gui.utils import ProgressMeter
from gui.pluginmanager import GuiPluginManager
import widgets import widgets
import ManagedWindow import ManagedWindow
from QuestionDialog import OptionDialog from QuestionDialog import OptionDialog
@ -1422,7 +1423,7 @@ def make_gui_option(option, dbstate, uistate, track):
""" """
widget = None widget = None
label = True label = True
pmgr = gen.plug.PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
external_options = pmgr.get_external_opt_dict() external_options = pmgr.get_external_opt_dict()
if isinstance(option, gen.plug.menu.PersonOption): if isinstance(option, gen.plug.menu.PersonOption):
widget = GuiPersonOption(option, dbstate, uistate, track) widget = GuiPersonOption(option, dbstate, uistate, track)

@ -42,7 +42,8 @@ from gettext import gettext as _
import const import const
from ReportBase import report, standalone_categories from ReportBase import report, standalone_categories
import _Tool import _Tool
from gen.plug import PluginManager, REPORT, TOOL from gen.plug import REPORT, TOOL
from gui.pluginmanager import GuiPluginManager
import ManagedWindow import ManagedWindow
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -76,7 +77,7 @@ class PluginDialog(ManagedWindow.ManagedWindow):
self.imap = {} self.imap = {}
self.msg = msg self.msg = msg
self.content = content self.content = content
self._pmgr = PluginManager.get_instance() self._pmgr = GuiPluginManager.get_instance()
ManagedWindow.ManagedWindow.__init__(self, uistate, track, ManagedWindow.ManagedWindow.__init__(self, uistate, track,
self.__class__) self.__class__)

@ -45,7 +45,8 @@ import gobject
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import ManagedWindow import ManagedWindow
import Errors import Errors
from gen.plug import PluginManager, PluginRegister, PTYPE_STR from gen.plug import PluginRegister, PTYPE_STR
from gui.pluginmanager import GuiPluginManager
import _Tool as Tool import _Tool as Tool
from QuestionDialog import InfoDialog from QuestionDialog import InfoDialog
import config import config
@ -67,7 +68,7 @@ class PluginStatus(ManagedWindow.ManagedWindow):
ManagedWindow.ManagedWindow.__init__(self, uistate, track, ManagedWindow.ManagedWindow.__init__(self, uistate, track,
self.__class__) self.__class__)
self.__pmgr = PluginManager.get_instance() self.__pmgr = GuiPluginManager.get_instance()
self.__preg = PluginRegister.get_instance() self.__preg = PluginRegister.get_instance()
self.set_window(gtk.Dialog("", uistate.window, self.set_window(gtk.Dialog("", uistate.window,
gtk.DIALOG_DESTROY_WITH_PARENT, gtk.DIALOG_DESTROY_WITH_PARENT,

@ -54,10 +54,10 @@ import gtk
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.plug import (PluginManager, CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY, from gen.plug import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY,
CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE, CATEGORY_QR_MISC, CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE, CATEGORY_QR_MISC,
CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY) CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY)
from gui.pluginmanager import GuiPluginManager
def create_quickreport_menu(category,dbstate,uistate, handle) : def create_quickreport_menu(category,dbstate,uistate, handle) :
""" This functions querries the registered quick reports with """ This functions querries the registered quick reports with
@ -84,7 +84,7 @@ def create_quickreport_menu(category,dbstate,uistate, handle) :
#select the reports to show #select the reports to show
showlst = [] showlst = []
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
for pdata in pmgr.get_reg_quick_reports(): for pdata in pmgr.get_reg_quick_reports():
if pdata.supported and pdata.category == category : if pdata.supported and pdata.category == category :
#add tuple function, translated name, name, status #add tuple function, translated name, name, status
@ -115,7 +115,7 @@ def get_quick_report_list(qv_category=None):
CATEGORY_QR_REPOSITORY or None for all CATEGORY_QR_REPOSITORY or None for all
""" """
names = [] names = []
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
for pdata in pmgr.get_reg_quick_reports(): for pdata in pmgr.get_reg_quick_reports():
if qv_category == pdata.category or qv_category is None: if qv_category == pdata.category or qv_category is None:
names.append(pdata) # (see below for item struct) names.append(pdata) # (see below for item struct)
@ -124,7 +124,7 @@ def get_quick_report_list(qv_category=None):
def run_quick_report_by_name(dbstate, uistate, report_name, handle, def run_quick_report_by_name(dbstate, uistate, report_name, handle,
container=None): container=None):
report = None report = None
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
for pdata in pmgr.get_reg_quick_reports(): for pdata in pmgr.get_reg_quick_reports():
if pdata.id == report_name: if pdata.id == report_name:
report = pdata report = pdata
@ -142,7 +142,7 @@ def run_quick_report_by_name_direct(report_name, database, document, handle):
from docgen import TextBufDoc from docgen import TextBufDoc
from Simple import make_basic_stylesheet from Simple import make_basic_stylesheet
report = None report = None
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
for pdata in pmgr.get_reg_quick_reports(): for pdata in pmgr.get_reg_quick_reports():
if pdata.id == report_name: if pdata.id == report_name:
report = pdata report = pdata
@ -174,7 +174,7 @@ def run_report(dbstate, uistate, category, handle, pdata, container=None):
from docgen import TextBufDoc from docgen import TextBufDoc
from Simple import make_basic_stylesheet from Simple import make_basic_stylesheet
container = None container = None
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
mod = pmgr.load_plugin(pdata) mod = pmgr.load_plugin(pdata)
if not mod: if not mod:
print "QuickView Error: plugin does not load" print "QuickView Error: plugin does not load"

@ -20,6 +20,13 @@
# $Id:Relationship.py 9912 2008-01-22 09:17:46Z acraphae $ # $Id:Relationship.py 9912 2008-01-22 09:17:46Z acraphae $
#-------------------------------------------------------------------------
#
# python modules
#
#-------------------------------------------------------------------------
import os
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GRAMPS modules # GRAMPS modules
@ -28,8 +35,8 @@
import gen.lib import gen.lib
from TransUtils import sgettext as _ from TransUtils import sgettext as _
from gen.plug import PluginRegister, BasePluginManager
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
@ -1740,6 +1747,38 @@ class RelationshipCalculator(object):
""" """
self.dirtymap = True self.dirtymap = True
#-------------------------------------------------------------------------
#
# define the default relationshipcalculator
#
#-------------------------------------------------------------------------
__RELCALC_CLASS = None
def get_relationship_calculator(reinit=False):
"""
Return the relationship calculator for the current language.
"""
global __RELCALC_CLASS
if __RELCALC_CLASS is None or reinit:
__RELCALC_CLASS = RelationshipCalculator
# set correct relationship calculator based on LANG
for plugin in PluginRegister.get_instance().relcalc_plugins():
if os.environ["LANG"] in plugin.lang_list:
pmgr = BasePluginManager.get_instance()
#the loaded module is put in variable mod
mod = pmgr.load_plugin(plugin)
if mod:
__RELCALC_CLASS = eval('mod.' + plugin.relcalcclass)
break
return __RELCALC_CLASS()
#-------------------------------------------------------------------------
#
# Tests
#
#-------------------------------------------------------------------------
def _test(rc, onlybirth, inlawa, inlawb, printrelstr): def _test(rc, onlybirth, inlawa, inlawb, printrelstr):
""" this is a generic test suite for the singular relationship """ this is a generic test suite for the singular relationship

@ -40,7 +40,7 @@ log = logging.getLogger(".")
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import Utils import Utils
from gen.plug import PluginManager from gen.plug import BasePluginManager
from gen.plug.docgen import (StyleSheet, StyleSheetList, PaperStyle, from gen.plug.docgen import (StyleSheet, StyleSheetList, PaperStyle,
PAPER_PORTRAIT, PAPER_LANDSCAPE) PAPER_PORTRAIT, PAPER_LANDSCAPE)
from gen.plug.menu import (FamilyOption, PersonOption, NoteOption, from gen.plug.menu import (FamilyOption, PersonOption, NoteOption,
@ -121,7 +121,7 @@ class CommandLineReport(object):
def __init__(self, database, name, category, option_class, options_str_dict, def __init__(self, database, name, category, option_class, options_str_dict,
noopt=False): noopt=False):
pmgr = PluginManager.get_instance() pmgr = BasePluginManager.get_instance()
self.__textdoc_plugins = [] self.__textdoc_plugins = []
self.__drawdoc_plugins = [] self.__drawdoc_plugins = []
self.__bookdoc_plugins = [] self.__bookdoc_plugins = []

@ -35,7 +35,7 @@ import gobject
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from _Constants import CATEGORY_DRAW from _Constants import CATEGORY_DRAW
from _DocReportDialog import DocReportDialog from _DocReportDialog import DocReportDialog
from gen.plug import PluginManager from gui.pluginmanager import GuiPluginManager
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

@ -34,7 +34,7 @@ import gobject
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.plug import PluginManager from gui.pluginmanager import GuiPluginManager
from _Constants import CATEGORY_TEXT from _Constants import CATEGORY_TEXT
from _DocReportDialog import DocReportDialog from _DocReportDialog import DocReportDialog
@ -52,7 +52,7 @@ class _TextFormatComboBox(gtk.ComboBox):
gtk.ComboBox.__init__(self) gtk.ComboBox.__init__(self)
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
self.__textdoc_plugins = [] self.__textdoc_plugins = []
for plugin in pmgr.get_docgen_plugins(): for plugin in pmgr.get_docgen_plugins():
if plugin.get_text_support(): if plugin.get_text_support():

@ -48,7 +48,7 @@ import gen
from clidbman import CLIDbManager, NAME_FILE, find_locker_name from clidbman import CLIDbManager, NAME_FILE, find_locker_name
from PluginUtils import Tool from PluginUtils import Tool
from gen.plug import PluginManager from gen.plug import BasePluginManager
from ReportBase import CATEGORY_BOOK, CATEGORY_CODE, cl_report from ReportBase import CATEGORY_BOOK, CATEGORY_CODE, cl_report
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -146,7 +146,7 @@ class ArgHandler(object):
# or an empty string. # or an empty string.
family_tree_format = os.path.splitext(fname)[-1][1:].lower() family_tree_format = os.path.splitext(fname)[-1][1:].lower()
pmgr = PluginManager.get_instance() pmgr = BasePluginManager.get_instance()
plugin_found = False plugin_found = False
for plugin in pmgr.get_import_plugins(): for plugin in pmgr.get_import_plugins():
if family_tree_format == plugin.get_extension(): if family_tree_format == plugin.get_extension():
@ -189,7 +189,7 @@ class ArgHandler(object):
# or an empty string. # or an empty string.
family_tree_format = os.path.splitext(fname)[-1][1:].lower() family_tree_format = os.path.splitext(fname)[-1][1:].lower()
pmgr = PluginManager.get_instance() pmgr = BasePluginManager.get_instance()
plugin_found = False plugin_found = False
for plugin in pmgr.get_export_plugins(): for plugin in pmgr.get_export_plugins():
if family_tree_format == plugin.get_extension(): if family_tree_format == plugin.get_extension():
@ -403,7 +403,7 @@ class ArgHandler(object):
""" """
Command-line import routine. Try to import filename using the family_tree_format. Command-line import routine. Try to import filename using the family_tree_format.
""" """
pmgr = PluginManager.get_instance() pmgr = BasePluginManager.get_instance()
for plugin in pmgr.get_import_plugins(): for plugin in pmgr.get_import_plugins():
if family_tree_format == plugin.get_extension(): if family_tree_format == plugin.get_extension():
import_function = plugin.get_import_function() import_function = plugin.get_import_function()
@ -425,7 +425,7 @@ class ArgHandler(object):
Command-line export routine. Command-line export routine.
Try to write into filename using the family_tree_format. Try to write into filename using the family_tree_format.
""" """
pmgr = PluginManager.get_instance() pmgr = BasePluginManager.get_instance()
for plugin in pmgr.get_export_plugins(): for plugin in pmgr.get_export_plugins():
if family_tree_format == plugin.get_extension(): if family_tree_format == plugin.get_extension():
export_function = plugin.get_export_function() export_function = plugin.get_export_function()
@ -440,7 +440,7 @@ class ArgHandler(object):
""" """
Command-line action routine. Try to perform specified action. Command-line action routine. Try to perform specified action.
""" """
pmgr = PluginManager.get_instance() pmgr = BasePluginManager.get_instance()
if action == "report": if action == "report":
try: try:
options_str_dict = dict( [ tuple(chunk.split('=')) options_str_dict = dict( [ tuple(chunk.split('='))

@ -49,7 +49,7 @@ LOG = logging.getLogger(".clidbman")
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gen.db import gen.db
from gen.plug import PluginManager from gen.plug import BasePluginManager
import config import config
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -258,7 +258,7 @@ class CLIDbManager(object):
@return: A tuple of (new_path, name) for the new database @return: A tuple of (new_path, name) for the new database
or (None, None) if no import was performed. or (None, None) if no import was performed.
""" """
pmgr = PluginManager.get_instance() pmgr = BasePluginManager.get_instance()
(name, ext) = os.path.splitext(os.path.basename(filename)) (name, ext) = os.path.splitext(os.path.basename(filename))
format = ext[1:].lower() format = ext[1:].lower()

@ -52,7 +52,7 @@ import Errors
import DbState import DbState
from gen.db import (GrampsDBDir, FileVersionDeclineToUpgrade) from gen.db import (GrampsDBDir, FileVersionDeclineToUpgrade)
import gen.db.exceptions import gen.db.exceptions
from gen.plug import PluginManager from gen.plug import BasePluginManager
from Utils import get_researcher from Utils import get_researcher
import RecentFiles import RecentFiles
@ -184,7 +184,7 @@ class CLIManager(object):
else: else:
self.db_loader = None self.db_loader = None
self.file_loaded = False self.file_loaded = False
self._pmgr = PluginManager.get_instance() self._pmgr = BasePluginManager.get_instance()
def open_activate(self, path): def open_activate(self, path):
""" """

@ -30,14 +30,14 @@ from _pluginreg import (PluginData, PluginRegister, REPORT, TOOL,
CATEGORY_QR_FAMILY, CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE, CATEGORY_QR_FAMILY, CATEGORY_QR_EVENT, CATEGORY_QR_SOURCE,
CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY, CATEGORY_QR_NOTE, CATEGORY_QR_PLACE, CATEGORY_QR_REPOSITORY, CATEGORY_QR_NOTE,
CATEGORY_QR_DATE, PTYPE_STR ) CATEGORY_QR_DATE, PTYPE_STR )
from _manager import PluginManager from _manager import BasePluginManager
from _import import ImportPlugin from _import import ImportPlugin
from _export import ExportPlugin from _export import ExportPlugin
from _docgenplugin import DocGenPlugin from _docgenplugin import DocGenPlugin
from utils import * from utils import *
__all__ = [ "docbackend", "docgen", "menu", Plugin, PluginData, __all__ = [ "docbackend", "docgen", "menu", Plugin, PluginData,
PluginRegister, PluginManager, PluginRegister, BasePluginManager,
ImportPlugin, ExportPlugin, DocGenPlugin, ImportPlugin, ExportPlugin, DocGenPlugin,
REPORT, TOOL, CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_CODE, REPORT, TOOL, CATEGORY_TEXT, CATEGORY_DRAW, CATEGORY_CODE,
CATEGORY_WEB, CATEGORY_BOOK, CATEGORY_GRAPHVIZ, CATEGORY_WEB, CATEGORY_BOOK, CATEGORY_GRAPHVIZ,

@ -45,9 +45,7 @@ from gettext import gettext as _
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gen.utils import gen.utils
import Relationship
from gen.plug import PluginRegister from gen.plug import PluginRegister
import config
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -58,30 +56,27 @@ _UNAVAILABLE = _("No description was provided")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# PluginManager # BasePluginManager
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class PluginManager(gen.utils.Callback): class BasePluginManager(object):
""" PluginManager is a Singleton which manages plugins """ """ unique singleton storage class for a PluginManager. """
__instance = None __instance = None
__signals__ = { 'plugins-reloaded' : None }
def get_instance(): def get_instance():
""" Use this function to get the instance of the PluginManager """ """ Use this function to get the instance of the PluginManager """
if PluginManager.__instance is None: if BasePluginManager.__instance is None:
PluginManager.__instance = 1 # Set to 1 for __init__() BasePluginManager.__instance = 1 # Set to 1 for __init__()
PluginManager.__instance = PluginManager() BasePluginManager.__instance = BasePluginManager()
return PluginManager.__instance return BasePluginManager.__instance
get_instance = staticmethod(get_instance) get_instance = staticmethod(get_instance)
def __init__(self): def __init__(self):
""" This function should only be run once by get_instance() """ """ This function should only be run once by get_instance() """
if PluginManager.__instance is not 1: if BasePluginManager.__instance is not 1:
raise Exception("This class is a singleton. " raise Exception("This class is a singleton. "
"Use the get_instance() method") "Use the get_instance() method")
gen.utils.Callback.__init__(self)
self.__import_plugins = [] self.__import_plugins = []
self.__export_plugins = [] self.__export_plugins = []
@ -91,28 +86,12 @@ class PluginManager(gen.utils.Callback):
self.__failmsg_list = [] self.__failmsg_list = []
self.__external_opt_dict = {} self.__external_opt_dict = {}
self.__success_list = [] self.__success_list = []
self.__relcalc_class = Relationship.RelationshipCalculator
self.__mod2text = {} self.__mod2text = {}
self.__pgr = PluginRegister.get_instance() self.__pgr = PluginRegister.get_instance()
self.__registereddir_set = set() self.__registereddir_set = set()
self.__loaded_plugins = {} self.__loaded_plugins = {}
self.__hidden_plugins = set([])
for id in config.get('plugin.hiddenplugins'):
self.__hidden_plugins.add(id)
self.__hidden_changed()
def __hidden_changed(self, *args):
#if hidden changed, stored data must be emptied as it could contain
#something that now must be hidden
self.__import_plugins = []
self.__export_plugins = []
self.__docgen_plugins = []
#objects that need to know if the plugins available changed, are
#listening to this signal to update themselves. If a plugin becomes
#(un)hidden, this should happen, so we emit.
self.emit('plugins-reloaded')
def reg_plugins(self, direct): def reg_plugins(self, direct):
""" """
@ -133,16 +112,7 @@ class PluginManager(gen.utils.Callback):
# registereddir_list list for use on reloading. # registereddir_list list for use on reloading.
self.__registereddir_set.add(dirpath) self.__registereddir_set.add(dirpath)
self.__pgr.scan_dir(dirpath) self.__pgr.scan_dir(dirpath)
# set correct relationship calculator based on LANG
for plugin in self.__pgr.relcalc_plugins():
if os.environ["LANG"] in plugin.lang_list:
#the loaded module is put in variable mod
mod = self.load_plugin(plugin)
if mod:
self.__relcalc_class = eval('mod.' +
plugin.relcalcclass)
break
# load plugins that request to be loaded on startup # load plugins that request to be loaded on startup
for plugin in self.__pgr.filter_load_on_reg(): for plugin in self.__pgr.filter_load_on_reg():
mod = self.load_plugin(plugin) mod = self.load_plugin(plugin)
@ -167,6 +137,15 @@ class PluginManager(gen.utils.Callback):
self.__failmsg_list.append((filename, sys.exc_info())) self.__failmsg_list.append((filename, sys.exc_info()))
return None return None
def empty_managed_plugins(self):
""" For some plugins, managed Plugin are used. These are only
reobtained from the registry if this method is called
"""
# TODO: do other lists need to be reset here, too?
self.__import_plugins = []
self.__export_plugins = []
self.__docgen_plugins = []
def reload_plugins(self): def reload_plugins(self):
""" Reload previously loaded plugins """ """ Reload previously loaded plugins """
pymod = re.compile(r"^(.*)\.py$") pymod = re.compile(r"^(.*)\.py$")
@ -175,10 +154,7 @@ class PluginManager(gen.utils.Callback):
self.__failmsg_list = [] self.__failmsg_list = []
# attempt to reload all plugins that have succeeded in the past # attempt to reload all plugins that have succeeded in the past
# TODO: do other lists need to be reset here, too? self.empty_managed_plugins()
self.__import_plugins[:] = []
self.__export_plugins[:] = []
self.__docgen_plugins[:] = []
for plugin in self.__success_list: for plugin in self.__success_list:
filename = plugin[0] filename = plugin[0]
@ -211,35 +187,6 @@ class PluginManager(gen.utils.Callback):
except: except:
self.__failmsg_list.append((filename, sys.exc_info())) self.__failmsg_list.append((filename, sys.exc_info()))
self.emit('plugins-reloaded')
def get_hidden_plugin_ids(self):
"""
Returns copy of the set hidden plugin ids
"""
return self.__hidden_plugins.copy()
def hide_plugin(self, id):
""" Hide plugin with given id. This will hide the plugin so queries do
not return it anymore, and write this change to the config.
Note that config will then emit a signal
"""
self.__hidden_plugins.add(id)
hideset = [x for x in self.__hidden_plugins]
config.set('plugin.hiddenplugins', hideset)
config.save()
self.__hidden_changed()
def unhide_plugin(self, id):
""" Unhide plugin with given id. This will unhide the plugin so queries
return it again, and write this change to the config
"""
self.__hidden_plugins.remove(id)
hideset = [x for x in self.__hidden_plugins]
config.set('plugin.hiddenplugins', hideset)
config.save()
self.__hidden_changed()
def get_fail_list(self): def get_fail_list(self):
""" Return the list of failed plugins. """ """ Return the list of failed plugins. """
return self.__failmsg_list return self.__failmsg_list
@ -249,38 +196,33 @@ class PluginManager(gen.utils.Callback):
return self.__success_list return self.__success_list
def get_reg_reports(self, gui=True): def get_reg_reports(self, gui=True):
""" Return list of non hidden registered reports """ Return list of registered reports
:Param gui: bool indicating if GUI reports or CLI reports must be :Param gui: bool indicating if GUI reports or CLI reports must be
returned returned
""" """
return [plg for plg in self.__pgr.report_plugins(gui) if plg.id not in return self.__pgr.report_plugins(gui)
self.__hidden_plugins]
def get_reg_tools(self, gui=True): def get_reg_tools(self, gui=True):
""" Return list of non hidden registered tools """ Return list of registered tools
:Param gui: bool indicating if GUI reports or CLI reports must be :Param gui: bool indicating if GUI reports or CLI reports must be
returned returned
""" """
return [plg for plg in self.__pgr.tool_plugins(gui) if plg.id not in return self.__pgr.tool_plugins(gui)
self.__hidden_plugins]
def get_reg_quick_reports(self): def get_reg_quick_reports(self):
""" Return list of non hidden registered quick reports """ Return list of registered quick reports
""" """
return [plg for plg in self.__pgr.quickreport_plugins() if plg.id not in return self.__pgr.quickreport_plugins()
self.__hidden_plugins]
def get_reg_mapservices(self): def get_reg_mapservices(self):
""" Return list of non hidden registered mapservices """ Return list of registered mapservices
""" """
return [plg for plg in self.__pgr.mapservice_plugins() if plg.id not in return self.__pgr.mapservice_plugins()
self.__hidden_plugins]
def get_reg_bookitems(self): def get_reg_bookitems(self):
""" Return list of non hidden reports registered as bookitem """ Return list of reports registered as bookitem
""" """
return [plg for plg in self.__pgr.bookitem_plugins() if plg.id not in return self.__pgr.bookitem_plugins()
self.__hidden_plugins]
def get_external_opt_dict(self): def get_external_opt_dict(self):
""" Return the dictionary of external options. """ """ Return the dictionary of external options. """
@ -290,6 +232,21 @@ class PluginManager(gen.utils.Callback):
""" Given a module name, return the module description. """ """ Given a module name, return the module description. """
return self.__mod2text.get(module, '') return self.__mod2text.get(module, '')
def get_reg_importers(self):
""" Return list of registered importers
"""
return self.__pgr.import_plugins()
def get_reg_exporters(self):
""" Return list of registered exporters
"""
return self.__pgr.export_plugins()
def get_reg_docgens(self):
""" Return list of registered docgen
"""
return self.__pgr.docgen_plugins()
def get_import_plugins(self): def get_import_plugins(self):
""" """
Get the list of import plugins. Get the list of import plugins.
@ -300,9 +257,7 @@ class PluginManager(gen.utils.Callback):
## only PluginData, loading from module when importfunction needed? ## only PluginData, loading from module when importfunction needed?
if self.__import_plugins == []: if self.__import_plugins == []:
#The module still needs to be imported #The module still needs to be imported
imps = [pdata for pdata in self.__pgr.import_plugins() if pdata.id for pdata in self.get_reg_importers():
not in self.__hidden_plugins]
for pdata in imps:
mod = self.load_plugin(pdata) mod = self.load_plugin(pdata)
if mod: if mod:
imp = gen.plug.ImportPlugin(name=pdata.name, imp = gen.plug.ImportPlugin(name=pdata.name,
@ -323,9 +278,7 @@ class PluginManager(gen.utils.Callback):
## only PluginData, loading from module when export/options needed? ## only PluginData, loading from module when export/options needed?
if self.__export_plugins == []: if self.__export_plugins == []:
#The modules still need to be imported #The modules still need to be imported
exps = [pdata for pdata in self.__pgr.export_plugins() if pdata.id for pdata in self.get_reg_exporters():
not in self.__hidden_plugins]
for pdata in exps:
mod = self.load_plugin(pdata) mod = self.load_plugin(pdata)
if mod: if mod:
exp = gen.plug.ExportPlugin(name=pdata.name, exp = gen.plug.ExportPlugin(name=pdata.name,
@ -349,9 +302,7 @@ class PluginManager(gen.utils.Callback):
## So, only do import when docgen.get_basedoc() is requested ## So, only do import when docgen.get_basedoc() is requested
if self.__docgen_plugins == []: if self.__docgen_plugins == []:
#The modules still need to be imported #The modules still need to be imported
dgdps = [pdata for pdata in self.__pgr.docgen_plugins() if pdata.id for pdata in self.get_reg_docgens():
not in self.__hidden_plugins]
for pdata in dgdps:
mod = self.load_plugin(pdata) mod = self.load_plugin(pdata)
if mod: if mod:
dgp = gen.plug.DocGenPlugin(name=pdata.name, dgp = gen.plug.DocGenPlugin(name=pdata.name,
@ -394,9 +345,3 @@ class PluginManager(gen.utils.Callback):
if item.get_module_name() not in failed_module_names ][:] if item.get_module_name() not in failed_module_names ][:]
self.__docgen_plugins[:] = [ item for item in self.__docgen_plugins self.__docgen_plugins[:] = [ item for item in self.__docgen_plugins
if item.get_module_name() not in failed_module_names ][:] if item.get_module_name() not in failed_module_names ][:]
def get_relationship_calculator(self):
"""
Return the relationship calculator for the current language.
"""
return self.__relcalc_class()

@ -59,7 +59,7 @@ import const
import config import config
import gen.db import gen.db
import Utils import Utils
from gen.plug import PluginManager from gui.pluginmanager import GuiPluginManager
from QuestionDialog import (DBErrorDialog, ErrorDialog, QuestionDialog2, from QuestionDialog import (DBErrorDialog, ErrorDialog, QuestionDialog2,
WarningDialog) WarningDialog)
import Errors import Errors
@ -113,7 +113,7 @@ class DbLoader(CLIDbLoader):
if not warn_dialog.run(): if not warn_dialog.run():
return False return False
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
import_dialog = gtk.FileChooserDialog(_('GRAMPS: Import database'), import_dialog = gtk.FileChooserDialog(_('GRAMPS: Import database'),
self.uistate.window, self.uistate.window,
@ -323,7 +323,7 @@ def format_maker():
The auto selection is always added as the first one. The auto selection is always added as the first one.
The returned box contains both the label and the selector. The returned box contains both the label and the selector.
""" """
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
format_list = [ ('auto', _('Automatically detected')) ] format_list = [ ('auto', _('Automatically detected')) ]
for plugin in pmgr.get_import_plugins(): for plugin in pmgr.get_import_plugins():

@ -69,7 +69,7 @@ import pango
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from QuestionDialog import ErrorDialog, QuestionDialog from QuestionDialog import ErrorDialog, QuestionDialog
from gen.db import GrampsDBDir from gen.db import GrampsDBDir
from gen.plug import PluginManager from gui.pluginmanager import GuiPluginManager
from cli.clidbman import CLIDbManager, NAME_FILE, time_val from cli.clidbman import CLIDbManager, NAME_FILE, time_val
import GrampsDbUtils import GrampsDbUtils
from DdTargets import DdTargets from DdTargets import DdTargets
@ -795,7 +795,7 @@ def check_out(dbase, rev, path, callback):
) )
return return
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
for plugin in pmgr.get_import_plugins(): for plugin in pmgr.get_import_plugins():
if plugin.get_extension() == "gramps": if plugin.get_extension() == "gramps":
rdr = plugin.get_import_function() rdr = plugin.get_import_function()
@ -838,7 +838,7 @@ def check_in(dbase, filename, callback, cursor_func = None):
if cursor_func: if cursor_func:
cursor_func(_("Creating data to be archived...")) cursor_func(_("Creating data to be archived..."))
plugin_manager = PluginManager.get_instance() plugin_manager = GuiPluginManager.get_instance()
for plugin in plugin_manager.get_export_plugins(): for plugin in plugin_manager.get_export_plugins():
if plugin.get_extension() == "gramps": if plugin.get_extension() == "gramps":
export_function = plugin.get_export_function() export_function = plugin.get_export_function()

@ -59,7 +59,9 @@ import gtk
from cli.grampscli import CLIManager from cli.grampscli import CLIManager
from PluginUtils import Tool, PluginWindows, \ from PluginUtils import Tool, PluginWindows, \
ReportPluginDialog, ToolPluginDialog, gui_tool ReportPluginDialog, ToolPluginDialog, gui_tool
from gen.plug import PluginManager, REPORT from gen.plug import REPORT
from gui.pluginmanager import GuiPluginManager
import Relationship
import ReportBase import ReportBase
import DisplayState import DisplayState
import const import const
@ -215,6 +217,8 @@ class ViewManager(CLIManager):
def __init__(self, dbstate): def __init__(self, dbstate):
CLIManager.__init__(self, dbstate, False) CLIManager.__init__(self, dbstate, False)
#set pluginmanager to GUI one
self._pmgr = GuiPluginManager.get_instance()
self.page_is_changing = False self.page_is_changing = False
self.active_page = None self.active_page = None
self.views = [] self.views = []
@ -235,7 +239,11 @@ class ViewManager(CLIManager):
self.__build_main_window() self.__build_main_window()
self.__connect_signals() self.__connect_signals()
self.do_reg_plugins() self.do_reg_plugins()
#plugins loaded now set relationship class
self.rel_class = Relationship.get_relationship_calculator()
self.uistate.set_relationship_class()
def _errordialog(title, errormessage): def _errordialog(title, errormessage):
""" """
@ -255,8 +263,6 @@ class ViewManager(CLIManager):
self.window = gtk.Window() self.window = gtk.Window()
self.window.set_icon_from_file(const.ICON) self.window.set_icon_from_file(const.ICON)
self.window.set_default_size(width, height) self.window.set_default_size(width, height)
self.rel_class = self._pmgr.get_relationship_calculator()
vbox = gtk.VBox() vbox = gtk.VBox()
self.window.add(vbox) self.window.add(vbox)
@ -553,7 +559,6 @@ class ViewManager(CLIManager):
self.fileactions.set_sensitive(False) self.fileactions.set_sensitive(False)
self.__build_tools_menu(self._pmgr.get_reg_tools()) self.__build_tools_menu(self._pmgr.get_reg_tools())
self.__build_report_menu(self._pmgr.get_reg_reports()) self.__build_report_menu(self._pmgr.get_reg_reports())
self.uistate.set_relationship_class()
self._pmgr.connect('plugins-reloaded', self._pmgr.connect('plugins-reloaded',
self.__rebuild_report_and_tool_menus) self.__rebuild_report_and_tool_menus)
self.fileactions.set_sensitive(True) self.fileactions.set_sensitive(True)
@ -1448,7 +1453,7 @@ def run_plugin(pdata, dbstate, uistate):
1/ load plugin. 1/ load plugin.
2/ the report is run 2/ the report is run
""" """
mod = PluginManager.get_instance().load_plugin(pdata) mod = GuiPluginManager.get_instance().load_plugin(pdata)
if not mod: if not mod:
#import of plugin failed #import of plugin failed
ErrorDialog( ErrorDialog(

@ -69,7 +69,7 @@ import const
import Utils import Utils
import ListModel import ListModel
import Errors import Errors
from gen.plug import PluginManager from gui.pluginmanager import GuiPluginManager
from gen.plug.docgen import StyleSheet, StyleSheetList from gen.plug.docgen import StyleSheet, StyleSheetList
from QuestionDialog import WarningDialog, ErrorDialog from QuestionDialog import WarningDialog, ErrorDialog
from gen.plug.menu import PersonOption, FilterOption, FamilyOption from gen.plug.menu import PersonOption, FilterOption, FamilyOption
@ -198,7 +198,7 @@ class BookItem(object):
""" """
self.dbase = dbase self.dbase = dbase
self.style_name = "default" self.style_name = "default"
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
for pdata in pmgr.get_reg_bookitems(): for pdata in pmgr.get_reg_bookitems():
if pdata.id == name: if pdata.id == name:
@ -748,7 +748,7 @@ class BookReportSelector(ManagedWindow.ManagedWindow):
The selections are read from the book item registry. The selections are read from the book item registry.
""" """
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
regbi = pmgr.get_reg_bookitems() regbi = pmgr.get_reg_bookitems()
if not regbi: if not regbi:
return return
@ -1061,7 +1061,7 @@ class _BookFormatComboBox(gtk.ComboBox):
gtk.ComboBox.__init__(self) gtk.ComboBox.__init__(self)
pmgr = PluginManager.get_instance() pmgr = GuiPluginManager.get_instance()
self.__bookdoc_plugins = [] self.__bookdoc_plugins = []
for plugin in pmgr.get_docgen_plugins(): for plugin in pmgr.get_docgen_plugins():
if plugin.get_text_support() and plugin.get_draw_support(): if plugin.get_text_support() and plugin.get_draw_support():

@ -43,10 +43,6 @@ from gen.plug.menu import (BooleanOption, EnumeratedListOption,
from ReportBase import Report, ReportUtils, MenuReportOptions from ReportBase import Report, ReportUtils, MenuReportOptions
from Utils import probably_alive from Utils import probably_alive
MODE_GUI = PluginManager.REPORT_MODE_GUI
MODE_BKI = PluginManager.REPORT_MODE_BKI
MODE_CLI = PluginManager.REPORT_MODE_CLI
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# Global functions # Global functions

@ -36,7 +36,7 @@ import time
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from BasicUtils import name_displayer from BasicUtils import name_displayer
from Errors import ReportError from Errors import ReportError
from gen.plug import PluginManager import Relationship
from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SERIF, PARA_ALIGN_CENTER, FONT_SERIF, PARA_ALIGN_CENTER,
PARA_ALIGN_LEFT, PARA_ALIGN_RIGHT) PARA_ALIGN_LEFT, PARA_ALIGN_RIGHT)
@ -251,8 +251,7 @@ class Calendar(Report):
people = self.database.iter_person_handles() people = self.database.iter_person_handles()
self.progress.set_pass(_('Applying Filter...'), self.database.get_number_of_people()) self.progress.set_pass(_('Applying Filter...'), self.database.get_number_of_people())
people = self.filter.apply(self.database, people, self.progress) people = self.filter.apply(self.database, people, self.progress)
pmgr = PluginManager.get_instance() rel_calc = Relationship.get_relationship_calculator()
rel_calc = pmgr.get_relationship_calculator()
self.progress.set_pass(_('Reading database...'), len(people)) self.progress.set_pass(_('Reading database...'), len(people))
for person_handle in people: for person_handle in people:

@ -33,7 +33,7 @@ Display a person's relations to the home person
from Simple import SimpleAccess, SimpleDoc from Simple import SimpleAccess, SimpleDoc
from gettext import gettext as _ from gettext import gettext as _
from gen.plug import PluginManager import Relationship
# define the formatting string once as a constant. Since this is reused # define the formatting string once as a constant. Since this is reused
@ -60,9 +60,7 @@ class AllRelReport():
self.person = person self.person = person
self.sdb = SimpleAccess(database) self.sdb = SimpleAccess(database)
self.sdoc = SimpleDoc(document) self.sdoc = SimpleDoc(document)
self.rel_class = Relationship.get_relationship_calculator()
pmgr = PluginManager.get_instance()
self.rel_class = pmgr.get_relationship_calculator()
self.msg_list = [] self.msg_list = []

@ -27,7 +27,7 @@ Display a person's siblings in a report window
""" """
from Simple import SimpleAccess, SimpleDoc, SimpleTable from Simple import SimpleAccess, SimpleDoc, SimpleTable
from gen.plug import PluginManager import Relationship
from gettext import gettext as _ from gettext import gettext as _
def run(database, document, person): def run(database, document, person):
@ -39,8 +39,7 @@ def run(database, document, person):
sdb = SimpleAccess(database) sdb = SimpleAccess(database)
sdoc = SimpleDoc(document) sdoc = SimpleDoc(document)
stab = SimpleTable(sdb) stab = SimpleTable(sdb)
pmgr = PluginManager.get_instance() rel_class = Relationship.get_relationship_calculator()
rel_class = pmgr.get_relationship_calculator()
# display the title # display the title
sdoc.title(_("Siblings of %s") % sdb.name(person)) sdoc.title(_("Siblings of %s") % sdb.name(person))

@ -38,7 +38,7 @@ import datetime, time
from BasicUtils import name_displayer as _nd from BasicUtils import name_displayer as _nd
from Errors import ReportError from Errors import ReportError
from gen.lib import NameType, EventType, Name, Date, Person from gen.lib import NameType, EventType, Name, Date, Person
from gen.plug import PluginManager import Relationship
from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SERIF, PARA_ALIGN_RIGHT, FONT_SERIF, PARA_ALIGN_RIGHT,
PARA_ALIGN_LEFT, PARA_ALIGN_CENTER) PARA_ALIGN_LEFT, PARA_ALIGN_CENTER)
@ -200,8 +200,7 @@ class CalendarReport(Report):
self.progress.set_pass(_('Applying Filter...'), self.progress.set_pass(_('Applying Filter...'),
self.database.get_number_of_people()) self.database.get_number_of_people())
people = self.filter.apply(self.database, people, self.progress) people = self.filter.apply(self.database, people, self.progress)
pmgr = PluginManager.get_instance() rel_calc = Relationship.get_relationship_calculator()
rel_calc = pmgr.get_relationship_calculator()
self.progress.set_pass(_('Reading database...'), len(people)) self.progress.set_pass(_('Reading database...'), len(people))
for person_handle in people: for person_handle in people:

@ -38,7 +38,7 @@ from gettext import gettext as _
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from BasicUtils import name_displayer from BasicUtils import name_displayer
from Errors import ReportError from Errors import ReportError
from gen.plug import PluginManager import Relationship
from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle,
FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER)
from gen.plug.menu import NumberOption, BooleanOption, PersonOption from gen.plug.menu import NumberOption, BooleanOption, PersonOption
@ -85,7 +85,7 @@ class KinshipReport(Report):
raise ReportError(_("Person %s is not in the Database") % pid ) raise ReportError(_("Person %s is not in the Database") % pid )
self.__db = database self.__db = database
self.rel_calc = PluginManager.get_instance().get_relationship_calculator() self.rel_calc = Relationship.get_relationship_calculator()
self.kinship_map = {} self.kinship_map = {}
self.spouse_map = {} self.spouse_map = {}

@ -45,7 +45,7 @@ import gtk
from BasicUtils import name_displayer from BasicUtils import name_displayer
import ManagedWindow import ManagedWindow
from DisplayModels import PeopleModel from DisplayModels import PeopleModel
from gen.plug import PluginManager import Relationship
from QuestionDialog import ErrorDialog from QuestionDialog import ErrorDialog
from PluginUtils import Tool from PluginUtils import Tool
@ -86,8 +86,7 @@ class RelCalc(Tool.Tool, ManagedWindow.ManagedWindow):
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__) ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
self.dbstate = dbstate self.dbstate = dbstate
pmgr = PluginManager.get_instance() self.relationship = Relationship.get_relationship_calculator()
self.relationship = pmgr.get_relationship_calculator()
self.relationship.connect_db_signals(dbstate) self.relationship.connect_db_signals(dbstate)
self.glade = Glade() self.glade = Glade()