Relcal changes for plugins

svn: r1479
This commit is contained in:
Don Allingham 2003-04-30 00:24:32 +00:00
parent 251254abf0
commit 1fa91ea6bc
6 changed files with 215 additions and 444 deletions

View File

@ -1,3 +1,6 @@
Version 0.9.2
* Fixed duplicate place problem.
Version 0.9.1 Version 0.9.1
* Custom paper sizes may be set for reports * Custom paper sizes may be set for reports
* Witnesses may be added to an event. The witnesses do not have to be in * Witnesses may be added to an event. The witnesses do not have to be in

View File

@ -79,6 +79,19 @@ _textdoc = []
_drawdoc = [] _drawdoc = []
_failmsg = [] _failmsg = []
#-------------------------------------------------------------------------
#
# Default relationship calculator
#
#-------------------------------------------------------------------------
import Relationship
_relcalc_task = Relationship.get_relationship
#-------------------------------------------------------------------------
#
#
#-------------------------------------------------------------------------
_unavailable = _("No description was provided"), _unavailable = _("No description was provided"),
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -453,9 +466,13 @@ def register_tool(task, name,
del_index = i del_index = i
if del_index != -1: if del_index != -1:
del _tools[del_index] del _tools[del_index]
_tools.append((task, category, name, description, xpm, status, author_name, author_email)) _tools.append((task, category, name, description, xpm, status, author_name, author_name))
#-------------------------------------------------------------------------
#
# Text document registration
#
#-------------------------------------------------------------------------
def register_text_doc(name,classref, table, paper, style, ext): def register_text_doc(name,classref, table, paper, style, ext):
"""Register a text document generator""" """Register a text document generator"""
for n in _textdoc: for n in _textdoc:
@ -463,6 +480,11 @@ def register_text_doc(name,classref, table, paper, style, ext):
return return
_textdoc.append((name,classref,table,paper,style,ext)) _textdoc.append((name,classref,table,paper,style,ext))
#-------------------------------------------------------------------------
#
# Drawing document registration
#
#-------------------------------------------------------------------------
def register_draw_doc(name,classref,paper,style, ext): def register_draw_doc(name,classref,paper,style, ext):
"""Register a drawing document generator""" """Register a drawing document generator"""
for n in _drawdoc: for n in _drawdoc:
@ -470,6 +492,23 @@ def register_draw_doc(name,classref,paper,style, ext):
return return
_drawdoc.append((name,classref,paper,style,ext)) _drawdoc.append((name,classref,paper,style,ext))
#-------------------------------------------------------------------------
#
# Relationchip calculator registration
#
#-------------------------------------------------------------------------
def register_relcalc(func, languages):
"""Register a relationshp calculator"""
import sys
global _relcal_task
if sys.environ.get('LANG') in languages:
_relcalc_task = func
def relationship_function():
global _relcal_task
return _relcalc_task
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Image attributes # Image attributes

View File

@ -33,148 +33,150 @@ import GrampsCfg
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
level_name = [ "", "First", "Second", "Third", "Fourth", "Fifth", "Sixth", _level_name = [ "", "first", "second", "third", "fourth", "fifth", "sixth",
"Seventh", "Eighth", "Ninth", "Tenth", "Eleventh", "Twelfth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth",
"Thirteenth", "Fourteenth", "Fifteenth", "Sixteenth", "thirteenth", "fourteenth", "fifteenth", "sixteenth",
"Seventeenth", "Eigthteenth", "Nineteenth", "Twentieth" ] "seventeenth", "eigthteenth", "nineteenth", "twentieth" ]
removed_level = [ "", " once removed", " twice removed", " three times removed", _removed_level = [ "", " once removed", " twice removed", " three times removed",
" four times removed", " five times removed", " six times removed", " four times removed", " five times removed", " six times removed",
" sevent times removed", " eight times removed", " nine times removed", " sevent times removed", " eight times removed", " nine times removed",
" ten times removed", " eleven times removed", " twelve times removed", " ten times removed", " eleven times removed", " twelve times removed",
" thirteen times removed", " fourteen times removed", " fifteen times removed", " thirteen times removed", " fourteen times removed", " fifteen times removed",
" sixteen times removed", " seventeen times removed", " eighteen times removed", " sixteen times removed", " seventeen times removed", " eighteen times removed",
" nineteen times removed", " twenty times removed" ] " nineteen times removed", " twenty times removed" ]
father_level = [ "", "Father", "Grandfather", "Great Grandfather", "Second Great Grandfather", _father_level = [ "", "father", "grandfather", "great grandfather", "second great grandfather",
"Third Great Grandfather", "Fourth Great Grandfather", "third great grandfather", "fourth great grandfather",
"Fifth Great Grandfather", "Sixth Great Grandfather", "fifth great grandfather", "sixth great grandfather",
"Seventh Great Grandfather", "Eighth Great Grandfather", "seventh great grandfather", "eighth great grandfather",
"Ninth Great Grandfather", "Tenth Great Grandfather", "ninth great grandfather", "tenth great grandfather",
"Eleventh Great Grandfather", "Twelefth Great Grandfather", "eleventh great grandfather", "twelefth great grandfather",
"Thirteenth Great Grandfather", "Fourteenth Great Grandfather", "thirteenth great grandfather", "fourteenth great grandfather",
"Fifteenth Great Grandfather", "Sixteenth Great Grandfather", "fifteenth great grandfather", "sixteenth great grandfather",
"Seventeenth Great Grandfather", "Eightteenth Great Grandfather", "seventeenth great grandfather", "eightteenth great grandfather",
"Ninetheen Great Grandfather", "Twentieth Great Grandfather", ] "ninetheen great grandfather", "twentieth great grandfather", ]
mother_level = [ "", "Mother", "Grandmother", "Great Grandmother", "Second Great Grandmother", _mother_level = [ "", "mother", "grandmother", "great grandmother", "second great grandmother",
"Third Great Grandmother", "Fourth Great Grandmother", "third great grandmother", "fourth great grandmother",
"Fifth Great Grandmother", "Sixth Great Grandmother", "fifth great grandmother", "sixth great grandmother",
"Seventh Great Grandmother", "Eighth Great Grandmother", "seventh great grandmother", "eighth great grandmother",
"Ninth Great Grandmother", "Tenth Great Grandmother", "ninth great grandmother", "tenth great grandmother",
"Eleventh Great Grandmother", "Twelefth Great Grandmother", "eleventh great grandmother", "twelefth great grandmother",
"Thirteenth Great Grandmother", "Fourteenth Great Grandmother", "thirteenth great grandmother", "fourteenth great grandmother",
"Fifteenth Great Grandmother", "Sixteenth Great Grandmother", "fifteenth great grandmother", "sixteenth great grandmother",
"Seventeenth Great Grandmother", "Eightteenth Great Grandmother", "seventeenth great grandmother", "eightteenth great grandmother",
"Ninetheen Great Grandmother", "Twentieth Great Grandmother", ] "ninetheen great grandmother", "twentieth great grandmother", ]
son_level = [ "", "Son", "Grandson", "Great Grandson", "Second Great Grandson", _son_level = [ "", "son", "grandson", "great grandson", "second great grandson",
"Third Great Grandson", "Fourth Great Grandson", "third great grandson", "fourth great grandson",
"Fifth Great Grandson", "Sixth Great Grandson", "fifth great grandson", "sixth great grandson",
"Seventh Great Grandson", "Eighth Great Grandson", "seventh great grandson", "eighth great grandson",
"Ninth Great Grandson", "Tenth Great Grandson", "ninth great grandson", "tenth great grandson",
"Eleventh Great Grandson", "Twelefth Great Grandson", "eleventh great grandson", "twelefth great grandson",
"Thirteenth Great Grandson", "Fourteenth Great Grandson", "thirteenth great grandson", "fourteenth great grandson",
"Fifteenth Great Grandson", "Sixteenth Great Grandson", "fifteenth great grandson", "sixteenth great grandson",
"Seventeenth Great Grandson", "Eightteenth Great Grandson", "seventeenth great grandson", "eightteenth great grandson",
"Ninetheen Great Grandson", "Twentieth Great Grandson", ] "ninetheen great grandson", "twentieth great grandson", ]
daughter_level = [ "", "Daughter", "Granddaughter", "Great Granddaughter", "Second Great Granddaughter", _daughter_level = [ "", "daughter", "granddaughter", "great granddaughter",
"Third Great Granddaughter", "Fourth Great Granddaughter", "second great granddaughter",
"Fifth Great Granddaughter", "Sixth Great Granddaughter", "third great granddaughter", "fourth great granddaughter",
"Seventh Great Granddaughter", "Eighth Great Granddaughter", "fifth great granddaughter", "sixth great granddaughter",
"Ninth Great Granddaughter", "Tenth Great Granddaughter", "seventh great granddaughter", "eighth great granddaughter",
"Eleventh Great Granddaughter", "Twelefth Great Granddaughter", "ninth great granddaughter", "tenth great granddaughter",
"Thirteenth Great Granddaughter", "Fourteenth Great Granddaughter", "eleventh great granddaughter", "twelefth great granddaughter",
"Fifteenth Great Granddaughter", "Sixteenth Great Granddaughter", "thirteenth great granddaughter", "fourteenth great granddaughter",
"Seventeenth Great Granddaughter", "Eightteenth Great Granddaughter", "fifteenth great granddaughter", "sixteenth great granddaughter",
"Ninetheen Great Granddaughter", "Twentieth Great Granddaughter", ] "seventeenth great granddaughter", "eightteenth great granddaughter",
"ninetheen great granddaughter", "twentieth great granddaughter", ]
sister_level = [ "", "Sister", "Aunt", "Grandaunt", "Great Grandaunt", "Second Great Grandaunt", _sister_level = [ "", "sister", "aunt", "grandaunt", "great grandaunt", "second great grandaunt",
"Third Great Grandaunt", "Fourth Great Grandaunt", "third great grandaunt", "fourth great grandaunt",
"Fifth Great Grandaunt", "Sixth Great Grandaunt", "fifth great grandaunt", "sixth great grandaunt",
"Seventh Great Grandaunt", "Eighth Great Grandaunt", "seventh great grandaunt", "eighth great grandaunt",
"Ninth Great Grandaunt", "Tenth Great Grandaunt", "ninth great grandaunt", "tenth great grandaunt",
"Eleventh Great Grandaunt", "Twelefth Great Grandaunt", "eleventh great grandaunt", "twelefth great grandaunt",
"Thirteenth Great Grandaunt", "Fourteenth Great Grandaunt", "thirteenth great grandaunt", "fourteenth great grandaunt",
"Fifteenth Great Grandaunt", "Sixteenth Great Grandaunt", "fifteenth great grandaunt", "sixteenth great grandaunt",
"Seventeenth Great Grandaunt", "Eightteenth Great Grandaunt", "seventeenth great grandaunt", "eightteenth great grandaunt",
"Ninetheen Great Grandaunt", "Twentieth Great Grandaunt", ] "ninetheen great grandaunt", "twentieth great grandaunt", ]
brother_level = [ "", "Brother", "Uncle", "Granduncle", "Great Granduncle", "Second Great Granduncle", _brother_level = [ "", "brother", "uncle", "granduncle", "great granduncle", "second great granduncle",
"Third Great Granduncle", "Fourth Great Granduncle", "third great granduncle", "fourth great granduncle",
"Fifth Great Granduncle", "Sixth Great Granduncle", "fifth great granduncle", "sixth great granduncle",
"Seventh Great Granduncle", "Eighth Great Granduncle", "seventh great granduncle", "eighth great granduncle",
"Ninth Great Granduncle", "Tenth Great Granduncle", "ninth great granduncle", "tenth great granduncle",
"Eleventh Great Granduncle", "Twelefth Great Granduncle", "eleventh great granduncle", "twelefth great granduncle",
"Thirteenth Great Granduncle", "Fourteenth Great Granduncle", "thirteenth great granduncle", "fourteenth great granduncle",
"Fifteenth Great Granduncle", "Sixteenth Great Granduncle", "fifteenth great granduncle", "sixteenth great granduncle",
"Seventeenth Great Granduncle", "Eightteenth Great Granduncle", "seventeenth great granduncle", "eightteenth great granduncle",
"Ninetheen Great Granduncle", "Twentieth Great Granduncle", ] "ninetheen great granduncle", "twentieth great granduncle", ]
nephew_level = [ "", "Nephew", "Grandnephew", "Great Grandnephew", "Second Great Grandnephew", _nephew_level = [ "", "nephew", "grandnephew", "great grandnephew", "second great grandnephew",
"Third Great Grandnephew", "Fourth Great Grandnephew", "third great grandnephew", "fourth great grandnephew",
"Fifth Great Grandnephew", "Sixth Great Grandnephew", "fifth great grandnephew", "sixth great grandnephew",
"Seventh Great Grandnephew", "Eighth Great Grandnephew", "seventh great grandnephew", "eighth great grandnephew",
"Ninth Great Grandnephew", "Tenth Great Grandnephew", "ninth great grandnephew", "tenth great grandnephew",
"Eleventh Great Grandnephew", "Twelefth Great Grandnephew", "eleventh great grandnephew", "twelefth great grandnephew",
"Thirteenth Great Grandnephew", "Fourteenth Great Grandnephew", "thirteenth great grandnephew", "fourteenth great grandnephew",
"Fifteenth Great Grandnephew", "Sixteenth Great Grandnephew", "fifteenth great grandnephew", "sixteenth great grandnephew",
"Seventeenth Great Grandnephew", "Eightteenth Great Grandnephew", "seventeenth great grandnephew", "eightteenth great grandnephew",
"Ninetheen Great Grandnephew", "Twentieth Great Grandnephew", ] "ninetheen great grandnephew", "twentieth great grandnephew", ]
niece_level = [ "", "Niece", "Grandniece", "Great Grandniece", "Second Great Grandniece",
"Third Great Grandniece", "Fourth Great Grandniece", _niece_level = [ "", "niece", "grandniece", "great grandniece", "second great grandniece",
"Fifth Great Grandniece", "Sixth Great Grandniece", "third great grandniece", "fourth great grandniece",
"Seventh Great Grandniece", "Eighth Great Grandniece", "fifth great grandniece", "sixth great grandniece",
"Ninth Great Grandniece", "Tenth Great Grandniece", "seventh great grandniece", "eighth great grandniece",
"Eleventh Great Grandniece", "Twelefth Great Grandniece", "ninth great grandniece", "tenth great grandniece",
"Thirteenth Great Grandniece", "Fourteenth Great Grandniece", "eleventh great grandniece", "twelefth great grandniece",
"Fifteenth Great Grandniece", "Sixteenth Great Grandniece", "thirteenth great grandniece", "fourteenth great grandniece",
"Seventeenth Great Grandniece", "Eightteenth Great Grandniece", "fifteenth great grandniece", "sixteenth great grandniece",
"Ninetheen Great Grandniece", "Twentieth Great Grandniece", ] "seventeenth great grandniece", "eightteenth great grandniece",
"ninetheen great grandniece", "twentieth great grandniece", ]
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def filter(person,index,list,map): def apply_filter(person,index,plist,pmap):
if person == None: if person == None:
return return
list.append(person) plist.append(person)
map[person.getId()] = index pmap[person.getId()] = index
family = person.getMainParents() family = person.getMainParents()
if family != None: if family != None:
filter(family.getFather(),index+1,list,map) apply_filter(family.getFather(),index+1,plist,pmap)
filter(family.getMother(),index+1,list,map) apply_filter(family.getMother(),index+1,plist,pmap)
def get_cousin(f,s,level,removed): def get_cousin(level,removed):
return "%s cousin%s of %s" % (level_name[level],removed_level[removed],f) return "%s cousin%s" % (_level_name[level],_removed_level[removed])
def get_father(f,s,level): def get_father(level):
return "%s of %s" % (father_level[level],f) return _father_level[level]
def get_son(f,s,level): def get_son(level):
return "%s of %s" % (son_level[level],f) return _son_level[level]
def get_mother(f,s,level): def get_mother(level):
return "%s of %s" % (mother_level[level],f) return _mother_level[level]
def get_daughter(f,s,level): def get_daughter(level):
return "%s of %s" % (daughter_level[level],f) return _daughter_level[level]
def get_aunt(f,s,level): def get_aunt(level):
return "%s of %s" % (sister_level[level],f) return _sister_level[level]
def get_uncle(f,s,level): def get_uncle(level):
return "%s of %s" % (brother_level[level],f) return _brother_level[level]
def get_nephew(f,s,level): def get_nephew(level):
return "%s of %s" % (nephew_level[level],f) return _nephew_level[level]
def get_niece(f,s,level): def get_niece(level):
return "%s of %s" % (niece_level[level],f) return _niece_level[level],f
def is_spouse(orig,other): def is_spouse(orig,other):
for f in orig.getFamilyList(): for f in orig.getFamilyList():
@ -183,6 +185,10 @@ def is_spouse(orig,other):
return 0 return 0
def get_relationship(orig_person,other_person): def get_relationship(orig_person,other_person):
"""
returns a string representing the relationshp between the two people,
along with a list of common ancestors (typically father,mother)
"""
firstMap = {} firstMap = {}
firstList = [] firstList = []
secondMap = {} secondMap = {}
@ -191,18 +197,18 @@ def get_relationship(orig_person,other_person):
rank = 9999999 rank = 9999999
if orig_person == None: if orig_person == None:
return "No Home Person has been defined" return "undefined"
firstName = orig_person.getPrimaryName().getRegularName() firstName = orig_person.getPrimaryName().getRegularName()
secondName = other_person.getPrimaryName().getRegularName() secondName = other_person.getPrimaryName().getRegularName()
if orig_person == other_person: if orig_person == other_person:
return firstName return ('', [])
if is_spouse(orig_person,other_person): if is_spouse(orig_person,other_person):
return "Spouse of %s" % (firstName) return ("spouse",[])
filter(orig_person,0,firstList,firstMap) apply_filter(orig_person,0,firstList,firstMap)
filter(other_person,0,secondList,secondMap) apply_filter(other_person,0,secondList,secondMap)
for person in firstList: for person in firstList:
if person in secondList: if person in secondList:
@ -232,32 +238,32 @@ def get_relationship(orig_person,other_person):
firstRel = secondMap[person.getId()] firstRel = secondMap[person.getId()]
if firstRel == -1: if firstRel == -1:
return "No relationship to %s" % firstName return ("",[])
elif firstRel == 0: elif firstRel == 0:
if secondRel == 0: if secondRel == 0:
return firstName return ('',common)
elif other_person.getGender() == RelLib.Person.male: elif other_person.getGender() == RelLib.Person.male:
return get_father(firstName,secondName,secondRel) return (get_father(secondRel),common)
else: else:
return get_mother(firstName,secondName,secondRel) return (get_mother(secondRel),common)
elif secondRel == 0: elif secondRel == 0:
if other_person.getGender() == RelLib.Person.male: if other_person.getGender() == RelLib.Person.male:
return get_son(firstName,secondName,firstRel) return (get_son(firstRel),common)
else: else:
return get_daughter(firstName,secondName,firstRel) return (get_daughter(firstRel),common)
elif firstRel == 1: elif firstRel == 1:
if other_person.getGender() == RelLib.Person.male: if other_person.getGender() == RelLib.Person.male:
return get_uncle(firstName,secondName,secondRel) return (get_uncle(secondRel),common)
else: else:
return get_aunt(firstName,secondName,secondRel) return (get_aunt(secondRel),common)
elif secondRel == 1: elif secondRel == 1:
if other_person.getGender() == RelLib.Person.male: if other_person.getGender() == RelLib.Person.male:
return get_nephew(firstName,secondName,firstRel-1) return (get_nephew(firstRel-1),common)
else: else:
return get_niece(firstName,secondName,firstRel-1) return (get_niece(firstRel-1),common)
else: else:
if secondRel > firstRel: if secondRel > firstRel:
return get_cousin(firstName,secondName,firstRel-1,secondRel-firstRel) return (get_cousin(firstRel-1,secondRel-firstRel),common)
else: else:
return get_cousin(firstName,secondName,secondRel-1,firstRel-secondRel) return (get_cousin(secondRel-1,firstRel-secondRel),common)

View File

@ -279,7 +279,8 @@ class PdfDoc(TextDoc.TextDoc):
def write_text(self,text): def write_text(self,text):
text = text.replace('&','&'); # Must be first text = text.replace('&','&'); # Must be first
text = text.replace('<','&lt;'); text = text.replace('<','&lt;');
self.text = self.text + text.replace('>','&gt;'); text = text.replace('>','&gt;');
self.text = self.text + text.replace('\n','<br>');
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -301,5 +302,5 @@ Plugins.register_text_doc(
table=1, table=1,
paper=1, paper=1,
style=1, style=1,
ext="pdf" ext=".pdf"
) )

