8021: Grafical reports don't use the correct name format

This commit is contained in:
Paul Franklin 2014-09-10 15:40:13 -07:00
parent 13ff503bed
commit 8e0fb6fd2c
4 changed files with 78 additions and 55 deletions

View File

@ -23,12 +23,12 @@
"""Reports/Graphical Reports/Ancestor Tree""" """Reports/Graphical Reports/Ancestor Tree"""
#------------------------------------------------------------------------
#
# Python modules
#
#------------------------------------------------------------------------
from __future__ import division from __future__ import division
#------------------------------------------------------------------------
#
# python modules
#
#------------------------------------------------------------------------
import math import math
def log2(val): def log2(val):
""" """
@ -51,7 +51,6 @@ from gramps.gen.plug.menu import (TextOption, NumberOption, BooleanOption,
PersonOption) PersonOption)
from gramps.gen.plug.report import Report, MenuReportOptions, stdoptions from gramps.gen.plug.report import Report, MenuReportOptions, stdoptions
from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import utils as ReportUtils
from gramps.gen.display.name import NameDisplay
from gramps.gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, from gramps.gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SANS_SERIF, PARA_ALIGN_CENTER) FONT_SANS_SERIF, PARA_ALIGN_CENTER)
from gramps.plugins.lib.libtreebase import * from gramps.plugins.lib.libtreebase import *
@ -135,8 +134,8 @@ class TitleN(TitleNoDisplay):
class TitleA(TitleBox): class TitleA(TitleBox):
"""Title class for the report """ """Title class for the report """
def __init__(self, doc, locale): def __init__(self, doc, locale, name_displayer):
self._locale = locale self._nd = name_displayer
TitleBox.__init__(self, doc, "AC2-Title") TitleBox.__init__(self, doc, "AC2-Title")
self._ = locale.translation.sgettext self._ = locale.translation.sgettext
@ -144,7 +143,7 @@ class TitleA(TitleBox):
"""Calculate the title of the report""" """Calculate the title of the report"""
name = "" name = ""
if center is not None: if center is not None:
name = NameDisplay(self._locale).display(center) name = self._nd.display(center)
# feature request 2356: avoid genitive form # feature request 2356: avoid genitive form
self.text = self._("Ancestor Graph for %s") % name self.text = self._("Ancestor Graph for %s") % name
@ -166,7 +165,7 @@ class CalcItems(object):
#str = "" #str = ""
#if self.get_val('miss_val'): #if self.get_val('miss_val'):
# str = "_____" # str = "_____"
self.__calc_l = CalcLines(dbase, [], __gui._locale) self.__calc_l = CalcLines(dbase, [], __gui._locale, __gui._nd)
self.__blank_father = None self.__blank_father = None
self.__blank_mother = None self.__blank_mother = None
@ -622,10 +621,11 @@ class GUIConnect():
def __init__(self): #We are BORG! def __init__(self): #We are BORG!
self.__dict__ = self.__shared_state self.__dict__ = self.__shared_state
def set__opts(self, options, locale): def set__opts(self, options, locale, name_displayer):
""" Set only once as we are BORG. """ """ Set only once as we are BORG. """
self.__opts = options self.__opts = options
self._locale = locale self._locale = locale
self._nd = name_displayer
def get_val(self, val): def get_val(self, val):
""" Get a GUI value. """ """ Get a GUI value. """
@ -640,7 +640,7 @@ class GUIConnect():
GUI options """ GUI options """
title_type = self.get_val('report_title') title_type = self.get_val('report_title')
if title_type: if title_type:
return TitleA(doc, self._locale) return TitleA(doc, self._locale, self._nd)
else: else:
return TitleN(doc, self._locale) return TitleN(doc, self._locale)
@ -670,6 +670,7 @@ class AncestorTree(Report):
lang = options.menu.get_option_by_name('trans').get_value() lang = options.menu.get_option_by_name('trans').get_value()
self._locale = self.set_locale(lang) self._locale = self.set_locale(lang)
self._nd = self._name_display
def begin_report(self): def begin_report(self):
""" """
@ -695,7 +696,7 @@ class AncestorTree(Report):
database = self.database database = self.database
self.connect = GUIConnect() self.connect = GUIConnect()
self.connect.set__opts(self.options.menu, self._locale) self.connect.set__opts(self.options.menu, self._locale, self._nd)
#Set up the canvas that we will print on. #Set up the canvas that we will print on.
style_sheet = self.doc.get_style_sheet() style_sheet = self.doc.get_style_sheet()
@ -746,7 +747,8 @@ class AncestorTree(Report):
if self.connect.get_val("inc_note"): if self.connect.get_val("inc_note"):
note_box = NoteBox(self.doc, "AC2-note-box", note_box = NoteBox(self.doc, "AC2-note-box",
self.connect.get_val("note_place")) self.connect.get_val("note_place"))
subst = SubstKeywords(self.database, self._locale, None, None) subst = SubstKeywords(self.database, self._locale, self._nd,
None, None)
note_box.text = subst.replace_and_clean( note_box.text = subst.replace_and_clean(
self.connect.get_val('note_disp')) self.connect.get_val('note_disp'))
self.canvas.add_note(note_box) self.canvas.add_note(note_box)

View File

@ -26,6 +26,12 @@
Reports/Graphical Reports/Familial Tree Reports/Graphical Reports/Familial Tree
Reports/Graphical Reports/Personal Tree Reports/Graphical Reports/Personal Tree
""" """
#------------------------------------------------------------------------
#
# Python modules
#
#------------------------------------------------------------------------
from __future__ import division from __future__ import division
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@ -129,8 +135,9 @@ class PlaceHolderBox(BoxBase):
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class DescendantTitleBase(TitleBox): class DescendantTitleBase(TitleBox):
def __init__(self, dbase, doc, locale, boxstr = "CG2-Title"): def __init__(self, dbase, doc, locale, name_displayer,
self._locale = locale boxstr = "CG2-Title"):
self._nd = name_displayer
TitleBox.__init__(self, doc, boxstr) TitleBox.__init__(self, doc, boxstr)
self.database = dbase self.database = dbase
self._ = locale.translation.sgettext self._ = locale.translation.sgettext
@ -146,10 +153,10 @@ class DescendantTitleBase(TitleBox):
person_list = person_list + person_list2 person_list = person_list + person_list2
person_list2 = [] person_list2 = []
names = self._get_names(person_list) names = self._get_names(person_list, self._nd)
if person_list2: if person_list2:
names2 = self._get_names(person_list2) names2 = self._get_names(person_list2, self._nd)
if len(names) + len(names2) == 3: if len(names) + len(names2) == 3:
if len(names) == 1: if len(names) == 1:
title = self._("Descendant Chart for %(person)s and " title = self._("Descendant Chart for %(person)s and "
@ -214,8 +221,8 @@ class TitleDPY(DescendantTitleBase):
"""Descendant (Person yes start with parents) Chart """Descendant (Person yes start with parents) Chart
Title class for the report """ Title class for the report """
def __init__(self, dbase, doc, locale): def __init__(self, dbase, doc, locale, name_displayer):
DescendantTitleBase.__init__(self, dbase, doc, locale) DescendantTitleBase.__init__(self, dbase, doc, locale, name_displayer)
def calc_title(self, person_id): def calc_title(self, person_id):
"""Calculate the title of the report""" """Calculate the title of the report"""
@ -241,8 +248,8 @@ class TitleDPN(DescendantTitleBase):
"""Descendant (Person no start with parents) Chart """Descendant (Person no start with parents) Chart
Title class for the report """ Title class for the report """
def __init__(self, dbase, doc, locale): def __init__(self, dbase, doc, locale, name_displayer):
DescendantTitleBase.__init__(self, dbase, doc, locale) DescendantTitleBase.__init__(self, dbase, doc, locale, name_displayer)
def calc_title(self, person_id): def calc_title(self, person_id):
"""Calculate the title of the report""" """Calculate the title of the report"""
@ -257,8 +264,8 @@ class TitleDFY(DescendantTitleBase):
"""Descendant (Family yes start with parents) Chart """Descendant (Family yes start with parents) Chart
Title class for the report """ Title class for the report """
def __init__(self, dbase, doc, locale): def __init__(self, dbase, doc, locale, name_displayer):
DescendantTitleBase.__init__(self, dbase, doc, locale) DescendantTitleBase.__init__(self, dbase, doc, locale, name_displayer)
def get_parent_list(self, person): def get_parent_list(self, person):
""" return a list of my parents. If none, return me """ """ return a list of my parents. If none, return me """
@ -297,8 +304,8 @@ class TitleDFN(DescendantTitleBase):
"""Descendant (Family no start with parents) Chart """Descendant (Family no start with parents) Chart
Title class for the report """ Title class for the report """
def __init__(self, dbase, doc, locale): def __init__(self, dbase, doc, locale, name_displayer):
DescendantTitleBase.__init__(self, dbase, doc, locale) DescendantTitleBase.__init__(self, dbase, doc, locale, name_displayer)
def calc_title(self, family_id): def calc_title(self, family_id):
"""Calculate the title of the report""" """Calculate the title of the report"""
@ -310,14 +317,14 @@ class TitleDFN(DescendantTitleBase):
class TitleF(DescendantTitleBase): class TitleF(DescendantTitleBase):
"""Family Chart Title class for the report """ """Family Chart Title class for the report """
def __init__(self, dbase, doc, locale): def __init__(self, dbase, doc, locale, name_displayer):
DescendantTitleBase.__init__(self, dbase, doc, locale) DescendantTitleBase.__init__(self, dbase, doc, locale, name_displayer)
def calc_title(self, family_id): def calc_title(self, family_id):
"""Calculate the title of the report""" """Calculate the title of the report"""
parents = self.get_parents(family_id) parents = self.get_parents(family_id)
names = self._get_names(parents) names = self._get_names(parents, self._nd)
if len(parents) == 1: if len(parents) == 1:
title = self._("Family Chart for %(person)s") % { title = self._("Family Chart for %(person)s") % {
@ -333,8 +340,8 @@ class TitleF(DescendantTitleBase):
class TitleC(DescendantTitleBase): class TitleC(DescendantTitleBase):
"""Cousin Chart Title class for the report """ """Cousin Chart Title class for the report """
def __init__(self, dbase, doc, locale): def __init__(self, dbase, doc, locale, name_displayer):
DescendantTitleBase.__init__(self, dbase, doc, locale) DescendantTitleBase.__init__(self, dbase, doc, locale, name_displayer)
def calc_title(self, family_id): def calc_title(self, family_id):
"""Calculate the title of the report""" """Calculate the title of the report"""
@ -346,7 +353,7 @@ class TitleC(DescendantTitleBase):
#ok we have the children. Make a title off of them #ok we have the children. Make a title off of them
# translators: needed for Arabic, ignore otherwise # translators: needed for Arabic, ignore otherwise
cousin_names = self._(', ').join(self._get_names(kids)) cousin_names = self._(', ').join(self._get_names(kids, self._nd))
self.text = self._("Cousin Chart for %(names)s") % { self.text = self._("Cousin Chart for %(names)s") % {
'names' : cousin_names} 'names' : cousin_names}
@ -1190,10 +1197,11 @@ class GuiConnect():
def __init__(self): #We are BORG! def __init__(self): #We are BORG!
self.__dict__ = self.__shared_state self.__dict__ = self.__shared_state
def set__opts(self, options, which, locale): def set__opts(self, options, which, locale, name_displayer):
self._opts = options self._opts = options
self._which_report = which.split(",")[0] self._which_report = which.split(",")[0]
self._locale = locale self._locale = locale
self._nd = name_displayer
def get_val(self, val): def get_val(self, val):
""" Get a GUI value. """ """ Get a GUI value. """
@ -1211,19 +1219,19 @@ class GuiConnect():
if Title_type == 1: #Descendant Chart if Title_type == 1: #Descendant Chart
if self._which_report == _RPT_NAME: if self._which_report == _RPT_NAME:
if self.get_val('show_parents'): if self.get_val('show_parents'):
return TitleDPY(database, doc, self._locale) return TitleDPY(database, doc, self._locale, self._nd)
else: else:
return TitleDPN(database, doc, self._locale) return TitleDPN(database, doc, self._locale, self._nd)
else: else:
if self.get_val('show_parents'): if self.get_val('show_parents'):
return TitleDFY(database, doc, self._locale) return TitleDFY(database, doc, self._locale, self._nd)
else: else:
return TitleDFN(database, doc, self._locale) return TitleDFN(database, doc, self._locale, self._nd)
if Title_type == 2: if Title_type == 2:
return TitleF(database, doc, self._locale) return TitleF(database, doc, self._locale, self._nd)
else: #Title_type == 3 else: #Title_type == 3
return TitleC(database, doc, self._locale) return TitleC(database, doc, self._locale, self._nd)
def Make_Tree(self, database, canvas): def Make_Tree(self, database, canvas):
if self._which_report == _RPT_NAME: if self._which_report == _RPT_NAME:
@ -1237,7 +1245,7 @@ class GuiConnect():
#str = "" #str = ""
#if self.get_val('miss_val'): #if self.get_val('miss_val'):
# str = "_____" # str = "_____"
return CalcLines(database, display_repl, self._locale) return CalcLines(database, display_repl, self._locale, self._nd)
def working_lines(self, box): def working_lines(self, box):
display = self.get_val("descend_disp") display = self.get_val("descend_disp")
@ -1282,6 +1290,7 @@ class DescendTree(Report):
lang = options.menu.get_option_by_name('trans').get_value() lang = options.menu.get_option_by_name('trans').get_value()
self._locale = self.set_locale(lang) self._locale = self.set_locale(lang)
self._nd = self._name_display
def begin_report(self): def begin_report(self):
""" make the report in its full size and pages to print on """ make the report in its full size and pages to print on
@ -1292,7 +1301,7 @@ class DescendTree(Report):
self.Connect = GuiConnect() self.Connect = GuiConnect()
self.Connect.set__opts(self.options.menu, self.options.name, self.Connect.set__opts(self.options.menu, self.options.name,
self._locale) self._locale, self._nd)
style_sheet = self.doc.get_style_sheet() style_sheet = self.doc.get_style_sheet()
font_normal = style_sheet.get_paragraph_style("CG2-Normal").get_font() font_normal = style_sheet.get_paragraph_style("CG2-Normal").get_font()
@ -1329,7 +1338,8 @@ class DescendTree(Report):
if self.Connect.get_val("inc_note"): if self.Connect.get_val("inc_note"):
note_box = NoteBox(self.doc, "CG2-note-box", note_box = NoteBox(self.doc, "CG2-note-box",
self.Connect.get_val("note_place")) self.Connect.get_val("note_place"))
subst = SubstKeywords(self.database, self._locale, None, None) subst = SubstKeywords(self.database, self._locale, self._nd,
None, None)
note_box.text = subst.replace_and_clean( note_box.text = subst.replace_and_clean(
self.Connect.get_val('note_disp')) self.Connect.get_val('note_disp'))
self.canvas.add_note(note_box) self.canvas.add_note(note_box)

View File

@ -33,6 +33,11 @@ Will return a value such as:
Mary Smith was born on 3/28/1923. Mary Smith was born on 3/28/1923.
""" """
#------------------------------------------------------------------------
#
# Python modules
#
#------------------------------------------------------------------------
from __future__ import print_function from __future__ import print_function
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@ -40,7 +45,6 @@ from __future__ import print_function
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gramps.gen.display.name import NameDisplay
from gramps.gen.lib import EventType, PlaceType, Location from gramps.gen.lib import EventType, PlaceType, Location
from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback
from gramps.gen.constfunc import STRTYPE, cuni from gramps.gen.constfunc import STRTYPE, cuni
@ -149,6 +153,10 @@ class NameFormat(GenericFormat):
otherwise, parse through a format string and put the name parts in otherwise, parse through a format string and put the name parts in
""" """
def __init__(self, _in, locale, name_displayer):
GenericFormat.__init__(self, _in, locale)
self._nd = name_displayer
def get_name(self, person, aka): def get_name(self, person, aka):
""" A helper method for retrieving the person's name """ """ A helper method for retrieving the person's name """
name = None name = None
@ -164,7 +172,7 @@ class NameFormat(GenericFormat):
def _default_format(self, name): def _default_format(self, name):
""" display the name as set in preferences """ """ display the name as set in preferences """
return NameDisplay(self._locale).sorted_name(name) return self._nd.sorted_name(name)
def parse_format(self, name): def parse_format(self, name):
""" Parse the name """ """ Parse the name """
@ -788,11 +796,12 @@ class AttributeParse(object):
class VariableParse(object): class VariableParse(object):
""" Parse the individual variables """ """ Parse the individual variables """
def __init__(self, friend, database, consumer_in, locale): def __init__(self, friend, database, consumer_in, locale, name_displayer):
self.friend = friend self.friend = friend
self.database = database self.database = database
self._in = consumer_in self._in = consumer_in
self._locale = locale self._locale = locale
self._nd = name_displayer
def is_a(self): def is_a(self):
""" check """ """ check """
@ -868,7 +877,7 @@ class VariableParse(object):
return place_f.parse_format(self.database, place) return place_f.parse_format(self.database, place)
def __parse_name(self, person, attrib_parse): def __parse_name(self, person, attrib_parse):
name_format = NameFormat(self._in, self._locale) name_format = NameFormat(self._in, self._locale, self._nd)
name = name_format.get_name(person, attrib_parse.get_name()) name = name_format.get_name(person, attrib_parse.get_name())
return name_format.parse_format(name) return name_format.parse_format(name)
@ -1044,7 +1053,8 @@ class SubstKeywords(object):
this will specify the specific family/spouse to work with. this will specify the specific family/spouse to work with.
If none given, then the first/preferred family/spouse is used If none given, then the first/preferred family/spouse is used
""" """
def __init__(self, database, locale, person_handle, family_handle=None): def __init__(self, database, locale, name_displayer,
person_handle, family_handle=None):
"""get the person and find the family/spouse to use for this display""" """get the person and find the family/spouse to use for this display"""
self.database = database self.database = database
@ -1053,6 +1063,7 @@ class SubstKeywords(object):
self.spouse = None self.spouse = None
self.line = None # Consumable_string - set below self.line = None # Consumable_string - set below
self._locale = locale self._locale = locale
self._nd = name_displayer
if self.person is None: if self.person is None:
return return
@ -1096,7 +1107,8 @@ class SubstKeywords(object):
#First we are going take care of all variables/groups #First we are going take care of all variables/groups
#break down all {} (groups) and $ (vars) into either #break down all {} (groups) and $ (vars) into either
#(TXT.text, resulting_string) or (TXT.remove, '') #(TXT.text, resulting_string) or (TXT.remove, '')
variable = VariableParse(self, self.database, self.line, self._locale) # $ variable = VariableParse(self, self.database, self.line,
self._locale, self._nd)
while self.line.this: while self.line.this:
if self.line.this == "{": if self.line.this == "{":

View File

@ -30,13 +30,12 @@ from __future__ import division
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# gramps modules # Gramps modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import utils as ReportUtils
from gramps.gen.display.name import NameDisplay
from gramps.plugins.lib.libsubstkeyword import SubstKeywords from gramps.plugins.lib.libsubstkeyword import SubstKeywords
from gramps.gen.plug.docgen import (IndexMark, INDEX_TYPE_TOC) from gramps.gen.plug.docgen import (IndexMark, INDEX_TYPE_TOC)
@ -54,11 +53,12 @@ class CalcLines(object):
Receive: Individual and family handle, and display format [string] Receive: Individual and family handle, and display format [string]
return: [Text] ready for a box. return: [Text] ready for a box.
""" """
def __init__(self, dbase, repl, locale): def __init__(self, dbase, repl, locale, name_displayer):
self.database = dbase self.database = dbase
self.display_repl = repl self.display_repl = repl
#self.default_string = default_str #self.default_string = default_str
self._locale = locale self._locale = locale
self._nd = name_displayer
def calc_lines(self, _indi_handle, _fams_handle, workinglines): def calc_lines(self, _indi_handle, _fams_handle, workinglines):
""" """
@ -69,7 +69,7 @@ class CalcLines(object):
#################### ####################
#1.1 Get our line information here #1.1 Get our line information here
subst = SubstKeywords(self.database, self._locale, subst = SubstKeywords(self.database, self._locale, self._nd,
_indi_handle, _fams_handle) _indi_handle, _fams_handle)
lines = subst.replace_and_clean(workinglines) lines = subst.replace_and_clean(workinglines)
@ -678,11 +678,10 @@ class TitleBox(BoxBase):
self.width = PT2CM(self.doc.string_width(self.font, self.text)) self.width = PT2CM(self.doc.string_width(self.font, self.text))
self.height = PT2CM(self.font.get_size() * 1.2) self.height = PT2CM(self.font.get_size() * 1.2)
def _get_names(self, persons): def _get_names(self, persons, name_displayer):
""" A helper function that receives a list of persons and """ A helper function that receives a list of persons and
returns their names in a list """ returns their names in a list """
return [NameDisplay(self._locale).display(person) return [name_displayer.display(person) for person in persons]
for person in persons]
def display(self): def display(self):
""" display the title box. """ """ display the title box. """