Writing Extentions for gramps
<<< Previous |  | Next >>>

# Writing Import Filters

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.

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.

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.

As with the other plugin types, an import filter must be registered with `gramps`. This is accomplished by calling the `Plugins.register_import` task. The `Plugins.register_import` 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 File->Import menu.

    import Plugins

    def gedcom_import(database,filename,callback):
        ... actual code ...

    Plugins.register_import(gedcom_import,"GEDCOM import")

Figure 4. Sample Import Implementation

<<< Previous | Home | Next >>>
Writing Tools |  | Writing Export Filters