Add DocGenPlugin to be used to register all docgen plugins. This replaces the array of variables which was more difficult to read.

svn: r12359
This commit is contained in:
Brian Matherly
2009-03-19 02:24:29 +00:00
parent 82f5f01a6a
commit c56c25b932
25 changed files with 545 additions and 497 deletions

View File

@@ -10,6 +10,7 @@ pkgdatadir = $(datadir)/@PACKAGE@/gen/plug
pkgdata_PYTHON = \
__init__.py \
_docgen.py \
_export.py \
_import.py \
_manager.py \

View File

@@ -25,5 +25,7 @@ from _plugin import Plugin
from _manager import PluginManager
from _import import ImportPlugin
from _export import ExportPlugin
from _docgen import DocGenPlugin
__all__ = [ "menu", Plugin, PluginManager, ImportPlugin, ExportPlugin ]
__all__ = [ "menu", Plugin, PluginManager, ImportPlugin, ExportPlugin, \
DocGenPlugin ]

109
src/gen/plug/_docgen.py Normal file
View File

@@ -0,0 +1,109 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2008 Brian G. Matherly
#
# 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
#
# $Id: $
"""
This module provides the Plugin class for document generator plugins.
"""
from gen.plug import Plugin
import BaseDoc
class DocGenPlugin(Plugin):
"""
This class represents a plugin for generating documents from Gramps
"""
def __init__(self, name, description, basedoc, paper, style, extension):
"""
@param name: A friendly name to call this plugin.
Example: "Plain Text"
@type name: string
@param description: A short description of the plugin.
Example: "This plugin will generate text documents in plain text."
@type description: string
@param basedoc: A class that implements the BaseDoc.BaseDoc
interface.
@type basedoc: BaseDoc.BaseDoc
@param paper: Indicates whether the plugin uses paper or not.
True = use paper; False = do not use paper
@type paper: bool
@param style: Indicates whether the plugin uses styles or not.
True = use styles; False = do not use styles
@type style: bool
@param extension: The extension for the output file.
Example: "txt"
@type extension: str
@return: nothing
"""
Plugin.__init__(self, name, description, basedoc.__module__)
self.__basedoc = basedoc
self.__paper = paper
self.__style = style
self.__extension = extension
def get_basedoc(self):
"""
Get the BaseDoc class for this plugin.
@return: the BaseDoc.BaseDoc class passed into __init__
"""
return self.__basedoc
def get_paper_used(self):
"""
Get the paper flag for this plugin.
@return: bool - True = use paper; False = do not use paper
"""
return self.__paper
def get_style_support(self):
"""
Get the style flag for this plugin.
@return: bool - True = use styles; False = do not use styles
"""
return self.__style
def get_extension(self):
"""
Get the file extension for the output file.
@return: str
"""
return self.__extension
def get_text_support(self):
"""
Check if the plugin supports the BaseDoc.TextDoc interface.
@return: bool: True if TextDoc is supported; False if TextDoc is not
supported.
"""
return bool(issubclass(self.__basedoc, BaseDoc.TextDoc))
def get_draw_support(self):
"""
Check if the plugin supports the BaseDoc.DrawDoc interface.
@return: bool: True if DrawDoc is supported; False if DrawDoc is not
supported.
"""
return bool(issubclass(self.__basedoc, BaseDoc.DrawDoc))

View File

