gramps/gramps2/doc/extending-gramps/C/extending-gramps/x83.html
Don Allingham 0ca0ae439e Initial revision
svn: r1140
2002-10-20 14:25:16 +00:00

369 lines
6.3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML
><HEAD
><TITLE
>Writing Reports</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
REL="HOME"
TITLE="Writing Extentions for gramps"
HREF="t1.html"><LINK
REL="PREVIOUS"
TITLE="Writing Filters"
HREF="x57.html"><LINK
REL="NEXT"
TITLE="Writing Tools"
HREF="x131.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Writing Extentions for gramps</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x57.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x131.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="writingreports">Writing Reports</H1
>
<P
> Users can create their own report generators and add them to
<TT
CLASS="APPLICATION"
>gramps</TT
>. By adding the report generator
to the user's private plugin directory (<TT
CLASS="FILENAME"
>~/.gramps/plugins</TT
>), the report
generator will be automatically recognized the next time that the
program is started.
</P
>
<DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="createreport">Creating a report generator</H2
>
<P
> Fewer restrictions are made on report generators than on
filters. The report generator is passed the current
<TT
CLASS="APPLICATION"
>gramps</TT
> database and the active
person. The generator needs to take special care to make sure
that it does not alter the database in anyway.
</P
>
<P
> A report generator is a function that takes two arguments
a database (of type <TT
CLASS="FUNCTION"
>RelDataBase</TT
>)
and the currently selected person (of type
<TT
CLASS="FUNCTION"
>Person</TT
>). When called, this task should
generate the desired report.
</P
>
<P
> This function's implementation can be as simple as generating
output without the user's intervention, or it could display a
graphical interface to allow the user to select options and
customize a report.
</P
>
<P
> As with filters, the report generator must be registered before
<TT
CLASS="APPLICATION"
>gramps</TT
> will understand it. The report
generator is registered using the
<TT
CLASS="FUNCTION"
>Plugins.register_report</TT
>. This function
takes five arguments.
</P
>
<P
></P
><UL
><LI
> <P
> <TT
CLASS="GUILABEL"
><B
>The report generation task</B
></TT
> This task
that generates the report.
</P
>
</LI
><LI
> <P
> <TT
CLASS="GUILABEL"
><B
>The report category</B
></TT
> The category in
which the report is grouped in the
<B
CLASS="GUIMENU"
>Reports</B
> menu and
in the <SPAN
CLASS="INTERFACE"
>Report Selection</SPAN
> dialog.
</P
>
</LI
><LI
> <P
> <TT
CLASS="GUILABEL"
><B
>The report name</B
></TT
>
The name of the report.
</P
>
</LI
><LI
> <P
> <TT
CLASS="GUILABEL"
><B
>A text description of the report</B
></TT
> The
description appears in the report selection tool to provide
the user with a description of what the tools does.
</P
>
</LI
><LI
> <P
> <TT
CLASS="GUILABEL"
><B
>A graphic logo in XPM format</B
></TT
> This may
be either a path to a filename, or a list of strings
containting the XPM data. If a filename is specified, care
must be taken to make sure the file location is relocatable
and can be determined at runtime.
</P
>
</LI
></UL
>
<P
> While only the task and report name are required, it is
recommended to provide all five parameters.
</P
>
<DIV
CLASS="FIGURE"
><A
NAME="reportsrc">
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;import Plugins
def report(database,person):
... actual code ...
Plugins.register_report(
task=report,
category="Category",
name="Report Name",
description="A text descripition of the report generator",
xpm="%s/myfile.xpm" % os.path.dirname(__file__)
)
</PRE
></TD
></TR
></TABLE
>
<P
><B
>Figure 2. Sample report implementation</B
></P
></DIV
>
</DIV
>
<DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="alittlehelp">A little help - Format Interfaces</H2
>
<P
> <TT
CLASS="APPLICATION"
>gramps</TT
> provides some help with
writing reports. Several generic python classes exist that aid
in the writing of report generators. These classes provide an
abstract interface for a type of document, such as a drawing,
word processor document, or a spreadsheet. From these core
classes, <TT
CLASS="APPLICATION"
>gramps</TT
> derives interfaces to
various document formats. This means that by coding to the
generic word processing class (<TT
CLASS="FUNCTION"
>TextDoc</TT
>), a
report generator can instant access to multiple file formats
(such as HTML, OpenOffice, and AbiWord).
</P
>
<P
> This scheme of deriving a output format from a generic base
class also makes it easier to add new formats. Creating a new
derivied class targeting a different format (such as
<TT
CLASS="APPLICATION"
>KWord</TT
> or
<TT
CLASS="APPLICATION"
>LaTeX</TT
>) makes it easy for existing
report generators to use the new formats.
</P
>
</DIV
>
</DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x57.html"
ACCESSKEY="P"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="t1.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x131.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Writing Filters</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Writing Tools</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>