View File

@ -72,7 +72,6 @@ import VersionControl
import ReadXML import ReadXML
import ListModel import ListModel
import GrampsXML import GrampsXML
import Relationship
try: try:
import GrampsZODB import GrampsZODB
@ -138,6 +137,7 @@ class Gramps:
self.db.set_pprefix(GrampsCfg.pprefix) self.db.set_pprefix(GrampsCfg.pprefix)
GrampsCfg.loadConfig(self.full_update) GrampsCfg.loadConfig(self.full_update)
self.relationship = Plugins.relationship_function()
self.init_interface() self.init_interface()
if arg != None: if arg != None:
@ -1027,10 +1027,24 @@ class Gramps:
pname = GrampsCfg.nameof(self.active_person) pname = GrampsCfg.nameof(self.active_person)
name = "[%s] %s" % (self.active_person.getId(),pname) name = "[%s] %s" % (self.active_person.getId(),pname)
else: else:
name = Relationship.get_relationship(self.db.getDefaultPerson(), name = self.display_relationship()
self.active_person)
self.status_text(name) self.status_text(name)
return 0 return 0
def display_relationship(self):
try:
pname = GrampsCfg.nameof(self.db.getDefaultPerson())
(name,plist) = self.relationship(self.db.getDefaultPerson(),
self.active_person)
if name:
return _("%(relationship)s of %(person)s") % {
'relationship' : name, 'person' : pname }
else:
return ""
except:
import DisplayTrace
DisplayTrace.DisplayTrace()
def on_open_activate(self,obj): def on_open_activate(self,obj):
wFs = gtk.glade.XML(const.revisionFile, "dbopen") wFs = gtk.glade.XML(const.revisionFile, "dbopen")