@@ -95,13 +95,11 @@ class PluginManager(gen.utils.Callback):
self.__tool_list = []
self.__import_plugins = []
self.__export_plugins = []
self.__docgen_plugins = []
self.__general_plugins = []
self.__mapservice_list = []
self.__attempt_list = []
self.__loaddir_list = []
self.__textdoc_list = []
self.__bookdoc_list = []
self.__drawdoc_list = []
self.__failmsg_list = []
self.__bkitems_list = []
self.__cl_list = []
@@ -169,6 +167,7 @@ class PluginManager(gen.utils.Callback):
# TODO: do other lists need to be reset here, too?
self.__import_plugins[:] = []
self.__export_plugins[:] = []
self.__docgen_plugins[:] = []
for plugin in self.__success_list:
filename = plugin[0]
@@ -250,18 +249,6 @@ class PluginManager(gen.utils.Callback):
""" Return the list of book plugins. """
return self.__bkitems_list
def get_text_doc_list(self):
""" Return the list of text document generator plugins. """
return self.__textdoc_list
def get_draw_doc_list(self):
""" Return the list of graphical document generator plugins. """
return self.__drawdoc_list
def get_book_doc_list(self):
""" Return the list of book document generator plugins. """
return self.__bookdoc_list
def get_cl_list(self):
""" Return the list of command line report plugins. """
return self.__cl_list
@@ -288,6 +275,8 @@ class PluginManager(gen.utils.Callback):
self.__import_plugins.append(plugin)
elif isinstance(plugin, gen.plug.ExportPlugin):
self.__export_plugins.append(plugin)
elif isinstance(plugin, gen.plug.DocGenPlugin):
self.__docgen_plugins.append(plugin)
elif isinstance(plugin, gen.plug.Plugin):
self.__general_plugins.append(plugin)
@@ -308,7 +297,15 @@ class PluginManager(gen.utils.Callback):
@return: [gen.plug.ExportPlugin] (a list of ExportPlugin instances)
"""
return self.__export_plugins
def get_docgen_plugins(self):
"""
Get the list of docgen plugins.
@return: [gen.plug.DocGenPlugin] (a list of DocGenPlugin instances)
"""
return self.__docgen_plugins
def register_tool(self, name, category, tool_class, options_class,
modes, translated_name, status=_("Unknown"),
description=_UNAVAILABLE, author_name=_("Unknown"),
@@ -461,59 +458,6 @@ class PluginManager(gen.utils.Callback):
self.__cl_list.append( (name, category, report_class, options_class,
translated_name, unsupported, require_active) )
def register_text_doc(self, name, classref, paper, style, ext, clname=''):
"""
Register a text document generator.
"""
del_index = -1
for i in range(0, len(self.__textdoc_list)):
val = self.__textdoc_list[i]
if val[0] == name:
del_index = i
if del_index != -1:
del self.__textdoc_list[del_index]
if not clname:
clname = ext[1:]
self.__textdoc_list.append( (name, classref, paper, style,
ext, clname) )
self.__mod2text[classref.__module__] = name
def register_book_doc(self, name, classref, paper, style, ext, clname=''):
"""
Register a text document generator.
"""
del_index = -1
for i in range(0, len(self.__bookdoc_list)):
val = self.__bookdoc_list[i]
if val[0] == name:
del_index = i
if del_index != -1:
del self.__bookdoc_list[del_index]
if not clname:
clname = ext[1:]
self.__bookdoc_list.append( (name, classref, paper, style, ext,
clname) )
def register_draw_doc(self, name, classref, paper, style, ext, clname=''):
"""
Register a drawing document generator.
"""
del_index = -1
for i in range(0, len(self.__drawdoc_list)):
val = self.__drawdoc_list[i]
if val[0] == name:
del_index = i
if del_index != -1:
del self.__drawdoc_list[del_index]
if not clname:
clname = ext[1:]
self.__drawdoc_list.append( (name, classref, paper, style, ext,
clname) )
self.__mod2text[classref.__module__] = name
def register_quick_report(self, name, category, run_func, translated_name,
status=_("Unknown"), description=_UNAVAILABLE,
author_name=_("Unknown"),
@@ -595,6 +539,8 @@ class PluginManager(gen.utils.Callback):
if item.get_module_name() not in failed_module_names ][:]
self.__import_plugins[:] = [ item for item in self.__import_plugins
if item.get_module_name() not in failed_module_names ][:]
self.__docgen_plugins[:] = [ item for item in self.__docgen_plugins
if item.get_module_name() not in failed_module_names ][:]
self.__tool_list[:] = [ item for item in self.__tool_list
if item[0].__module__ not in failed_module_names ][:]
self.__cli_tool_list[:] = [ item for item in self.__cli_tool_list
@@ -608,12 +554,6 @@ class PluginManager(gen.utils.Callback):
if item[2].__module__ not in failed_module_names ][:]
self.__cl_list[:] = [ item for item in self.__cl_list
if item[2].__module__ not in failed_module_names ][:]
self.__textdoc_list[:] = [ item for item in self.__textdoc_list
if item[1].__module__ not in failed_module_names ][:]
self.__bookdoc_list[:] = [ item for item in self.__bookdoc_list
if item[1].__module__ not in failed_module_names ][:]
self.__drawdoc_list[:] = [ item for item in self.__drawdoc_list
if item[1].__module__ not in failed_module_names ][:]
def register_relcalc(self, relclass, languages):
"""