diff --git a/src/plugins/lib/libnarrate.py b/src/plugins/lib/libnarrate.py index 19415efad..f387c00db 100644 --- a/src/plugins/lib/libnarrate.py +++ b/src/plugins/lib/libnarrate.py @@ -2070,7 +2070,7 @@ class Narrator(object): return text - def get_married_string(self, family, is_first=True): + def get_married_string(self, family, is_first=True, name_display=None): """ Get a string narrating the marriage of the subject. Example sentences: @@ -2085,7 +2085,9 @@ class Narrator(object): :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` + :type is_first: bool + :param name_display: An object to be used for displaying names + :type is_first: :class:`~gen.display.name,NameDisplay` :returns: A sentence about the subject's marriage. :rtype: unicode """ @@ -2100,8 +2102,11 @@ class Narrator(object): date = self.__empty_date place = self.__empty_place - spouse_name = _nd.display(spouse) - + if not name_display: + spouse_name = _nd.display(spouse) + else: + spouse_name = name_display.display(spouse) + if event: if self.__use_fulldate : mdate = self.__get_date(event.get_date_object()) diff --git a/src/plugins/textreport/AncestorReport.py b/src/plugins/textreport/AncestorReport.py index 020507f9f..15d961d02 100644 --- a/src/plugins/textreport/AncestorReport.py +++ b/src/plugins/textreport/AncestorReport.py @@ -30,6 +30,7 @@ # #------------------------------------------------------------------------ import math +import copy from gen.ggettext import gettext as _ #------------------------------------------------------------------------ @@ -37,7 +38,7 @@ from gen.ggettext import gettext as _ # gramps modules # #------------------------------------------------------------------------ -from gen.display.name import displayer as name_displayer +from gen.display.name import displayer as global_name_display from Errors import ReportError from gen.lib import ChildRefType from gen.plug.menu import (BooleanOption, NumberOption, PersonOption, @@ -87,9 +88,9 @@ class AncestorReport(Report): gen - Maximum number of generations to include. pagebbg - Whether to include page breaks between generations. + name_format - Preferred format to display names """ - Report.__init__(self, database, options_class) self.map = {} @@ -104,6 +105,14 @@ class AncestorReport(Report): raise ReportError(_("Person %s is not in the Database") % pid ) language = menu.get_option_by_name('trans').get_value() translator = Translator(language) + + # Copy the global NameDisplay so that we don't change application + # defaults. + self._name_display = copy.deepcopy(global_name_display) + name_format = menu.get_option_by_name("name_format").get_value() + if name_format != 0: + self._name_display.set_default_format(name_format) + self._ = translator.gettext self.__narrator = Narrator(self.database, use_fulldate=True, translator=translator) @@ -177,7 +186,7 @@ class AncestorReport(Report): # Write the title line. Set in INDEX marker so that this section will be # identified as a major category if this is included in a Book report. - name = name_displayer.display_formal(self.center_person) + name = self._name_display.display_formal(self.center_person) title = self._("Ahnentafel Report for %s") % name mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.start_paragraph("AHN-Title") @@ -208,7 +217,7 @@ class AncestorReport(Report): self.doc.start_paragraph("AHN-Entry","%d." % key) person = self.database.get_person_from_handle(self.map[key]) - name = name_displayer.display(person) + name = self._name_display.display(person) mark = ReportUtils.get_person_mark(self.database, person) # write the name in bold @@ -234,7 +243,7 @@ class AncestorReport(Report): self.doc.write_text(self.__narrator.get_buried_string()) self.doc.end_paragraph() - + #------------------------------------------------------------------------ # # AncestorOptions @@ -258,6 +267,16 @@ class AncestorOptions(MenuReportOptions): pid = PersonOption(_("Center Person")) pid.set_help(_("The center person for the report")) menu.add_option(category_name, "pid", pid) + + # We must figure out the value of the first option before we can + # create the EnumeratedListOption + fmt_list = global_name_display.get_name_format() + name_format = EnumeratedListOption(_("Name format"), 0) + name_format.add_item(0, _("Default")) + for num, name, fmt_str, act in fmt_list: + name_format.add_item(num, name) + name_format.set_help(_("Select the format to display names")) + menu.add_option(category_name, "name_format", name_format) maxgen = NumberOption(_("Generations"), 10, 1, 100) maxgen.set_help(_("The number of generations to include in the report")) diff --git a/src/plugins/textreport/BirthdayReport.py b/src/plugins/textreport/BirthdayReport.py index e5fb88317..afbe77399 100644 --- a/src/plugins/textreport/BirthdayReport.py +++ b/src/plugins/textreport/BirthdayReport.py @@ -27,6 +27,7 @@ # python modules # #------------------------------------------------------------------------ +import copy from gen.ggettext import gettext as _ from gen.ggettext import ngettext import datetime, time @@ -36,7 +37,7 @@ import datetime, time # GRAMPS modules # #------------------------------------------------------------------------ -from gen.display.name import displayer as _nd +from gen.display.name import displayer as global_name_display from Errors import ReportError from gen.lib import NameType, EventType, Name, Date, Person import Relationship @@ -72,7 +73,6 @@ class CalendarReport(Report): self.titletext = mgobn('titletext') self.relationships = mgobn('relationships') self.year = mgobn('year') - self.name_format = mgobn('name_format') self.country = mgobn('country') self.anniversaries = mgobn('anniversaries') self.start_dow = mgobn('start_dow') @@ -85,6 +85,14 @@ class CalendarReport(Report): self.filter_option = menu.get_option_by_name('filter') self.filter = self.filter_option.get_filter() pid = mgobn('pid') + + # Copy the global NameDisplay so that we don't change application + # defaults. + self._name_display = copy.deepcopy(global_name_display) + name_format = menu.get_option_by_name("name_format").get_value() + if name_format != 0: + self._name_display.set_default_format(name_format) + self.center_person = database.get_person_from_gramps_id(pid) if (self.center_person == None) : raise ReportError(_("Person %s is not in the Database") % pid ) @@ -112,8 +120,7 @@ class CalendarReport(Report): surname_obj.set_surname(maiden_name) else: name = Name(primary_name) - name.set_display_as(self.name_format) - return _nd.display_name(name) + return self._name_display.display_name(name) def add_day_item(self, text, month, day): """ Add an item to a day. """ @@ -359,10 +366,9 @@ class CalendarOptions(MenuReportOptions): self.__update_filters() - # We must figure out the value of the first option before we can - # create the EnumeratedListOption - fmt_list = _nd.get_name_format() - name_format = EnumeratedListOption(_("Name format"), fmt_list[0][0]) + fmt_list = global_name_display.get_name_format() + name_format = EnumeratedListOption(_("Name format"), 0) + name_format.add_item(0, _("Default")) for num, name, fmt_str, act in fmt_list: name_format.add_item(num, name) name_format.set_help(_("Select the format to display names")) diff --git a/src/plugins/textreport/DescendReport.py b/src/plugins/textreport/DescendReport.py index 7fd7b1d44..b86806d51 100644 --- a/src/plugins/textreport/DescendReport.py +++ b/src/plugins/textreport/DescendReport.py @@ -33,6 +33,7 @@ Reports/Text Reports/Descendant Report. # standard python modules # #------------------------------------------------------------------------ +import copy from gen.ggettext import gettext as _ #------------------------------------------------------------------------ @@ -42,8 +43,9 @@ from gen.ggettext import gettext as _ #------------------------------------------------------------------------ from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) -from gen.plug.menu import NumberOption, PersonOption, BooleanOption, EnumeratedListOption -from gen.display.name import displayer as _nd +from gen.plug.menu import (NumberOption, PersonOption, BooleanOption, + EnumeratedListOption) +from gen.display.name import displayer as global_name_display from Errors import ReportError from gen.plug.report import Report from gen.plug.report import utils as ReportUtils @@ -125,8 +127,10 @@ class Printinfo(): A base class used to help make the individual numbering system classes. This class must first be initialized with set_class_vars """ - def __init__(self, doc, database, numbering, showmarriage, showdivorce): + def __init__(self, doc, database, numbering, showmarriage, showdivorce,\ + name_display): #classes + self._name_display = name_display self.doc = doc self.database = database self.numbering = numbering @@ -184,7 +188,7 @@ class Printinfo(): display_num = self.numbering.number(level) self.doc.start_paragraph("DR-Level%d" % min(level, 32), display_num) mark = ReportUtils.get_person_mark(self.database, person) - self.doc.write_text(_nd.display(person), mark) + self.doc.write_text(self._name_display.display(person), mark) self.dump_string(person) self.doc.end_paragraph() @@ -194,7 +198,7 @@ class Printinfo(): spouse = self.database.get_person_from_handle(spouse_handle) mark = ReportUtils.get_person_mark(self.database, spouse) self.doc.start_paragraph("DR-Spouse%d" % min(level, 32)) - name = _nd.display(spouse) + name = self._name_display.display(spouse) self.doc.write_text(_("sp. %(spouse)s") % {'spouse':name}, mark) self.dump_string(spouse, family_handle) self.doc.end_paragraph() @@ -260,6 +264,7 @@ class DescendantReport(Report): that come in the options class. gen - Maximum number of generations to include. + name_format - Preferred format to display names """ Report.__init__(self, database, options_class) @@ -288,11 +293,18 @@ class DescendantReport(Report): marrs = menu.get_option_by_name('marrs').get_value() divs = menu.get_option_by_name('divs').get_value() - self.objPrint = Printinfo(self.doc, database, obj, marrs, divs) + # Copy the global NameDisplay so that we don't change application defaults. + self._name_display = copy.deepcopy(global_name_display) + name_format = menu.get_option_by_name("name_format").get_value() + if name_format != 0: + self._name_display.set_default_format(name_format) + + self.objPrint = Printinfo(self.doc, database, obj, marrs, divs, + self._name_display) def write_report(self): self.doc.start_paragraph("DR-Title") - name = _nd.display(self.center_person) + name = self._name_display.display(self.center_person) title = _("Descendants of %s") % name mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) @@ -322,6 +334,16 @@ class DescendantOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) menu.add_option(category_name, "pid", pid) + # We must figure out the value of the first option before we can + # create the EnumeratedListOption + fmt_list = global_name_display.get_name_format() + name_format = EnumeratedListOption(_("Name format"), 0) + name_format.add_item(0, _("Default")) + for num, name, fmt_str, act in fmt_list: + name_format.add_item(num, name) + name_format.set_help(_("Select the format to display names")) + menu.add_option(category_name, "name_format", name_format) + numbering = EnumeratedListOption(_("Numbering system"), "Simple") numbering.set_items([ ("Simple", _("Simple numbering")), diff --git a/src/plugins/textreport/DetAncestralReport.py b/src/plugins/textreport/DetAncestralReport.py index 4643f3092..5bf3d9a5d 100644 --- a/src/plugins/textreport/DetAncestralReport.py +++ b/src/plugins/textreport/DetAncestralReport.py @@ -33,6 +33,7 @@ # standard python modules # #------------------------------------------------------------------------ +import copy from gen.ggettext import gettext as _ #------------------------------------------------------------------------ @@ -40,7 +41,7 @@ from gen.ggettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------ -from gen.display.name import displayer as _nd +from gen.display.name import displayer as global_name_display from Errors import ReportError from gen.lib import EventType, FamilyRelType, Person, NoteType from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, @@ -101,6 +102,7 @@ class DetAncestorReport(Report): childref - Whether to add descendant references in child list. addimages - Whether to include images. pid - The Gramps ID of the center person for the report. + name_format - Preferred format to display names """ Report.__init__(self, database, options_class) @@ -136,6 +138,13 @@ class DetAncestorReport(Report): if (self.center_person == None) : raise ReportError(_("Person %s is not in the Database") % pid ) + # Copy the global NameDisplay so that we don't change application + # defaults. + self._name_display = copy.deepcopy(global_name_display) + name_format = menu.get_option_by_name("name_format").get_value() + if name_format != 0: + self._name_display.set_default_format(name_format) + self.gen_handles = {} self.prev_gen_handles = {} @@ -179,7 +188,7 @@ class DetAncestorReport(Report): def write_report(self): self.apply_filter(self.center_person.get_handle(), 1) - name = _nd.display_name(self.center_person.get_primary_name()) + name = self._name_display.display_name(self.center_person.get_primary_name()) self.doc.start_paragraph("DAR-Title") title = self._("Ancestral Report for %s") % name mark = IndexMark(title, INDEX_TYPE_TOC, 1) @@ -242,7 +251,7 @@ class DetAncestorReport(Report): self.doc.start_paragraph("DAR-First-Entry","%s." % str(key)) - name = _nd.display_formal(person) + name = self._name_display.display_formal(person) mark = ReportUtils.get_person_mark(self.database, person) self.doc.start_bold() @@ -341,7 +350,7 @@ class DetAncestorReport(Report): if first: self.doc.start_paragraph('DAR-MoreHeader') self.doc.write_text(self._('More about %(person_name)s:') % { - 'person_name' : _nd.display(person) }) + 'person_name' : self._name_display.display(person) }) self.doc.end_paragraph() first = 0 @@ -471,14 +480,16 @@ class DetAncestorReport(Report): father_handle = family.get_father_handle() if mother_handle: mother = self.database.get_person_from_handle(mother_handle) - mother_name = _nd.display_name(mother.get_primary_name()) + mother_name = \ + self._name_display.display_name(mother.get_primary_name()) mother_mark = ReportUtils.get_person_mark(self.database, mother) else: mother_name = "" mother_mark = "" if father_handle: father = self.database.get_person_from_handle(father_handle) - father_name = _nd.display_name(father.get_primary_name()) + father_name = \ + self._name_display.display_name(father.get_primary_name()) father_mark = ReportUtils.get_person_mark(self.database, father) else: father_name = "" @@ -501,10 +512,14 @@ class DetAncestorReport(Report): family = self.database.get_family_from_handle(family_handle) spouse_handle = ReportUtils.find_spouse(person,family) spouse = self.database.get_person_from_handle(spouse_handle) + if spouse: + name = self._name_display.display_formal(spouse) + else: + name = "" text = "" spouse_mark = ReportUtils.get_person_mark(self.database, spouse) - text = self.__narrator.get_married_string(family, is_first) + text = self.__narrator.get_married_string(family, is_first, self._name_display) if text: self.doc.write_text_citation(text, spouse_mark) @@ -520,14 +535,14 @@ class DetAncestorReport(Report): mother_handle = family.get_mother_handle() if mother_handle: mother = self.database.get_person_from_handle(mother_handle) - mother_name = _nd.display(mother) + mother_name = self._name_display.display(mother) else: mother_name = self._("unknown") father_handle = family.get_father_handle() if father_handle: father = self.database.get_person_from_handle(father_handle) - father_name = _nd.display(father) + father_name = self._name_display.display(father) else: father_name = self._("unknown") @@ -542,7 +557,7 @@ class DetAncestorReport(Report): for child_ref in family.get_child_ref_list(): child_handle = child_ref.ref child = self.database.get_person_from_handle(child_handle) - child_name = _nd.display(child) + child_name = self._name_display.display(child) child_mark = ReportUtils.get_person_mark(self.database, child) if self.childref and self.prev_gen_handles.get(child_handle): @@ -570,14 +585,14 @@ class DetAncestorReport(Report): mother_handle = family.get_mother_handle() if mother_handle: mother = self.database.get_person_from_handle(mother_handle) - mother_name = _nd.display(mother) + mother_name = self._name_display.display(mother) else: mother_name = self._("unknown") father_handle = family.get_father_handle() if father_handle: father = self.database.get_person_from_handle(father_handle) - father_name = _nd.display(father) + father_name = self._name_display.display(father) else: father_name = self._("unknown") @@ -634,7 +649,7 @@ class DetAncestorReport(Report): photo = plist[0] ReportUtils.insert_image(self.database, self.doc, photo) - name = _nd.display_formal(ind) + name = self._name_display.display_formal(ind) mark = ReportUtils.get_person_mark(self.database, ind) if family.get_relationship() == FamilyRelType.MARRIED: @@ -707,6 +722,16 @@ class DetAncestorOptions(MenuReportOptions): pid = PersonOption(_("Center Person")) pid.set_help(_("The center person for the report")) addopt("pid", pid) + + # We must figure out the value of the first option before we can + # create the EnumeratedListOption + fmt_list = global_name_display.get_name_format() + name_format = EnumeratedListOption(_("Name format"), 0) + name_format.add_item(0, _("Default")) + for num, name, fmt_str, act in fmt_list: + name_format.add_item(num, name) + name_format.set_help(_("Select the format to display names")) + addopt("name_format", name_format) gen = NumberOption(_("Generations"),10,1,100) gen.set_help(_("The number of generations to include in the report")) diff --git a/src/plugins/textreport/DetDescendantReport.py b/src/plugins/textreport/DetDescendantReport.py index 823548342..4b13b1ac9 100644 --- a/src/plugins/textreport/DetDescendantReport.py +++ b/src/plugins/textreport/DetDescendantReport.py @@ -34,6 +34,7 @@ # standard python modules # #------------------------------------------------------------------------ +import copy from gen.ggettext import gettext as _ from functools import partial @@ -42,7 +43,7 @@ from functools import partial # GRAMPS modules # #------------------------------------------------------------------------ -from gen.display.name import displayer as _nd +from gen.display.name import displayer as global_name_display from Errors import ReportError from gen.lib import FamilyRelType, Person, NoteType from gen.plug.menu import (BooleanOption, NumberOption, PersonOption, @@ -113,6 +114,7 @@ class DetDescendantReport(Report): incpaths - Whether to include the path of descendancy from the start-person to each descendant. incssign - Whether to include a sign ('+') before the descendant number in the child-list to indicate a child has succession. pid - The Gramps ID of the center person for the report. + name_format - Preferred format to display names """ Report.__init__(self, database, options_class) @@ -170,6 +172,13 @@ class DetDescendantReport(Report): translator = Translator(language) self._ = translator.gettext + # Copy the global NameDisplay so that we don't change application + # defaults. + self._name_display = copy.deepcopy(global_name_display) + name_format = menu.get_option_by_name("name_format").get_value() + if name_format != 0: + self._name_display.set_default_format(name_format) + self.__narrator = Narrator(self.database, self.verbose, use_call, use_fulldate, empty_date, empty_place, @@ -266,7 +275,7 @@ class DetDescendantReport(Report): else: raise AttributeError("no such numbering: '%s'" % self.numbering) - name = _nd.display_name(self.center_person.get_primary_name()) + name = self._name_display.display_name(self.center_person.get_primary_name()) self.doc.start_paragraph("DDR-Title") @@ -313,11 +322,13 @@ class DetDescendantReport(Report): father_handle = family.get_father_handle() if mother_handle and mother_handle in self.dnumber: person = self.database.get_person_from_handle(mother_handle) - person_name = _nd.display_name(person.get_primary_name()) + person_name = \ + self._name_display.display_name(person.get_primary_name()) path.append(person_name) elif father_handle and father_handle in self.dnumber: person = self.database.get_person_from_handle(father_handle) - person_name = _nd.display_name(person.get_primary_name()) + person_name = \ + self._name_display.display_name(person.get_primary_name()) path.append(person_name) else: break @@ -345,7 +356,7 @@ class DetDescendantReport(Report): val = self.dnumber[person_handle] self.doc.start_paragraph("DDR-First-Entry","%s." % val) - name = _nd.display_formal(person) + name = self._name_display.display_formal(person) mark = ReportUtils.get_person_mark(self.database, person) self.doc.start_bold() @@ -471,14 +482,16 @@ class DetDescendantReport(Report): father_handle = family.get_father_handle() if mother_handle: mother = self.database.get_person_from_handle(mother_handle) - mother_name = _nd.display_name(mother.get_primary_name()) + mother_name = \ + self._name_display.display_name(mother.get_primary_name()) mother_mark = ReportUtils.get_person_mark(self.database, mother) else: mother_name = "" mother_mark = "" if father_handle: father = self.database.get_person_from_handle(father_handle) - father_name = _nd.display_name(father.get_primary_name()) + father_name = \ + self._name_display.display_name(father.get_primary_name()) father_mark = ReportUtils.get_person_mark(self.database, father) else: father_name = "" @@ -500,10 +513,14 @@ class DetDescendantReport(Report): family = self.database.get_family_from_handle(family_handle) spouse_handle = ReportUtils.find_spouse(person, family) spouse = self.database.get_person_from_handle(spouse_handle) + if spouse: + name = self._name_display.display_formal(spouse) + else: + name = "" text = "" spouse_mark = ReportUtils.get_person_mark(self.database, spouse) - text = self.__narrator.get_married_string(family, is_first) + text = self.__narrator.get_married_string(family, is_first, self._name_display) if text: self.doc.write_text_citation(text, spouse_mark) @@ -522,7 +539,7 @@ class DetDescendantReport(Report): mate = self.database.get_person_from_handle(mate_handle) self.doc.start_paragraph("DDR-MoreHeader") - name = _nd.display_formal(mate) + name = self._name_display.display_formal(mate) mark = ReportUtils.get_person_mark(self.database, mate) if family.get_relationship() == FamilyRelType.MARRIED: self.doc.write_text(self._("Spouse: %s") % name, mark) @@ -539,14 +556,14 @@ class DetDescendantReport(Report): mother_handle = family.get_mother_handle() if mother_handle: mother = self.database.get_person_from_handle(mother_handle) - mother_name = _nd.display(mother) + mother_name = self._name_display.display(mother) else: mother_name = self._("unknown") father_handle = family.get_father_handle() if father_handle: father = self.database.get_person_from_handle(father_handle) - father_name = _nd.display(father) + father_name = self._name_display.display(father) else: father_name = self._("unknown") @@ -573,7 +590,7 @@ class DetDescendantReport(Report): for child_ref in family.get_child_ref_list(): child_handle = child_ref.ref child = self.database.get_person_from_handle(child_handle) - child_name = _nd.display(child) + child_name = self._name_display.display(child) child_mark = ReportUtils.get_person_mark(self.database, child) if self.childref and self.prev_gen_handles.get(child_handle): @@ -689,7 +706,7 @@ class DetDescendantReport(Report): def write_person_info(self, person): - name = _nd.display_formal(person) + name = self._name_display.display_formal(person) self.__narrator.set_subject(person) plist = person.get_media_list() @@ -762,7 +779,7 @@ class DetDescendantReport(Report): if first: self.doc.start_paragraph('DDR-MoreHeader') self.doc.write_text(self._('More about %(person_name)s:') % { - 'person_name' : _nd.display(person) }) + 'person_name' : self._name_display.display(person) }) self.doc.end_paragraph() first = 0 @@ -847,6 +864,16 @@ class DetDescendantOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) add_option("pid", pid) + # We must figure out the value of the first option before we can + # create the EnumeratedListOption + fmt_list = global_name_display.get_name_format() + name_format = EnumeratedListOption(_("Name format"), 0) + name_format.add_item(0, _("Default")) + for num, name, fmt_str, act in fmt_list: + name_format.add_item(num, name) + name_format.set_help(_("Select the format to display names")) + add_option("name_format", name_format) + numbering = EnumeratedListOption(_("Numbering system"), "Henry") numbering.set_items([ ("Henry", _("Henry numbering")), diff --git a/src/plugins/textreport/EndOfLineReport.py b/src/plugins/textreport/EndOfLineReport.py index d7956f627..b9d5e5663 100644 --- a/src/plugins/textreport/EndOfLineReport.py +++ b/src/plugins/textreport/EndOfLineReport.py @@ -28,6 +28,7 @@ # python modules # #------------------------------------------------------------------------ +import copy from gen.ggettext import gettext as _ #------------------------------------------------------------------------ @@ -35,12 +36,12 @@ from gen.ggettext import gettext as _ # gramps modules # #------------------------------------------------------------------------ -from gen.display.name import displayer as name_displayer +from gen.display.name import displayer as global_name_display from Errors import ReportError from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, TableStyle, TableCellStyle, FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) -from gen.plug.menu import PersonOption +from gen.plug.menu import (PersonOption, EnumeratedListOption) from gen.plug.report import Report from gen.plug.report import utils as ReportUtils from gen.plug.report import MenuReportOptions @@ -65,6 +66,7 @@ class EndOfLineReport(Report): This report needs the following parameters (class variables) that come in the options class. + name_format - Preferred format to display names """ Report.__init__(self, database, options_class) @@ -74,6 +76,13 @@ class EndOfLineReport(Report): if (self.center_person == None) : raise ReportError(_("Person %s is not in the Database") % pid ) + # Copy the global NameDisplay so that we don't change application + # defaults. + self._name_display = copy.deepcopy(global_name_display) + name_format = menu.get_option_by_name("name_format").get_value() + if name_format != 0: + self._name_display.set_default_format(name_format) + # eol_map is a map whose: # keys are the generations of the people # values are a map whose: @@ -134,7 +143,7 @@ class EndOfLineReport(Report): The routine the actually creates the report. At this point, the document is opened and ready for writing. """ - pname = name_displayer.display(self.center_person) + pname = self._name_display.display(self.center_person) self.doc.start_paragraph("EOL-Title") title = _("End of Line Report for %s") % pname @@ -173,7 +182,7 @@ class EndOfLineReport(Report): """ person = self.database.get_person_from_handle(person_handle) - name = name_displayer.display(person) + name = self._name_display.display(person) mark = ReportUtils.get_person_mark(self.database, person) birth_date = "" birth_ref = person.get_birth_ref() @@ -208,7 +217,7 @@ class EndOfLineReport(Report): names = [] for person_handle in pedigree: person = self.database.get_person_from_handle(person_handle) - names.append(name_displayer.display(person)) + names.append(self._name_display.display(person)) text = " -- ".join(names) self.doc.start_row() self.doc.start_cell('EOL-TableCell') @@ -243,6 +252,17 @@ class EndOfLineOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) menu.add_option(category_name, "pid", pid) + # We must figure out the value of the first option before we can + # create the EnumeratedListOption + fmt_list = global_name_display.get_name_format() + name_format = EnumeratedListOption(_("Name format"), 0) + name_format.add_item(0, _("Default")) + for num, name, fmt_str, act in fmt_list: + name_format.add_item(num, name) + name_format.set_help(_("Select the format to display names")) + menu.add_option(category_name, "name_format", name_format) + + def make_default_style(self, default_style): """Make the default output style for the End of Line Report.""" # Paragraph Styles diff --git a/src/plugins/textreport/FamilyGroup.py b/src/plugins/textreport/FamilyGroup.py index a6126375a..b742ae04c 100644 --- a/src/plugins/textreport/FamilyGroup.py +++ b/src/plugins/textreport/FamilyGroup.py @@ -29,6 +29,7 @@ # Python Library # #------------------------------------------------------------------------ +import copy from functools import partial #------------------------------------------------------------------------ @@ -37,7 +38,7 @@ from functools import partial # #------------------------------------------------------------------------ import gen.lib -from gen.plug.menu import BooleanOption, FamilyOption +from gen.plug.menu import (BooleanOption, FamilyOption, EnumeratedListOption) from gen.plug.report import Report from gen.plug.report import utils as ReportUtils from gen.plug.report import MenuReportOptions @@ -46,7 +47,7 @@ from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, TableStyle, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) import DateHandler from gen.ggettext import sgettext as _ -from gen.display.name import displayer as _nd +from gen.display.name import displayer as global_name_display #------------------------------------------------------------------------ # @@ -70,6 +71,7 @@ class FamilyGroup(Report): family_handle - Handle of the family to write report on. includeAttrs - Whether to include attributes + name_format - Preferred format to display names """ Report.__init__(self, database, options_class) menu = options_class.menu @@ -83,6 +85,13 @@ class FamilyGroup(Report): else: self.family_handle = None + # Copy the global NameDisplay so that we don't change application + # defaults. + self._name_display = copy.deepcopy(global_name_display) + name_format = menu.get_option_by_name("name_format").get_value() + if name_format != 0: + self._name_display.set_default_format(name_format) + get_option_by_name = menu.get_option_by_name get_value = lambda name:get_option_by_name(name).get_value() self.recursive = get_value('recursive') @@ -160,7 +169,7 @@ class FamilyGroup(Report): father_handle = family.get_father_handle() if father_handle: father = self.database.get_person_from_handle(father_handle) - father_name = _nd.display(father) + father_name = self._name_display.display(father) if self.incRelDates: birth_ref = father.get_birth_ref() birth = " " @@ -177,7 +186,7 @@ class FamilyGroup(Report): mother_handle = family.get_mother_handle() if mother_handle: mother = self.database.get_person_from_handle(mother_handle) - mother_name = _nd.display(mother) + mother_name = self._name_display.display(mother) if self.incRelDates: birth_ref = mother.get_birth_ref() birth = " " @@ -264,7 +273,7 @@ class FamilyGroup(Report): person = gen.lib.Person() else: person = self.database.get_person_from_handle(person_handle) - name = _nd.display(person) + name = self._name_display.display(person) self.doc.start_table(title,'FGR-ParentTable') self.doc.start_row() @@ -339,7 +348,7 @@ class FamilyGroup(Report): if self.incParNames: for alt_name in person.get_alternate_names(): name_type = str( alt_name.get_type() ) - name = _nd.display_name(alt_name) + name = self._name_display.display_name(alt_name) self.dump_parent_line(name_type, name) self.doc.end_table() @@ -454,7 +463,7 @@ class FamilyGroup(Report): self.doc.end_paragraph() self.doc.end_cell() - name = _nd.display(person) + name = self._name_display.display(person) mark = ReportUtils.get_person_mark(self.database,person) self.doc.start_cell('FGR-ChildName',3) self.doc.start_paragraph('FGR-ChildText') @@ -514,7 +523,7 @@ class FamilyGroup(Report): self.doc.start_paragraph('FGR-Normal') spouse = self.database.get_person_from_handle(spouse_id) - spouse_name = _nd.display(spouse) + spouse_name = self._name_display.display(spouse) if self.incRelDates: birth = " " birth_ref = spouse.get_birth_ref() @@ -621,6 +630,17 @@ class FamilyGroupOptions(MenuReportOptions): family_id = FamilyOption(_("Center Family")) family_id.set_help(_("The center family for the report")) add_option("family_id", family_id) + + # We must figure out the value of the first option before we can + # create the EnumeratedListOption + fmt_list = global_name_display.get_name_format() + name_format = EnumeratedListOption(_("Name format"), 0) + name_format.add_item(0, _("Default")) + for num, name, fmt_str, act in fmt_list: + name_format.add_item(num, name) + name_format.set_help(_("Select the format to display names")) + add_option("name_format", name_format) + recursive = BooleanOption(_('Recursive'),False) recursive.set_help(_("Create reports for all descendants " diff --git a/src/plugins/textreport/IndivComplete.py b/src/plugins/textreport/IndivComplete.py index baa2e2002..798392c29 100644 --- a/src/plugins/textreport/IndivComplete.py +++ b/src/plugins/textreport/IndivComplete.py @@ -30,6 +30,7 @@ # #------------------------------------------------------------------------ import os +import copy from gen.ggettext import gettext as _ from collections import defaultdict @@ -44,13 +45,13 @@ from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, TableStyle, PARA_ALIGN_CENTER) import DateHandler from gen.plug.menu import (BooleanOption, FilterOption, PersonOption, - BooleanListOption) + BooleanListOption, EnumeratedListOption) from gen.plug.report import Report from gen.plug.report import utils as ReportUtils from gen.plug.report import MenuReportOptions from gen.plug.report import Bibliography from gen.plug.report import endnotes as Endnotes -from gen.display.name import displayer as _nd +from gen.display.name import displayer as global_name_display from Utils import media_path_full from QuestionDialog import WarningDialog @@ -160,6 +161,7 @@ class IndivCompleteReport(Report): cites - Whether or not to include source information. sort - Whether ot not to sort events into chronological order. sections - Which event groups should be given separate sections. + name_format - Preferred format to display names """ Report.__init__(self, database, options_class) @@ -177,6 +179,13 @@ class IndivCompleteReport(Report): self.section_list = menu.get_option_by_name('sections').get_selected() + # Copy the global NameDisplay so that we don't change application + # defaults. + self._name_display = copy.deepcopy(global_name_display) + name_format = menu.get_option_by_name("name_format").get_value() + if name_format != 0: + self._name_display.set_default_format(name_format) + def write_fact(self, event_ref, event, event_group): """ Writes a single event. @@ -306,7 +315,7 @@ class IndivCompleteReport(Report): father_handle = family.get_father_handle() if father_handle: father = self.database.get_person_from_handle(father_handle) - fname = _nd.display(father) + fname = self._name_display.display(father) mark = ReportUtils.get_person_mark(self.database, father) self.write_p_entry(_('Father'), fname, frel, mark) else: @@ -315,7 +324,7 @@ class IndivCompleteReport(Report): mother_handle = family.get_mother_handle() if mother_handle: mother = self.database.get_person_from_handle(mother_handle) - mname = _nd.display(mother) + mname = self._name_display.display(mother) mark = ReportUtils.get_person_mark(self.database, mother) self.write_p_entry(_('Mother'), mname, mrel, mark) else: @@ -343,7 +352,7 @@ class IndivCompleteReport(Report): name_type = str( name.get_type() ) self.doc.start_row() self.normal_cell(name_type) - text = _nd.display_name(name) + text = self._name_display.display_name(name) endnotes = "" if self.use_srcs: endnotes = Endnotes.cite_source(self.bibli, name) @@ -408,7 +417,7 @@ class IndivCompleteReport(Report): self.doc.start_paragraph("IDS-Spouse") if spouse_id: spouse = self.database.get_person_from_handle(spouse_id) - text = _nd.display(spouse) + text = self._name_display.display(spouse) mark = ReportUtils.get_person_mark(self.database, spouse) else: text = _("unknown") @@ -432,7 +441,7 @@ class IndivCompleteReport(Report): for child_ref in child_ref_list: self.doc.start_paragraph("IDS-Normal") child = self.database.get_person_from_handle(child_ref.ref) - name = _nd.display(child) + name = self._name_display.display(child) mark = ReportUtils.get_person_mark(self.database, child) self.doc.write_text(name, mark) self.doc.end_paragraph() @@ -531,7 +540,7 @@ class IndivCompleteReport(Report): self.bibli = Bibliography(Bibliography.MODE_DATE|Bibliography.MODE_PAGE) media_list = self.person.get_media_list() - name = _nd.display(self.person) + name = self._name_display.display(self.person) title = _("Summary of %s") % name mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.start_paragraph("IDS-Title") @@ -560,7 +569,7 @@ class IndivCompleteReport(Report): self.doc.start_row() self.normal_cell("%s:" % _("Name")) name = self.person.get_primary_name() - text = _nd.display_name(name) + text = self._name_display.display_name(name) mark = ReportUtils.get_person_mark(self.database, self.person) endnotes = "" if self.use_srcs: @@ -585,7 +594,7 @@ class IndivCompleteReport(Report): if father_inst_id: father_inst = self.database.get_person_from_handle( father_inst_id) - father = _nd.display(father_inst) + father = self._name_display.display(father_inst) fmark = ReportUtils.get_person_mark(self.database, father_inst) else: father = "" @@ -594,7 +603,7 @@ class IndivCompleteReport(Report): if mother_inst_id: mother_inst = self.database.get_person_from_handle( mother_inst_id) - mother = _nd.display(mother_inst) + mother = self._name_display.display(mother_inst) mmark = ReportUtils.get_person_mark(self.database, mother_inst) else: mother = "" @@ -661,6 +670,17 @@ class IndivCompleteOptions(MenuReportOptions): self.__pid.set_help(_("The center person for the filter.")) menu.add_option(category_name, "pid", self.__pid) self.__pid.connect('value-changed', self.__update_filters) + + # We must figure out the value of the first option before we can + # create the EnumeratedListOption + fmt_list = global_name_display.get_name_format() + name_format = EnumeratedListOption(_("Name format"), 0) + name_format.add_item(0, _("Default")) + for num, name, fmt_str, act in fmt_list: + name_format.add_item(num, name) + name_format.set_help(_("Select the format to display names")) + menu.add_option(category_name, "name_format", name_format) + self.__update_filters() diff --git a/src/plugins/textreport/KinshipReport.py b/src/plugins/textreport/KinshipReport.py index 74ecbb192..c2812a59b 100644 --- a/src/plugins/textreport/KinshipReport.py +++ b/src/plugins/textreport/KinshipReport.py @@ -30,6 +30,7 @@ # python modules # #------------------------------------------------------------------------ +import copy from gen.ggettext import gettext as _ #------------------------------------------------------------------------ @@ -37,12 +38,13 @@ from gen.ggettext import gettext as _ # gramps modules # #------------------------------------------------------------------------ -from gen.display.name import displayer as name_displayer +from gen.display.name import displayer as global_name_display from Errors import ReportError import Relationship from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, FONT_SANS_SERIF, INDEX_TYPE_TOC, PARA_ALIGN_CENTER) -from gen.plug.menu import NumberOption, BooleanOption, PersonOption +from gen.plug.menu import (NumberOption, BooleanOption, PersonOption, + EnumeratedListOption) from gen.plug.report import Report from gen.plug.report import utils as ReportUtils from gen.plug.report import MenuReportOptions @@ -74,6 +76,7 @@ class KinshipReport(Report): inccousins - Whether to include cousins. incaunts - Whether to include aunts/uncles/nephews/nieces. pid - The Gramps ID of the center person for the report. + name_format - Preferred format to display names """ Report.__init__(self, database, options_class) @@ -88,6 +91,13 @@ class KinshipReport(Report): if (self.person == None) : raise ReportError(_("Person %s is not in the Database") % pid ) + # Copy the global NameDisplay so that we don't change application + # defaults. + self._name_display = copy.deepcopy(global_name_display) + name_format = menu.get_option_by_name("name_format").get_value() + if name_format != 0: + self._name_display.set_default_format(name_format) + self.__db = database self.rel_calc = Relationship.get_relationship_calculator() @@ -99,7 +109,7 @@ class KinshipReport(Report): The routine the actually creates the report. At this point, the document is opened and ready for writing. """ - pname = name_displayer.display(self.person) + pname = self._name_display.display(self.person) self.doc.start_paragraph("KIN-Title") title = _("Kinship Report for %s") % pname @@ -285,7 +295,7 @@ class KinshipReport(Report): """ person = self.database.get_person_from_handle(person_handle) - name = name_displayer.display(person) + name = self._name_display.display(person) mark = ReportUtils.get_person_mark(self.database, person) birth_date = "" birth = get_birth_or_fallback(self.database, person) @@ -328,7 +338,17 @@ class KinshipOptions(MenuReportOptions): pid = PersonOption(_("Center Person")) pid.set_help(_("The center person for the report")) menu.add_option(category_name, "pid", pid) - + + # We must figure out the value of the first option before we can + # create the EnumeratedListOption + fmt_list = global_name_display.get_name_format() + name_format = EnumeratedListOption(_("Name format"), 0) + name_format.add_item(0, _("Default")) + for num, name, fmt_str, act in fmt_list: + name_format.add_item(num, name) + name_format.set_help(_("Select the format to display names")) + menu.add_option(category_name, "name_format", name_format) + maxdescend = NumberOption(_("Max Descendant Generations"), 2, 1, 20) maxdescend.set_help(_("The maximum number of descendant generations")) menu.add_option(category_name, "maxdescend", maxdescend) diff --git a/src/plugins/textreport/NumberOfAncestorsReport.py b/src/plugins/textreport/NumberOfAncestorsReport.py index 2f1f1904b..4f7b71f34 100644 --- a/src/plugins/textreport/NumberOfAncestorsReport.py +++ b/src/plugins/textreport/NumberOfAncestorsReport.py @@ -31,6 +31,7 @@ # standard python modules # #------------------------------------------------------------------------ +import copy from gen.ggettext import gettext as _ from gen.ggettext import ngettext import locale @@ -41,9 +42,9 @@ import math # GRAMPS modules # #------------------------------------------------------------------------ -from gen.display.name import displayer as name_displayer +from gen.display.name import displayer as global_name_display from Errors import ReportError -from gen.plug.menu import PersonOption +from gen.plug.menu import PersonOption, EnumeratedListOption from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle, FONT_SANS_SERIF, PARA_ALIGN_CENTER, INDEX_TYPE_TOC) @@ -69,6 +70,7 @@ class NumberOfAncestorsReport(Report): database - the GRAMPS database instance person - currently selected person options_class - instance of the Options class for this report + name_format - Preferred format to display names """ Report.__init__(self, database, options_class) self.__db = database @@ -77,6 +79,13 @@ class NumberOfAncestorsReport(Report): if (self.__person == None) : raise ReportError(_("Person %s is not in the Database") % pid ) + # Copy the global NameDisplay so that we don't change application + # defaults. + self._name_display = copy.deepcopy(global_name_display) + name_format = menu.get_option_by_name("name_format").get_value() + if name_format != 0: + self._name_display.set_default_format(name_format) + def write_report(self): """ The routine the actually creates the report. At this point, the document @@ -88,7 +97,7 @@ class NumberOfAncestorsReport(Report): thisgen[self.__person.get_handle()]=1 self.doc.start_paragraph("NOA-Title") - name = name_displayer.display(self.__person) + name = self._name_display.display(self.__person) title = _("Number of Ancestors for %s") % name mark = IndexMark(title, INDEX_TYPE_TOC, 1) self.doc.write_text(title, mark) @@ -183,6 +192,16 @@ class NumberOfAncestorsOptions(MenuReportOptions): pid.set_help(_("The center person for the report")) menu.add_option(category_name, "pid", pid) + # We must figure out the value of the first option before we can + # create the EnumeratedListOption + fmt_list = global_name_display.get_name_format() + name_format = EnumeratedListOption(_("Name format"), 0) + name_format.add_item(0, _("Default")) + for num, name, fmt_str, act in fmt_list: + name_format.add_item(num, name) + name_format.set_help(_("Select the format to display names")) + menu.add_option(category_name, "name_format", name_format) + def make_default_style(self, default_style): """Make the default output style for the Number of Ancestors Report.""" font = FontStyle()