5875df7c48
svn: r1140
276 lines
4.7 KiB
HTML
276 lines
4.7 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
|
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>Writing 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 Extentions for gramps"
|
|
HREF="t1.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="Writing Reports"
|
|
HREF="x83.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="t1.html"
|
|
ACCESSKEY="P"
|
|
><<< Previous</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
></TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="x83.html"
|
|
ACCESSKEY="N"
|
|
>Next >>></A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="SECT1"
|
|
><H1
|
|
CLASS="SECT1"
|
|
><A
|
|
NAME="writingfilters">Writing Filters</H1
|
|
>
|
|
<P
|
|
> Users can create their own filters and add them to
|
|
<TT
|
|
CLASS="APPLICATION"
|
|
>gramps</TT
|
|
>. By adding the filter to the
|
|
user's private filter directory (<TT
|
|
CLASS="FILENAME"
|
|
>~/.gramps/filters</TT
|
|
>), the filter will
|
|
be automatically recognized the next time that the program is
|
|
started.
|
|
</P
|
|
>
|
|
<DIV
|
|
CLASS="SECT2"
|
|
><H2
|
|
CLASS="SECT2"
|
|
><A
|
|
NAME="createfilter">Creating a filter</H2
|
|
>
|
|
<P
|
|
> Each filter is a class derived from the
|
|
<TT
|
|
CLASS="FUNCTION"
|
|
>Filter.Filter</TT
|
|
> class. The
|
|
<TT
|
|
CLASS="FUNCTION"
|
|
>__init__</TT
|
|
> task may be overridden, but if so,
|
|
should call the <TT
|
|
CLASS="FUNCTION"
|
|
>__init__</TT
|
|
> function on the
|
|
<TT
|
|
CLASS="FUNCTION"
|
|
>Filter.Filter</TT
|
|
> class. The parent class
|
|
provides the variable <TT
|
|
CLASS="FUNCTION"
|
|
>self.text</TT
|
|
>, which
|
|
contains the text string passed as the qualifier. This string
|
|
provides additional information provided by the user. For
|
|
example, if the filter is used to match names, the qualifier
|
|
would be used to provide the name that is being compared
|
|
against.
|
|
</P
|
|
>
|
|
<P
|
|
> All filter classes must define a <TT
|
|
CLASS="FUNCTION"
|
|
>match</TT
|
|
>
|
|
function. The function takes one argument (other than
|
|
<TT
|
|
CLASS="FUNCTION"
|
|
>self</TT
|
|
>), which is an object of type
|
|
<TT
|
|
CLASS="FUNCTION"
|
|
>Person</TT
|
|
> to compare against. The function
|
|
should return a 1 if the person matches the filter, or a zero if
|
|
the person does not.
|
|
</P
|
|
>
|
|
<P
|
|
> Each filter must be registered, so that
|
|
<TT
|
|
CLASS="APPLICATION"
|
|
>gramps</TT
|
|
> knows about it. This is
|
|
accomplished by calling the
|
|
<TT
|
|
CLASS="FUNCTION"
|
|
>Filter.register_filter</TT
|
|
> function. This
|
|
function takes three arguments - the filter class, a
|
|
description, and flag that indicates if the qualifier string is
|
|
needed. The description string appears in the pull down
|
|
interface within <TT
|
|
CLASS="APPLICATION"
|
|
>gramps</TT
|
|
>, and helps
|
|
the user choose the appropriate filter. The qualifier flag tells
|
|
<TT
|
|
CLASS="APPLICATION"
|
|
>gramps</TT
|
|
> whether or not the filter
|
|
needs a qualifier string. If this flag is 0,
|
|
<TT
|
|
CLASS="APPLICATION"
|
|
>gramps</TT
|
|
> will disable the entry of a
|
|
qualifier string.
|
|
</P
|
|
>
|
|
<DIV
|
|
CLASS="FIGURE"
|
|
><A
|
|
NAME="filtersrc">
|
|
<TABLE
|
|
BORDER="0"
|
|
BGCOLOR="#E0E0E0"
|
|
WIDTH="100%"
|
|
><TR
|
|
><TD
|
|
><PRE
|
|
CLASS="PROGRAMLISTING"
|
|
> import Filter
|
|
import string
|
|
|
|
# class definition
|
|
|
|
class SubString(Filter.Filter):
|
|
|
|
def match(self,person):
|
|
name = person.getPrimaryName().getName()
|
|
return string.find(name,self.text) >= 0
|
|
|
|
Filter.register_filter(SubString,
|
|
description="Names that contain a substring",
|
|
qualifier=1)
|
|
|
|
</PRE
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
>
|
|
<P
|
|
><B
|
|
>Figure 1. Sample filter implementation</B
|
|
></P
|
|
></DIV
|
|
>
|
|
</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="t1.html"
|
|
ACCESSKEY="P"
|
|
><<< 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="x83.html"
|
|
ACCESSKEY="N"
|
|
>Next >>></A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>Writing Extentions for gramps</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
> </TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>Writing Reports</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |