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

@@ -58,6 +58,7 @@ except:
#
#-------------------------------------------------------------------------
import gtk
import gobject
from gtk import glade
from gtk import RESPONSE_OK
@@ -78,7 +79,6 @@ import ManagedWindow
# Import from specific modules in ReportBase
from ReportBase import CATEGORY_BOOK, book_categories
from ReportBase._BookFormatComboBox import BookFormatComboBox
from ReportBase._ReportDialog import ReportDialog
from ReportBase._DocReportDialog import DocReportDialog
from ReportBase._CommandLineReport import CommandLineReport
@@ -1039,6 +1039,45 @@ class BookItemDialog(ReportDialog):
def parse_target_frame(self):
"""Target frame is not used."""
return 1
#-------------------------------------------------------------------------
#
# _BookFormatComboBox
#
#-------------------------------------------------------------------------
class _BookFormatComboBox(gtk.ComboBox):
def __init__(self, active):
gtk.ComboBox.__init__(self)
pmgr = PluginManager.get_instance()
self.__bookdoc_plugins = []
for plugin in pmgr.get_docgen_plugins():
if plugin.get_text_support() and plugin.get_draw_support():
self.__bookdoc_plugins.append(plugin)
self.store = gtk.ListStore(gobject.TYPE_STRING)
self.set_model(self.store)
cell = gtk.CellRendererText()
self.pack_start(cell, True)
self.add_attribute(cell, 'text', 0)
index = 0
active_index = 0
for plugin in self.__bookdoc_plugins:
name = plugin.get_name()
self.store.append(row=[name])
if plugin.get_extension() == active:
active_index = index
index = index + 1
self.set_active(active_index)
def get_active_plugin(self):
"""
Get the plugin represented by the currently active selection.
"""
return self.__bookdoc_plugins[self.get_active()]
#------------------------------------------------------------------------
#
@@ -1053,6 +1092,7 @@ class BookReportDialog(DocReportDialog):
"""
def __init__(self, dbstate, uistate, book, options):
self.format_menu = None
self.options = options
self.page_html_added = False
DocReportDialog.__init__(self, dbstate, uistate, options,
@@ -1117,8 +1157,7 @@ class BookReportDialog(DocReportDialog):
"""Build a menu of document types that are appropriate for
this text report. This menu will be generated based upon
whether the document requires table support, etc."""
self.format_menu = BookFormatComboBox()
self.format_menu.set(self.doc_type_changed, None, active)
self.format_menu = _BookFormatComboBox( active )
def make_document(self):
"""Create a document of the type requested by the user."""

View File

@@ -2,8 +2,8 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier <benny.malengier@gramps-project.org>
# Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier <benny.malengier@gramps-project.org>
#
# 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
@@ -35,7 +35,7 @@ from gettext import gettext as _
#
#------------------------------------------------------------------------
import BaseDoc
from gen.plug import PluginManager
from gen.plug import PluginManager, DocGenPlugin
import Errors
import Utils
@@ -365,10 +365,21 @@ class AsciiDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
#------------------------------------------------------------------------
#
# Register the document generator with the GRAMPS plugin system
# register_plugin
#
#------------------------------------------------------------------------
print_label = None
pmgr = PluginManager.get_instance()
pmgr.register_text_doc(_("Plain Text"), AsciiDoc, 1, 1, ".txt")
def register_plugin():
"""
Register the document generator with the GRAMPS plugin system.
"""
pmgr = PluginManager.get_instance()
plugin = DocGenPlugin(name = _("Plain Text"),
description = _("Generates documents in plain text "
"format (.txt)."),
basedoc = AsciiDoc,
paper = True,
style = True,
extension = "txt" )
pmgr.register_plugin(plugin)
register_plugin()

View File

@@ -1,8 +1,8 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2007 Zsolt Foldvari
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2007 Zsolt Foldvari
# Copyright (C) 2008-2009 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
@@ -44,7 +44,7 @@ import os
#------------------------------------------------------------------------
import BaseDoc
from CairoDoc import CairoDoc
from gen.plug import PluginManager
from gen.plug import PluginManager, DocGenPlugin
import Errors
#------------------------------------------------------------------------
@@ -613,13 +613,24 @@ class GtkPrint(CairoDoc):
context.set_cairo_context(cr, PRINTER_DPI, PRINTER_DPI)
return True
#------------------------------------------------------------------------
#
# register_plugin
#
#------------------------------------------------------------------------
def register_plugin():
"""
Register the document generator with the GRAMPS plugin system
"""
pmgr = PluginManager.get_instance()
plugin = DocGenPlugin(name = _('Print...'),
description = _("Generates documents and prints them "
"directly."),
basedoc = GtkPrint,
paper = True,
style = True,
extension = "" )
pmgr.register_plugin(plugin)
#------------------------------------------------------------------------
#
# Register the document generator with the GRAMPS plugin system
#
#------------------------------------------------------------------------
pmgr = PluginManager.get_instance()
pmgr.register_text_doc(_('Print...'), GtkPrint, 1, 1, "")
pmgr.register_draw_doc(_('Print...'), GtkPrint, 1, 1, "")
pmgr.register_book_doc(_('Print...'), GtkPrint, 1, 1, "")
register_plugin()

View File

@@ -2,8 +2,8 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier <benny.malengier@gramps-project.org>
# Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier <benny.malengier@gramps-project.org>
#
# 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
@@ -37,7 +37,7 @@ from gettext import gettext as _
# GRAMPS modules
#
#------------------------------------------------------------------------
from gen.plug import PluginManager
from gen.plug import PluginManager, DocGenPlugin
import ImgManip
import tarfile
import const
@@ -472,8 +472,21 @@ class HtmlDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
#------------------------------------------------------------------------
#
# Register the document generator with the GRAMPS plugin system
# register_plugin
#
#------------------------------------------------------------------------
pmgr = PluginManager.get_instance()
pmgr.register_text_doc(_('HTML'), HtmlDoc, 0, 1, ".html")
def register_plugin():
"""
Register the document generator with the GRAMPS plugin system.
"""
pmgr = PluginManager.get_instance()
plugin = DocGenPlugin(name = _('HTML'),
description = _("Generates documents in HTML "
"format."),
basedoc = HtmlDoc,
paper = False,
style = True,
extension = "html" )
pmgr.register_plugin(plugin)
register_plugin()

View File

@@ -2,7 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2008 Raphael Ackermann
# 2002-2003 Donald A. Peterson
# 2003 Alex Roitman
@@ -40,7 +40,7 @@ from gettext import gettext as _
#
#------------------------------------------------------------------------
import BaseDoc
from gen.plug import PluginManager
from gen.plug import PluginManager, DocGenPlugin
import ImgManip
import Errors
import Utils
@@ -637,11 +637,23 @@ class LaTeXDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
self.f.write('\\end{verbatim}')
self.end_paragraph()
#------------------------------------------------------------------------
#
# Register plugins
# register_plugin
#
#------------------------------------------------------------------------
pmgr = PluginManager.get_instance()
pmgr.register_text_doc(_('LaTeX'), LaTeXDoc, 1, 0, ".tex")
def register_plugin():
"""
Register the document generator with the GRAMPS plugin system.
"""
pmgr = PluginManager.get_instance()
plugin = DocGenPlugin(name = _('LaTeX'),
description = _("Generates documents in LaTeX "
"format."),
basedoc = LaTeXDoc,
paper = True,
style = False,
extension = "tex" )
pmgr.register_plugin(plugin)
register_plugin()

View File

@@ -3,7 +3,7 @@
#
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2005-2006 Serge Noiraud
# Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2007-2009 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
@@ -46,7 +46,7 @@ from xml.sax.saxutils import escape
#-------------------------------------------------------------------------
import BaseDoc
import const
from gen.plug import PluginManager
from gen.plug import PluginManager, DocGenPlugin
from ReportBase import ReportUtils
import ImgManip
import FontScale
@@ -1138,12 +1138,23 @@ class ODFDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
self.cntnt.write('</draw:text-box>')
self.cntnt.write('</draw:frame>\n')
#--------------------------------------------------------------------------
#------------------------------------------------------------------------
#
# Register plugins
# register_plugin
#
#--------------------------------------------------------------------------
pmgr = PluginManager.get_instance()
pmgr.register_text_doc(_('Open Document Text'), ODFDoc, 1, 1, ".odt")
pmgr.register_book_doc(_("Open Document Text"), ODFDoc, 1, 1, ".odt")
pmgr.register_draw_doc(_("Open Document Text"), ODFDoc, 1, 1, ".odt")
#------------------------------------------------------------------------
def register_plugin():
"""
Register the document generator with the GRAMPS plugin system.
"""
pmgr = PluginManager.get_instance()
plugin = DocGenPlugin(name = _('Open Document Text'),
description = _("Generates documents in Open "
"Document Text format (.odt)."),
basedoc = ODFDoc,
paper = True,
style = True,
extension = "odt" )
pmgr.register_plugin(plugin)
register_plugin()

View File

@@ -2,7 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2007-2009 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
@@ -32,7 +32,7 @@ from gettext import gettext as _
#Gramps modules
#-------------------------------------------------------------------------
from ReportBase import ReportUtils, run_print_dialog, get_print_dialog_app
from gen.plug import PluginManager
from gen.plug import PluginManager, DocGenPlugin
import BaseDoc
import Errors
@@ -343,5 +343,23 @@ class PSDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc):
self.f.write("(%s) show\n" % lines[i])
self.f.write('grestore\n')
pmgr = PluginManager.get_instance()
pmgr.register_draw_doc(_("PostScript"), PSDrawDoc, 1, 1, ".ps")
#------------------------------------------------------------------------
#
# register_plugin
#
#------------------------------------------------------------------------
def register_plugin():
"""
Register the document generator with the GRAMPS plugin system.
"""
pmgr = PluginManager.get_instance()
plugin = DocGenPlugin(name = _("PostScript"),
description = _("Generates documents in postscript "
"format (.ps)."),
basedoc = PSDrawDoc,
paper = True,
style = True,
extension = "ps" )
pmgr.register_plugin(plugin)
register_plugin()

View File

@@ -37,7 +37,7 @@ from gettext import gettext as _
#
#------------------------------------------------------------------------
from CairoDoc import CairoDoc
from gen.plug import PluginManager
from gen.plug import PluginManager, DocGenPlugin
import Utils
#------------------------------------------------------------------------
@@ -126,19 +126,24 @@ class PdfDoc(CairoDoc):
# load the result into an external viewer
if self.open_req:
Utils.open_file_with_default_application(self._filename)
#------------------------------------------------------------------------
#
# Functions
#
#------------------------------------------------------------------------
def register_docgen():
"""Register the docgen with the GRAMPS plugin system.
"""
doc_name = _('PDF document')
pmgr = PluginManager.get_instance()
pmgr.register_text_doc(doc_name, PdfDoc, 1, 1, ".pdf")
pmgr.register_draw_doc(doc_name, PdfDoc, 1, 1, ".pdf")
pmgr.register_book_doc(doc_name, PdfDoc, 1, 1, ".pdf")
register_docgen()
#------------------------------------------------------------------------
#
# register_plugin
#
#------------------------------------------------------------------------
def register_plugin():
"""
Register the document generator with the GRAMPS plugin system.
"""
pmgr = PluginManager.get_instance()
plugin = DocGenPlugin(name = _('PDF document'),
description = _("Generates documents in PDF "
"format (.pdf)."),
basedoc = PdfDoc,
paper = True,
style = True,
extension = "pdf" )
pmgr.register_plugin(plugin)
register_plugin()

View File

@@ -2,7 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2009 Gary Burton
#
# This program is free software; you can redistribute it and/or modify
@@ -35,7 +35,7 @@ from gettext import gettext as _
#
#------------------------------------------------------------------------
import BaseDoc
from gen.plug import PluginManager
from gen.plug import PluginManager, DocGenPlugin
import ImgManip
import Errors
import Utils
@@ -434,8 +434,21 @@ class RTFDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
#------------------------------------------------------------------------
#
# Register the document generator with the GRAMPS plugin system
# register_plugin
#
#------------------------------------------------------------------------
pmgr = PluginManager.get_instance()
pmgr.register_text_doc(_('RTF document'), RTFDoc, 1, 1, ".rtf")
def register_plugin():
"""
Register the document generator with the GRAMPS plugin system.
"""
pmgr = PluginManager.get_instance()
plugin = DocGenPlugin(name = _('RTF document'),
description = _("Generates documents in Rich Text "
"format (.rtf)."),
basedoc = RTFDoc,
paper = True,
style = True,
extension = "rtf" )
pmgr.register_plugin(plugin)
register_plugin()

View File

@@ -2,7 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2007-2009 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
@@ -34,7 +34,7 @@ import StringIO
# Gramps modules
#
#-------------------------------------------------------------------------
from gen.plug import PluginManager
from gen.plug import PluginManager, DocGenPlugin
import BaseDoc
import Errors
@@ -257,11 +257,23 @@ class SvgDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc):
def units(val):
return (val[0]*35.433, val[1]*35.433)
#-------------------------------------------------------------------------
#------------------------------------------------------------------------
#
# Register document generator
# register_plugin
#
#-------------------------------------------------------------------------
pmgr = PluginManager.get_instance()
pmgr.register_draw_doc(_("SVG (Scalable Vector Graphics)"), SvgDrawDoc, 1, 1,
".svg")
#------------------------------------------------------------------------
def register_plugin():
"""
Register the document generator with the GRAMPS plugin system.
"""
pmgr = PluginManager.get_instance()
plugin = DocGenPlugin(name = _("SVG (Scalable Vector Graphics)"),
description = _("Generates documents in Scalable "
"Vector Graphics format (.svg)."),
basedoc = SvgDrawDoc,
paper = True,
style = True,
extension = "svg" )
pmgr.register_plugin(plugin)
register_plugin()