2001-10-19 05:38:30 +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
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2001-11-02 23:16:33 +05:30
|
|
|
from intl import gettext
|
|
|
|
_ = gettext
|
2001-10-19 05:38:30 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import libglade
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2001-12-09 10:54:29 +05:30
|
|
|
import RelLib
|
2001-10-19 05:38:30 +05:30
|
|
|
import const
|
|
|
|
import sort
|
2002-02-22 09:25:32 +05:30
|
|
|
import Utils
|
|
|
|
import GrampsCfg
|
2001-10-19 05:38:30 +05:30
|
|
|
|
2002-04-14 20:19:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ChooseParents
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2001-10-19 05:38:30 +05:30
|
|
|
class ChooseParents:
|
2001-12-09 10:54:29 +05:30
|
|
|
"""
|
|
|
|
Displays the Choose Parents dialog box, allowing the parents
|
|
|
|
to be edited.
|
|
|
|
"""
|
2001-10-30 09:18:57 +05:30
|
|
|
def __init__(self,db,person,family,family_update,full_update):
|
2001-10-19 05:38:30 +05:30
|
|
|
self.db = db
|
|
|
|
self.person = person
|
|
|
|
self.family = family
|
2001-10-30 09:18:57 +05:30
|
|
|
self.family_update = family_update
|
|
|
|
self.full_update = full_update
|
2002-03-28 19:54:59 +05:30
|
|
|
self.old_type = ""
|
|
|
|
self.type = ""
|
2001-10-19 05:38:30 +05:30
|
|
|
|
|
|
|
if self.family:
|
|
|
|
self.father = self.family.getFather()
|
|
|
|
self.mother = self.family.getMother()
|
|
|
|
else:
|
|
|
|
self.mother = None
|
|
|
|
self.father = None
|
|
|
|
|
|
|
|
self.glade = libglade.GladeXML(const.gladeFile,"familyDialog")
|
|
|
|
self.top = self.glade.get_widget("familyDialog")
|
2001-12-09 10:54:29 +05:30
|
|
|
self.mother_rel = self.glade.get_widget("mrel")
|
|
|
|
self.father_rel = self.glade.get_widget("frel")
|
2001-10-19 05:38:30 +05:30
|
|
|
self.fcombo = self.glade.get_widget("prel_combo")
|
|
|
|
self.prel = self.glade.get_widget("prel")
|
|
|
|
self.title = self.glade.get_widget("chooseTitle")
|
|
|
|
self.father_list = self.glade.get_widget("fatherList")
|
|
|
|
self.mother_list = self.glade.get_widget("motherList")
|
|
|
|
self.flabel = self.glade.get_widget("flabel")
|
|
|
|
self.mlabel = self.glade.get_widget("mlabel")
|
2001-11-27 07:56:02 +05:30
|
|
|
self.fcombo.set_popdown_strings(const.familyRelations)
|
|
|
|
|
2002-03-28 19:54:59 +05:30
|
|
|
self.mother_list.set_column_visibility(2,0)
|
|
|
|
self.father_list.set_column_visibility(2,0)
|
|
|
|
self.mother_list.set_sort_column(2)
|
|
|
|
self.father_list.set_sort_column(2)
|
|
|
|
|
2002-03-25 02:27:53 +05:30
|
|
|
for (f,mr,fr) in self.person.getParentList():
|
|
|
|
if f == self.family:
|
|
|
|
self.mother_rel.set_text(_(mr))
|
|
|
|
self.father_rel.set_text(_(fr))
|
|
|
|
break
|
|
|
|
else:
|
2001-12-09 10:54:29 +05:30
|
|
|
self.mother_rel.set_text(_("Birth"))
|
|
|
|
self.father_rel.set_text(_("Birth"))
|
2001-10-19 05:38:30 +05:30
|
|
|
|
2002-03-29 06:26:28 +05:30
|
|
|
if self.family:
|
|
|
|
self.type = self.family.getRelationship()
|
|
|
|
else:
|
|
|
|
self.type = "Married"
|
2002-03-28 19:54:59 +05:30
|
|
|
self.prel.set_text(_(self.type))
|
|
|
|
self.redraw()
|
|
|
|
|
2001-10-19 05:38:30 +05:30
|
|
|
self.glade.signal_autoconnect({
|
2001-12-09 10:54:29 +05:30
|
|
|
"on_motherList_select_row" : self.mother_list_select_row,
|
|
|
|
"on_fatherList_select_row" : self.father_list_select_row,
|
|
|
|
"on_save_parents_clicked" : self.save_parents_clicked,
|
2002-03-26 21:13:04 +05:30
|
|
|
"on_add_parent_clicked" : self.add_parent_clicked,
|
2001-12-09 10:54:29 +05:30
|
|
|
"on_prel_changed" : self.parent_relation_changed,
|
2002-02-22 09:25:32 +05:30
|
|
|
"on_combo_insert_text" : Utils.combo_insert_text,
|
|
|
|
"destroy_passed_object" : Utils.destroy_passed_object
|
2001-10-19 05:38:30 +05:30
|
|
|
})
|
|
|
|
|
2002-02-22 09:25:32 +05:30
|
|
|
text = _("Choose the Parents of %s") % GrampsCfg.nameof(self.person)
|
2001-10-19 05:38:30 +05:30
|
|
|
self.title.set_text(text)
|
|
|
|
self.top.show()
|
|
|
|
|
2002-03-28 19:54:59 +05:30
|
|
|
def redraw(self):
|
2001-10-19 05:38:30 +05:30
|
|
|
|
|
|
|
self.father_list.freeze()
|
|
|
|
self.mother_list.freeze()
|
|
|
|
self.father_list.clear()
|
|
|
|
self.mother_list.clear()
|
|
|
|
|
2002-03-28 19:54:59 +05:30
|
|
|
self.father_list.append(["Unknown","",""])
|
2001-10-19 05:38:30 +05:30
|
|
|
self.father_list.set_row_data(0,None)
|
|
|
|
|
2002-03-28 19:54:59 +05:30
|
|
|
self.mother_list.append(["Unknown","",""])
|
2001-10-19 05:38:30 +05:30
|
|
|
self.mother_list.set_row_data(0,None)
|
|
|
|
|
|
|
|
father_index = 1
|
|
|
|
mother_index = 1
|
2002-03-26 21:13:04 +05:30
|
|
|
fsel = 0
|
|
|
|
msel = 0
|
2002-06-14 10:00:20 +05:30
|
|
|
for key in self.db.getPersonKeys():
|
|
|
|
person = self.db.getPerson(key)
|
2001-12-09 10:54:29 +05:30
|
|
|
if person == self.person:
|
|
|
|
continue
|
|
|
|
if person.getGender() == RelLib.Person.unknown:
|
2001-10-19 05:38:30 +05:30
|
|
|
continue
|
2002-03-26 21:13:04 +05:30
|
|
|
if self.father == person:
|
|
|
|
fsel = father_index
|
|
|
|
if self.mother == person:
|
|
|
|
msel = mother_index
|
2002-03-28 19:54:59 +05:30
|
|
|
name = person.getPrimaryName()
|
|
|
|
rdata = [Utils.phonebook_name(person),Utils.birthday(person),
|
|
|
|
sort.build_sort_name(name)]
|
|
|
|
if self.type == "Partners":
|
2001-10-19 05:38:30 +05:30
|
|
|
self.father_list.append(rdata)
|
|
|
|
self.father_list.set_row_data(father_index,person)
|
|
|
|
father_index = father_index + 1
|
|
|
|
self.mother_list.append(rdata)
|
|
|
|
self.mother_list.set_row_data(mother_index,person)
|
|
|
|
mother_index = mother_index + 1
|
2001-12-09 10:54:29 +05:30
|
|
|
elif person.getGender() == RelLib.Person.male:
|
2001-10-19 05:38:30 +05:30
|
|
|
self.father_list.append(rdata)
|
|
|
|
self.father_list.set_row_data(father_index,person)
|
|
|
|
father_index = father_index + 1
|
|
|
|
else:
|
|
|
|
self.mother_list.append(rdata)
|
|
|
|
self.mother_list.set_row_data(mother_index,person)
|
|
|
|
mother_index = mother_index + 1
|
|
|
|
|
2002-03-26 21:13:04 +05:30
|
|
|
self.mother_list.select_row(msel,0)
|
2002-03-28 19:54:59 +05:30
|
|
|
self.mother_list.sort()
|
2002-03-26 21:13:04 +05:30
|
|
|
self.father_list.select_row(fsel,0)
|
2002-03-28 19:54:59 +05:30
|
|
|
self.father_list.sort()
|
|
|
|
self.mother_list.thaw()
|
|
|
|
self.father_list.thaw()
|
|
|
|
self.father_list.moveto(self.father_list.selection[0],0)
|
|
|
|
self.mother_list.moveto(self.mother_list.selection[0],0)
|
|
|
|
|
|
|
|
if self.type == "Partners":
|
2002-03-26 21:13:04 +05:30
|
|
|
self.mlabel.set_label(_("Parent"))
|
|
|
|
self.flabel.set_label(_("Parent"))
|
2001-10-19 05:38:30 +05:30
|
|
|
else:
|
2002-03-26 21:13:04 +05:30
|
|
|
self.mlabel.set_label(_("Mother"))
|
|
|
|
self.flabel.set_label(_("Father"))
|
2001-10-19 05:38:30 +05:30
|
|
|
|
2002-03-28 19:54:59 +05:30
|
|
|
def parent_relation_changed(self,obj):
|
|
|
|
self.old_type = self.type
|
|
|
|
self.type = const.save_frel(obj.get_text())
|
|
|
|
if self.old_type == "Partners" or self.type == "Partners":
|
|
|
|
self.redraw()
|
|
|
|
|
2001-10-19 05:38:30 +05:30
|
|
|
def find_family(self,father,mother):
|
2001-12-09 10:54:29 +05:30
|
|
|
"""
|
|
|
|
Finds the family associated with the father and mother.
|
|
|
|
If one does not exist, it is created.
|
|
|
|
"""
|
2001-10-19 05:38:30 +05:30
|
|
|
if not father and not mother:
|
|
|
|
return None
|
|
|
|
|
|
|
|
families = self.db.getFamilyMap().values()
|
|
|
|
for family in families:
|
|
|
|
if family.getFather() == father and family.getMother() == mother:
|
|
|
|
return family
|
|
|
|
elif family.getFather() == mother and family.getMother() == father:
|
|
|
|
return family
|
|
|
|
|
|
|
|
family = self.db.newFamily()
|
|
|
|
family.setFather(father)
|
|
|
|
family.setMother(mother)
|
2001-10-24 12:21:36 +05:30
|
|
|
family.addChild(self.person)
|
2001-10-19 05:38:30 +05:30
|
|
|
|
|
|
|
if father:
|
2001-10-24 12:21:36 +05:30
|
|
|
father.addFamily(family)
|
2001-10-19 05:38:30 +05:30
|
|
|
if mother:
|
2001-10-24 12:21:36 +05:30
|
|
|
mother.addFamily(family)
|
2001-10-19 05:38:30 +05:30
|
|
|
return family
|
|
|
|
|
2001-12-09 10:54:29 +05:30
|
|
|
def mother_list_select_row(self,obj,a,b,c):
|
2001-10-19 05:38:30 +05:30
|
|
|
self.mother = obj.get_row_data(a)
|
|
|
|
|
2001-12-09 10:54:29 +05:30
|
|
|
def father_list_select_row(self,obj,a,b,c):
|
2001-10-19 05:38:30 +05:30
|
|
|
self.father = obj.get_row_data(a)
|
|
|
|
|
2001-12-09 10:54:29 +05:30
|
|
|
def save_parents_clicked(self,obj):
|
|
|
|
mother_rel = const.childRelations[self.mother_rel.get_text()]
|
|
|
|
father_rel = const.childRelations[self.father_rel.get_text()]
|
2001-10-19 05:38:30 +05:30
|
|
|
|
|
|
|
if self.father or self.mother:
|
|
|
|
if self.mother and not self.father:
|
2001-12-09 10:54:29 +05:30
|
|
|
if self.mother.getGender() == RelLib.Person.male:
|
2001-10-24 12:21:36 +05:30
|
|
|
self.father = self.mother
|
2001-10-19 05:38:30 +05:30
|
|
|
self.mother = None
|
|
|
|
self.family = self.find_family(self.father,self.mother)
|
|
|
|
elif self.father and not self.mother:
|
2001-12-09 10:54:29 +05:30
|
|
|
if self.father.getGender() == RelLib.Person.female:
|
2001-10-19 05:38:30 +05:30
|
|
|
self.mother = self.father
|
|
|
|
self.father = None
|
|
|
|
self.family = self.find_family(self.father,self.mother)
|
|
|
|
elif self.mother.getGender() != self.father.getGender():
|
2002-03-28 19:54:59 +05:30
|
|
|
if self.type == "Partners":
|
|
|
|
self.type = "Unknown"
|
2001-12-09 10:54:29 +05:30
|
|
|
if self.father.getGender() == RelLib.Person.female:
|
2001-10-19 05:38:30 +05:30
|
|
|
x = self.father
|
|
|
|
self.father = self.mother
|
|
|
|
self.mother = x
|
|
|
|
self.family = self.find_family(self.father,self.mother)
|
|
|
|
else:
|
2002-03-28 19:54:59 +05:30
|
|
|
self.type = "Partners"
|
2001-10-19 05:38:30 +05:30
|
|
|
self.family = self.find_family(self.father,self.mother)
|
|
|
|
else:
|
|
|
|
self.family = None
|
|
|
|
|
2002-02-22 09:25:32 +05:30
|
|
|
Utils.destroy_passed_object(obj)
|
2001-10-19 05:38:30 +05:30
|
|
|
if self.family:
|
2002-03-28 19:54:59 +05:30
|
|
|
self.family.setRelationship(self.type)
|
2001-12-09 10:54:29 +05:30
|
|
|
self.change_family_type(self.family,mother_rel,father_rel)
|
2002-03-16 22:56:58 +05:30
|
|
|
self.family_update(None)
|
2001-10-19 05:38:30 +05:30
|
|
|
|
2002-03-26 21:13:04 +05:30
|
|
|
def add_new_parent(self,person):
|
2002-03-28 19:54:59 +05:30
|
|
|
self.type = const.save_frel(self.prel.get_text())
|
|
|
|
rdata = [Utils.phonebook_name(person),Utils.birthday(person),
|
|
|
|
sort.build_sort_name(person.getPrimaryName())]
|
|
|
|
|
|
|
|
if self.type == "Partners":
|
|
|
|
self.parent_relation_changed(self.prel)
|
|
|
|
elif person.getGender() == RelLib.Person.male:
|
|
|
|
self.father_list.insert(0,rdata)
|
|
|
|
self.father_list.set_row_data(0,person)
|
|
|
|
self.father_list.select_row(0,0)
|
|
|
|
self.father_list.sort()
|
|
|
|
self.father_list.moveto(self.father_list.selection[0],0)
|
|
|
|
else:
|
|
|
|
self.mother_list.insert(0,rdata)
|
|
|
|
self.mother_list.set_row_data(0,person)
|
|
|
|
self.mother_list.select_row(0,0)
|
|
|
|
self.mother_list.moveto(0,0)
|
|
|
|
self.mother_list.sort()
|
|
|
|
self.mother_list.moveto(self.mother_list.selection[0],0)
|
2002-03-26 21:13:04 +05:30
|
|
|
self.full_update()
|
|
|
|
|
|
|
|
def add_parent_clicked(self,obj):
|
|
|
|
import QuickAdd
|
|
|
|
QuickAdd.QuickAdd(self.db,"male",self.add_new_parent)
|
2001-12-09 10:54:29 +05:30
|
|
|
|
|
|
|
def change_family_type(self,family,mother_rel,father_rel):
|
|
|
|
"""
|
|
|
|
Changes the family type of the specified family. If the family
|
|
|
|
is None, the the relationship type shoud be deleted.
|
|
|
|
"""
|
2002-03-24 08:45:54 +05:30
|
|
|
if self.person not in family.getChildList():
|
|
|
|
family.addChild(self.person)
|
2002-03-25 02:27:53 +05:30
|
|
|
for fam in self.person.getParentList():
|
2002-03-24 08:45:54 +05:30
|
|
|
if family == fam[0]:
|
|
|
|
if mother_rel == fam[1] and father_rel == fam[2]:
|
|
|
|
return
|
|
|
|
if mother_rel != fam[1] or father_rel != fam[2]:
|
|
|
|
self.person.removeAltFamily(family)
|
2001-12-09 10:54:29 +05:30
|
|
|
self.person.addAltFamily(family,mother_rel,father_rel)
|
2002-03-24 08:45:54 +05:30
|
|
|
break
|
2001-10-19 05:38:30 +05:30
|
|
|
else:
|
2002-03-24 08:45:54 +05:30
|
|
|
self.person.addAltFamily(family,mother_rel,father_rel)
|
2002-02-22 09:25:32 +05:30
|
|
|
Utils.modified()
|
2001-10-19 05:38:30 +05:30
|
|
|
|