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

@ -392,6 +392,7 @@ src/PluginUtils/_Tool.py
src/gen/utils/dbutils.py src/gen/utils/dbutils.py
src/gen/utils/progressmon.py src/gen/utils/progressmon.py
src/gen/plug/__init__.py src/gen/plug/__init__.py
src/gen/plug/_docgen.py
src/gen/plug/_export.py src/gen/plug/_export.py
src/gen/plug/_import.py src/gen/plug/_import.py
src/gen/plug/_manager.py src/gen/plug/_manager.py
@ -418,11 +419,9 @@ src/gen/plug/menu/_text.py
# ReportBase package # ReportBase package
src/ReportBase/_BookFormatComboBox.py
src/ReportBase/_CommandLineReport.py src/ReportBase/_CommandLineReport.py
src/ReportBase/_Constants.py src/ReportBase/_Constants.py
src/ReportBase/_DocReportDialog.py src/ReportBase/_DocReportDialog.py
src/ReportBase/_DrawFormatComboBox.py
src/ReportBase/_DrawReportDialog.py src/ReportBase/_DrawReportDialog.py
src/ReportBase/_Endnotes.py src/ReportBase/_Endnotes.py
src/ReportBase/_GraphvizReportDialog.py src/ReportBase/_GraphvizReportDialog.py
@ -437,7 +436,6 @@ src/ReportBase/_ReportUtils.py
src/ReportBase/_StyleComboBox.py src/ReportBase/_StyleComboBox.py
src/ReportBase/_StyleEditor.py src/ReportBase/_StyleEditor.py
src/ReportBase/_TemplateParser.py src/ReportBase/_TemplateParser.py
src/ReportBase/_TextFormatComboBox.py
src/ReportBase/_TextReportDialog.py src/ReportBase/_TextReportDialog.py
# gen # gen

View File

@ -136,8 +136,6 @@ IPREFIX = ('preferences', 'iprefix', 2)
OPREFIX = ('preferences', 'oprefix', 2) OPREFIX = ('preferences', 'oprefix', 2)
PPREFIX = ('preferences', 'pprefix', 2) PPREFIX = ('preferences', 'pprefix', 2)
SPREFIX = ('preferences', 'sprefix', 2) SPREFIX = ('preferences', 'sprefix', 2)
GOUTPUT_PREFERENCE = ('preferences', 'goutput-preference', 2)
OUTPUT_PREFERENCE = ('preferences', 'output-preference', 2)
PAPER_METRIC = ('preferences', 'paper-metric', 1) PAPER_METRIC = ('preferences', 'paper-metric', 1)
PAPER_PREFERENCE = ('preferences', 'paper-preference', 2) PAPER_PREFERENCE = ('preferences', 'paper-preference', 2)
RECENT_FILE = ('paths', 'recent-file', 2) RECENT_FILE = ('paths', 'recent-file', 2)
@ -285,9 +283,7 @@ default_value = {
IPREFIX : 'I%04d', IPREFIX : 'I%04d',
OPREFIX : 'O%04d', OPREFIX : 'O%04d',
PPREFIX : 'P%04d', PPREFIX : 'P%04d',
SPREFIX : 'S%04d', SPREFIX : 'S%04d',
GOUTPUT_PREFERENCE : 'No default format',
OUTPUT_PREFERENCE : 'No default format',
PAPER_METRIC : 0, PAPER_METRIC : 0,
PAPER_PREFERENCE : 'Letter', PAPER_PREFERENCE : 'Letter',
RECENT_FILE : '', RECENT_FILE : '',

View File

@ -5,11 +5,9 @@ pkgdatadir = $(datadir)/@PACKAGE@/ReportBase
pkgdata_PYTHON = \ pkgdata_PYTHON = \
__init__.py\ __init__.py\
_Bibliography.py\ _Bibliography.py\
_BookFormatComboBox.py\
_CommandLineReport.py\ _CommandLineReport.py\
_Constants.py\ _Constants.py\
_DocReportDialog.py\ _DocReportDialog.py\
_DrawFormatComboBox.py\
_DrawReportDialog.py\ _DrawReportDialog.py\
_Endnotes.py\ _Endnotes.py\
_FileEntry.py\ _FileEntry.py\
@ -23,7 +21,6 @@ pkgdata_PYTHON = \
_StyleComboBox.py\ _StyleComboBox.py\
_StyleEditor.py\ _StyleEditor.py\
_TemplateParser.py\ _TemplateParser.py\
_TextFormatComboBox.py\
_TextReportDialog.py\ _TextReportDialog.py\
_WebReportDialog.py _WebReportDialog.py

View File

@ -1,92 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2001-2006 Donald N. Allingham
# 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:_BookFormatComboBox.py 9912 2008-01-22 09:17:46Z acraphae $
#-------------------------------------------------------------------------
#
# GTK libraries
#
#-------------------------------------------------------------------------
import gtk
import gobject
#-------------------------------------------------------------------------
#
# GRAMPS classes
#
#-------------------------------------------------------------------------
import Config
import PluginUtils
import gen
#-------------------------------------------------------------------------
#
# get_text_doc_menu
#
#-------------------------------------------------------------------------
class BookFormatComboBox(gtk.ComboBox):
def __init__(self):
pmgr = gen.plug.PluginManager.get_instance()
self.__book_doc_list = pmgr.get_book_doc_list()
self.__book_doc_list.sort()
gtk.ComboBox.__init__(self)
def set(self, callback, obj=None, active=None):
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)
out_pref = Config.get(Config.OUTPUT_PREFERENCE)
index = 0
active_index = 0
self.data = []
for item in self.__book_doc_list:
self.data.append(item)
name = item[0]
self.store.append(row=[name])
if item[5] == active:
active_index = index
elif not active and name == out_pref:
active_index = index
index += 1
self.set_active(active_index)
def get_reference(self):
return self.data[self.get_active()][1]
def get_label(self):
return self.data[self.get_active()][0]
def get_paper(self):
return self.data[self.get_active()][2]
def get_ext(self):
return self.data[self.get_active()][4]
def is_file_output(self):
return len(self.get_ext()) > 0
def get_clname(self):
return self.data[self.get_active()][5]

View File

@ -108,6 +108,21 @@ class CommandLineReport:
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 = gen.plug.PluginManager.get_instance()
self.__textdoc_plugins = []
self.__drawdoc_plugins = []
self.__bookdoc_plugins = []
for plugin in pmgr.get_docgen_plugins():
if plugin.get_text_support() and plugin.get_extension():
self.__textdoc_plugins.append(plugin)
if plugin.get_draw_support() and plugin.get_extension():
self.__drawdoc_plugins.append(plugin)
if plugin.get_text_support() and \
plugin.get_draw_support() and \
plugin.get_extension():
self.__bookdoc_plugins.append(plugin)
self.database = database self.database = database
self.category = category self.category = category
self.format = None self.format = None
@ -125,11 +140,6 @@ class CommandLineReport:
""" """
Initialize the options that are hard-coded into the report system. Initialize the options that are hard-coded into the report system.
""" """
pmgr = gen.plug.PluginManager.get_instance()
_textdoc_list = pmgr.get_text_doc_list()
_drawdoc_list = pmgr.get_draw_doc_list()
_bookdoc_list = pmgr.get_book_doc_list()
self.options_dict = { self.options_dict = {
'of' : self.option_class.handler.module_name, 'of' : self.option_class.handler.module_name,
'off' : self.option_class.handler.get_format_name(), 'off' : self.option_class.handler.get_format_name(),
@ -142,7 +152,7 @@ class CommandLineReport:
self.options_help = { self.options_help = {
'of' : ["=filename", "Output file name. MANDATORY", ""], 'of' : ["=filename", "Output file name. MANDATORY", ""],
'off' : ["=format", "Output file format.", ""], 'off' : ["=format", "Output file format.", []],
'style' : ["=name", "Style name.", ""], 'style' : ["=name", "Style name.", ""],
'papers' : ["=name", "Paper size name.", ""], 'papers' : ["=name", "Paper size name.", ""],
'papero' : ["=num", "Paper orientation number.", ""], 'papero' : ["=num", "Paper orientation number.", ""],
@ -156,14 +166,17 @@ class CommandLineReport:
"whatever_name") "whatever_name")
if self.category == CATEGORY_TEXT: if self.category == CATEGORY_TEXT:
self.options_help['off'][2] = \ for plugin in self.__textdoc_plugins:
[ item[6] for item in _textdoc_list ] self.options_help['off'][2].append(
plugin.get_extension() + "\t" + plugin.get_description() )
elif self.category == CATEGORY_DRAW: elif self.category == CATEGORY_DRAW:
self.options_help['off'][2] = \ for plugin in self.__drawdoc_plugins:
[ item[6] for item in _drawdoc_list ] self.options_help['off'][2].append(
plugin.get_extension() + "\t" + plugin.get_description() )
elif self.category == CATEGORY_BOOK: elif self.category == CATEGORY_BOOK:
self.options_help['off'][2] = \ for plugin in self.__bookdoc_plugins:
[ item[6] for item in _bookdoc_list ] self.options_help['off'][2].append(
plugin.get_extension() + "\t" + plugin.get_description() )
else: else:
self.options_help['off'][2] = "NA" self.options_help['off'][2] = "NA"
@ -284,29 +297,27 @@ class CommandLineReport:
self.option_class.handler.output = self.options_dict['of'] self.option_class.handler.output = self.options_dict['of']
pmgr = gen.plug.PluginManager.get_instance()
if self.category == CATEGORY_TEXT: if self.category == CATEGORY_TEXT:
for item in pmgr.get_text_doc_list(): for plugin in self.__textdoc_plugins:
if item[6] == self.options_dict['off']: if plugin.get_extension() == self.options_dict['off']:
self.format = item[1] self.format = plugin.get_basedoc()
if self.format is None: if self.format is None:
# Pick the first one as the default. # Pick the first one as the default.
self.format = pmgr.get_text_doc_list()[0][1] self.format = self.__textdoc_plugins[0].get_basedoc()
elif self.category == CATEGORY_DRAW: elif self.category == CATEGORY_DRAW:
for item in pmgr.get_draw_doc_list(): for plugin in self.__drawdoc_plugins:
if item[6] == self.options_dict['off']: if plugin.get_extension() == self.options_dict['off']:
self.format = item[1] self.format = plugin.get_basedoc()
if self.format is None: if self.format is None:
# Pick the first one as the default. # Pick the first one as the default.
self.format = pmgr.get_draw_doc_list()[0][1] self.format = self.__drawdoc_plugins[0].get_basedoc()
elif self.category == CATEGORY_BOOK: elif self.category == CATEGORY_BOOK:
for item in pmgr.get_book_doc_list(): for plugin in self.__bookdoc_plugins:
if item[6] == self.options_dict['off']: if plugin.get_extension() == self.options_dict['off']:
self.format = item[1] self.format = plugin.get_basedoc()
if self.format is None: if self.format is None:
# Pick the first one as the default. # Pick the first one as the default.
self.format = pmgr.get_book_doc_list()[0][1] self.format = self.__bookdoc_plugins[0].get_basedoc()
else: else:
self.format = None self.format = None

View File

@ -104,7 +104,8 @@ class DocReportDialog(ReportDialog):
file format. For example, a HTML document doesn't need any file format. For example, a HTML document doesn't need any
paper size/orientation options, but it does need a template paper size/orientation options, but it does need a template
file. Those chances are made here.""" file. Those chances are made here."""
if obj.is_file_output(): docgen_plugin = obj.get_active_plugin()
if docgen_plugin.get_extension():
self.open_with_app.set_sensitive (True) self.open_with_app.set_sensitive (True)
else: else:
self.open_with_app.set_sensitive (False) self.open_with_app.set_sensitive (False)
@ -114,7 +115,7 @@ class DocReportDialog(ReportDialog):
if self.page_html_added: if self.page_html_added:
self.notebook.remove_page(0) self.notebook.remove_page(0)
if obj.get_paper() == 1: if docgen_plugin.get_paper_used():
self.paper_label = gtk.Label('<b>%s</b>'%_("Paper Options")) self.paper_label = gtk.Label('<b>%s</b>'%_("Paper Options"))
self.paper_label.set_use_markup(True) self.paper_label.set_use_markup(True)
self.notebook.insert_page(self.paper_frame,self.paper_label,0) self.notebook.insert_page(self.paper_frame,self.paper_label,0)
@ -125,15 +126,12 @@ class DocReportDialog(ReportDialog):
self.notebook.insert_page(self.html_table,self.html_label,0) self.notebook.insert_page(self.html_table,self.html_label,0)
self.html_table.show_all() self.html_table.show_all()
if obj.is_file_output(): ext_val = docgen_plugin.get_extension()
if ext_val:
fname = self.target_fileentry.get_full_path(0) fname = self.target_fileentry.get_full_path(0)
(spath, ext) = os.path.splitext(fname) (spath, ext) = os.path.splitext(fname)
ext_val = obj.get_ext() fname = spath + "." + ext_val
if ext_val:
fname = spath + ext_val
else:
fname = spath
self.target_fileentry.set_filename(fname) self.target_fileentry.set_filename(fname)
self.target_fileentry.set_sensitive(True) self.target_fileentry.set_sensitive(True)
else: else:
@ -142,8 +140,8 @@ class DocReportDialog(ReportDialog):
# Does this report format use styles? # Does this report format use styles?
if self.style_button: if self.style_button:
self.style_button.set_sensitive(obj.get_styles()) self.style_button.set_sensitive(docgen_plugin.get_style_support())
self.style_menu.set_sensitive(obj.get_styles()) self.style_menu.set_sensitive(docgen_plugin.get_style_support())
self.page_html_added = True self.page_html_added = True
def setup_format_frame(self): def setup_format_frame(self):
@ -165,13 +163,13 @@ class DocReportDialog(ReportDialog):
yoptions=gtk.SHRINK) yoptions=gtk.SHRINK)
self.row += 1 self.row += 1
ext = self.format_menu.get_ext() ext = self.format_menu.get_active_plugin().get_extension()
if ext is None: if ext is None:
ext = "" ext = ""
else: else:
spath = self.get_default_directory() spath = self.get_default_directory()
base = self.get_default_basename() base = self.get_default_basename()
spath = os.path.normpath("%s/%s%s" % (spath, base, ext)) spath = os.path.normpath("%s/%s.%s" % (spath, base, ext))
self.target_fileentry.set_filename(spath) self.target_fileentry.set_filename(spath)
def setup_report_options_frame(self): def setup_report_options_frame(self):
@ -253,8 +251,9 @@ class DocReportDialog(ReportDialog):
def parse_format_frame(self): def parse_format_frame(self):
"""Parse the format frame of the dialog. Save the user """Parse the format frame of the dialog. Save the user
selected output format for later use.""" selected output format for later use."""
self.format = self.format_menu.get_reference() docgen_plugin = self.format_menu.get_active_plugin()
format_name = self.format_menu.get_clname() self.format = docgen_plugin.get_basedoc()
format_name = docgen_plugin.get_extension()
self.options.handler.set_format_name(format_name) self.options.handler.set_format_name(format_name)
def parse_html_frame(self): def parse_html_frame(self):

