From ef066a3b6af1286f30570d45ba5e8398eca7771f Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 5 Feb 2009 02:23:46 +0000 Subject: [PATCH] Feature #2393: Allow the use of user-defined (mega)-widgets by MD Nauta; added register_option() svn: r11861 --- src/PluginUtils/_GuiOptions.py | 5 +++++ src/gen/plug/_manager.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/PluginUtils/_GuiOptions.py b/src/PluginUtils/_GuiOptions.py index 468b4e9dc..1a74e0b3a 100644 --- a/src/PluginUtils/_GuiOptions.py +++ b/src/PluginUtils/_GuiOptions.py @@ -1415,6 +1415,8 @@ def make_gui_option(option, tooltips, dbstate, uistate, track): """ widget = None label = True + pmgr = gen.plug.PluginManager.get_instance() + external_options = pmgr.get_external_opt_dict() if tooltips == None: tooltips = gtk.Tooltips() elif type(tooltips) == type(""): @@ -1455,6 +1457,9 @@ def make_gui_option(option, tooltips, dbstate, uistate, track): tooltips) elif isinstance(option, gen.plug.menu.PlaceListOption): widget = GuiPlaceListOption(option, dbstate, uistate, track, tooltips) + elif option.__class__ in external_options: + widget = external_options[option.__class__](option, dbstate, uistate, + track, tooltips) else: raise AttributeError( "can't make GuiOption: unknown option type: '%s'" % option) diff --git a/src/gen/plug/_manager.py b/src/gen/plug/_manager.py index c32befb8c..1373f8faf 100644 --- a/src/gen/plug/_manager.py +++ b/src/gen/plug/_manager.py @@ -106,6 +106,7 @@ class PluginManager(gen.utils.Callback): self.__bkitems_list = [] self.__cl_list = [] self.__cli_tool_list = [] + self.__external_opt_dict = {} self.__success_list = [] self.__relcalc_class = Relationship.RelationshipCalculator @@ -269,6 +270,10 @@ class PluginManager(gen.utils.Callback): """ Return the list of command line tool plugins. """ return self.__cli_tool_list + def get_external_opt_dict(self): + """ Return the dictionary of external options. """ + return self.__external_opt_dict + def get_module_description(self, module): """ Given a module name, return the module description. """ return self.__mod2text.get(module, '') @@ -563,6 +568,21 @@ class PluginManager(gen.utils.Callback): self.__mod2text[mapservice.__module__] = tooltip + def register_option(self, option, guioption): + """ + Register an external option. + + Register a mapping from option to guioption for an option + that is not native to Gramps but provided by the plugin writer. + This should typically be called during initialisation of a + ReportOptions class. + @param option: the option class + @type option: class that inherits from gen.plug.menu.Option + @param guioption: the gui-option class + @type guioption: class that inherits from gtk.Widget. + """ + self.__external_opt_dict[option] = guioption; + def __purge_failed(self): """ Purge the failed plugins from the corresponding lists.