View File

@ -45,249 +45,9 @@ import gtk.glade
import RelLib import RelLib
import Utils import Utils
import ListModel import ListModel
import Plugins
from intl import gettext as _ from intl import gettext as _
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def filter(person,index,list,map):
if person == None:
return
list.append(person)
map[person.getId()] = index
family = person.getMainParents()
if family != None:
filter(family.getFather(),index+1,list,map)
filter(family.getMother(),index+1,list,map)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def get_cousin(f,s,level,removed):
if level == 1:
if removed == 0:
return _("%(p1)s is the first cousin of %(p2)s.") % {
'p1' : f, 'p2' : s}
elif removed == 1:
return _("%(p1)s is the first cousin once removed of %(p2)s.") % {
'p1' : f, 'p2' : s}
elif removed == 2:
return _("%(p1)s is the first cousin twice removed of %(p2)s.") % {
'p1' : f,'p2' : s}
else:
return _("%(p1)s is the first cousin %(removed)d times removed of %(p2)s.") % {
'p1' :f, 'p2' :s, 'removed' : removed}
elif level == 2:
if removed == 0:
return _("%(p1)s is the second cousin of %(p2)s.") % {
'p1' : f, 'p2' : s }
elif removed == 1:
return _("%(p1)s is the second cousin once removed of %(p2)s.") % {
'p1' : f, 'p2' : s }
elif removed == 2:
return _("%(p1)s is the second cousin twice removed of %(p2)s.") % {
'p1' : f, 'p2' : s }
else:
return _("%(p1)s is the second cousin %(removed)d times removed of %(p2)s.") % {
'p1' : f, 'p2' : s, 'removed' : removed }
elif level == 3:
if removed == 0:
return _("%(p1)s is the third cousin of %(p2)s.") % {
'p1' : f, 'p2' : s }
elif removed == 1:
return _("%(p1)s is the third cousin once removed of %(p2)s.") % {
'p1' : f, 'p2' : s }
elif removed == 2:
return _("%(p1)s is the third cousin twice removed of %(p2)s.") % {
'p1' : f, 'p2' : s }
else:
return _("%(p1)s is the third cousin %(removed)d times removed of %(p2)s.") % {
'p1' : f, 'p2' : s, 'removed' : removed }
else:
if removed == 0:
return _("%(p1)s is the %(level)dth cousin of %(p2)s.") % {
'p1': f, 'level': level, 'p2' : s }
elif removed == 1:
return _("%(p1)s is the %(level)dth cousin once removed of %(p2)s.") % {
'p1': f, 'level': level, 'p2' : s }
elif removed == 2:
return _("%(p1)s is the %(level)dth cousin twice removed of %(p2)s.") % {
'p1': f, 'level': level, 'p2' : s }
else:
return _("%(p1)s is the %(level)dth cousin %(removed)d times removed of %(p2)s.") % {
'p1': f, 'level': level, 'removed' : removed, 'p2' : s }
def get_father(f,s,level):
if level == 1:
return _("%(p1)s is the father of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 2:
return _("%(p1)s is the grandfather of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 3:
return _("%(p1)s is the great grandfather of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 4:
return _("%(p1)s is the second great grandfather of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 5:
return _("%(p1)s is the third great grandfather of %(p2)s.") % {
'p1': s, 'p2': f }
else:
return _("%(p1)s is the %(level)dth great grandfather of %(p2)s.") % {
'p1': s, 'level' : level-2, 'p2': f }
def get_son(f,s,level):
if level == 1:
return _("%(p1)s is the son of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 2:
return _("%(p1)s is the grandson of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 3:
return _("%(p1)s is the great grandson of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 4:
return _("%(p1)s is the second great grandson of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 5:
return _("%(p1)s is the third great grandson of %(p2)s.") % {
'p1': s, 'p2': f }
else:
return _("%(p1)s is the %(level)dth great grandson of %(p2)s.") % {
'p1': s, 'level' : level-2, 'p2': f }
def get_mother(f,s,level):
if level == 1:
return _("%(p1)s is the mother of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 2:
return _("%(p1)s is the grandmother of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 3:
return _("%(p1)s is the great grandmother of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 4:
return _("%(p1)s is the second great grandmother of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 5:
return _("%(p1)s is the third great grandmother of %(p2)s.") % {
'p1': s, 'p2': f }
else:
return _("%(p1)s is the %(level)dth great grandmother of %(p2)s.") % {
'p1': s, 'level' : level-2, 'p2': f }
def get_daughter(f,s,level):
if level == 1:
return _("%(p1)s is the daughter of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 2:
return _("%(p1)s is the granddaughter of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 3:
return _("%(p1)s is the great granddaughter of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 4:
return _("%(p1)s is the second great granddaughter of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 5:
return _("%(p1)s is the third great granddaughter of %(p2)s.") % {
'p1': s, 'p2': f }
else:
return _("%(p1)s is the %(level)dth great granddaughter of %(p2)s.") % {
'p1': s, 'level' : level-2, 'p2': f }
def get_aunt(f,s,level):
if level == 1:
return _("%(p1)s is the sister of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 2:
return _("%(p1)s is the aunt of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 3:
return _("%(p1)s is the grandaunt of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 4:
return _("%(p1)s is the great grandaunt of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 5:
return _("%(p1)s is the second great grandaunt of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 6:
return _("%(p1)s is the third great grandaunt of %(p2)s.") % {
'p1': s, 'p2': f }
else:
return _("%(p1)s is the %(level)dth great grandaunt of %(p2)s.") % {
'p1': s, 'level' : level-3, 'p2': f }
def get_uncle(f,s,level):
if level == 1:
return _("%(p1)s is the brother of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 2:
return _("%(p1)s is the uncle of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 3:
return _("%(p1)s is the granduncle of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 4:
return _("%(p1)s is the great granduncle of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 5:
return _("%(p1)s is the second great granduncle of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 6:
return _("%(p1)s is the third great granduncle of %(p2)s.") % {
'p1': s, 'p2': f }
else:
return _("%(p1)s is the %(level)dth great granduncle of %(p2)s.") % {
'p1': s, 'level' : level-3, 'p2': f }
def get_nephew(f,s,level):
if level == 1:
return _("%(p1)s is the nephew of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 2:
return _("%(p1)s is the grandnephew of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 3:
return _("%(p1)s is the great grandnephew of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 4:
return _("%(p1)s is the second great grandnephew of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 5:
return _("%(p1)s is the third great grandnephew of %(p2)s.") % {
'p1': s, 'p2': f }
else:
return _("%(p1)s is the %(level)dth great grandnephew of %(p2)s.") % {
'p1': s, 'level' : level-2, 'p2': f }
def get_niece(f,s,level):
if level == 1:
return _("%(p1)s is the niece of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 2:
return _("%(p1)s is the grandniece of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 3:
return _("%(p1)s is the great grandniece of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 4:
return _("%(p1)s is the second great grandniece of %(p2)s.") % {
'p1': s, 'p2': f }
elif level == 5:
return _("%(p1)s is the third great grandniece of %(p2)s.") % {
'p1': s, 'p2': f }
else:
return _("%(p1)s is the %(level)dth great grandniece of %(p2)s.") % {
'p1': s, 'level' : level-2, 'p2': f }
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #
@ -309,6 +69,7 @@ class RelCalc:
def __init__(self,database,person): def __init__(self,database,person):
self.person = person self.person = person
self.db = database self.db = database
self.relationship = Plugins.relationship_function()
base = os.path.dirname(__file__) base = os.path.dirname(__file__)
glade_file = "%s/relcalc.glade" % base glade_file = "%s/relcalc.glade" % base
@ -341,50 +102,23 @@ class RelCalc:
}) })
def on_apply_clicked(self,obj): def on_apply_clicked(self,obj):
firstMap = {}
firstList = []
secondMap = {}
secondList = []
common = []
rank = 9999999
model,iter = self.clist.get_selected() model,iter = self.clist.get_selected()
if not iter: if not iter:
return return
id = self.clist.get_object(iter) id = self.clist.get_object(iter)
other_person = self.db.getPerson(id) other_person = self.db.getPerson(id)
filter(self.person,0,firstList,firstMap)
filter(other_person,0,secondList,secondMap)
for person in firstList:
if person in secondList:
new_rank = firstMap[person.getId()]
if new_rank < rank:
rank = new_rank
common = [ person ]
elif new_rank == rank:
common.append(person)
firstRel = -1
secondRel = -1
firstName = self.person.getPrimaryName().getRegularName()
secondName = other_person.getPrimaryName().getRegularName()
(rel_string,common) = self.relationship(self.person,other_person)
length = len(common) length = len(common)
if length == 1: if length == 1:
person = common[0] person = common[0]
secondRel = firstMap[person.getId()]
firstRel = secondMap[person.getId()]
name = person.getPrimaryName().getRegularName() name = person.getPrimaryName().getRegularName()
commontext = " " + _("Their common ancestor is %s.") % name commontext = " " + _("Their common ancestor is %s.") % name
elif length == 2: elif length == 2:
p1 = common[0] p1 = common[0]
p2 = common[1] p2 = common[1]
secondRel = firstMap[p1.getId()]
firstRel = secondMap[p1.getId()]
commontext = " " + _("Their common ancestors are %s and %s.") % \ commontext = " " + _("Their common ancestors are %s and %s.") % \
(p1.getPrimaryName().getRegularName(),\ (p1.getPrimaryName().getRegularName(),\
p2.getPrimaryName().getRegularName()) p2.getPrimaryName().getRegularName())
@ -392,8 +126,6 @@ class RelCalc:
index = 0 index = 0
commontext = " " + _("Their common ancestors are : ") commontext = " " + _("Their common ancestors are : ")
for person in common: for person in common:
secondRel = firstMap[person.getId()]
firstRel = secondMap[person.getId()]
if index != 0: if index != 0:
commontext = commontext + ", " commontext = commontext + ", "
commontext = commontext + person.getPrimaryName().getRegularName() commontext = commontext + person.getPrimaryName().getRegularName()
@ -402,42 +134,18 @@ class RelCalc:
else: else:
commontext = "" commontext = ""
if firstRel == -1:
msg = _("There is no relationship between %s and %s.")
text = msg % (firstName,secondName)
elif firstRel == 0:
if secondRel == 0:
text = _("%s and %s are the same person.") % (firstName,secondName)
elif other_person.getGender() == RelLib.Person.male:
text = get_father(firstName,secondName,secondRel)
else:
text = get_mother(firstName,secondName,secondRel)
elif secondRel == 0:
if other_person.getGender() == RelLib.Person.male:
text = get_son(firstName,secondName,firstRel)
else:
text = get_daughter(firstName,secondName,firstRel)
elif firstRel == 1:
if other_person.getGender() == RelLib.Person.male:
text = get_uncle(firstName,secondName,secondRel)
else:
text = get_aunt(firstName,secondName,secondRel)
elif secondRel == 1:
if other_person.getGender() == RelLib.Person.male:
text = get_nephew(firstName,secondName,firstRel-1)
else:
text = get_niece(firstName,secondName,firstRel-1)
else:
if secondRel > firstRel:
text = get_cousin(firstName,secondName,firstRel-1,secondRel-firstRel)
else:
text = get_cousin(firstName,secondName,secondRel-1,firstRel-secondRel)
text1 = self.glade.get_widget("text1").get_buffer() text1 = self.glade.get_widget("text1").get_buffer()
if firstRel == 0 or secondRel == 0: p1 = self.person.getPrimaryName().getName()
text1.set_text(text) p2 = other_person.getPrimaryName().getName()
else:
text1.set_text(text + commontext) if rel_string == "":
rstr = _("%(person)s and %(active_person)s are not related.") % {
'person' : p2, 'active_person' : p1 }
else:
rstr = _("%(person)s is the %(relationship)s of %(active_person)s.") % {
'person' : p2, 'relationship' : rel_string, 'active_person' : p1 }
text1.set_text("%s %s" % (rstr, commontext))
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #