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

219 lines
3.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML
><HEAD
><TITLE
>Writing Import Filters</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 Tools"
HREF="x131.html"><LINK
REL="NEXT"
TITLE="Writing Export Filters"
HREF="x177.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="x131.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="x177.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="writingimportfilters">Writing Import Filters</H1
>
<P
> Import filters are similar to tools, since they are allowed to
modify the databases. An import filter is a task that accepts
three arguments a database, the filename of the file that
is to be imported, and a callback function.
</P
>
<P
> The database may or may not have data already in it. The import
filter cannot assume that data neither already exists nor that the
database is empty.
</P
>
<P
> The callback function is different from the callback function used
for tools. The import filter's callback function is used to
indicate progress and update the status bar during the import
process. The function takes a value between 0.0 and 1.0, where 0.0
represents the start of the import and 1.0 represents the
completion of the import.
</P
>
<P
> As with the other plugin types, an import filter must be
registered with <TT
CLASS="APPLICATION"
>gramps</TT
>. This is
accomplished by calling the
<TT
CLASS="FUNCTION"
>Plugins.register_import</TT
> task. The
<TT
CLASS="FUNCTION"
>Plugins.register_import</TT
> accepts two arguments
the function the performs the import and a string
providing a brief description. This description is used as the
menu entry under the
+ + + + + +<B
CLASS="GUIMENU"
>File</B
>+
+ + + + + + -&gt;<B
CLASS="GUISUBMENU"
>Import</B
>+
+ + + +
menu.
</P
>
<DIV
CLASS="FIGURE"
><A
NAME="importexample">
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>&#13;import Plugins
def gedcom_import(database,filename,callback):
... actual code ...
Plugins.register_import(gedcom_import,"GEDCOM import")
</PRE
></TD
></TR
></TABLE
>
<P
><B
>Figure 4. Sample Import Implementation</B
></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="x131.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="x177.html"
ACCESSKEY="N"
>Next &#62;&#62;&#62;</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Writing Tools</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Writing Export Filters</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>