The Simple Access docs starts with a small example Python.
(Provides a simplified database access interface to the Gramps database.)
sa = SimpleAccess(database)
print "Person : ", sa.name(person)
print "Gender : ", sa.gender(person)
print "Birth date : ", sa.birth_date(person)
print "Birth place : ", sa.birth_place(person)
print "Death date : ", sa.death_date(person)
print "Death place : ", sa.death_place(person)
print "Father : ", sa.name(sa.father(person))
print "Mother : ", sa.name(sa.mother(person))
print "Spouse : ", sa.name(sa.spouse(person))
print "Marriage Type : ", sa.marriage_type(person)
print "Marriage Date : ", sa.marriage_date(person)
print "Marriage Place: ", sa.marriage_place(person)
for child in sa.children(person):
print "Child : ", sa.name(child)
# Print out burial and baptism events
for event in sa.events( person , [ "Burial", "Baptism" ]):
print "Event : ", sa.event_type(event), sa.event_date(event),
print sa.event_place(event)
This is supposed to produce:
Person : Garner, Lewis Anderson
Gender : male
Birth date : 6/21/1855
Birth place : Great Falls, MT
Death date : 6/28/1911
Death place : Twin Falls, ID
Father : Garner, Robert W.
Mother : Zielinski, Phoebe Emily
Spouse : Martel, Luella Jacques
Marriage Type : Married
Marriage Date : 4/1/1875
Marriage Place: Paragould, AR
Child : Garner, Eugene Stanley
Child : Garner, Jesse V.
Child : Garner, Raymond E.
Child : Garner, Jennie S.
Child : Garner, Walter E.
Child : Garner, Daniel Webster
Child : Garner, Bertha P.
Child : Garner, Elizabeth
Event : Burial 7/1/1911 Twin Falls, ID
What is most simplistic way this example code can be made to run?
Using the Python Shell gramplet? Maybe a QuickReport add-on?
Note that this was in an older piece of developer documentation. The example code is in Python2 and Gramps has since evolved to use Python3. So the code needs a minor tweak for the newer Print syntax. Also, it helps to insert a line that explicitly shows how that this code can rely upon the database
object from the _simpleaccess
module in the gramps.gen.simple
package:
from gramps.gen.simple._simpleaccess import SimpleAccess
It seems like showing that data for the Active Person is the best “instant gratification” example each addon.
A lesson stepping through with that output is better than a “Hello World” example and could be applied to several add-on types: gramplet, report (with plain text, simple document, simple table implementations), quick report, view mode, tool.