gramps/src/AddSpouse.py

370 lines
13 KiB
Python
Raw Normal View History

2002-10-20 19:55:16 +05:30
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2004 Donald N. Allingham
2002-10-20 19:55:16 +05:30
#
# 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
#
# $Id$
2002-10-20 19:55:16 +05:30
"""
The AddSpouse module provides the AddSpouse class that allows the user to
add a new spouse to the active person.
"""
__author__ = "Donald N. Allingham"
__version__ = "$Revision$"
#-------------------------------------------------------------------------
#
# internationalization
#
#-------------------------------------------------------------------------
2003-08-17 07:44:33 +05:30
from gettext import gettext as _
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
import gtk.glade
import gnome
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# gramps modules
#
#-------------------------------------------------------------------------
import RelLib
import const
import Utils
import GrampsCfg
import PeopleModel
2004-02-26 10:21:57 +05:30
import Date
2004-05-14 04:15:51 +05:30
import Marriage
2002-10-20 19:55:16 +05:30
#-------------------------------------------------------------------------
#
# AddSpouse
#
#-------------------------------------------------------------------------
class AddSpouse:
"""
Displays the AddSpouse dialog, allowing the user to create a new
family with the passed person as one spouse, and another person to
be selected.
"""
def __init__(self,parent,db,person,update,addperson,family=None):
2002-10-20 19:55:16 +05:30
"""
Displays the AddSpouse dialog box.
db - database to which to add the new family
person - the current person, will be one of the parents
update - function that updates the family display
addperson - function that adds a person to the person view
"""
self.parent = parent
2002-10-20 19:55:16 +05:30
self.db = db
self.update = update
self.person = person
self.gender = self.person.get_gender()
2002-10-20 19:55:16 +05:30
self.addperson = addperson
2002-11-28 11:22:02 +05:30
self.active_family = family
2002-10-20 19:55:16 +05:30
self.filter_func = self.likely_filter
# determine the gender of the people to be loaded into
# the potential spouse list. If Partners is selected, use
# the same gender as the current person.
birth_id = self.person.get_birth_id()
death_id = self.person.get_death_id()
self.bday = self.db.find_event_from_id(birth_id)
self.dday = self.db.find_event_from_id(death_id)
if birth_id:
self.bday = self.db.find_event_from_id(birth_id).get_date_object()
else:
self.bday = Date.Date()
if death_id:
self.dday = self.db.find_event_from_id(death_id).get_date_object()
else:
self.dday = Date.Date()
2003-08-17 07:44:33 +05:30
self.glade = gtk.glade.XML(const.gladeFile, "spouseDialog","gramps")
2002-10-20 19:55:16 +05:30
self.relation_def = self.glade.get_widget("reldef")
2002-10-20 19:55:16 +05:30
self.rel_combo = self.glade.get_widget("rel_combo")
self.relation_type = self.glade.get_widget("rel_type")
self.spouse_list = self.glade.get_widget("spouse_list")
self.showall = self.glade.get_widget('showall')
self.set_gender()
self.renderer = gtk.CellRendererText()
self.slist = PeopleModel.PeopleModel(self.db)
self.spouse_list.set_model(self.slist)
self.selection = self.spouse_list.get_selection()
self.selection.connect('changed',self.select_row)
self.add_columns(self.spouse_list)
2002-10-20 19:55:16 +05:30
self.ok = self.glade.get_widget('spouse_ok')
self.ok.set_sensitive(0)
self.rel_combo.set_popdown_strings(const.familyRelations)
title = _("Choose Spouse/Partner of %s") % GrampsCfg.nameof(person)
2003-03-06 11:42:51 +05:30
Utils.set_titles(self.glade.get_widget('spouseDialog'),
self.glade.get_widget('title'),title,
_('Choose Spouse/Partner'))
2002-10-20 19:55:16 +05:30
2002-10-20 19:55:16 +05:30
self.glade.signal_autoconnect({
"on_select_spouse_clicked" : self.select_spouse_clicked,
"on_spouse_help_clicked" : self.on_spouse_help_clicked,
"on_show_toggled" : self.on_show_toggled,
2002-10-20 19:55:16 +05:30
"on_new_spouse_clicked" : self.new_spouse_clicked,
"on_rel_type_changed" : self.relation_type_changed,
"destroy_passed_object" : Utils.destroy_passed_object
})
self.relation_type.set_text(_("Married"))
self.update_data()
2002-10-20 19:55:16 +05:30
def add_columns(self,tree):
column = gtk.TreeViewColumn(_('Name'), self.renderer,text=0)
column.set_resizable(gtk.TRUE)
#column.set_clickable(gtk.TRUE)
column.set_min_width(225)
tree.append_column(column)
column = gtk.TreeViewColumn(_('ID'), self.renderer,text=1)
column.set_resizable(gtk.TRUE)
#column.set_clickable(gtk.TRUE)
column.set_min_width(75)
tree.append_column(column)
column = gtk.TreeViewColumn(_('Birth date'), self.renderer,text=3)
#column.set_resizable(gtk.TRUE)
column.set_clickable(gtk.TRUE)
tree.append_column(column)
def on_spouse_help_clicked(self,obj):
"""Display the relevant portion of GRAMPS manual"""
gnome.help_display('gramps-manual','gramps-edit-quick')
def get_selected_ids(self):
mlist = []
self.selection.selected_foreach(self.select_function,mlist)
return mlist
def select_function(self,store,path,iter,id_list):
id_list.append(store.get_value(iter,PeopleModel.COLUMN_INT_ID))
2002-10-20 19:55:16 +05:30
def select_row(self,obj):
"""
Called with a row has be unselected. Used to enable the OK button
2002-10-20 19:55:16 +05:30
when a row has been selected.
"""
idlist = self.get_selected_ids()
if idlist and idlist[0]:
2002-10-20 19:55:16 +05:30
self.ok.set_sensitive(1)
else:
self.ok.set_sensitive(0)
def new_spouse_clicked(self,obj):
"""
Called when the spouse to be added does not exist, and needs
to be created and added to the database
"""
import EditPerson
2002-10-20 19:55:16 +05:30
* src/PlaceView.py: Make sure to add new place after edit * src/AddMedia.py: unicode conversion from gtk.Entry * src/AddSpouse.py: unicode conversion from gtk.Entry * src/AddrEdit.py: unicode conversion from gtk.Entry * src/AttrEdit.py: unicode conversion from gtk.Entry * src/AutoComp.py: unicode conversion from gtk.Entry * src/ChooseParents.py: unicode conversion from gtk.Entry * src/DateEdit.py: unicode conversion from gtk.Entry * src/EditPerson.py: unicode conversion from gtk.Entry * src/EditPlace.py: unicode conversion from gtk.Entry * src/EditSource.py: unicode conversion from gtk.Entry * src/EventEdit.py: unicode conversion from gtk.Entry * src/Find.py: unicode conversion from gtk.Entry * src/GrampsCfg.py: unicode conversion from gtk.Entry * src/ImageSelect.py: unicode conversion from gtk.Entry * src/LocEdit.py: unicode conversion from gtk.Entry * src/Marriage.py: unicode conversion from gtk.Entry * src/MergeData.py: unicode conversion from gtk.Entry * src/NameEdit.py: unicode conversion from gtk.Entry * src/PeopleView.py: unicode conversion from gtk.Entry * src/Report.py: unicode conversion from gtk.Entry * src/SelectChild.py: unicode conversion from gtk.Entry * src/Sources.py: unicode conversion from gtk.Entry * src/StartupDialog.py: unicode conversion from gtk.Entry * src/StyleEditor.py: unicode conversion from gtk.Entry * src/UrlEdit.py: unicode conversion from gtk.Entry * src/Utils.py: unicode conversion from gtk.Entry * src/VersionControl.py: unicode conversion from gtk.Entry * src/Witness.py: unicode conversion from gtk.Entry svn: r2534
2003-12-17 10:53:16 +05:30
relation = const.save_frel(unicode(self.relation_type.get_text()))
2002-10-20 19:55:16 +05:30
if relation == "Partners":
if self.person.get_gender() == RelLib.Person.male:
gen = RelLib.Person.male
2002-10-20 19:55:16 +05:30
else:
gen = RelLib.Person.female
elif self.person.get_gender() == RelLib.Person.male:
gen = RelLib.Person.female
2002-10-20 19:55:16 +05:30
else:
gen = RelLib.Person.male
2002-10-20 19:55:16 +05:30
person = RelLib.Person()
person.set_gender(gen)
EditPerson.EditPerson(self.parent,person,self.db,self.update_list)
2002-10-20 19:55:16 +05:30
def update_list(self,epo,change):
2002-10-20 19:55:16 +05:30
"""
Updates the potential spouse list after a person has been added
to database. Called by the QuickAdd class when the dialog has
been closed.
"""
person = epo.person
trans = self.db.start_transaction()
id = person.get_id()
if id == "":
id = self.db.add_person(person,trans)
else:
self.db.add_person_no_map(person,id,trans)
person = self.db.try_to_find_person_from_id(id)
n = person.get_primary_name().get_name()
self.db.add_transaction(trans,_('Add Person (%s)' % n))
2002-10-20 19:55:16 +05:30
self.addperson(person)
self.update_data(id)
self.slist = PeopleModel.PeopleModel(self.db)
self.slist.rebuild_data()
self.spouse_list.set_model(self.slist)
path = self.slist.on_get_path(person.get_id())
top_path = self.slist.on_get_path(person.get_primary_name().get_surname())
self.spouse_list.expand_row(top_path,0)
self.selection.select_path(path)
#self.spouse_list.scroll_to_cell(path,None,1,0.5,0)
#self.slist.center_selected()
2002-10-20 19:55:16 +05:30
def select_spouse_clicked(self,obj):
"""
Called when the spouse to be added already exists and has been
selected from the list.
"""
idlist = self.get_selected_ids()
if not idlist or not idlist[0]:
2002-10-20 19:55:16 +05:30
return
spouse = self.db.get_person(idlist[0])
2002-10-20 19:55:16 +05:30
# don't do anything if the marriage already exists
for f in self.person.get_family_id_list():
fam = self.db.find_family_from_id(f)
if spouse.get_id() == fam.get_mother_id() or spouse.get_id() == fam.get_father_id():
2002-10-20 19:55:16 +05:30
Utils.destroy_passed_object(obj)
return
trans = self.db.start_transaction()
2002-11-28 11:22:02 +05:30
if not self.active_family:
self.active_family = self.db.new_family(trans)
self.person.add_family_id(self.active_family.get_id())
self.db.commit_person(self.person,trans)
spouse.add_family_id(self.active_family.get_id())
self.db.commit_person(spouse,trans)
2002-10-20 19:55:16 +05:30
if self.person.get_gender() == RelLib.Person.male:
self.active_family.set_mother_id(spouse.get_id())
self.active_family.set_father_id(self.person.get_id())
2002-10-20 19:55:16 +05:30
else:
self.active_family.set_father_id(spouse.get_id())
self.active_family.set_mother_id(self.person.get_id())
2002-10-20 19:55:16 +05:30
rtype = const.save_frel(unicode(self.relation_type.get_text()))
self.active_family.set_relationship(rtype)
self.db.commit_family(self.active_family,trans)
2004-05-19 11:43:36 +05:30
self.db.add_transaction(trans,_("Add Spouse"))
2002-10-20 19:55:16 +05:30
Utils.destroy_passed_object(obj)
2002-11-28 11:22:02 +05:30
self.update(self.active_family)
2004-04-17 00:45:02 +05:30
m = Marriage.Marriage(self.parent, self.active_family,
self.parent.db, self.parent.new_after_edit,
self.parent.family_view.load_family)
m.on_add_clicked()
2002-10-20 19:55:16 +05:30
def relation_type_changed(self,obj):
self.update_data()
def all_filter(self, person):
return person.get_gender() != self.sgender
2002-10-20 19:55:16 +05:30
def likely_filter(self, person):
if person.get_gender() == self.sgender:
return 0
2004-02-26 10:21:57 +05:30
pd_id = person.get_death_id()
pb_id = person.get_birth_id()
if pd_id:
pdday = self.db.find_event_from_id(pd_id).get_date_object()
2004-02-26 10:21:57 +05:30
else:
pdday = Date.Date()
if pb_id:
pbday = self.db.find_event_from_id(pb_id).get_date_object()
else:
pbday = Date.Date()
if self.bday.get_year_valid():
if pbday.get_year_valid():
# reject if person birthdate differs more than
# 100 years from spouse birthdate
if abs(pbday.get_year() - self.bday.get_year()) > 100:
return 0
if pdday.get_year_valid():
# reject if person birthdate is after the spouse deathdate
if self.bday.get_low_year() + 10 > pdday.get_high_year():
return 0
# reject if person birthdate is more than 100 years
# before the spouse deathdate
if self.bday.get_high_year() + 100 < pdday.get_low_year():
return 0
if self.dday.get_year_valid():
if pbday.get_year_valid():
# reject if person deathdate was prior to
# the spouse birthdate
if self.dday.get_high_year() < pbday.get_low_year() + 10:
return 0
if pdday.get_year_valid():
# reject if person deathdate differs more than
# 100 years from spouse deathdate
if abs(pdday.get_year() - self.dday.get_year()) > 100:
return 0
return 1
def set_gender(self):
text = unicode(self.relation_type.get_text())
self.relation_def.set_text(const.relationship_def(text))
2002-10-20 19:55:16 +05:30
if text == _("Partners"):
if self.gender == RelLib.Person.male:
self.sgender = RelLib.Person.female
2002-10-20 19:55:16 +05:30
else:
self.sgender = RelLib.Person.male
2002-10-20 19:55:16 +05:30
else:
if self.gender == RelLib.Person.male:
self.sgender = RelLib.Person.male
2002-10-20 19:55:16 +05:30
else:
self.sgender = RelLib.Person.female
def update_data(self,person = None):
"""
Called whenever the relationship type changes. Rebuilds the
the potential spouse list.
"""
self.slist = PeopleModel.PeopleModel(self.db)
self.spouse_list.set_model(self.slist)
2002-10-20 19:55:16 +05:30
def on_show_toggled(self,obj):
if self.filter_func == self.likely_filter:
self.filter_func = self.all_filter
else:
self.filter_func = self.likely_filter
self.update_data()