Difference between revisions of "Quick Views"

(New page: Quick reports are reports that are available in the context menu's of person, family, ... They are easy to make by users, even with limited coding knowledge. [[Category:Developers/Genera...)

Introduction

Many users want to produce a report quickly for their specific needs, but are hindered by the fact they do not want to learn python fully, nor the intricacies of a complicated program like GRAMPS.

For them, starting in GRAMPS 3.0 a new tool has been constructed: the quick reports. These reports are short textual reports that the user can register with GRAMPS, so they automatically appear in the context menu's.
Accompanying this, a simple database access and simple document interface has been constructed, so as to hide as much complexity as possible.

Where to store my quick report

A quick report is one single file. You can store it in your plugins directory. Go into your home folder and go to the hidden directory .gramps. In this directory you will find the plugins directory. Just add your plugin there, and it will appear within GRAMPS.

For the terminal users, you can get there as follows:

cd ~/.gramps/plugins

Example 1

Code

Quick Report context menu on Person View

How better than to learn something than using an example?
Here it goes. We want a report to show all siblings of a person. That is, brothers and sisters from all families the person is part of. The quick report is then the following:

Analysis: registering the report

The above code is GPL licensed, written by Don.
Let's analyse this. We start at the bottom where the report is registered with register_quick_report. This is the function GRAMPS will look for in your file. You need to give:

name = a unique name: a name GRAMPS identifies the plugin with, don't use spaces or strange symbols.

category = a special constant indicating where the report will be shown. You can use CATEGORY_QR_PERSON to see the report on person editor and view, or CATEGORY_QR_FAMILY to see the report on family editor or view.

run_func = the function you create in this plugin and that GRAMPS will execute when the user selects your quick report in the menu

translated_name = the name of the report as it will appear in the menu

status = is your report Stable or Unstable. Not used at the moment. On distributing GRAMPS we only include stable reports.

description = a description of what your plugin does. This appears in a tooltip over the menu

author_name = your name

author_email= your email, so people can congratulate you with your work, or ask for bug fixes...

Analysis: the run function

If the user clicks in the quick report menu on your report, the run function is executed with three parameters:

run_function(database, document, handle)

So, your report recieved from gramps the database on which to work, the document on which to write, and the handle (=unique identifier) of the object the user is on. For a person quick report, this is a person handle, for family, a family handle.

In this example, the function called is

def run(database, document, person):

Analysis: accessing the data

Now that your plugin runs, you need to open the database, start the document, access data, and write it out.
We do this using the Simple Database API. So,

Note that we use _ for every string for translation, which comes from the line

27 from gettext import gettext as _

You can replace this by

46 sdoc.title("Siblings of %s" % sdb.name(person))

to just try it out for yourself, without a translation option.

As we will write a list, it is usefull to define the structure of your text one time, and reuse this. That is the __FMT constant, defined as

33 __FMT = "%-30s\t%-10s\t%s"

So we have 30 spaces for the Sibling field, then a tab (\t), then 10 spaces for the Gender, another tab and the last stringfield for the birth date.

Everything is set up, now we write out the lines with all the siblings, leaving out the active person himself, as he is in the title field!

52 # grab our current id, so we can filter the active person out
53 # of the data
54
55 gid = sdb.gid(person)
56
57 # loop through each family in which the person is a child
58 for family in sdb.child_in(person):
59
60 # loop through each child in the family
61 for child in sdb.children(family):
62
63 # only display if this child is not the active person
64 if sdb.gid(child) != gid:
65 sdoc.paragraph(__FMT % (
66 sdb.name(child),
67 sdb.gender(child),
68 sdb.birth_date(child)))

Here, the easy access classes from the Simple Access API have been used to quickly achieve what we want.

Example 2

A second example can be found in the GRAMPS code. See all_events.py. In this report, all events for a person are printed, and all events for a family. Two quick reports are hence registered, one for person, and one for family.

Remarks

At the moment quick reports have not been enabled for events, place, repository or sources. If you write a report for that, just mail the developers list with a request to activate this. It would only be 30 to 60 min of work.

The possibilities are enormous. If you are an experienced hacker, there is no need to limit yourself to the simple database API. Also, if you make a real report, you can at the same time register a quick report with default settings.