* src/plugins/rel_it.py: Convert to class.
svn: r3063
This commit is contained in:
parent
1d2fca439f
commit
2c6cb2d1da
@ -1,3 +1,6 @@
|
|||||||
|
2004-03-27 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||||
|
* src/plugins/rel_it.py: Convert to class.
|
||||||
|
|
||||||
2004-01-26 Alex Roitman <shura@alex.neuro.umn.edu>
|
2004-01-26 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||||
* src/plugins/FtmStyleDescendants.py (_make_default_style,
|
* src/plugins/FtmStyleDescendants.py (_make_default_style,
|
||||||
print_children): Add new style for numbering children.
|
print_children): Add new style for numbering children.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
# Copyright (C) 2003 Donald N. Allingham
|
# Copyright (C) 2003-2004 Donald N. Allingham
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -19,6 +19,8 @@
|
|||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# $Id$
|
||||||
|
|
||||||
#
|
#
|
||||||
# Written by Lorenzo Cappelletti <lorenzo.cappelletti@email.it>, 2003
|
# Written by Lorenzo Cappelletti <lorenzo.cappelletti@email.it>, 2003
|
||||||
#
|
#
|
||||||
@ -30,9 +32,9 @@
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
import RelLib
|
import RelLib
|
||||||
|
import Relationship
|
||||||
from Relationship import apply_filter, is_spouse
|
import types
|
||||||
from Plugins import register_relcalc
|
from gettext import gettext as _
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -50,151 +52,145 @@ _level =\
|
|||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Specific relationship functions
|
|
||||||
#
|
#
|
||||||
# To be honest, I doubt that this relationship naming method is widely
|
|
||||||
# spread... If you know of a rigorous, italian naming convention,
|
|
||||||
# please, drop me an email.
|
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
class RelationshipCalculator(Relationship.RelationshipCalculator):
|
||||||
|
|
||||||
def get_parents (level):
|
def __init__(self,db):
|
||||||
|
Relationship.RelationshipCalculator.__init__(self,db)
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Specific relationship functions
|
||||||
|
#
|
||||||
|
# To be honest, I doubt that this relationship naming method is widely
|
||||||
|
# spread... If you know of a rigorous, italian naming convention,
|
||||||
|
# please, drop me an email.
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
def get_parents (self,level):
|
||||||
|
if level>len(_level)-1:
|
||||||
|
return _("remote ancestors")
|
||||||
|
else:
|
||||||
return "%si genitori" % _level[level]
|
return "%si genitori" % _level[level]
|
||||||
|
|
||||||
def get_father (level, gender="o"):
|
def get_father (self,level, gender="o"):
|
||||||
if level == 0: return ""
|
if level>len(_level)-1:
|
||||||
|
return _("remote ancestor")
|
||||||
|
elif level == 0: return ""
|
||||||
elif level == 1: return "padre"
|
elif level == 1: return "padre"
|
||||||
elif level == 2: return "nonn%s" % gender
|
elif level == 2: return "nonn%s" % gender
|
||||||
elif level == 3: return "bisnonn%s" % gender
|
elif level == 3: return "bisnonn%s" % gender
|
||||||
else : return "%s%s nonn%s" % (_level[level], gender, gender)
|
else : return "%s%s nonn%s" % (_level[level], gender, gender)
|
||||||
|
|
||||||
def get_mother (level):
|
def get_mother (self,level):
|
||||||
if level == 1: return "madre"
|
if level == 1: return "madre"
|
||||||
else : return get_father(level, "a")
|
else : return self.get_father(level, "a")
|
||||||
|
|
||||||
def get_son (level, gender="o"):
|
def get_son (self, level, gender="o"):
|
||||||
if level == 0: return ""
|
if level>len(_level)-1:
|
||||||
|
return _("remote descendant")
|
||||||
|
elif level == 0: return ""
|
||||||
elif level == 1: return "figli%s" % gender
|
elif level == 1: return "figli%s" % gender
|
||||||
elif level == 2: return "nipote"
|
elif level == 2: return "nipote"
|
||||||
elif level == 3: return "pronipote"
|
elif level == 3: return "pronipote"
|
||||||
else : return "%s%s nipote" % (_level[level], gender)
|
else : return "%s%s nipote" % (_level[level], gender)
|
||||||
|
|
||||||
def get_daughter (level):
|
def get_daughter (self, level):
|
||||||
return get_son(level, "a")
|
return self.get_son(level, "a")
|
||||||
|
|
||||||
def get_uncle (level, gender="o"):
|
def get_uncle (self, level, gender="o"):
|
||||||
if level == 0: return ""
|
if level>len(_level)-1:
|
||||||
|
return _("remote ancestor")
|
||||||
|
elif level == 0: return ""
|
||||||
elif level == 1: return "fratello"
|
elif level == 1: return "fratello"
|
||||||
elif level == 2: return "zi%s" % gender
|
elif level == 2: return "zi%s" % gender
|
||||||
elif level == 3: return "prozi%s" % gender
|
elif level == 3: return "prozi%s" % gender
|
||||||
else : return "%s%s zi%s" % (_level[level], gender, gender)
|
else : return "%s%s zi%s" % (_level[level], gender, gender)
|
||||||
|
|
||||||
def get_aunt (level):
|
def get_aunt (self,level):
|
||||||
if level == 1: return "sorella"
|
if level == 1: return "sorella"
|
||||||
else : return get_uncle(level, "a")
|
else : return self.get_uncle(level, "a")
|
||||||
|
|
||||||
def get_nephew (level, gender="o"):
|
def get_nephew (self,level, gender="o"):
|
||||||
if level == 0: return ""
|
if level>len(_level)-1:
|
||||||
|
return _("remote descendant")
|
||||||
|
elif level == 0: return ""
|
||||||
elif level == 1: return "nipote"
|
elif level == 1: return "nipote"
|
||||||
elif level == 2: return "pronipote"
|
elif level == 2: return "pronipote"
|
||||||
else : return "%s%s nipote" % (_level[level], gender)
|
else : return "%s%s nipote" % (_level[level], gender)
|
||||||
|
|
||||||
def get_niece(level):
|
def get_niece(self,level):
|
||||||
return get_nephew(level, "a")
|
return self.get_nephew(level, "a")
|
||||||
|
|
||||||
def get_male_cousin (levelA, levelB, gender="o"):
|
def get_male_cousin (self,levelA, levelB, gender="o"):
|
||||||
|
if levelA+levelB>len(_level):
|
||||||
|
return _("remote relative")
|
||||||
|
else:
|
||||||
return "cugin%s di %so grado (%i-%i)" \
|
return "cugin%s di %so grado (%i-%i)" \
|
||||||
% (gender, _level[levelA+levelB-1], levelA, levelB)
|
% (gender, _level[levelA+levelB-1], levelA, levelB)
|
||||||
|
|
||||||
def get_female_cousin (levelA, levelB):
|
def get_female_cousin (self,levelA, levelB):
|
||||||
return get_male_cousin(levelA, levelB, "a")
|
return self.get_male_cousin(levelA, levelB, "a")
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# get_relationship
|
||||||
|
#
|
||||||
|
#-------------------------------------------------------------------------
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
def get_relationship(self,orig_person,other_person):
|
||||||
#
|
|
||||||
# get_relationship
|
|
||||||
#
|
|
||||||
#-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
def get_relationship(orig_person,other_person):
|
|
||||||
"""
|
"""
|
||||||
returns a string representing the relationshp between the two people,
|
returns a string representing the relationshp between the two people,
|
||||||
along with a list of common ancestors (typically father,mother)
|
along with a list of common ancestors (typically father,mother)
|
||||||
"""
|
"""
|
||||||
firstMap = {}
|
|
||||||
firstList = []
|
|
||||||
secondMap = {}
|
|
||||||
secondList = []
|
|
||||||
common = []
|
|
||||||
rank = 9999999
|
|
||||||
|
|
||||||
if orig_person == None:
|
if orig_person == None:
|
||||||
return ("non definito",[])
|
return ("non definito",[])
|
||||||
|
|
||||||
if orig_person == other_person:
|
if orig_person == other_person:
|
||||||
return ('', [])
|
return ('', [])
|
||||||
if is_spouse(orig_person,other_person):
|
|
||||||
|
if self.is_spouse(orig_person,other_person):
|
||||||
return ("coniuge",[])
|
return ("coniuge",[])
|
||||||
|
|
||||||
apply_filter(orig_person,0,firstList,firstMap)
|
(firstRel,secondRel,common) = self.get_relationship_distance(orig_person,other_person)
|
||||||
apply_filter(other_person,0,secondList,secondMap)
|
|
||||||
|
|
||||||
for person in firstList:
|
if type(common) == types.StringType or type(common) == types.UnicodeType:
|
||||||
if person in secondList:
|
return (common,[])
|
||||||
new_rank = firstMap[person.get_id()]
|
elif common:
|
||||||
if new_rank < rank:
|
person_id = common[0]
|
||||||
rank = new_rank
|
else:
|
||||||
common = [ person ]
|
|
||||||
elif new_rank == rank:
|
|
||||||
common.append(person)
|
|
||||||
|
|
||||||
firstRel = -1
|
|
||||||
secondRel = -1
|
|
||||||
|
|
||||||
length = len(common)
|
|
||||||
|
|
||||||
if length == 1:
|
|
||||||
person = common[0]
|
|
||||||
secondRel = firstMap[person.get_id()]
|
|
||||||
firstRel = secondMap[person.get_id()]
|
|
||||||
elif length == 2:
|
|
||||||
p1 = common[0]
|
|
||||||
secondRel = firstMap[p1.get_id()]
|
|
||||||
firstRel = secondMap[p1.get_id()]
|
|
||||||
elif length > 2:
|
|
||||||
person = common[0]
|
|
||||||
secondRel = firstMap[person.get_id()]
|
|
||||||
firstRel = secondMap[person.get_id()]
|
|
||||||
|
|
||||||
if firstRel == -1:
|
|
||||||
return ("",[])
|
return ("",[])
|
||||||
elif firstRel == 0:
|
|
||||||
|
if firstRel == 0:
|
||||||
if secondRel == 0:
|
if secondRel == 0:
|
||||||
return ('',common)
|
return ('',common)
|
||||||
elif other_person.get_gender() == RelLib.Person.male:
|
elif other_person.get_gender() == RelLib.Person.male:
|
||||||
return (get_father(secondRel),common)
|
return (self.get_father(secondRel),common)
|
||||||
else:
|
else:
|
||||||
return (get_mother(secondRel),common)
|
return (self.get_mother(secondRel),common)
|
||||||
elif secondRel == 0:
|
elif secondRel == 0:
|
||||||
if other_person.get_gender() == RelLib.Person.male:
|
if other_person.get_gender() == RelLib.Person.male:
|
||||||
return (get_son(firstRel),common)
|
return (self.get_son(firstRel),common)
|
||||||
else:
|
else:
|
||||||
return (get_daughter(firstRel),common)
|
return (self.get_daughter(firstRel),common)
|
||||||
elif firstRel == 1:
|
elif firstRel == 1:
|
||||||
if other_person.get_gender() == RelLib.Person.male:
|
if other_person.get_gender() == RelLib.Person.male:
|
||||||
return (get_uncle(secondRel),common)
|
return (self.get_uncle(secondRel),common)
|
||||||
else:
|
else:
|
||||||
return (get_aunt(secondRel),common)
|
return (self.get_aunt(secondRel),common)
|
||||||
elif secondRel == 1:
|
elif secondRel == 1:
|
||||||
if other_person.get_gender() == RelLib.Person.male:
|
if other_person.get_gender() == RelLib.Person.male:
|
||||||
return (get_nephew(firstRel-1),common)
|
return (self.get_nephew(firstRel-1),common)
|
||||||
else:
|
else:
|
||||||
return (get_niece(firstRel-1),common)
|
return (self.get_niece(firstRel-1),common)
|
||||||
else:
|
else:
|
||||||
if other_person.get_gender() == RelLib.Person.male:
|
if other_person.get_gender() == RelLib.Person.male:
|
||||||
return (get_male_cousin(firstRel-1, secondRel-1), common)
|
return (self.get_male_cousin(firstRel-1, secondRel-1), common)
|
||||||
else:
|
else:
|
||||||
return (get_female_cousin(firstRel-1, secondRel-1), common)
|
return (self.get_female_cousin(firstRel-1, secondRel-1), common)
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -202,8 +198,9 @@ def get_relationship(orig_person,other_person):
|
|||||||
# Function registration
|
# Function registration
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
from Plugins import register_relcalc
|
||||||
|
|
||||||
register_relcalc(get_relationship,
|
register_relcalc(RelationshipCalculator,
|
||||||
["it", "IT", "it_IT", "it_IT@euro", "it_IT.utf8"])
|
["it", "IT", "it_IT", "it_IT@euro", "it_IT.utf8"])
|
||||||
|
|
||||||
# Local variables:
|
# Local variables:
|
||||||
|
Loading…
Reference in New Issue
Block a user