* src/plugins/IndivComplete.py: Call doc.init() after open.

* src/plugins/IndivSummary.py: Call doc.init() after open.
* src/plugins/RelCalc.py: Use class of calculator.
* src/plugins/rel_ru.py: Convert to class.
* src/Plugins.py: Register _relcalc_class.
* src/gramps_main.py: Use class of relationship calculator.


svn: r2835
This commit is contained in:
Alex Roitman 2004-02-15 07:08:55 +00:00
parent 2baffc68d2
commit 47a66cdf75
7 changed files with 205 additions and 177 deletions

View File

@ -18,6 +18,13 @@
* src/plugins/WebPage.py: Add tab with index page options.
* src/sort: Typos.
* src/plugins/IndivComplete.py: Call doc.init() after open.
* src/plugins/IndivSummary.py: Call doc.init() after open.
* src/plugins/RelCalc.py: Use class of calculator.
* src/plugins/rel_ru.py: Convert to class.
* src/Plugins.py: Register _relcalc_class.
* src/gramps_main.py: Use class of relationship calculator.
2004-02-13 Egyeki Gergely <egeri@elte.hu>
* src/po/hu.po: Update
* doc/gramps-manual/hu/filtref.xml: Update

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2003 Donald N. Allingham
# Copyright (C) 2000-2004 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
@ -88,6 +88,7 @@ _bkitems = []
#
#-------------------------------------------------------------------------
import Relationship
_relcalc_class = Relationship.RelationshipCalculator
#-------------------------------------------------------------------------
#
@ -530,21 +531,22 @@ def register_draw_doc(name,classref,paper,style, ext,
#-------------------------------------------------------------------------
#
# Relationchip calculator registration
# Relationship calculator registration
#
#-------------------------------------------------------------------------
def register_relcalc(func, languages):
def register_relcalc(relclass, languages):
"""Register a relationshp calculator"""
global _relcalc_task
global _relcalc_class
try:
if os.environ["LANG"] in languages:
_relcalc_task = func
_relcalc_class = relclass
except:
pass
def relationship_function(db):
return Relationship.RelationshipCalculator(db)
def relationship_class(db):
global _relcalc_class
return _relcalc_class(db)
#-------------------------------------------------------------------------
#

View File

@ -141,7 +141,8 @@ class Gramps:
self.db.set_pprefix(GrampsCfg.pprefix)
GrampsCfg.loadConfig(self.pref_callback)
self.relationship = Plugins.relationship_function(self.db)
self.RelClass = Plugins.relationship_class(self.db)
self.relationship = self.RelClass.get_relationship
self.init_interface()
if args:
@ -660,7 +661,8 @@ class Gramps:
Plugins.build_export_menu(export_menu,self.export_callback)
Plugins.build_import_menu(import_menu,self.import_callback)
self.relationship = Plugins.relationship_function(self.db)
self.RelClass = Plugins.relationship_class(self.db)
self.relationship = self.RelClass.get_relationship
def init_filters(self):
@ -1395,7 +1397,7 @@ class Gramps:
def display_relationship(self):
try:
pname = GrampsCfg.nameof(self.db.get_default_person())
(name,plist) = self.relationship.get_relationship(self.db.get_default_person(),
(name,plist) = self.relationship(self.db.get_default_person(),
self.active_person)
if name:

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2003 Donald N. Allingham
# Copyright (C) 2000-2004 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
@ -82,6 +82,7 @@ class IndivComplete(Report.Report):
if output:
self.standalone = 1
self.d.open(output)
self.d.init()
else:
self.standalone = 0

View File

@ -1,7 +1,7 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2003 Donald N. Allingham
# Copyright (C) 2000-2004 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
@ -18,6 +18,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
"Generate files/Individual Summary"
#------------------------------------------------------------------------
@ -80,6 +82,7 @@ class IndivSummary(Report.Report):
if output:
self.standalone = 1
self.d.open(output)
self.d.init()
else:
self.standalone = 0
self.newpage = newpage

View File

@ -69,7 +69,8 @@ class RelCalc:
def __init__(self,database,person):
self.person = person
self.db = database
self.relationship = Plugins.relationship_function()
self.RelClass = Plugins.relationship_class(database)
self.relationship = self.RelClass.get_relationship
base = os.path.dirname(__file__)
glade_file = "%s/relcalc.glade" % base

View File

@ -33,7 +33,7 @@
import RelLib
import GrampsCfg
from Relationship import apply_filter as getallancestors
import Relationship
#-------------------------------------------------------------------------
#
@ -107,86 +107,94 @@ _niece_level = [
#
#
#-------------------------------------------------------------------------
class RelationshipCalculator(Relationship.RelationshipCalculator):
def get_junior_male_cousin(level,removed):
def __init__(self,db):
Relationship.RelationshipCalculator.__init__(self,db)
def get_junior_male_cousin(self,level,removed):
if removed > len(_junior_male_removed_level)-1 or level>len(_male_cousin_level)-1:
return "дальний родственник"
else:
return "%s %s" % (_male_cousin_level[level],_junior_male_removed_level[removed])
def get_senior_male_cousin(level,removed):
def get_senior_male_cousin(self,level,removed):
if removed > len(_senior_male_removed_level)-1 or level>len(_male_cousin_level)-1:
return "дальний родственник"
else:
return "%s %s" % (_male_cousin_level[level],_senior_male_removed_level[removed])
def get_junior_female_cousin(level,removed):
def get_junior_female_cousin(self,level,removed):
if removed > len(_junior_female_removed_level)-1 or level>len(_male_cousin_level)-1:
return "дальняя родственница"
else:
return "%s %s" % (_female_cousin_level[level],_junior_female_removed_level[removed])
def get_senior_female_cousin(level,removed):
def get_senior_female_cousin(self,level,removed):
if removed > len(_senior_female_removed_level)-1 or level>len(_male_cousin_level)-1:
return "дальняя родственница"
else:
return "%s %s" % (_female_cousin_level[level],_senior_female_removed_level[removed])
def get_father(level):
def get_father(self,level):
if level>len(_father_level)-1:
return "дальний предок"
else:
return _father_level[level]
def get_son(level):
def get_son(self,level):
if level>len(_son_level)-1:
return "дальний потомок"
else:
return _son_level[level]
def get_mother(level):
def get_mother(self,level):
if level>len(_mother_level)-1:
return "дальний предок"
else:
return _mother_level[level]
def get_daughter(level):
def get_daughter(self,level):
if level>len(_daughter_level)-1:
return "дальний потомок"
else:
return _daughter_level[level]
def get_aunt(level):
def get_aunt(self,level):
if level>len(_sister_level)-1:
return "дальний предок"
else:
return _sister_level[level]
def get_uncle(level):
def get_uncle(self,level):
if level>len(_brother_level)-1:
return "дальний предок"
else:
return _brother_level[level]
def get_nephew(level):
def get_nephew(self,level):
if level>len(_nephew_level)-1:
return "дальний потомок"
else:
return _nephew_level[level]
def get_niece(level):
def get_niece(self,level):
if level>len(_niece_level)-1:
return "дальний потомок"
else:
return _niece_level[level]
def is_spouse(orig,other):
def is_spouse(self,orig,other):
for f in orig.get_family_id_list():
if other == f.get_father_id() or other == f.get_mother_id():
family = self.db.find_family_from_id(f)
if family:
if other == family.get_father_id() or other == family.get_mother_id():
return 1
else:
return 0
return 0
def get_relationship(orig_person,other_person):
def get_relationship(self,orig_person,other_person):
"""
Returns a string representing the relationshp between the two people,
along with a list of common ancestors (typically father,mother)
@ -209,11 +217,14 @@ def get_relationship(orig_person,other_person):
if orig_person == other_person:
return ('', [])
if is_spouse(orig_person,other_person):
if self.is_spouse(orig_person,other_person):
return ("spouse",[])
getallancestors(orig_person,0,firstList,firstMap)
getallancestors(other_person,0,secondList,secondMap)
self.apply_filter(orig_person,0,firstList,firstMap)
self.apply_filter(other_person,0,secondList,secondMap)
print len(firstList)
print len(secondList)
for person in firstList:
if person in secondList:
@ -243,39 +254,40 @@ def get_relationship(orig_person,other_person):
firstRel = secondMap[person.get_id()]
if firstRel == -1:
print '2'
return ("",[])
elif firstRel == 0:
if secondRel == 0:
return ('',common)
elif other_person.get_gender() == RelLib.Person.male:
return (get_father(secondRel),common)
return (self.get_father(secondRel),common)
else:
return (get_mother(secondRel),common)
return (self.get_mother(secondRel),common)
elif secondRel == 0:
if other_person.get_gender() == RelLib.Person.male:
return (get_son(firstRel),common)
return (self.get_son(firstRel),common)
else:
return (get_daughter(firstRel),common)
return (self.get_daughter(firstRel),common)
elif firstRel == 1:
if other_person.get_gender() == RelLib.Person.male:
return (get_uncle(secondRel),common)
return (self.get_uncle(secondRel),common)
else:
return (get_aunt(secondRel),common)
return (self.get_aunt(secondRel),common)
elif secondRel == 1:
if other_person.get_gender() == RelLib.Person.male:
return (get_nephew(firstRel-1),common)
return (self.get_nephew(firstRel-1),common)
else:
return (get_niece(firstRel-1),common)
return (self.get_niece(firstRel-1),common)
elif secondRel > firstRel:
if other_person.get_gender() == RelLib.Person.male:
return (get_senior_male_cousin(firstRel-1,secondRel-firstRel),common)
return (self.get_senior_male_cousin(firstRel-1,secondRel-firstRel),common)
else:
return (get_senior_female_cousin(firstRel-1,secondRel-firstRel),common)
return (self.get_senior_female_cousin(firstRel-1,secondRel-firstRel),common)
else:
if other_person.get_gender() == RelLib.Person.male:
return (get_junior_male_cousin(secondRel-1,firstRel-secondRel),common)
return (self.get_junior_male_cousin(secondRel-1,firstRel-secondRel),common)
else:
return (get_junior_female_cousin(secondRel-1,firstRel-secondRel),common)
return (self.get_junior_female_cousin(secondRel-1,firstRel-secondRel),common)
#-------------------------------------------------------------------------
@ -285,5 +297,5 @@ def get_relationship(orig_person,other_person):
#-------------------------------------------------------------------------
from Plugins import register_relcalc
register_relcalc(get_relationship,
register_relcalc(RelationshipCalculator,
["ru","RU","ru_RU","koi8r","ru_koi8r","russian","Russian","ru_RU.koi8r","ru_RU.KOI8-R","ru_RU.utf8","ru_RU.UTF8", "ru_RU.utf-8","ru_RU.UTF-8","ru_RU.iso88595","ru_RU.iso8859-5","ru_RU.iso-8859-5"])