diff --git a/src/ReportBase/_ReportUtils.py b/src/ReportBase/_ReportUtils.py index 493a9097a..bb9126c07 100644 --- a/src/ReportBase/_ReportUtils.py +++ b/src/ReportBase/_ReportUtils.py @@ -2,7 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2007-2008 Brian G. Matherly +# Copyright (C) 2007-2009 Brian G. Matherly # Copyright (C) 2008 James Friedmann # # @@ -194,37 +194,6 @@ def get_death_or_fallback(database, person): return event return None -def old_calc_age(database, person): - """ - Calculate age. - - Returns a date difference span. - """ - birth_ref = person.get_birth_ref() - if birth_ref: - birth = database.get_event_from_handle(birth_ref.ref).get_date_object() - birth_year_valid = birth.get_year_valid() - else: - birth_year_valid = None - death_ref = person.get_death_ref() - if death_ref: - death = database.get_event_from_handle(death_ref.ref).get_date_object() - death_year_valid = death.get_year_valid() - else: - death_year_valid = None - - # wihtout at least a year for each event we're clueless - if not (birth_year_valid and death_year_valid): - return None - - return death - birth - -def common_name(person, use_call=False): - if use_call and person.get_primary_name().get_call_name(): - return person.get_primary_name().get_call_name() - else: - return person.get_primary_name().get_first_name() - #------------------------------------------------------------------------- # # Indexing function diff --git a/src/plugins/lib/libnarrate.py b/src/plugins/lib/libnarrate.py index 73c421b45..70ace066d 100644 --- a/src/plugins/lib/libnarrate.py +++ b/src/plugins/lib/libnarrate.py @@ -48,10 +48,27 @@ from ReportBase import ReportUtils #------------------------------------------------------------------------- # -# Support functions +# Private constants # #------------------------------------------------------------------------- -def empty_notes(whatever): +# In string arrays, the first strings should include the name, the second +# strings should not include the name. +_NAME_INDEX_INCLUDE_NAME = 0 +_NAME_INDEX_EXCLUDE_NAME = 1 + +# In string arrays, the first strings should not include age. +# The following strings should include year, month and day units. +_AGE_INDEX_NO_AGE = 0 +_AGE_INDEX_YEARS = 1 +_AGE_INDEX_MONTHS = 2 +_AGE_INDEX_DAYS = 3 + +#------------------------------------------------------------------------- +# +# Private functions +# +#------------------------------------------------------------------------- +def _get_empty_endnote_numbers(obj): """ Empty stab function for when endnotes are not needed """ @@ -62,102 +79,101 @@ def empty_notes(whatever): # Born strings # #------------------------------------------------------------------------ - born_full_date_with_place = [ + { + Person.UNKNOWN : _("%(unknown_gender_name)s was born on %(birth_date)s in %(birth_place)s."), + Person.MALE : _("%(male_name)s was born on %(birth_date)s in %(birth_place)s."), + Person.FEMALE : _("%(female_name)s was born on %(birth_date)s in %(birth_place)s."), + }, { Person.UNKNOWN : _("This person was born on %(birth_date)s in %(birth_place)s."), Person.MALE : _("He was born on %(birth_date)s in %(birth_place)s."), Person.FEMALE : _("She was born on %(birth_date)s in %(birth_place)s."), }, - { - Person.UNKNOWN : _("%(unknown_gender_name)s was born on %(birth_date)s in %(birth_place)s."), - Person.MALE : _("%(male_name)s was born on %(birth_date)s in %(birth_place)s."), - Person.FEMALE : _("%(female_name)s was born on %(birth_date)s in %(birth_place)s."), - }, _("Born %(birth_date)s in %(birth_place)s."), ] born_modified_date_with_place = [ - { - Person.UNKNOWN : _("This person was born %(modified_date)s in %(birth_place)s."), - Person.MALE : _("He was born %(modified_date)s in %(birth_place)s."), - Person.FEMALE : _("She was born %(modified_date)s in %(birth_place)s."), - }, { Person.UNKNOWN : _("%(unknown_gender_name)s was born %(modified_date)s in %(birth_place)s."), Person.MALE : _("%(male_name)s was born %(modified_date)s in %(birth_place)s."), Person.FEMALE : _("%(female_name)s was born %(modified_date)s in %(birth_place)s."), }, + { + Person.UNKNOWN : _("This person was born %(modified_date)s in %(birth_place)s."), + Person.MALE : _("He was born %(modified_date)s in %(birth_place)s."), + Person.FEMALE : _("She was born %(modified_date)s in %(birth_place)s."), + }, _("Born %(modified_date)s in %(birth_place)s."), ] born_full_date_no_place = [ - { - Person.UNKNOWN : _("This person was born on %(birth_date)s."), - Person.MALE : _("He was born on %(birth_date)s."), - Person.FEMALE : _("She was born on %(birth_date)s."), - }, { Person.UNKNOWN : _("%(unknown_gender_name)s was born on %(birth_date)s."), Person.MALE : _("%(male_name)s was born on %(birth_date)s."), Person.FEMALE : _("%(female_name)s was born on %(birth_date)s."), }, + { + Person.UNKNOWN : _("This person was born on %(birth_date)s."), + Person.MALE : _("He was born on %(birth_date)s."), + Person.FEMALE : _("She was born on %(birth_date)s."), + }, _("Born %(birth_date)s."), ] born_modified_date_no_place = [ - { - Person.UNKNOWN : _("This person was born %(modified_date)s."), - Person.MALE : _("He was born %(modified_date)s."), - Person.FEMALE : _("She was born %(modified_date)s."), - }, { Person.UNKNOWN : _("%(unknown_gender_name)s was born %(modified_date)s."), Person.MALE : _("%(male_name)s was born %(modified_date)s."), Person.FEMALE : _("%(female_name)s was born %(modified_date)s."), + }, + { + Person.UNKNOWN : _("This person was born %(modified_date)s."), + Person.MALE : _("He was born %(modified_date)s."), + Person.FEMALE : _("She was born %(modified_date)s."), }, _("Born %(modified_date)s."), ] born_partial_date_with_place = [ - { - Person.UNKNOWN : _("This person was born in %(month_year)s in %(birth_place)s."), - Person.MALE : _("He was born in %(month_year)s in %(birth_place)s."), - Person.FEMALE : _("She was born in %(month_year)s in %(birth_place)s."), - }, { Person.UNKNOWN : _("%(unknown_gender_name)s was born in %(month_year)s in %(birth_place)s."), Person.MALE : _("%(male_name)s was born in %(month_year)s in %(birth_place)s."), Person.FEMALE : _("%(female_name)s was born in %(month_year)s in %(birth_place)s."), }, + { + Person.UNKNOWN : _("This person was born in %(month_year)s in %(birth_place)s."), + Person.MALE : _("He was born in %(month_year)s in %(birth_place)s."), + Person.FEMALE : _("She was born in %(month_year)s in %(birth_place)s."), + }, _("Born %(month_year)s in %(birth_place)s."), ] born_partial_date_no_place = [ - { - Person.UNKNOWN : _("This person was born in %(month_year)s."), - Person.MALE : _("He was born in %(month_year)s."), - Person.FEMALE : _("She was born in %(month_year)s."), - }, { Person.UNKNOWN : _("%(unknown_gender_name)s was born in %(month_year)s."), Person.MALE : _("%(male_name)s was born in %(month_year)s."), Person.FEMALE : _("%(female_name)s was born in %(month_year)s."), }, + { + Person.UNKNOWN : _("This person was born in %(month_year)s."), + Person.MALE : _("He was born in %(month_year)s."), + Person.FEMALE : _("She was born in %(month_year)s."), + }, _("Born %(month_year)s."), ] born_no_date_with_place = [ - { - Person.UNKNOWN : _("This person was born in %(birth_place)s."), - Person.MALE : _("He was born in %(birth_place)s."), - Person.FEMALE : _("She was born in %(birth_place)s."), - }, { Person.UNKNOWN : _("%(unknown_gender_name)s was born in %(birth_place)s."), Person.MALE : _("%(male_name)s was born in %(birth_place)s."), Person.FEMALE : _("%(female_name)s was born in %(birth_place)s."), }, + { + Person.UNKNOWN : _("This person was born in %(birth_place)s."), + Person.MALE : _("He was born in %(birth_place)s."), + Person.FEMALE : _("She was born in %(birth_place)s."), + }, _("Born in %(birth_place)s."), ] @@ -166,27 +182,7 @@ born_no_date_with_place = [ # Died strings # #------------------------------------------------------------------------ - died_full_date_with_place = [ - { Person.UNKNOWN : [ - _("This person died on %(death_date)s in %(death_place)s."), - _("This person died on %(death_date)s in %(death_place)s at the age of %(age)d years."), - _("This person died on %(death_date)s in %(death_place)s at the age of %(age)d months."), - _("This person died on %(death_date)s in %(death_place)s at the age of %(age)d days."), - ], - Person.MALE : [ - _("He died on %(death_date)s in %(death_place)s."), - _("He died on %(death_date)s in %(death_place)s at the age of %(age)d years."), - _("He died on %(death_date)s in %(death_place)s at the age of %(age)d months."), - _("He died on %(death_date)s in %(death_place)s at the age of %(age)d days."), - ], - Person.FEMALE : [ - _("She died on %(death_date)s in %(death_place)s."), - _("She died on %(death_date)s in %(death_place)s at the age of %(age)d years."), - _("She died on %(death_date)s in %(death_place)s at the age of %(age)d months."), - _("She died on %(death_date)s in %(death_place)s at the age of %(age)d days."), - ], - }, { Person.UNKNOWN : [ _("%(unknown_gender_name)s died on %(death_date)s in %(death_place)s."), _("%(unknown_gender_name)s died on %(death_date)s in %(death_place)s at the age of %(age)d years."), @@ -206,6 +202,25 @@ died_full_date_with_place = [ _("%(female_name)s died on %(death_date)s in %(death_place)s at the age of %(age)d days."), ], }, + { Person.UNKNOWN : [ + _("This person died on %(death_date)s in %(death_place)s."), + _("This person died on %(death_date)s in %(death_place)s at the age of %(age)d years."), + _("This person died on %(death_date)s in %(death_place)s at the age of %(age)d months."), + _("This person died on %(death_date)s in %(death_place)s at the age of %(age)d days."), + ], + Person.MALE : [ + _("He died on %(death_date)s in %(death_place)s."), + _("He died on %(death_date)s in %(death_place)s at the age of %(age)d years."), + _("He died on %(death_date)s in %(death_place)s at the age of %(age)d months."), + _("He died on %(death_date)s in %(death_place)s at the age of %(age)d days."), + ], + Person.FEMALE : [ + _("She died on %(death_date)s in %(death_place)s."), + _("She died on %(death_date)s in %(death_place)s at the age of %(age)d years."), + _("She died on %(death_date)s in %(death_place)s at the age of %(age)d months."), + _("She died on %(death_date)s in %(death_place)s at the age of %(age)d days."), + ], + }, [ _("Died %(death_date)s in %(death_place)s."), _("Died %(death_date)s in %(death_place)s (age %(age)d years)."), @@ -215,25 +230,6 @@ died_full_date_with_place = [ ] died_modified_date_with_place = [ - { Person.UNKNOWN : [ - _("This person died %(death_date)s in %(death_place)s."), - _("This person died %(death_date)s in %(death_place)s at the age of %(age)d years."), - _("This person died %(death_date)s in %(death_place)s at the age of %(age)d months."), - _("This person died %(death_date)s in %(death_place)s at the age of %(age)d days."), - ], - Person.MALE : [ - _("He died %(death_date)s in %(death_place)s."), - _("He died %(death_date)s in %(death_place)s at the age of %(age)d years."), - _("He died %(death_date)s in %(death_place)s at the age of %(age)d months."), - _("He died %(death_date)s in %(death_place)s at the age of %(age)d days."), - ], - Person.FEMALE : [ - _("She died %(death_date)s in %(death_place)s."), - _("She died %(death_date)s in %(death_place)s at the age of %(age)d years."), - _("She died %(death_date)s in %(death_place)s at the age of %(age)d months."), - _("She died %(death_date)s in %(death_place)s at the age of %(age)d days."), - ], - }, { Person.UNKNOWN : [ _("%(unknown_gender_name)s died %(death_date)s in %(death_place)s."), _("%(unknown_gender_name)s died %(death_date)s in %(death_place)s at the age of %(age)d years."), @@ -253,6 +249,25 @@ died_modified_date_with_place = [ _("%(female_name)s died %(death_date)s in %(death_place)s at the age of %(age)d days."), ], }, + { Person.UNKNOWN : [ + _("This person died %(death_date)s in %(death_place)s."), + _("This person died %(death_date)s in %(death_place)s at the age of %(age)d years."), + _("This person died %(death_date)s in %(death_place)s at the age of %(age)d months."), + _("This person died %(death_date)s in %(death_place)s at the age of %(age)d days."), + ], + Person.MALE : [ + _("He died %(death_date)s in %(death_place)s."), + _("He died %(death_date)s in %(death_place)s at the age of %(age)d years."), + _("He died %(death_date)s in %(death_place)s at the age of %(age)d months."), + _("He died %(death_date)s in %(death_place)s at the age of %(age)d days."), + ], + Person.FEMALE : [ + _("She died %(death_date)s in %(death_place)s."), + _("She died %(death_date)s in %(death_place)s at the age of %(age)d years."), + _("She died %(death_date)s in %(death_place)s at the age of %(age)d months."), + _("She died %(death_date)s in %(death_place)s at the age of %(age)d days."), + ], + }, [ _("Died %(death_date)s in %(death_place)s."), _("Died %(death_date)s in %(death_place)s (age %(age)d years)."), @@ -262,25 +277,6 @@ died_modified_date_with_place = [ ] died_full_date_no_place = [ - { Person.UNKNOWN : [ - _("This person died on %(death_date)s."), - _("This person died on %(death_date)s at the age of %(age)d years."), - _("This person died on %(death_date)s at the age of %(age)d months."), - _("This person died on %(death_date)s at the age of %(age)d days."), - ], - Person.MALE : [ - _("He died on %(death_date)s."), - _("He died on %(death_date)s at the age of %(age)d years."), - _("He died on %(death_date)s at the age of %(age)d months."), - _("He died on %(death_date)s at the age of %(age)d days."), - ], - Person.FEMALE : [ - _("She died on %(death_date)s."), - _("She died on %(death_date)s at the age of %(age)d years."), - _("She died on %(death_date)s at the age of %(age)d months."), - _("She died on %(death_date)s at the age of %(age)d days."), - ], - }, { Person.UNKNOWN : [ _("%(unknown_gender_name)s died on %(death_date)s."), _("%(unknown_gender_name)s died on %(death_date)s at the age of %(age)d years."), @@ -300,6 +296,25 @@ died_full_date_no_place = [ _("%(female_name)s died on %(death_date)s at the age of %(age)d days."), ], }, + { Person.UNKNOWN : [ + _("This person died on %(death_date)s."), + _("This person died on %(death_date)s at the age of %(age)d years."), + _("This person died on %(death_date)s at the age of %(age)d months."), + _("This person died on %(death_date)s at the age of %(age)d days."), + ], + Person.MALE : [ + _("He died on %(death_date)s."), + _("He died on %(death_date)s at the age of %(age)d years."), + _("He died on %(death_date)s at the age of %(age)d months."), + _("He died on %(death_date)s at the age of %(age)d days."), + ], + Person.FEMALE : [ + _("She died on %(death_date)s."), + _("She died on %(death_date)s at the age of %(age)d years."), + _("She died on %(death_date)s at the age of %(age)d months."), + _("She died on %(death_date)s at the age of %(age)d days."), + ], + }, [ _("Died %(death_date)s."), _("Died %(death_date)s (age %(age)d years)."), @@ -309,25 +324,6 @@ died_full_date_no_place = [ ] died_modified_date_no_place = [ - { Person.UNKNOWN : [ - _("This person died %(death_date)s."), - _("This person died %(death_date)s at the age of %(age)d years."), - _("This person died %(death_date)s at the age of %(age)d months."), - _("This person died %(death_date)s at the age of %(age)d days."), - ], - Person.MALE : [ - _("He died %(death_date)s."), - _("He died %(death_date)s at the age of %(age)d years."), - _("He died %(death_date)s at the age of %(age)d months."), - _("He died %(death_date)s at the age of %(age)d days."), - ], - Person.FEMALE : [ - _("She died %(death_date)s."), - _("She died %(death_date)s at the age of %(age)d years."), - _("She died %(death_date)s at the age of %(age)d months."), - _("She died %(death_date)s at the age of %(age)d days."), - ], - }, { Person.UNKNOWN : [ _("%(unknown_gender_name)s died %(death_date)s."), _("%(unknown_gender_name)s died %(death_date)s at the age of %(age)d years."), @@ -347,6 +343,25 @@ died_modified_date_no_place = [ _("%(female_name)s died %(death_date)s at the age of %(age)d days."), ], }, + { Person.UNKNOWN : [ + _("This person died %(death_date)s."), + _("This person died %(death_date)s at the age of %(age)d years."), + _("This person died %(death_date)s at the age of %(age)d months."), + _("This person died %(death_date)s at the age of %(age)d days."), + ], + Person.MALE : [ + _("He died %(death_date)s."), + _("He died %(death_date)s at the age of %(age)d years."), + _("He died %(death_date)s at the age of %(age)d months."), + _("He died %(death_date)s at the age of %(age)d days."), + ], + Person.FEMALE : [ + _("She died %(death_date)s."), + _("She died %(death_date)s at the age of %(age)d years."), + _("She died %(death_date)s at the age of %(age)d months."), + _("She died %(death_date)s at the age of %(age)d days."), + ], + }, [ _("Died %(death_date)s."), _("Died %(death_date)s (age %(age)d years)."), @@ -356,25 +371,6 @@ died_modified_date_no_place = [ ] died_partial_date_with_place = [ - { Person.UNKNOWN : [ - _("This person died in %(month_year)s in %(death_place)s."), - _("This person died in %(month_year)s in %(death_place)s at the age of %(age)d years."), - _("This person died in %(month_year)s in %(death_place)s at the age of %(age)d months."), - _("This person died in %(month_year)s in %(death_place)s at the age of %(age)d days."), - ], - Person.MALE : [ - _("He died in %(month_year)s in %(death_place)s."), - _("He died in %(month_year)s in %(death_place)s at the age of %(age)d years."), - _("He died in %(month_year)s in %(death_place)s at the age of %(age)d months."), - _("He died in %(month_year)s in %(death_place)s at the age of %(age)d days."), - ], - Person.FEMALE : [ - _("She died in %(month_year)s in %(death_place)s."), - _("She died in %(month_year)s in %(death_place)s at the age of %(age)d years."), - _("She died in %(month_year)s in %(death_place)s at the age of %(age)d months."), - _("She died in %(month_year)s in %(death_place)s at the age of %(age)d days."), - ] - }, { Person.UNKNOWN : [ _("%(unknown_gender_name)s died in %(month_year)s in %(death_place)s."), _("%(unknown_gender_name)s died in %(month_year)s in %(death_place)s at the age of %(age)d years."), @@ -394,6 +390,25 @@ died_partial_date_with_place = [ _("%(female_name)s died in %(month_year)s in %(death_place)s at the age of %(age)d days."), ], }, + { Person.UNKNOWN : [ + _("This person died in %(month_year)s in %(death_place)s."), + _("This person died in %(month_year)s in %(death_place)s at the age of %(age)d years."), + _("This person died in %(month_year)s in %(death_place)s at the age of %(age)d months."), + _("This person died in %(month_year)s in %(death_place)s at the age of %(age)d days."), + ], + Person.MALE : [ + _("He died in %(month_year)s in %(death_place)s."), + _("He died in %(month_year)s in %(death_place)s at the age of %(age)d years."), + _("He died in %(month_year)s in %(death_place)s at the age of %(age)d months."), + _("He died in %(month_year)s in %(death_place)s at the age of %(age)d days."), + ], + Person.FEMALE : [ + _("She died in %(month_year)s in %(death_place)s."), + _("She died in %(month_year)s in %(death_place)s at the age of %(age)d years."), + _("She died in %(month_year)s in %(death_place)s at the age of %(age)d months."), + _("She died in %(month_year)s in %(death_place)s at the age of %(age)d days."), + ] + }, [ _("Died %(month_year)s in %(death_place)s."), _("Died %(month_year)s in %(death_place)s (age %(age)d years)."), @@ -403,25 +418,6 @@ died_partial_date_with_place = [ ] died_partial_date_no_place = [ - { Person.UNKNOWN : [ - _("This person died in %(month_year)s."), - _("This person died in %(month_year)s at the age of %(age)d years."), - _("This person died in %(month_year)s at the age of %(age)d months."), - _("This person died in %(month_year)s at the age of %(age)d days."), - ], - Person.MALE : [ - _("He died in %(month_year)s."), - _("He died in %(month_year)s at the age of %(age)d years."), - _("He died in %(month_year)s at the age of %(age)d months."), - _("He died in %(month_year)s at the age of %(age)d days."), - ], - Person.FEMALE : [ - _("She died in %(month_year)s."), - _("She died in %(month_year)s at the age of %(age)d years."), - _("She died in %(month_year)s at the age of %(age)d months."), - _("She died in %(month_year)s at the age of %(age)d days."), - ], - }, { Person.UNKNOWN : [ _("%(unknown_gender_name)s died in %(month_year)s."), _("%(unknown_gender_name)s died in %(month_year)s at the age of %(age)d years."), @@ -441,6 +437,25 @@ died_partial_date_no_place = [ _("%(female_name)s died in %(month_year)s at the age of %(age)d days."), ], }, + { Person.UNKNOWN : [ + _("This person died in %(month_year)s."), + _("This person died in %(month_year)s at the age of %(age)d years."), + _("This person died in %(month_year)s at the age of %(age)d months."), + _("This person died in %(month_year)s at the age of %(age)d days."), + ], + Person.MALE : [ + _("He died in %(month_year)s."), + _("He died in %(month_year)s at the age of %(age)d years."), + _("He died in %(month_year)s at the age of %(age)d months."), + _("He died in %(month_year)s at the age of %(age)d days."), + ], + Person.FEMALE : [ + _("She died in %(month_year)s."), + _("She died in %(month_year)s at the age of %(age)d years."), + _("She died in %(month_year)s at the age of %(age)d months."), + _("She died in %(month_year)s at the age of %(age)d days."), + ], + }, [ _("Died %(month_year)s."), _("Died %(month_year)s (age %(age)d years)."), @@ -450,6 +465,25 @@ died_partial_date_no_place = [ ] died_no_date_with_place = [ + { Person.UNKNOWN : [ + _("%(unknown_gender_name)s died in %(death_place)s."), + _("%(unknown_gender_name)s died in %(death_place)s at the age of %(age)d years."), + _("%(unknown_gender_name)s died in %(death_place)s at the age of %(age)d months."), + _("%(unknown_gender_name)s died in %(death_place)s at the age of %(age)d days."), + ], + Person.MALE : [ + _("%(male_name)s died in %(death_place)s."), + _("%(male_name)s died in %(death_place)s at the age of %(age)d years."), + _("%(male_name)s died in %(death_place)s at the age of %(age)d months."), + _("%(male_name)s died in %(death_place)s at the age of %(age)d days."), + ], + Person.FEMALE : [ + _("%(female_name)s died in %(death_place)s."), + _("%(female_name)s died in %(death_place)s at the age of %(age)d years."), + _("%(female_name)s died in %(death_place)s at the age of %(age)d months."), + _("%(female_name)s died in %(death_place)s at the age of %(age)d days."), + ], + }, { Person.UNKNOWN : [ _("This person died in %(death_place)s."), @@ -470,25 +504,6 @@ died_no_date_with_place = [ _("She died in %(death_place)s at the age of %(age)d days."), ], }, - { Person.UNKNOWN : [ - _("%(unknown_gender_name)s died in %(death_place)s."), - _("%(unknown_gender_name)s died in %(death_place)s at the age of %(age)d years."), - _("%(unknown_gender_name)s died in %(death_place)s at the age of %(age)d months."), - _("%(unknown_gender_name)s died in %(death_place)s at the age of %(age)d days."), - ], - Person.MALE : [ - _("%(male_name)s died in %(death_place)s."), - _("%(male_name)s died in %(death_place)s at the age of %(age)d years."), - _("%(male_name)s died in %(death_place)s at the age of %(age)d months."), - _("%(male_name)s died in %(death_place)s at the age of %(age)d days."), - ], - Person.FEMALE : [ - _("%(female_name)s died in %(death_place)s."), - _("%(female_name)s died in %(death_place)s at the age of %(age)d years."), - _("%(female_name)s died in %(death_place)s at the age of %(age)d months."), - _("%(female_name)s died in %(death_place)s at the age of %(age)d days."), - ], - }, [ _("Died in %(death_place)s."), _("Died in %(death_place)s (age %(age)d years)."), @@ -498,25 +513,6 @@ died_no_date_with_place = [ ] died_no_date_no_place = [ - { Person.UNKNOWN : [ - "", - _("This person died at the age of %(age)d years."), - _("This person died at the age of %(age)d months."), - _("This person died at the age of %(age)d days."), - ], - Person.MALE : [ - "", - _("He died at the age of %(age)d years."), - _("He died at the age of %(age)d months."), - _("He died at the age of %(age)d days."), - ], - Person.FEMALE : [ - "", - _("She died at the age of %(age)d years."), - _("She died at the age of %(age)d months."), - _("She died at the age of %(age)d days."), - ], - }, { Person.UNKNOWN : [ "", _("%(unknown_gender_name)s died at the age of %(age)d years."), @@ -536,6 +532,25 @@ died_no_date_no_place = [ _("%(female_name)s died at the age of %(age)d days."), ], }, + { Person.UNKNOWN : [ + "", + _("This person died at the age of %(age)d years."), + _("This person died at the age of %(age)d months."), + _("This person died at the age of %(age)d days."), + ], + Person.MALE : [ + "", + _("He died at the age of %(age)d years."), + _("He died at the age of %(age)d months."), + _("He died at the age of %(age)d days."), + ], + Person.FEMALE : [ + "", + _("She died at the age of %(age)d years."), + _("She died at the age of %(age)d months."), + _("She died at the age of %(age)d days."), + ], + }, [ "", _("Died (age %(age)d years)."), @@ -544,13 +559,11 @@ died_no_date_no_place = [ ], ] - #------------------------------------------------------------------------ # # Buried strings # #------------------------------------------------------------------------ - buried_full_date_place = { Person.MALE: [ _("%(male_name)s was buried on %(burial_date)s in %(burial_place)s%(endnotes)s."), @@ -684,7 +697,6 @@ buried_no_date_no_place = { # Baptised strings # #------------------------------------------------------------------------ - baptised_full_date_place = { Person.MALE: [ _("%(male_name)s was baptised on %(baptism_date)s in %(baptism_place)s%(endnotes)s."), @@ -818,7 +830,6 @@ baptised_no_date_no_place = { # Christened strings # #------------------------------------------------------------------------ - christened_full_date_place = { Person.MALE: [ _("%(male_name)s was christened on %(christening_date)s in %(christening_place)s%(endnotes)s."), @@ -952,111 +963,110 @@ christened_no_date_no_place = { # child to parent relationships # #------------------------------------------------------------------------- - child_father_mother = { Person.UNKNOWN: [ - [ - _("This person is the child of %(father)s and %(mother)s."), - _("This person was the child of %(father)s and %(mother)s."), - ], [ _("%(male_name)s is the child of %(father)s and %(mother)s."), _("%(male_name)s was the child of %(father)s and %(mother)s."), ], + [ + _("This person is the child of %(father)s and %(mother)s."), + _("This person was the child of %(father)s and %(mother)s."), + ], _("Child of %(father)s and %(mother)s."), ], Person.MALE : [ - [ - _("He is the son of %(father)s and %(mother)s."), - _("He was the son of %(father)s and %(mother)s."), - ], [ _("%(male_name)s is the son of %(father)s and %(mother)s."), _("%(male_name)s was the son of %(father)s and %(mother)s."), ], + [ + _("He is the son of %(father)s and %(mother)s."), + _("He was the son of %(father)s and %(mother)s."), + ], _("Son of %(father)s and %(mother)s."), ], Person.FEMALE : [ - [ - _("She is the daughter of %(father)s and %(mother)s."), - _("She was the daughter of %(father)s and %(mother)s."), - ], [ _("%(female_name)s is the daughter of %(father)s and %(mother)s."), _("%(female_name)s was the daughter of %(father)s and %(mother)s."), ], + [ + _("She is the daughter of %(father)s and %(mother)s."), + _("She was the daughter of %(father)s and %(mother)s."), + ], _("Daughter of %(father)s and %(mother)s."), ] } child_father = { Person.UNKNOWN : [ - [ - _("This person is the child of %(father)s."), - _("This person was the child of %(father)s."), - ], [ _("%(male_name)s is the child of %(father)s."), _("%(male_name)s was the child of %(father)s."), ], + [ + _("This person is the child of %(father)s."), + _("This person was the child of %(father)s."), + ], _("Child of %(father)s."), ], Person.MALE : [ - [ - _("He is the son of %(father)s."), - _("He was the son of %(father)s."), - ], [ _("%(male_name)s is the son of %(father)s."), _("%(male_name)s was the son of %(father)s."), ], + [ + _("He is the son of %(father)s."), + _("He was the son of %(father)s."), + ], _("Son of %(father)s."), ], Person.FEMALE : [ - [ - _("She is the daughter of %(father)s."), - _("She was the daughter of %(father)s."), - ], [ _("%(female_name)s is the daughter of %(father)s."), _("%(female_name)s was the daughter of %(father)s."), ], + [ + _("She is the daughter of %(father)s."), + _("She was the daughter of %(father)s."), + ], _("Daughter of %(father)s."), ], } child_mother = { Person.UNKNOWN : [ - [ - _("This person is the child of %(mother)s."), - _("This person was the child of %(mother)s."), - ], [ _("%(male_name)s is the child of %(mother)s."), _("%(male_name)s was the child of %(mother)s."), ], + [ + _("This person is the child of %(mother)s."), + _("This person was the child of %(mother)s."), + ], _("Child of %(mother)s."), ], Person.MALE : [ - [ - _("He is the son of %(mother)s."), - _("He was the son of %(mother)s."), - ], [ _("%(male_name)s is the son of %(mother)s."), _("%(male_name)s was the son of %(mother)s."), ], + [ + _("He is the son of %(mother)s."), + _("He was the son of %(mother)s."), + ], _("Son of %(mother)s."), ], Person.FEMALE : [ - [ - _("She is the daughter of %(mother)s."), - _("She was the daughter of %(mother)s."), - ], [ _("%(female_name)s is the daughter of %(mother)s."), _("%(female_name)s was the daughter of %(mother)s."), ], + [ + _("She is the daughter of %(mother)s."), + _("She was the daughter of %(mother)s."), + ], _("Daughter of %(mother)s."), ], } @@ -1066,7 +1076,6 @@ child_mother = { # Marriage strings - Relationship type MARRIED # #------------------------------------------------------------------------ - marriage_first_date_place = { Person.UNKNOWN : [ _('This person married %(spouse)s in %(partial_date)s in %(place)s%(endnotes)s.'), @@ -1192,7 +1201,6 @@ marriage_also_only = { # Marriage strings - Relationship type UNMARRIED # #------------------------------------------------------------------------ - unmarried_first_date_place = { Person.UNKNOWN : [ _('This person had an unmarried relationship with %(spouse)s in %(partial_date)s in %(place)s%(endnotes)s.'), @@ -1319,7 +1327,6 @@ unmarried_also_only = { # i.e. CIVIL UNION or CUSTOM # #------------------------------------------------------------------------ - relationship_first_date_place = { Person.UNKNOWN : [ _('This person had a relationship with %(spouse)s in %(partial_date)s in %(place)s%(endnotes)s.'), @@ -1440,7 +1447,6 @@ relationship_also_only = { 'succinct' : _('Also relationship with %(spouse)s%(endnotes)s.'), } - #------------------------------------------------------------------------ # # Narrator @@ -1451,66 +1457,110 @@ class Narrator(object): Narrator is a class which provides narration text. """ - def __init__(self, dbase, verbose=True, empty_date="", empty_place=""): + def __init__(self, dbase, verbose=True, use_call_name=False, + empty_date="", empty_place="", + get_endnote_numbers=_get_empty_endnote_numbers): """ Initialize the narrator class. + + :param dbase: The database that contains the data to be narrated. + :type dbase: :class:`~gen.db.base,GrampsDbBase` + :param verbose: Specifies whether complete sentences should be used. + :type verbose: bool + :param use_call_name: Specifies whether a person's call name should be + used for the first name. + :type use_call_name: bool + :param empty_date: String to use when a date is not known. + :type empty_date: str + :param empty_place: String to use when a place is not known. + :type empty_place: str + :param get_endnote_numbers: A callable to use for getting a string + representing endnote numbers. + The function takes a :class:`~gen.lib.srcbase,SourceBase` instance. + A typical return value from get_endnote_numbers() would be "2a" and + would represent a reference to an endnote in a document. + :type get_endnote_numbers: + callable( :class:`~gen.lib.srcbase,SourceBase` ) """ self.__db = dbase self.__verbose = verbose + self.__use_call = use_call_name self.__empty_date = empty_date self.__empty_place = empty_place + self.__get_endnote_numbers = get_endnote_numbers + self.__person = None + self.__first_name = "" + self.__first_name_used = False - def born_str(self, person, person_name=None ): - """ - Check birth record. - Statement formats name precedes this - was born on Date. - was born on Date in Place. - was born in Month_Year. - was born in Month_Year in Place. - was born in Place. - '' + def set_subject(self, person): """ - - name_index = 1 - if person_name is None: - person_name = _nd.display(person) - elif person_name == 0: - name_index = 0 + Start a new story about this person. The person's first name will be + used in the first sentence. A pronoun will be used as the subject for + each subsequent sentence. + :param person: The person to be the subject of the story. + :type dbase: :class:`~gen.lib.person,Person` + """ + self.__person = person + + if self.__use_call and person.get_primary_name().get_call_name(): + self.__first_name = person.get_primary_name().get_call_name() + else: + self.__first_name = person.get_primary_name().get_first_name() + + self.__first_name_used = False + + def get_born_string(self): + """ + Get a string narrating the birth of the subject. + Example sentences: + Person was born on Date. + Person was born on Date in Place. + Person was born in Place. + '' + + :returns: A sentence about the subject's birth. + :rtype: unicode + """ + if not self.__first_name_used: + name_index = _NAME_INDEX_INCLUDE_NAME + self.__first_name_used = True + else: + name_index = _NAME_INDEX_EXCLUDE_NAME text = "" bplace = self.__empty_place bdate = self.__empty_date + birth_event = None bdate_full = False bdate_mod = False - birth_ref = person.get_birth_ref() + birth_ref = self.__person.get_birth_ref() if birth_ref and birth_ref.ref: - birth = self.__db.get_event_from_handle(birth_ref.ref) - if birth: - bdate = DateHandler.get_date(birth) - bplace_handle = birth.get_place_handle() + birth_event = self.__db.get_event_from_handle(birth_ref.ref) + if birth_event: + bdate = DateHandler.get_date(birth_event) + bplace_handle = birth_event.get_place_handle() if bplace_handle: place = self.__db.get_place_from_handle(bplace_handle) bplace = place.get_title() - bdate_obj = birth.get_date_object() + bdate_obj = birth_event.get_date_object() bdate_full = bdate_obj and bdate_obj.get_day_valid() bdate_mod = bdate_obj and \ bdate_obj.get_modifier() != Date.MOD_NONE value_map = { - 'name' : person_name, - 'male_name' : person_name, - 'unknown_gender_name' : person_name, - 'female_name' : person_name, + 'name' : self.__first_name, + 'male_name' : self.__first_name, + 'unknown_gender_name' : self.__first_name, + 'female_name' : self.__first_name, 'birth_date' : bdate, 'birth_place' : bplace, 'month_year' : bdate, 'modified_date' : bdate, } - gender = person.get_gender() + gender = self.__person.get_gender() if bdate: if bdate_mod: @@ -1547,99 +1597,77 @@ class Narrator(object): text = born_no_date_with_place[2] % value_map else: text = "" + + if text and birth_event: + text = text.rstrip(". ") + text = text + self.__get_endnote_numbers(birth_event) + ". " + if text: text = text + " " return text - #------------------------------------------------------------------------- - # - # died_str - # - #------------------------------------------------------------------------- - def died_str(self, person, person_name=None, span=None): + def get_died_string(self, include_age=False): """ - Write obit sentence. - FIRSTNAME died on Date - FIRSTNAME died on Date at the age of N Years - FIRSTNAME died on Date at the age of N Months - FIRSTNAME died on Date at the age of N Days - FIRSTNAME died on Date in Place - FIRSTNAME died on Date in Place at the age of N Years - FIRSTNAME died on Date in Place at the age of N Months - FIRSTNAME died on Date in Place at the age of N Days - FIRSTNAME died in Month_Year - FIRSTNAME died in Month_Year at the age of N Years - FIRSTNAME died in Month_Year at the age of N Months - FIRSTNAME died in Month_Year at the age of N Days - FIRSTNAME died in Month_Year in Place - FIRSTNAME died in Month_Year in Place at the age of N Years - FIRSTNAME died in Month_Year in Place at the age of N Months - FIRSTNAME died in Month_Year in Place at the age of N Days - FIRSTNAME died in Place - FIRSTNAME died in Place at the age of N Years - FIRSTNAME died in Place at the age of N Months - FIRSTNAME died in Place at the age of N Days - FIRSTNAME died - FIRSTNAME died at the age of N Years - FIRSTNAME died at the age of N Months - FIRSTNAME died at the age of N Days + Get a string narrating the death of the subject. + Example sentences: + Person died on Date + Person died on Date at the age of N Years + Person died on Date at the age of N Months + Person died on Date at the age of N Days + Person died on Date in Place + Person died on Date in Place at the age of N Years + Person died on Date in Place at the age of N Months + Person died on Date in Place at the age of N Days + Person died in Place + Person died in Place at the age of N Years + Person died in Place at the age of N Months + Person died in Place at the age of N Days + Person died + '' + + :returns: A sentence about the subject's death. + :rtype: unicode """ - name_index = 1 - if person_name is None: - person_name = _nd.display(person) - elif person_name == 0: - name_index = 0 + if not self.__first_name_used: + name_index = _NAME_INDEX_INCLUDE_NAME + self.__first_name_used = True + else: + name_index = _NAME_INDEX_EXCLUDE_NAME text = "" dplace = self.__empty_place ddate = self.__empty_date + death_event = None ddate_full = False ddate_mod = False - - death_ref = person.get_death_ref() + death_ref = self.__person.get_death_ref() if death_ref and death_ref.ref: - death = self.__db.get_event_from_handle(death_ref.ref) - if death: - ddate = DateHandler.get_date(death) - dplace_handle = death.get_place_handle() + death_event = self.__db.get_event_from_handle(death_ref.ref) + if death_event: + ddate = DateHandler.get_date(death_event) + dplace_handle = death_event.get_place_handle() if dplace_handle: place = self.__db.get_place_from_handle(dplace_handle) dplace = place.get_title() - ddate_obj = death.get_date_object() + ddate_obj = death_event.get_date_object() ddate_full = ddate_obj and ddate_obj.get_day_valid() ddate_mod = ddate_obj and \ ddate_obj.get_modifier() != Date.MOD_NONE - - # TODO: fixme to let date format itself - if span and span.is_valid(): - YEARS = 1 - MONTHS = 2 - DAYS = 3 - if span[0] != 0: - age = span[0] - age_units = YEARS - elif span[1] != 0: - age = span[1] - age_units = MONTHS - elif span[2] != 0: - age = span[2] - age_units = DAYS - else: - age = 0 - age_units = 0 + + if include_age: + age, age_index = self.__get_age_at_death() else: age = 0 - age_units = 0 - # end of todo ---------------------------- - + age_index = _AGE_INDEX_NO_AGE + value_map = { - 'name' : person_name, - 'unknown_gender_name' : person_name, - 'male_name' : person_name, - 'female_name' : person_name, + 'name' : self.__first_name, + 'unknown_gender_name' : self.__first_name, + 'male_name' : self.__first_name, + 'female_name' : self.__first_name, 'death_date' : ddate, 'modified_date' : ddate, 'death_place' : dplace, @@ -1647,76 +1675,76 @@ class Narrator(object): 'month_year' : ddate, } - gender = person.get_gender() + gender = self.__person.get_gender() if ddate: if ddate_mod: if dplace and self.__verbose: - text = died_modified_date_with_place[name_index][gender][age_units] % value_map + text = died_modified_date_with_place[name_index][gender][age_index] % value_map elif dplace: - text = died_modified_date_with_place[2][age_units] % value_map + text = died_modified_date_with_place[2][age_index] % value_map elif self.__verbose: - text = died_modified_date_no_place[name_index][gender][age_units] % value_map + text = died_modified_date_no_place[name_index][gender][age_index] % value_map else: - text = died_modified_date_no_place[2][age_units] % value_map + text = died_modified_date_no_place[2][age_index] % value_map elif ddate_full: if dplace and self.__verbose: - text = died_full_date_with_place[name_index][gender][age_units] % value_map + text = died_full_date_with_place[name_index][gender][age_index] % value_map elif dplace: - text = died_full_date_with_place[2][age_units] % value_map + text = died_full_date_with_place[2][age_index] % value_map elif self.__verbose: - text = died_full_date_no_place[name_index][gender][age_units] % value_map + text = died_full_date_no_place[name_index][gender][age_index] % value_map else: - text = died_full_date_no_place[2][age_units] % value_map + text = died_full_date_no_place[2][age_index] % value_map else: if dplace and self.__verbose: - text = died_partial_date_with_place[name_index][gender][age_units] % value_map + text = died_partial_date_with_place[name_index][gender][age_index] % value_map elif dplace: - text = died_partial_date_with_place[2][age_units] % value_map + text = died_partial_date_with_place[2][age_index] % value_map elif self.__verbose: - text = died_partial_date_no_place[name_index][gender][age_units] % value_map + text = died_partial_date_no_place[name_index][gender][age_index] % value_map else: - text = died_partial_date_no_place[2][age_units] % value_map + text = died_partial_date_no_place[2][age_index] % value_map else: if dplace and self.__verbose: - text = died_no_date_with_place[name_index][gender][age_units] % value_map + text = died_no_date_with_place[name_index][gender][age_index] % value_map elif dplace: - text = died_no_date_with_place[2][age_units] % value_map + text = died_no_date_with_place[2][age_index] % value_map elif self.__verbose: - text = died_no_date_no_place[name_index][gender][age_units] % value_map + text = died_no_date_no_place[name_index][gender][age_index] % value_map else: - text = died_no_date_no_place[2][age_units] % value_map + text = died_no_date_no_place[2][age_index] % value_map + + if text and death_event: + text = text.rstrip(". ") + text = text + self.__get_endnote_numbers(death_event) + ". " + if text: text = text + " " return text - - #------------------------------------------------------------------------- - # - # buried_str - # - #------------------------------------------------------------------------- - def buried_str(self, person, person_name=None, endnotes=None): + + def get_buried_string(self): """ - Check burial record. - Statement formats name precedes this - was buried on Date. - was buried on Date in Place. - was buried in Month_Year. - was buried in Month_Year in Place. - was buried in Place. + Get a string narrating the burial of the subject. + Example sentences: + Person was buried on Date. + Person was buried on Date in Place. + Person was buried in Month_Year. + Person was buried in Month_Year in Place. + Person was buried in Place. '' + + :returns: A sentence about the subject's burial. + :rtype: unicode """ - if not endnotes: - endnotes = empty_notes + if not self.__first_name_used: + name_index = _NAME_INDEX_INCLUDE_NAME + self.__first_name_used = True + else: + name_index = _NAME_INDEX_EXCLUDE_NAME - name_index = 0 - if person_name is None: - person_name = _nd.display(person) - elif person_name == 0: - name_index = 1 - - gender = person.get_gender() + gender = self.__person.get_gender() text = "" @@ -1726,7 +1754,7 @@ class Narrator(object): bdate_mod = False burial = None - for event_ref in person.get_event_ref_list(): + for event_ref in self.__person.get_event_ref_list(): event = self.__db.get_event_from_handle(event_ref.ref) if event and event.type.value == EventType.BURIAL \ and event_ref.role.value == EventRoleType.PRIMARY: @@ -1746,15 +1774,15 @@ class Narrator(object): return text values = { - 'unknown_gender_name' : person_name, - 'male_name' : person_name, - 'name' : person_name, - 'female_name' : person_name, + 'unknown_gender_name' : self.__first_name, + 'male_name' : self.__first_name, + 'name' : self.__first_name, + 'female_name' : self.__first_name, 'burial_date' : bdate, 'burial_place' : bplace, 'month_year' : bdate, 'modified_date' : bdate, - 'endnotes' : endnotes(event), + 'endnotes' : self.__get_endnote_numbers(event), } if bdate and bdate_mod and self.__verbose: @@ -1799,34 +1827,29 @@ class Narrator(object): if text: text = text + " " return text - - #------------------------------------------------------------------------- - # - # baptised_str - # - #------------------------------------------------------------------------- - def baptised_str(self, person, person_name=None, endnotes=None): + + def get_baptized_string(self): """ - Check baptism record. - Statement formats name precedes this - was baptised on Date. - was baptised on Date in Place. - was baptised in Month_Year. - was baptised in Month_Year in Place. - was baptised in Place. + Get a string narrating the baptism of the subject. + Example sentences: + Person was baptised on Date. + Person was baptised on Date in Place. + Person was baptised in Month_Year. + Person was baptised in Month_Year in Place. + Person was baptised in Place. '' + + :returns: A sentence about the subject's baptism. + :rtype: unicode """ + + if not self.__first_name_used: + name_index = _NAME_INDEX_INCLUDE_NAME + self.__first_name_used = True + else: + name_index = _NAME_INDEX_EXCLUDE_NAME - if not endnotes: - endnotes = empty_notes - - name_index = 0 - if person_name is None: - person_name = _nd.display(person) - elif person_name == 0: - name_index = 1 - - gender = person.get_gender() + gender = self.__person.get_gender() text = "" @@ -1836,7 +1859,7 @@ class Narrator(object): bdate_mod = False baptism = None - for event_ref in person.get_event_ref_list(): + for event_ref in self.__person.get_event_ref_list(): event = self.__db.get_event_from_handle(event_ref.ref) if event and event.type.value == EventType.BAPTISM \ and event_ref.role.value == EventRoleType.PRIMARY: @@ -1856,15 +1879,15 @@ class Narrator(object): return text values = { - 'unknown_gender_name' : person_name, - 'male_name' : person_name, - 'name' : person_name, - 'female_name' : person_name, + 'unknown_gender_name' : self.__first_name, + 'male_name' : self.__first_name, + 'name' : self.__first_name, + 'female_name' : self.__first_name, 'baptism_date' : bdate, 'baptism_place' : bplace, 'month_year' : bdate, 'modified_date' : bdate, - 'endnotes' : endnotes(event), + 'endnotes' : self.__get_endnote_numbers(event), } if bdate and bdate_mod and self.__verbose: @@ -1909,34 +1932,29 @@ class Narrator(object): if text: text = text + " " return text - - #------------------------------------------------------------------------- - # - # christened_str - # - #------------------------------------------------------------------------- - def christened_str(self, person, person_name=None, endnotes=None): + + def get_christened_string(self): """ - Check christening record. - Statement formats name precedes this - was christened on Date. - was christened on Date in Place. - was christened in Month_Year. - was christened in Month_Year in Place. - was christened in Place. + Get a string narrating the christening of the subject. + Example sentences: + Person was christened on Date. + Person was christened on Date in Place. + Person was christened in Month_Year. + Person was christened in Month_Year in Place. + Person was christened in Place. '' + + :returns: A sentence about the subject's christening. + :rtype: unicode """ + + if not self.__first_name_used: + name_index = _NAME_INDEX_INCLUDE_NAME + self.__first_name_used = True + else: + name_index = _NAME_INDEX_EXCLUDE_NAME - if not endnotes: - endnotes = empty_notes - - name_index = 0 - if person_name is None: - person_name = _nd.display(person) - elif person_name == 0: - name_index = 1 - - gender = person.get_gender() + gender = self.__person.get_gender() text = "" @@ -1946,7 +1964,7 @@ class Narrator(object): cdate_mod = False christening = None - for event_ref in person.get_event_ref_list(): + for event_ref in self.__person.get_event_ref_list(): event = self.__db.get_event_from_handle(event_ref.ref) if event and event.type.value == EventType.CHRISTEN \ and event_ref.role.value == EventRoleType.PRIMARY: @@ -1966,15 +1984,15 @@ class Narrator(object): return text values = { - 'unknown_gender_name' : person_name, - 'male_name' : person_name, - 'name' : person_name, - 'female_name' : person_name, + 'unknown_gender_name' : self.__first_name, + 'male_name' : self.__first_name, + 'name' : self.__first_name, + 'female_name' : self.__first_name, 'christening_date' : cdate, 'christening_place' : cplace, 'month_year' : cdate, 'modified_date' : cdate, - 'endnotes' : endnotes(event), + 'endnotes' : self.__get_endnote_numbers(event), } if cdate and cdate_mod and self.__verbose: @@ -2020,25 +2038,27 @@ class Narrator(object): text = text + " " return text - def married_str(self, person, family, endnotes=None, is_first=True): + def get_married_string(self, family, is_first=True): """ - Composes a string describing marriage of a person. Missing information - will be omitted without loss of readability. Optional references may be - added to birth and death events. - - @param database: GRAMPS database to which the Person object belongs - @type database: GrampsDbBase - @param person: Person instance whose marriage is discussed - @type person: Person - @param family: Family instance of the "marriage" being discussed - @param endnotes: Function to use for reference composition. If None - then references will not be added - @type endnotes: function - @returns: A composed string - @rtype: unicode + Get a string narrating the marriage of the subject. + Example sentences: + Person was married to Spouse on Date. + Person was married to Spouse. + Person was also married to Spouse on Date. + Person was also married to Spouse. + "" + + :param family: The family that contains the Spouse for this marriage. + :type family: :class:`~gen.lib.family,Family` + :param is_first: Indicates whether this sentence represents the first + marriage. If it is not the first marriage, the sentence will + include "also". + :type is_first: :class:`~gen.lib.family,Family` + :returns: A sentence about the subject's marriage. + :rtype: unicode """ - spouse_handle = ReportUtils.find_spouse(person, family) + spouse_handle = ReportUtils.find_spouse(self.__person, family) spouse = self.__db.get_person_from_handle(spouse_handle) event = ReportUtils.find_marriage(self.__db, family) @@ -2046,9 +2066,6 @@ class Narrator(object): if not spouse: return u"" - if not endnotes: - endnotes = empty_notes - date = self.__empty_date place = self.__empty_place spouse_name = _nd.display(spouse) @@ -2065,7 +2082,7 @@ class Narrator(object): values = { 'spouse' : spouse_name, - 'endnotes' : endnotes(event), + 'endnotes' : self.__get_endnote_numbers(event), 'full_date' : date, 'modified_date' : date, 'partial_date' : date, @@ -2082,7 +2099,7 @@ class Narrator(object): else: date_full = 0 - gender = person.get_gender() + gender = self.__person.get_gender() # This would be much simpler, excepting for translation considerations # Currently support FamilyRelType's: @@ -2216,43 +2233,41 @@ class Narrator(object): text = text + " " return text - def child_str(self, person, father_name="", mother_name="", person_name=0): + def get_child_string(self, father_name="", mother_name=""): """ - Composes a string describing person being a child. - - The string is composed in the following form: - 'He/She is/was the son/daughter of father_name and mother_name' + Get a string narrating the relationship to the parents of the subject. Missing information will be omitted without loss of readability. - - @param person_gender: Person.MALE, Person.FEMALE, or Person.UNKNOWN - @type person: Person.MALE, Person.FEMALE, or Person.UNKNOWN~ - @param father_name: String to use for father's name - @type father_name: unicode - @param mother_name: String to use for mother's name - @type mother_name: unicode - @param dead: Whether the person discussed is dead or not - @type dead: bool - @returns: A composed string - @rtype: unicode + Example sentences: + Person was the son of father_name and mother_name. + Person was the daughter of father_name and mother_name. + "" + + :param father_name: The name of the Subjects' father. + :type father_name: unicode + :param mother_name: The name of the Subjects' mother. + :type mother_name: unicode + :returns: A sentence about the subject's parents. + :rtype: unicode """ values = { 'father' : father_name, 'mother' : mother_name, - 'male_name' : person_name, - 'name' : person_name, - 'female_name' : person_name, - 'unknown_gender_name' : person_name, + 'male_name' : self.__first_name, + 'name' : self.__first_name, + 'female_name' : self.__first_name, + 'unknown_gender_name' : self.__first_name, } - dead = not Utils.probably_alive(person, self.__db) + dead = not Utils.probably_alive(self.__person, self.__db) - if person_name == 0: - index = 0 + if not self.__first_name_used: + index = _NAME_INDEX_INCLUDE_NAME + self.__first_name_used = True else: - index = 1 + index = _NAME_INDEX_EXCLUDE_NAME - gender = person.get_gender() + gender = self.__person.get_gender() text = "" if mother_name and father_name and self.__verbose: @@ -2269,4 +2284,50 @@ class Narrator(object): text = child_father[gender][2] % values if text: text = text + " " - return text \ No newline at end of file + return text + + def __get_age_at_death(self): + """ + Calculate the age the person died. + + Returns a tuple representing (age, age_index). + """ + birth_ref = self.__person.get_birth_ref() + if birth_ref: + birth_event = self.__db.get_event_from_handle(birth_ref.ref) + birth = birth_event.get_date_object() + birth_year_valid = birth.get_year_valid() + else: + birth_year_valid = False + death_ref = self.__person.get_death_ref() + if death_ref: + death_event = self.__db.get_event_from_handle(death_ref.ref) + death = death_event.get_date_object() + death_year_valid = death.get_year_valid() + else: + death_year_valid = False + + # wihtout at least a year for each event no age can be calculated + if birth_year_valid and death_year_valid: + span = death - birth + if span and span.is_valid(): + if span[0] != 0: + age = span[0] + age_index = _AGE_INDEX_YEARS + elif span[1] != 0: + age = span[1] + age_index = _AGE_INDEX_MONTHS + elif span[2] != 0: + age = span[2] + age_index = _AGE_INDEX_DAYS + else: + age = 0 + age_index = _AGE_INDEX_NO_AGE + else: + age = 0 + age_index = _AGE_INDEX_NO_AGE + else: + age = 0 + age_index = _AGE_INDEX_NO_AGE + + return age, age_index \ No newline at end of file diff --git a/src/plugins/textreport/AncestorReport.py b/src/plugins/textreport/AncestorReport.py index 190a23fd0..07fe6b22a 100644 --- a/src/plugins/textreport/AncestorReport.py +++ b/src/plugins/textreport/AncestorReport.py @@ -2,7 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2007-2008 Brian G. Matherly +# Copyright (C) 2007-2009 Brian G. Matherly # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -218,16 +218,11 @@ class AncestorReport(Report): if self.opt_namebrk: self.doc.write_text('\n') - # Write the birth, death, and buried strings by calling the standard - # functions in ReportUtils - - primary_name = person.get_primary_name() - first = primary_name.get_first_name() - - self.doc.write_text(self.__narrator.born_str(person, first)) - self.doc.write_text(self.__narrator.baptised_str( person, 0)) - self.doc.write_text(self.__narrator.died_str(person, 0)) - self.doc.write_text(self.__narrator.buried_str(person, 0)) + self.__narrator.set_subject(person) + self.doc.write_text(self.__narrator.get_born_string()) + self.doc.write_text(self.__narrator.get_baptized_string()) + self.doc.write_text(self.__narrator.get_died_string()) + self.doc.write_text(self.__narrator.get_buried_string()) self.doc.end_paragraph() diff --git a/src/plugins/textreport/DetAncestralReport.py b/src/plugins/textreport/DetAncestralReport.py index a6c81233f..7a6288de2 100644 --- a/src/plugins/textreport/DetAncestralReport.py +++ b/src/plugins/textreport/DetAncestralReport.py @@ -3,7 +3,7 @@ # # Copyright (C) 2000-2002 Bruce J. DeGrasse # Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2007-2008 Brian G. Matherly +# Copyright (C) 2007-2009 Brian G. Matherly # Copyright (C) 2008 James Friedmann # Copyright (C) 2009 Benny Malengier # @@ -104,7 +104,7 @@ class DetAncestorReport(Report): self.fulldate = menu.get_option_by_name('fulldates').get_value() self.listchildren = menu.get_option_by_name('listc').get_value() self.includenotes = menu.get_option_by_name('incnotes').get_value() - self.usecall = menu.get_option_by_name('usecall').get_value() + use_call = menu.get_option_by_name('usecall').get_value() blankplace = menu.get_option_by_name('repplace').get_value() blankdate = menu.get_option_by_name('repdate').get_value() self.calcageflag = menu.get_option_by_name('computeage').get_value() @@ -136,12 +136,12 @@ class DetAncestorReport(Report): else: empty_place = "" - self.__narrator = Narrator(self.database, self.verbose, - empty_date, empty_place) + self.__narrator = Narrator(self.database, self.verbose, use_call, + empty_date, empty_place, self.endnotes) self.bibli = Bibliography(Bibliography.MODE_PAGE) - def apply_filter(self,person_handle,index): + def apply_filter(self, person_handle, index): if (not person_handle) or (index >= 2**self.max_generations): return self.map[index] = person_handle @@ -150,21 +150,20 @@ class DetAncestorReport(Report): family_handle = person.get_main_parents_family_handle() if family_handle: family = self.database.get_family_from_handle(family_handle) - self.apply_filter(family.get_father_handle(),index*2) - self.apply_filter(family.get_mother_handle(),(index*2)+1) + self.apply_filter(family.get_father_handle(), index*2) + self.apply_filter(family.get_mother_handle(), (index*2)+1) def write_report(self): - self.apply_filter(self.center_person.get_handle(),1) + self.apply_filter(self.center_person.get_handle(), 1) name = _nd.display_name(self.center_person.get_primary_name()) self.doc.start_paragraph("DAR-Title") title = _("Ancestral Report for %s") % name - mark = IndexMark(title,INDEX_TYPE_TOC,1) - self.doc.write_text(title,mark) + mark = IndexMark(title, INDEX_TYPE_TOC, 1) + self.doc.write_text(title, mark) self.doc.end_paragraph() generation = 0 - need_header = 1 for key in sorted(self.map): if generation == 0 or key >= 2**generation: @@ -209,10 +208,11 @@ class DetAncestorReport(Report): person_handle = self.map[key] person = self.database.get_person_from_handle(person_handle) plist = person.get_media_list() + self.__narrator.set_subject(person) if self.addimages and len(plist) > 0: photo = plist[0] - ReportUtils.insert_image(self.database,self.doc,photo) + ReportUtils.insert_image(self.database, self.doc, photo) self.doc.start_paragraph("DAR-First-Entry","%s." % str(key)) @@ -220,7 +220,7 @@ class DetAncestorReport(Report): mark = ReportUtils.get_person_mark(self.database, person) self.doc.start_bold() - self.doc.write_text(name,mark) + self.doc.write_text(name, mark) if name[-1:] == '.': self.doc.write_text_citation("%s " % self.endnotes(person)) else: @@ -238,51 +238,32 @@ class DetAncestorReport(Report): { 'name' : '', 'id_str' : str(dkey) }) self.doc.end_paragraph() return 1 # Duplicate person - - # Check birth record - - first = ReportUtils.common_name(person,self.usecall) if not self.verbose: - self.write_parents(person, first) + self.write_parents(person) - text = self.__narrator.born_str(person, first) + text = self.__narrator.get_born_string() if text: - birth_ref = person.get_birth_ref() - if birth_ref: - birth = self.database.get_event_from_handle(birth_ref.ref) - text = text.rstrip(". ") - text = text + self.endnotes(birth) + ". " self.doc.write_text_citation(text) - first = 0 - text = self.__narrator.baptised_str(person, first, self.endnotes) + text = self.__narrator.get_baptized_string() if text: self.doc.write_text_citation(text) - text = self.__narrator.christened_str(person, first, self.endnotes) + text = self.__narrator.get_christened_string() if text: self.doc.write_text_citation(text) - span = self.calc_age(person) - text = self.__narrator.died_str(person, first, span) - if text: - death_ref = person.get_death_ref() - if death_ref: - death = self.database.get_event_from_handle(death_ref.ref) - text = text.rstrip(". ") - text = text + self.endnotes(death) + ". " - self.doc.write_text_citation(text) - first = 0 - - text = self.__narrator.buried_str(person, first, self.endnotes) + text = self.__narrator.get_died_string(self.calcageflag) if text: self.doc.write_text_citation(text) - first = ReportUtils.common_name(person, self.usecall) + text = self.__narrator.get_buried_string() + if text: + self.doc.write_text_citation(text) if self.verbose: - self.write_parents(person, first) + self.write_parents(person) if not key % 2 or key == 1: self.write_marriage(person) @@ -437,7 +418,7 @@ class DetAncestorReport(Report): self.doc.write_styled_note(note.get_styledtext(), note.get_format(),"DAR-MoreDetails") - def write_parents(self, person, firstName): + def write_parents(self, person): family_handle = person.get_main_parents_family_handle() if family_handle: family = self.database.get_family_from_handle(family_handle) @@ -458,14 +439,13 @@ class DetAncestorReport(Report): father_name = "" father_mark = "" - text = self.__narrator.child_str(person, father_name, mother_name, - firstName) + text = self.__narrator.get_child_string(father_name, mother_name) if text: self.doc.write_text(text) if father_mark: - self.doc.write_text("",father_mark) + self.doc.write_text("", father_mark) if mother_mark: - self.doc.write_text("",mother_mark) + self.doc.write_text("", mother_mark) def write_marriage(self, person): """ @@ -479,8 +459,7 @@ class DetAncestorReport(Report): text = "" spouse_mark = ReportUtils.get_person_mark(self.database, spouse) - text = self.__narrator.married_str(person, family, self.endnotes, - is_first) + text = self.__narrator.get_married_string(family, is_first) if text: self.doc.write_text_citation(text, spouse_mark) @@ -519,22 +498,24 @@ class DetAncestorReport(Report): child_handle = child_ref.ref child = self.database.get_person_from_handle(child_handle) child_name = _nd.display(child) - child_mark = ReportUtils.get_person_mark(self.database,child) + child_mark = ReportUtils.get_person_mark(self.database, child) if self.childref and self.prev_gen_handles.get(child_handle): value = str(self.prev_gen_handles.get(child_handle)) child_name += " [%s]" % value - self.doc.start_paragraph("DAR-ChildList",ReportUtils.roman(cnt).lower() + ".") + self.doc.start_paragraph("DAR-ChildList", + ReportUtils.roman(cnt).lower() + ".") cnt += 1 - self.doc.write_text("%s. " % child_name,child_mark) - self.doc.write_text(self.__narrator.born_str(child)) - self.doc.write_text(self.__narrator.died_str(child)) + self.__narrator.set_subject(child) + self.doc.write_text("%s. " % child_name, child_mark) + self.doc.write_text(self.__narrator.get_born_string()) + self.doc.write_text(self.__narrator.get_died_string()) self.doc.end_paragraph() - def write_family_events(self,family): + def write_family_events(self, family): if not family.get_event_ref_list(): return @@ -620,61 +601,32 @@ class DetAncestorReport(Report): self.doc.start_paragraph("DAR-Entry") - first_name = ReportUtils.common_name(ind, self.usecall) - print_name = first_name + self.__narrator.set_subject(ind) - text = self.__narrator.born_str(ind, print_name) - if text: - self.doc.write_text(text) - print_name = 0 - - text = self.__narrator.baptised_str(ind, print_name, - self.endnotes) + text = self.__narrator.get_born_string() if text: self.doc.write_text_citation(text) - print_name = 0 - text = self.__narrator.christened_str(ind, print_name, - self.endnotes) + text = self.__narrator.get_baptized_string() if text: self.doc.write_text_citation(text) - print_name = 0 - span = self.calc_age(ind) - text = self.__narrator.died_str(ind, print_name, span) + text = self.__narrator.get_christened_string() if text: - self.doc.write_text(text) - print_name = 0 - - text = self.__narrator.buried_str(ind, print_name, - self.endnotes) + self.doc.write_text_citation(text) + + text = self.__narrator.get_died_string(self.calcageflag) + if text: + self.doc.write_text_citation(text) + text = self.__narrator.get_buried_string() if text: self.doc.write_text_citation(text) - print_name = 0 - if print_name == 0: - print_name = first_name - self.write_parents(ind, print_name) + self.write_parents(ind) self.doc.end_paragraph() - def calc_age(self,ind): - """ - Calulate age. - - Returns a tuple (age,units) where units is an integer representing - time units: - no age info: 0 - years: 1 - months: 2 - days: 3 - """ - if self.calcageflag: - return ReportUtils.old_calc_age(self.database,ind) - else: - return None - def endnotes(self, obj): if not obj or not self.inc_sources: return "" @@ -729,8 +681,8 @@ class DetAncestorOptions(MenuReportOptions): listc.set_help(_("Whether to list children.")) menu.add_option(category_name,"listc",listc) - computeage = BooleanOption(_("Compute age"),True) - computeage.set_help(_("Whether to compute age.")) + computeage = BooleanOption(_("Compute death age"),True) + computeage.set_help(_("Whether to compute a person's age at death.")) menu.add_option(category_name,"computeage",computeage) omitda = BooleanOption(_("Omit duplicate ancestors"),True) diff --git a/src/plugins/textreport/DetDescendantReport.py b/src/plugins/textreport/DetDescendantReport.py index f8a383926..6aef97dec 100644 --- a/src/plugins/textreport/DetDescendantReport.py +++ b/src/plugins/textreport/DetDescendantReport.py @@ -3,7 +3,7 @@ # # Copyright (C) 2000-2002 Bruce J. DeGrasse # Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2007-2008 Brian G. Matherly +# Copyright (C) 2007-2009 Brian G. Matherly # Copyright (C) 2007 Robert Cawley # Copyright (C) 2008-2009 James Friedmann # Copyright (C) 2009 Benny Malengier @@ -50,7 +50,6 @@ from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, from ReportBase import (Report, ReportUtils, MenuReportOptions, Bibliography, Endnotes) import DateHandler -import Utils from libnarrate import Narrator @@ -110,7 +109,7 @@ class DetDescendantReport(Report): self.fulldate = menu.get_option_by_name('fulldates').get_value() self.listchildren = menu.get_option_by_name('listc').get_value() self.inc_notes = menu.get_option_by_name('incnotes').get_value() - self.usecall = menu.get_option_by_name('usecall').get_value() + use_call = menu.get_option_by_name('usecall').get_value() blankplace = menu.get_option_by_name('repplace').get_value() blankdate = menu.get_option_by_name('repdate').get_value() self.calcageflag = menu.get_option_by_name('computeage').get_value() @@ -147,8 +146,8 @@ class DetDescendantReport(Report): else: empty_place = "" - self.__narrator = Narrator(self.database, self.verbose, - empty_date, empty_place) + self.__narrator = Narrator(self.database, self.verbose, use_call, + empty_date, empty_place, self.endnotes) self.bibli = Bibliography(Bibliography.MODE_PAGE) @@ -214,7 +213,7 @@ class DetDescendantReport(Report): ix = max(self.map) self.apply_mod_reg_filter_aux(child_ref.ref, ix+1, cur_gen+1) - def apply_mod_reg_filter(self,person_handle): + def apply_mod_reg_filter(self, person_handle): self.apply_mod_reg_filter_aux(person_handle, 1, 1) mod_reg_number = 1 for generation in xrange(len(self.gen_keys)): @@ -246,7 +245,6 @@ class DetDescendantReport(Report): self.doc.write_text(title, mark) self.doc.end_paragraph() - keys = sorted(self.map) generation = 0 for generation in xrange(len(self.gen_keys)): @@ -414,7 +412,7 @@ class DetDescendantReport(Report): self.doc.write_styled_note(note.get_styledtext(), note.get_format(),"DDR-MoreDetails") - def write_parents(self, person, firstName): + def __write_parents(self, person): family_handle = person.get_main_parents_family_handle() if family_handle: family = self.database.get_family_from_handle(family_handle) @@ -434,8 +432,7 @@ class DetDescendantReport(Report): else: father_name = "" father_mark = "" - text = self.__narrator.child_str(person, father_name, mother_name, - firstName) + text = self.__narrator.get_child_string(father_name, mother_name) if text: self.doc.write_text(text) if father_mark: @@ -455,8 +452,7 @@ class DetDescendantReport(Report): text = "" spouse_mark = ReportUtils.get_person_mark(self.database, spouse) - text = self.__narrator.married_str(person, family, self.endnotes, - is_first) + text = self.__narrator.get_married_string(family, is_first) if text: self.doc.write_text_citation(text, spouse_mark) @@ -540,9 +536,9 @@ class DetDescendantReport(Report): cnt += 1 self.doc.write_text("%s. " % child_name, child_mark) - - self.doc.write_text(self.__narrator.born_str(child, 0)) - self.doc.write_text(self.__narrator.died_str(child, 0)) + self.__narrator.set_subject(child) + self.doc.write_text_citation(self.__narrator.get_born_string()) + self.doc.write_text_citation(self.__narrator.get_died_string()) self.doc.end_paragraph() def __write_family_events(self, family): @@ -580,6 +576,7 @@ class DetDescendantReport(Report): def write_person_info(self, person): name = _nd.display_formal(person) + self.__narrator.set_subject(person) plist = person.get_media_list() if self.addimages and len(plist) > 0: @@ -587,49 +584,32 @@ class DetDescendantReport(Report): ReportUtils.insert_image(self.database, self.doc, photo) self.doc.start_paragraph("DDR-Entry") - # Check birth record - first = ReportUtils.common_name(person, self.usecall) if not self.verbose: - self.write_parents(person, first) + self.__write_parents(person) - text = self.__narrator.born_str(person, first) + text = self.__narrator.get_born_string() if text: - birth_ref = person.get_birth_ref() - if birth_ref: - birth = self.database.get_event_from_handle(birth_ref.ref) - text = text.rstrip(". ") - text = text + self.endnotes(birth) + ". " self.doc.write_text_citation(text) - first = 0 - text = self.__narrator.baptised_str(person, first, self.endnotes) + text = self.__narrator.get_baptized_string() if text: self.doc.write_text_citation(text) - text = self.__narrator.christened_str(person, first, self.endnotes) + text = self.__narrator.get_christened_string() if text: self.doc.write_text_citation(text) - span = self.calc_age(person) - text = self.__narrator.died_str(person, first, span) - if text: - death_ref = person.get_death_ref() - if death_ref: - death = self.database.get_event_from_handle(death_ref.ref) - text = text.rstrip(". ") - text = text + self.endnotes(death) + ". " - self.doc.write_text_citation(text) - first = 0 - - text = self.__narrator.buried_str(person, first, self.endnotes) + text = self.__narrator.get_died_string(self.calcageflag) if text: self.doc.write_text_citation(text) - first = ReportUtils.common_name(person, self.usecall) + text = self.__narrator.get_buried_string() + if text: + self.doc.write_text_citation(text) if self.verbose: - self.write_parents(person, first) + self.__write_parents(person) self.write_marriage(person) self.doc.end_paragraph() @@ -710,22 +690,6 @@ class DetDescendantReport(Report): self.doc.write_text_citation( text ) self.doc.end_paragraph() - def calc_age(self,ind): - """ - Calulate age. - - Returns a tuple (age,units) where units is an integer representing - time units: - no age info: 0 - years: 1 - months: 2 - days: 3 - """ - if self.calcageflag: - return ReportUtils.old_calc_age(self.database, ind) - else: - return None - def endnotes(self, obj): if not obj or not self.inc_sources: return "" @@ -793,8 +757,8 @@ class DetDescendantOptions(MenuReportOptions): listc.set_help(_("Whether to list children.")) menu.add_option(category_name, "listc", listc) - computeage = BooleanOption(_("Compute age"), True) - computeage.set_help(_("Whether to compute age.")) + computeage = BooleanOption(_("Compute death age"),True) + computeage.set_help(_("Whether to compute a person's age at death.")) menu.add_option(category_name, "computeage", computeage) omitda = BooleanOption(_("Omit duplicate ancestors"), True)