gramps/doc/extending-gramps/C/extending-gramps/writingtools.html
2001-09-05 04:57:05 +00:00

265 lines
3.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML
><HEAD
><TITLE
>Writing Tools</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.59"><LINK
REL="HOME"
TITLE="Writing Extentions for gramps"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Writing Reports"
HREF="writingreports.html"><LINK
REL="NEXT"
TITLE="Writing Import Filters"
HREF="writingimportfilters.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><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="writingreports.html"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="writingimportfilters.html"
>Next &#62;&#62;&#62;</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="WRITINGTOOLS"
>Writing Tools</A
></H1
><P
> Users can create their own tools and add them to
<TT
CLASS="APPLICATION"
>gramps</TT
>. By adding the tool to the
user's private plugin directory (<TT
CLASS="FILENAME"
>~/.gramps/plugins</TT
>), the tool will be
automatically recognized the next time that
<TT
CLASS="APPLICATION"
>gramps</TT
> is started.
</P
><P
> Unlike a report generator, a tool is allowed to modify the
database. The tool is passed the current
<TT
CLASS="APPLICATION"
>gramps</TT
> database, the active person,
and a callback function. The callback function should be called
with a non-zero argument upon completion of the tool if the
database has been altered.
</P
><P
> As with filters and report generators, tools must be registered
before <TT
CLASS="APPLICATION"
>gramps</TT
> will understand it. The
tool is registered using the
<TT
CLASS="FUNCTION"
>Plugins.register_tool</TT
>. This function takes
four arguments.
</P
><P
></P
><UL
><LI
><P
> <TT
CLASS="GUILABEL"
><B
>The tool task</B
></TT
> This task
that executes the tool.
</P
></LI
><LI
><P
> <TT
CLASS="GUILABEL"
><B
>The tool category</B
></TT
> The category in which
the tool is grouped in the
<B
CLASS="GUIMENU"
>Tools</B
> menu and in
the <SPAN
CLASS="INTERFACE"
>Tool Selection</SPAN
> dialog.
</P
></LI
><LI
><P
> <TT
CLASS="GUILABEL"
><B
>The tool name</B
></TT
>
The name of the tool.
</P
></LI
><LI
><P
> <TT
CLASS="GUILABEL"
><B
>A text description of the tool</B
></TT
> The
description appears in the Tool Selection dialog to provide
the user with a description of what the tool does.
</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="TOOLSRC"
></A
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;import Plugins
def tool(database,person,callback):
... actual code ...
callback(1)
Plugins.register_tool(
task=tool,
category="Category",
name="Tool Name",
description="A text descripition of the tool"
)
</PRE
></TD
></TR
></TABLE
><P
><B
>Figure 3. Sample tool implementation</B
></P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="writingreports.html"
>&#60;&#60;&#60; Previous</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="writingimportfilters.html"
>Next &#62;&#62;&#62;</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Writing Reports</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Writing Import Filters</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>