diff --git a/src/SubstKeywords.py b/src/SubstKeywords.py new file mode 100644 index 000000000..6bd63b4eb --- /dev/null +++ b/src/SubstKeywords.py @@ -0,0 +1,75 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000 Donald N. Allingham +# +# 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +#------------------------------------------------------------------------ +# +# python classes +# +#------------------------------------------------------------------------ +import string + +#------------------------------------------------------------------------ +# +# SubstKeywords +# +#------------------------------------------------------------------------ +class SubstKeywords: + def __init__(self,person): + self.n = person.getPrimaryName().getRegularName() + self.N = person.getPrimaryName().getName() + self.b = person.getBirth().getDate() + self.d = person.getDeath().getDate() + self.B = person.getBirth().getPlaceName() + self.D = person.getDeath().getPlaceName() + self.i = "%s" % person.getId() + + if len(person.getFamilyList()) > 0: + f = person.getFamilyList()[0] + if f.getFather() == person: + self.s = f.getMother().getPrimaryName().getRegularName() + self.S = f.getMother().getPrimaryName().getName() + else: + self.s = "" + self.S = "" + self.m = '' + self.M = '' + for e in f.getEventList(): + if e.getName == 'Marriage': + self.m = e.getDate() + self.M = e.getPlace() + else: + self.s = "" + self.S = "" + self.m = "" + self.M = "" + + def replace(self,line): + line = string.replace(line,"$n",self.n) + line = string.replace(line,"$N",self.N) + line = string.replace(line,"$b",self.b) + line = string.replace(line,"$B",self.B) + line = string.replace(line,"$d",self.d) + line = string.replace(line,"$D",self.D) + line = string.replace(line,"$i",self.i) + line = string.replace(line,"$S",self.S) + line = string.replace(line,"$s",self.s) + line = string.replace(line,"$m",self.m) + line = string.replace(line,"$M",self.M) + return string.replace(line,"$$",'$') diff --git a/src/Utils.py b/src/Utils.py index eae7240ad..0888b9064 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -552,3 +552,4 @@ def build_string_optmenu(mapping, start_val): if start_index: myMenu.set_active(start_index) return myMenu + diff --git a/src/plugins/AncestorChart.py b/src/plugins/AncestorChart.py index 823eb2c70..d2f9fb33b 100644 --- a/src/plugins/AncestorChart.py +++ b/src/plugins/AncestorChart.py @@ -27,6 +27,7 @@ import string from FontScale import string_width from DrawDoc import * from Report import * +from SubstKeywords import SubstKeywords import libglade import gtk @@ -73,56 +74,10 @@ class AncestorChart: self.text[index] = [] - n = person.getPrimaryName().getRegularName() - N = person.getPrimaryName().getName() - b = person.getBirth().getDate() - d = person.getDeath().getDate() - B = person.getBirth().getPlaceName() - D = person.getDeath().getPlaceName() - if len(person.getFamilyList()) > 0: - f = person.getFamilyList()[0] - if f.getFather() == person: - s = f.getMother().getPrimaryName().getRegularName() - S = f.getMother().getPrimaryName().getName() - else: - s = "" - S = "" - m = '' - M = '' - for e in f.getEventList(): - if e.getName == 'Marriage': - m = e.getDate() - M = e.getPlace() - else: - s = "" - S = "" - m = "" - M = "" - - i = "%s" % person.getId() - A = GrampsCfg.attr_name - a = "" - for attr in person.getAttributeList(): - if attr.getType() == GrampsCfg.attr_name: - a = attr.getValue() - break - + subst = SubstKeywords(person) + for line in self.display: - line = string.replace(line,"$n",n) - line = string.replace(line,"$N",N) - line = string.replace(line,"$b",b) - line = string.replace(line,"$B",B) - line = string.replace(line,"$d",d) - line = string.replace(line,"$D",D) - line = string.replace(line,"$i",i) - line = string.replace(line,"$a",a) - line = string.replace(line,"$A",A) - line = string.replace(line,"$S",S) - line = string.replace(line,"$s",s) - line = string.replace(line,"$m",m) - line = string.replace(line,"$M",M) - line = string.replace(line,"$$",'$') - self.text[index].append(line) + self.text[index].append(subst.replace(line)) self.font = self.doc.style_list["Normal"].get_font() for line in self.text[index]: diff --git a/src/plugins/DesGraph.py b/src/plugins/DesGraph.py index ea4894831..4449b0f90 100644 --- a/src/plugins/DesGraph.py +++ b/src/plugins/DesGraph.py @@ -45,6 +45,7 @@ from FontScale import string_width from DrawDoc import * from Report import * from TextDoc import * +from SubstKeywords import SubstKeywords import intl _ = intl.gettext @@ -86,25 +87,9 @@ class DescendantReport: for (p,x,y) in self.v: self.text[p] = [] - - n = p.getPrimaryName().getRegularName() - N = p.getPrimaryName().getName() - b = p.getBirth().getDate() - d = p.getDeath().getDate() - B = p.getBirth().getPlaceName() - D = p.getDeath().getPlaceName() - i = "%s" % p.getId() - + subst = SubstKeywords(p) for line in self.display: - line = string.replace(line,"$n",n) - line = string.replace(line,"$N",N) - line = string.replace(line,"$b",b) - line = string.replace(line,"$B",B) - line = string.replace(line,"$d",d) - line = string.replace(line,"$D",D) - line = string.replace(line,"$i",i) - line = string.replace(line,"$$",'$') - self.text[p].append(line) + self.text[p].append(subst.replace(line)) self.font = self.doc.style_list["Normal"].get_font() for line in self.text[p]: