2002-10-20 19:55:16 +05:30
|
|
|
|
#
|
|
|
|
|
# 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
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
# internationalization
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
2002-11-03 02:49:58 +05:30
|
|
|
|
from intl import gettext as _
|
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
# GTK/Gnome modules
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
import gtk.glade
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
# gramps modules
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
2003-01-10 10:51:32 +05:30
|
|
|
|
import RelLib
|
2002-10-20 19:55:16 +05:30
|
|
|
|
import const
|
|
|
|
|
import Utils
|
2002-11-03 02:49:58 +05:30
|
|
|
|
import ListModel
|
2003-05-18 09:48:12 +05:30
|
|
|
|
import GrampsCfg
|
|
|
|
|
from RelLib import Person
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
# SelectChild
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
class SelectChild:
|
|
|
|
|
|
2002-11-15 09:19:39 +05:30
|
|
|
|
def __init__(self,db,family,person,redraw,add_person):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
self.db = db
|
|
|
|
|
self.person = person
|
|
|
|
|
self.family = family
|
|
|
|
|
self.redraw = redraw
|
2002-11-15 09:19:39 +05:30
|
|
|
|
self.add_person = add_person
|
2003-03-05 11:31:31 +05:30
|
|
|
|
self.xml = gtk.glade.XML(const.gladeFile,"select_child")
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
2003-05-18 09:48:12 +05:30
|
|
|
|
if person:
|
|
|
|
|
self.default_name = person.getPrimaryName().getSurname().upper()
|
|
|
|
|
else:
|
|
|
|
|
self.default_name = ""
|
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
self.xml.signal_autoconnect({
|
|
|
|
|
"on_save_child_clicked" : self.on_save_child_clicked,
|
|
|
|
|
"on_show_toggled" : self.on_show_toggled,
|
2002-11-03 02:49:58 +05:30
|
|
|
|
"on_add_person_clicked" : self.on_add_person_clicked,
|
2003-03-05 11:31:31 +05:30
|
|
|
|
"destroy_passed_object" : self.close
|
2002-10-20 19:55:16 +05:30
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
self.select_child_list = {}
|
2003-03-05 11:31:31 +05:30
|
|
|
|
self.top = self.xml.get_widget("select_child")
|
|
|
|
|
title_label = self.xml.get_widget('title')
|
2003-03-06 11:42:51 +05:30
|
|
|
|
|
|
|
|
|
Utils.set_titles(self.top,title_label,_('Add Children'))
|
2003-03-05 11:31:31 +05:30
|
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
|
self.add_child = self.xml.get_widget("childlist")
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
|
|
if (self.family):
|
|
|
|
|
father = self.family.getFather()
|
|
|
|
|
mother = self.family.getMother()
|
|
|
|
|
|
|
|
|
|
if father != None:
|
|
|
|
|
fname = father.getPrimaryName().getName()
|
|
|
|
|
label = _("Relationship to %s") % fname
|
|
|
|
|
self.xml.get_widget("flabel").set_text(label)
|
|
|
|
|
|
|
|
|
|
if mother != None:
|
|
|
|
|
mname = mother.getPrimaryName().getName()
|
|
|
|
|
label = _("Relationship to %s") % mname
|
|
|
|
|
self.xml.get_widget("mlabel").set_text(label)
|
|
|
|
|
else:
|
|
|
|
|
fname = self.person.getPrimaryName().getName()
|
|
|
|
|
label = _("Relationship to %s") % fname
|
|
|
|
|
|
2003-01-10 10:51:32 +05:30
|
|
|
|
if self.person.getGender() == RelLib.Person.male:
|
2002-10-20 19:55:16 +05:30
|
|
|
|
self.xml.get_widget("flabel").set_text(label)
|
|
|
|
|
self.xml.get_widget("mrel_combo").set_sensitive(0)
|
|
|
|
|
else:
|
|
|
|
|
self.xml.get_widget("mlabel").set_text(label)
|
|
|
|
|
self.xml.get_widget("frel_combo").set_sensitive(0)
|
|
|
|
|
|
|
|
|
|
self.mrel = self.xml.get_widget("mrel")
|
|
|
|
|
self.frel = self.xml.get_widget("frel")
|
|
|
|
|
self.mrel.set_text(_("Birth"))
|
2002-11-03 02:49:58 +05:30
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
self.frel.set_text(_("Birth"))
|
2002-11-03 02:49:58 +05:30
|
|
|
|
|
2003-03-03 10:02:53 +05:30
|
|
|
|
titles = [(_('Name'),3,150),(_('ID'),1,50), (_('Birth date'),4,100),
|
2002-11-15 09:19:39 +05:30
|
|
|
|
('',-1,0),('',-1,0)]
|
|
|
|
|
|
|
|
|
|
self.refmodel = ListModel.ListModel(self.add_child,titles)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
self.redraw_child_list(2)
|
|
|
|
|
|
2003-03-05 11:31:31 +05:30
|
|
|
|
def close(self,obj):
|
|
|
|
|
self.top.destroy()
|
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
def redraw_child_list(self,filter):
|
2002-11-03 02:49:58 +05:30
|
|
|
|
self.refmodel.clear()
|
2003-05-22 02:38:20 +05:30
|
|
|
|
self.refmodel.new_model()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
bday = self.person.getBirth().getDateObj()
|
|
|
|
|
dday = self.person.getDeath().getDateObj()
|
|
|
|
|
|
2002-11-08 09:12:25 +05:30
|
|
|
|
slist = {}
|
2002-10-20 19:55:16 +05:30
|
|
|
|
for f in self.person.getParentList():
|
|
|
|
|
if f:
|
|
|
|
|
if f[0].getFather():
|
2002-11-08 09:12:25 +05:30
|
|
|
|
slist[f[0].getFather().getId()] = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
elif f[0].getMother():
|
2002-11-08 09:12:25 +05:30
|
|
|
|
slist[f[0].getMother().getId()] = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
for c in f[0].getChildList():
|
2002-11-08 09:12:25 +05:30
|
|
|
|
slist[c.getId()] = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
|
|
person_list = []
|
|
|
|
|
for key in self.db.getPersonKeys():
|
|
|
|
|
person = self.db.getPerson(key)
|
|
|
|
|
if filter:
|
2002-11-08 09:12:25 +05:30
|
|
|
|
if slist.has_key(key) or person.getMainParents():
|
2002-10-20 19:55:16 +05:30
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
pdday = person.getDeath().getDateObj()
|
|
|
|
|
pbday = person.getBirth().getDateObj()
|
|
|
|
|
|
|
|
|
|
if bday.getYearValid():
|
|
|
|
|
if pbday.getYearValid():
|
|
|
|
|
# reject if child birthdate < parents birthdate + 10
|
|
|
|
|
if pbday.getLowYear() < bday.getHighYear()+10:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# reject if child birthdate > parents birthdate + 90
|
|
|
|
|
if pbday.getLowYear() > bday.getHighYear()+90:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if pdday.getYearValid():
|
|
|
|
|
# reject if child deathdate < parents birthdate+ 10
|
|
|
|
|
if pdday.getLowYear() < bday.getHighYear()+10:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if dday.getYearValid():
|
|
|
|
|
if pbday.getYearValid():
|
|
|
|
|
# reject if childs birth date > parents deathday + 3
|
|
|
|
|
if pbday.getLowYear() > dday.getHighYear()+3:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if pdday.getYearValid():
|
|
|
|
|
# reject if childs death date > parents deathday + 150
|
|
|
|
|
if pdday.getLowYear() > dday.getHighYear() + 150:
|
|
|
|
|
continue
|
|
|
|
|
|
2002-11-08 09:12:25 +05:30
|
|
|
|
person_list.append(person.getId())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
2003-05-18 09:48:12 +05:30
|
|
|
|
iter = None
|
2002-11-08 09:12:25 +05:30
|
|
|
|
for idval in person_list:
|
|
|
|
|
dinfo = self.db.getPersonDisplay(idval)
|
2002-11-03 02:49:58 +05:30
|
|
|
|
rdata = [dinfo[0],dinfo[1],dinfo[3],dinfo[5],dinfo[6]]
|
2003-05-18 09:48:12 +05:30
|
|
|
|
new_iter = self.refmodel.add(rdata)
|
|
|
|
|
names = dinfo[0].split(',')
|
|
|
|
|
if len(names):
|
|
|
|
|
ln = names[0].upper()
|
|
|
|
|
if self.default_name and ln == self.default_name and not iter:
|
|
|
|
|
iter = new_iter
|
|
|
|
|
|
2003-05-22 02:38:20 +05:30
|
|
|
|
self.refmodel.connect_model()
|
|
|
|
|
|
2003-05-18 09:48:12 +05:30
|
|
|
|
if iter:
|
|
|
|
|
self.refmodel.selection.select_iter(iter)
|
|
|
|
|
path = self.refmodel.model.get_path(iter)
|
|
|
|
|
col = self.add_child.get_column(0)
|
|
|
|
|
self.add_child.scroll_to_cell(path,col,1,0.5,0.0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
2003-05-22 02:38:20 +05:30
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
|
def on_save_child_clicked(self,obj):
|
2002-11-03 02:49:58 +05:30
|
|
|
|
store,iter = self.refmodel.selection.get_selected()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
|
if not iter:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
id = self.refmodel.model.get_value(iter,1)
|
|
|
|
|
select_child = self.db.getPerson(id)
|
|
|
|
|
if self.family == None:
|
|
|
|
|
self.family = self.db.newFamily()
|
|
|
|
|
self.person.addFamily(self.family)
|
2003-01-10 10:51:32 +05:30
|
|
|
|
if self.person.getGender() == RelLib.Person.male:
|
2002-11-03 02:49:58 +05:30
|
|
|
|
self.family.setFather(self.person)
|
|
|
|
|
else:
|
|
|
|
|
self.family.setMother(self.person)
|
|
|
|
|
|
|
|
|
|
self.family.addChild(select_child)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
|
mrel = const.childRelations[self.mrel.get_text()]
|
|
|
|
|
mother = self.family.getMother()
|
2003-01-10 10:51:32 +05:30
|
|
|
|
if mother and mother.getGender() != RelLib.Person.female:
|
2002-11-03 02:49:58 +05:30
|
|
|
|
if mrel == "Birth":
|
|
|
|
|
mrel = "Unknown"
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
|
frel = const.childRelations[self.frel.get_text()]
|
|
|
|
|
father = self.family.getFather()
|
2003-01-10 10:51:32 +05:30
|
|
|
|
if father and father.getGender() !=RelLib. Person.male:
|
2002-11-03 02:49:58 +05:30
|
|
|
|
if frel == "Birth":
|
|
|
|
|
frel = "Unknown"
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
|
select_child.addAltFamily(self.family,mrel,frel)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
|
Utils.modified()
|
2003-03-05 11:31:31 +05:30
|
|
|
|
self.top.destroy()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
self.redraw(self.family)
|
|
|
|
|
|
|
|
|
|
def on_show_toggled(self,obj):
|
2003-03-03 10:02:53 +05:30
|
|
|
|
self.redraw_child_list(not obj.get_active())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
|
def on_add_person_clicked(self,obj):
|
|
|
|
|
"""Called with the Add button is pressed. Calls the QuickAdd
|
|
|
|
|
class to create a new person."""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
2002-11-03 02:49:58 +05:30
|
|
|
|
import QuickAdd
|
2003-05-18 09:48:12 +05:30
|
|
|
|
|
|
|
|
|
autoname = GrampsCfg.lastnamegen
|
|
|
|
|
|
|
|
|
|
if autoname == 0:
|
|
|
|
|
name = self.north_american(0)
|
|
|
|
|
elif autoname == 2:
|
|
|
|
|
name = self.latin_american(0)
|
|
|
|
|
elif autoname == 3:
|
|
|
|
|
name = self.icelandic(0)
|
|
|
|
|
else:
|
|
|
|
|
name = ""
|
|
|
|
|
QuickAdd.QuickAdd(self.db,"male",self.add_new_parent, name)
|
2002-11-03 02:49:58 +05:30
|
|
|
|
|
|
|
|
|
def add_new_parent(self,person):
|
|
|
|
|
"""Adds a new person to either the father list or the mother list,
|
|
|
|
|
depending on the gender of the person."""
|
|
|
|
|
id = person.getId()
|
|
|
|
|
dinfo = self.db.getPersonDisplay(id)
|
|
|
|
|
rdata = [dinfo[0],dinfo[1],dinfo[3],dinfo[5],dinfo[6]]
|
2002-11-15 09:19:39 +05:30
|
|
|
|
self.refmodel.add_and_select(rdata)
|
|
|
|
|
self.add_person(person)
|
2003-06-02 04:16:00 +05:30
|
|
|
|
self.refmodel.center_selected()
|
2003-05-18 09:48:12 +05:30
|
|
|
|
|
|
|
|
|
def north_american(self,val):
|
|
|
|
|
if self.person.getGender() == Person.male:
|
|
|
|
|
return self.person.getPrimaryName().getSurname()
|
|
|
|
|
elif self.family:
|
|
|
|
|
f = self.family.getFather()
|
|
|
|
|
if f:
|
|
|
|
|
return f.getPrimaryName().getSurname()
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
def no_name(self,val):
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
def latin_american(self,val):
|
|
|
|
|
if self.family:
|
|
|
|
|
father = self.family.getFather()
|
|
|
|
|
mother = self.family.getMother()
|
|
|
|
|
if not father or not mother:
|
|
|
|
|
return ""
|
|
|
|
|
fsn = father.getPrimaryName().getSurname()
|
|
|
|
|
msn = mother.getPrimaryName().getSurname()
|
|
|
|
|
if not father or not mother:
|
|
|
|
|
return ""
|
|
|
|
|
try:
|
|
|
|
|
return "%s %s" % (fsn.split()[0],msn.split()[0])
|
|
|
|
|
except:
|
|
|
|
|
return ""
|
|
|
|
|
else:
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
def icelandic(self,val):
|
|
|
|
|
fname = ""
|
|
|
|
|
if self.person.getGender() == Person.male:
|
|
|
|
|
fname = self.person.getPrimaryName().getFirstName()
|
|
|
|
|
elif self.family:
|
|
|
|
|
f = self.family.getFather()
|
|
|
|
|
if f:
|
|
|
|
|
fname = f.getPrimaryName().getFirstName()
|
|
|
|
|
if fname:
|
|
|
|
|
fname = string.split(fname)[0]
|
|
|
|
|
if val == 0:
|
|
|
|
|
return "%ssson" % fname
|
|
|
|
|
elif val == 1:
|
|
|
|
|
return "%sd<EFBFBD>ttir" % fname
|
|
|
|
|
else:
|
|
|
|
|
return ""
|