View File

@ -1,85 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2001-2006 Donald N. Allingham
# 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:_DrawFormatComboBox.py 9912 2008-01-22 09:17:46Z acraphae $
import gtk
import gobject
import Config
import gen
#-------------------------------------------------------------------------
#
# get_text_doc_menu
#
#-------------------------------------------------------------------------
class DrawFormatComboBox(gtk.ComboBox):
def __init__(self):
pmgr = gen.plug.PluginManager.get_instance()
self.__drawdoc_list = pmgr.get_draw_doc_list()
self.__drawdoc_list.sort()
gtk.ComboBox.__init__(self)
def set(self,tables,callback, obj=None,active=None):
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)
out_pref = Config.get(Config.OUTPUT_PREFERENCE)
index = 0
active_index = 0
for item in self.__drawdoc_list:
if tables and item[2] == 0:
continue
name = item[0]
self.store.append(row=[name])
#if callback:
# menuitem.connect("activate",callback)
if item[5] == active:
active_index = index
elif not active and name == out_pref:
active_index = index
index = index + 1
self.set_active(active_index)
def get_reference(self):
return self.__drawdoc_list[self.get_active()][1]
def get_label(self):
return self.__drawdoc_list[self.get_active()][0]
def get_paper(self):
return self.__drawdoc_list[self.get_active()][2]
def get_styles(self):
return self.__drawdoc_list[self.get_active()][3]
def get_ext(self):
return self.__drawdoc_list[self.get_active()][4]
def is_file_output(self):
return len(self.get_ext()) > 0
def get_clname(self):
return self.__drawdoc_list[self.get_active()][5]

View File

@ -20,32 +20,88 @@
# $Id$ # $Id$
#-------------------------------------------------------------------------
#
# GTK modules
#
#-------------------------------------------------------------------------
import gtk
import gobject
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from _Constants import CATEGORY_DRAW from _Constants import CATEGORY_DRAW
from _DocReportDialog import DocReportDialog from _DocReportDialog import DocReportDialog
from _DrawFormatComboBox import DrawFormatComboBox from gen.plug import PluginManager
#-------------------------------------------------------------------------
#
# _DrawFormatComboBox
#
#-------------------------------------------------------------------------
class _DrawFormatComboBox(gtk.ComboBox):
"""
This class is a combo box that allows the selection of a docgen plugin
from all drawdoc plugins.
"""
def __init__(self, active):
gtk.ComboBox.__init__(self)
pmgr = PluginManager.get_instance()
self.__drawdoc_plugins = []
for plugin in pmgr.get_docgen_plugins():
if plugin.get_draw_support():
self.__drawdoc_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.__drawdoc_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.__drawdoc_plugins[self.get_active()]
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
# #
# Drawing reports # DrawReportDialog
# #
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
class DrawReportDialog(DocReportDialog): class DrawReportDialog(DocReportDialog):
"""A class of ReportDialog customized for drawing based reports.""" """
A class of ReportDialog customized for drawing based reports.
"""
def __init__(self, dbstate, uistate, opt, name, translated_name): def __init__(self, dbstate, uistate, opt, name, translated_name):
"""Initialize a dialog to request that the user select options """
Initialize a dialog to request that the user select options
for a basic drawing report. See the ReportDialog class for for a basic drawing report. See the ReportDialog class for
more information.""" more information.
"""
self.format_menu = None
self.category = CATEGORY_DRAW self.category = CATEGORY_DRAW
DocReportDialog.__init__(self, dbstate, uistate, opt, DocReportDialog.__init__(self, dbstate, uistate, opt,
name, translated_name) name, translated_name)
#------------------------------------------------------------------------
#
# Functions related to selecting/changing the current file format.
#
#------------------------------------------------------------------------
def make_doc_menu(self,active=None): def make_doc_menu(self,active=None):
"""Build a menu of document types that are appropriate for """
this drawing report.""" Build a menu of document types that are appropriate for
self.format_menu = DrawFormatComboBox() this drawing report.
self.format_menu.set(False,self.doc_type_changed, None, active) """
self.format_menu = _DrawFormatComboBox( active )

View File

@ -860,7 +860,6 @@ class GraphvizFormatComboBox(gtk.ComboBox):
self.pack_start(cell, True) self.pack_start(cell, True)
self.add_attribute(cell, 'text', 0) self.add_attribute(cell, 'text', 0)
out_pref = Config.get(Config.OUTPUT_PREFERENCE)
index = 0 index = 0
active_index = 0 active_index = 0
for item in _FORMATS: for item in _FORMATS:
@ -868,8 +867,6 @@ class GraphvizFormatComboBox(gtk.ComboBox):
self.store.append(row=[name]) self.store.append(row=[name])
if item['type'] == active: if item['type'] == active:
active_index = index active_index = index
elif not active and name == out_pref:
active_index = index
index = index + 1 index = index + 1
self.set_active(active_index) self.set_active(active_index)

View File

@ -1,81 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2001-2006 Donald N. Allingham
# 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:_TextFormatComboBox.py 9912 2008-01-22 09:17:46Z acraphae $
import gtk
import gobject
import Config
import gen
#-------------------------------------------------------------------------
#
# get_text_doc_menu
#
#-------------------------------------------------------------------------
class TextFormatComboBox(gtk.ComboBox):
def __init__(self):
pmgr = gen.plug.PluginManager.get_instance()
self.__text_doc_list = pmgr.get_text_doc_list()
self.__text_doc_list.sort()
gtk.ComboBox.__init__(self)
def set(self, callback, obj=None, active=None):
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)
out_pref = Config.get(Config.OUTPUT_PREFERENCE)
index = 0
active_index = 0
for item in self.__text_doc_list:
name = item[0]
self.store.append(row=[name])
if item[5] == active:
active_index = index
elif not active and name == out_pref:
active_index = index
index = index + 1
self.set_active(active_index)
def get_label(self):
return self.__text_doc_list[self.get_active()][0]
def get_reference(self):
return self.__text_doc_list[self.get_active()][1]
def get_paper(self):
return self.__text_doc_list[self.get_active()][2]
def get_styles(self):
return self.__text_doc_list[self.get_active()][3]
def get_ext(self):
return self.__text_doc_list[self.get_active()][4]
def is_file_output(self):
return len(self.get_ext()) > 0
def get_clname(self):
return self.__text_doc_list[self.get_active()][5]

View File

@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2001-2006 Donald N. Allingham # Copyright (C) 2001-2006 Donald N. Allingham
# Copyright (C) 2008-2009 Brian G. Matherly
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -20,34 +21,88 @@
# $Id$ # $Id$
#-------------------------------------------------------------------------
#
# GTK modules
#
#-------------------------------------------------------------------------
import gtk
import gobject
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from gen.plug import PluginManager
from _Constants import CATEGORY_TEXT from _Constants import CATEGORY_TEXT
from _DocReportDialog import DocReportDialog from _DocReportDialog import DocReportDialog
from _TextFormatComboBox import TextFormatComboBox
#-------------------------------------------------------------------------
#
# _TextFormatComboBox
#
#-------------------------------------------------------------------------
class _TextFormatComboBox(gtk.ComboBox):
"""
This class is a combo box that allows the selection of a docgen plugin
from all textdoc plugins.
"""
def __init__(self, active):
gtk.ComboBox.__init__(self)
pmgr = PluginManager.get_instance()
self.__textdoc_plugins = []
for plugin in pmgr.get_docgen_plugins():
if plugin.get_text_support():
self.__textdoc_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.__textdoc_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.__textdoc_plugins[self.get_active()]
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
# #
# Textual reports # TextReportDialog
# #
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
class TextReportDialog(DocReportDialog): class TextReportDialog(DocReportDialog):
"""A class of ReportDialog customized for text based reports.""" """
A class of ReportDialog customized for text based reports.
"""
def __init__(self, dbstate, uistate, options, name, translated_name): def __init__(self, dbstate, uistate, options, name, translated_name):
"""Initialize a dialog to request that the user select options """
Initialize a dialog to request that the user select options
for a basic text report. See the ReportDialog class for more for a basic text report. See the ReportDialog class for more
information.""" information.
"""
self.format_menu = None
self.category = CATEGORY_TEXT self.category = CATEGORY_TEXT
DocReportDialog.__init__(self, dbstate, uistate, options, DocReportDialog.__init__(self, dbstate, uistate, options,
name, translated_name) name, translated_name)
#------------------------------------------------------------------------ def make_doc_menu(self, active=None):
# """
# Functions related to selecting/changing the current file format. Build a menu of document types that are appropriate for
# this text report.
#------------------------------------------------------------------------ """
def make_doc_menu(self,active=None): self.format_menu = _TextFormatComboBox( active )
"""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 = TextFormatComboBox()
self.format_menu.set(self.doc_type_changed, None, active)

View File

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

View File

@ -25,5 +25,7 @@ from _plugin import Plugin
from _manager import PluginManager from _manager import PluginManager
from _import import ImportPlugin from _import import ImportPlugin
from _export import ExportPlugin 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.__tool_list = []
self.__import_plugins = [] self.__import_plugins = []
self.__export_plugins = [] self.__export_plugins = []
self.__docgen_plugins = []
self.__general_plugins = [] self.__general_plugins = []
self.__mapservice_list = [] self.__mapservice_list = []
self.__attempt_list = [] self.__attempt_list = []
self.__loaddir_list = [] self.__loaddir_list = []
self.__textdoc_list = []
self.__bookdoc_list = []
self.__drawdoc_list = []
self.__failmsg_list = [] self.__failmsg_list = []
self.__bkitems_list = [] self.__bkitems_list = []
self.__cl_list = [] self.__cl_list = []
@ -169,6 +167,7 @@ class PluginManager(gen.utils.Callback):
# TODO: do other lists need to be reset here, too? # TODO: do other lists need to be reset here, too?
self.__import_plugins[:] = [] self.__import_plugins[:] = []
self.__export_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]
@ -250,18 +249,6 @@ class PluginManager(gen.utils.Callback):
""" Return the list of book plugins. """ """ Return the list of book plugins. """
return self.__bkitems_list 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): def get_cl_list(self):
""" Return the list of command line report plugins. """ """ Return the list of command line report plugins. """
return self.__cl_list return self.__cl_list
@ -288,6 +275,8 @@ class PluginManager(gen.utils.Callback):
self.__import_plugins.append(plugin) self.__import_plugins.append(plugin)
elif isinstance(plugin, gen.plug.ExportPlugin): elif isinstance(plugin, gen.plug.ExportPlugin):
self.__export_plugins.append(plugin) self.__export_plugins.append(plugin)
elif isinstance(plugin, gen.plug.DocGenPlugin):
self.__docgen_plugins.append(plugin)
elif isinstance(plugin, gen.plug.Plugin): elif isinstance(plugin, gen.plug.Plugin):
self.__general_plugins.append(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: [gen.plug.ExportPlugin] (a list of ExportPlugin instances)
""" """
return self.__export_plugins 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, def register_tool(self, name, category, tool_class, options_class,
modes, translated_name, status=_("Unknown"), modes, translated_name, status=_("Unknown"),
description=_UNAVAILABLE, author_name=_("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, self.__cl_list.append( (name, category, report_class, options_class,
translated_name, unsupported, require_active) ) 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, def register_quick_report(self, name, category, run_func, translated_name,
status=_("Unknown"), description=_UNAVAILABLE, status=_("Unknown"), description=_UNAVAILABLE,
author_name=_("Unknown"), author_name=_("Unknown"),
@ -595,6 +539,8 @@ 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.__import_plugins[:] = [ item for item in self.__import_plugins self.__import_plugins[:] = [ item for item in self.__import_plugins
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
if item.get_module_name() not in failed_module_names ][:]
self.__tool_list[:] = [ item for item in self.__tool_list self.__tool_list[:] = [ item for item in self.__tool_list
if item[0].__module__ not in failed_module_names ][:] if item[0].__module__ not in failed_module_names ][:]
self.__cli_tool_list[:] = [ item for item in self.__cli_tool_list 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 ][:] if item[2].__module__ not in failed_module_names ][:]
self.__cl_list[:] = [ item for item in self.__cl_list self.__cl_list[:] = [ item for item in self.__cl_list
if item[2].__module__ not in failed_module_names ][:] 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): def register_relcalc(self, relclass, languages):
""" """

View File

@ -58,6 +58,7 @@ except:
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import gtk import gtk
import gobject
from gtk import glade from gtk import glade
from gtk import RESPONSE_OK from gtk import RESPONSE_OK
@ -78,7 +79,6 @@ import ManagedWindow
# Import from specific modules in ReportBase # Import from specific modules in ReportBase
from ReportBase import CATEGORY_BOOK, book_categories from ReportBase import CATEGORY_BOOK, book_categories
from ReportBase._BookFormatComboBox import BookFormatComboBox
from ReportBase._ReportDialog import ReportDialog from ReportBase._ReportDialog import ReportDialog
from ReportBase._DocReportDialog import DocReportDialog from ReportBase._DocReportDialog import DocReportDialog
from ReportBase._CommandLineReport import CommandLineReport from ReportBase._CommandLineReport import CommandLineReport
@ -1039,6 +1039,45 @@ class BookItemDialog(ReportDialog):
def parse_target_frame(self): def parse_target_frame(self):
"""Target frame is not used.""" """Target frame is not used."""
return 1 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): def __init__(self, dbstate, uistate, book, options):
self.format_menu = None
self.options = options self.options = options
self.page_html_added = False self.page_html_added = False
DocReportDialog.__init__(self, dbstate, uistate, options, DocReportDialog.__init__(self, dbstate, uistate, options,
@ -1117,8 +1157,7 @@ class BookReportDialog(DocReportDialog):
"""Build a menu of document types that are appropriate for """Build a menu of document types that are appropriate for
this text report. This menu will be generated based upon this text report. This menu will be generated based upon
whether the document requires table support, etc.""" whether the document requires table support, etc."""
self.format_menu = BookFormatComboBox() self.format_menu = _BookFormatComboBox( active )
self.format_menu.set(self.doc_type_changed, None, active)
def make_document(self): def make_document(self):
"""Create a document of the type requested by the user.""" """Create a document of the type requested by the user."""

View File

@ -2,8 +2,8 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2006 Donald N. Allingham # Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly # Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier <benny.malengier@gramps-project.org> # Copyright (C) 2009 Benny Malengier <benny.malengier@gramps-project.org>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -35,7 +35,7 @@ from gettext import gettext as _
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import BaseDoc import BaseDoc
from gen.plug import PluginManager from gen.plug import PluginManager, DocGenPlugin
import Errors import Errors
import Utils 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 def register_plugin():
pmgr = PluginManager.get_instance() """
pmgr.register_text_doc(_("Plain Text"), AsciiDoc, 1, 1, ".txt") 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 # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2007 Zsolt Foldvari # Copyright (C) 2007 Zsolt Foldvari
# Copyright (C) 2008 Brian G. Matherly # Copyright (C) 2008-2009 Brian G. Matherly
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -44,7 +44,7 @@ import os
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import BaseDoc import BaseDoc
from CairoDoc import CairoDoc from CairoDoc import CairoDoc
from gen.plug import PluginManager from gen.plug import PluginManager, DocGenPlugin
import Errors import Errors
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@ -613,13 +613,24 @@ class GtkPrint(CairoDoc):
context.set_cairo_context(cr, PRINTER_DPI, PRINTER_DPI) context.set_cairo_context(cr, PRINTER_DPI, PRINTER_DPI)
return True 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_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, "")

View File

@ -2,8 +2,8 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2006 Donald N. Allingham # Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly # Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier <benny.malengier@gramps-project.org> # Copyright (C) 2009 Benny Malengier <benny.malengier@gramps-project.org>
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -37,7 +37,7 @@ from gettext import gettext as _
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gen.plug import PluginManager from gen.plug import PluginManager, DocGenPlugin
import ImgManip import ImgManip
import tarfile import tarfile
import const 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() def register_plugin():
pmgr.register_text_doc(_('HTML'), HtmlDoc, 0, 1, ".html") """
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 # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2006 Donald N. Allingham # 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 # Copyright (C) 2008 Raphael Ackermann
# 2002-2003 Donald A. Peterson # 2002-2003 Donald A. Peterson
# 2003 Alex Roitman # 2003 Alex Roitman
@ -40,7 +40,7 @@ from gettext import gettext as _
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import BaseDoc import BaseDoc
from gen.plug import PluginManager from gen.plug import PluginManager, DocGenPlugin
import ImgManip import ImgManip
import Errors import Errors
import Utils import Utils
@ -637,11 +637,23 @@ class LaTeXDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
self.f.write('\\end{verbatim}') self.f.write('\\end{verbatim}')
self.end_paragraph() self.end_paragraph()
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# Register plugins # register_plugin
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
pmgr = PluginManager.get_instance() def register_plugin():
pmgr.register_text_doc(_('LaTeX'), LaTeXDoc, 1, 0, ".tex") """
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) 2000-2006 Donald N. Allingham
# Copyright (C) 2005-2006 Serge Noiraud # 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 # 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 # 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 BaseDoc
import const import const
from gen.plug import PluginManager from gen.plug import PluginManager, DocGenPlugin
from ReportBase import ReportUtils from ReportBase import ReportUtils
import ImgManip import ImgManip
import FontScale import FontScale
@ -1138,12 +1138,23 @@ class ODFDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
self.cntnt.write('</draw:text-box>') self.cntnt.write('</draw:text-box>')
self.cntnt.write('</draw:frame>\n') self.cntnt.write('</draw:frame>\n')
#-------------------------------------------------------------------------- #------------------------------------------------------------------------
# #
# Register plugins # register_plugin
# #
#-------------------------------------------------------------------------- #------------------------------------------------------------------------
pmgr = PluginManager.get_instance() def register_plugin():
pmgr.register_text_doc(_('Open Document Text'), ODFDoc, 1, 1, ".odt") """
pmgr.register_book_doc(_("Open Document Text"), ODFDoc, 1, 1, ".odt") Register the document generator with the GRAMPS plugin system.
pmgr.register_draw_doc(_("Open Document Text"), ODFDoc, 1, 1, ".odt") """
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 # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2006 Donald N. Allingham # 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 # 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 # it under the terms of the GNU General Public License as published by
@ -32,7 +32,7 @@ from gettext import gettext as _
#Gramps modules #Gramps modules
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from ReportBase import ReportUtils, run_print_dialog, get_print_dialog_app 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 BaseDoc
import Errors import Errors
@ -343,5 +343,23 @@ class PSDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc):
self.f.write("(%s) show\n" % lines[i]) self.f.write("(%s) show\n" % lines[i])
self.f.write('grestore\n') 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 CairoDoc import CairoDoc
from gen.plug import PluginManager from gen.plug import PluginManager, DocGenPlugin
import Utils import Utils
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@ -126,19 +126,24 @@ class PdfDoc(CairoDoc):
# load the result into an external viewer # load the result into an external viewer
if self.open_req: if self.open_req:
Utils.open_file_with_default_application(self._filename) 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 # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2006 Donald N. Allingham # 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 # Copyright (C) 2009 Gary Burton
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
@ -35,7 +35,7 @@ from gettext import gettext as _
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import BaseDoc import BaseDoc
from gen.plug import PluginManager from gen.plug import PluginManager, DocGenPlugin
import ImgManip import ImgManip
import Errors import Errors
import Utils 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() def register_plugin():
pmgr.register_text_doc(_('RTF document'), RTFDoc, 1, 1, ".rtf") """
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 # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2006 Donald N. Allingham # 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 # 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 # it under the terms of the GNU General Public License as published by
@ -34,7 +34,7 @@ import StringIO
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.plug import PluginManager from gen.plug import PluginManager, DocGenPlugin
import BaseDoc import BaseDoc
import Errors import Errors
@ -257,11 +257,23 @@ class SvgDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc):
def units(val): def units(val):
return (val[0]*35.433, val[1]*35.433) return (val[0]*35.433, val[1]*35.433)
#------------------------------------------------------------------------- #------------------------------------------------------------------------
# #
# Register document generator # register_plugin
# #
#------------------------------------------------------------------------- #------------------------------------------------------------------------
pmgr = PluginManager.get_instance() def register_plugin():
pmgr.register_draw_doc(_("SVG (Scalable Vector Graphics)"), SvgDrawDoc, 1, 1, """
".svg") 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()