2
# Gramps - a GTK+/GNOME based genealogy program
4
# Copyright (C) 2000-2003 Donald N. Allingham
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
# $Id: AddSpouse.py,v 1.23 2003/12/17 18:38:02 dallingham Exp $
24
The AddSpouse module provides the AddSpouse class that allows the user to
25
add a new spouse to the active person.
28
__author__ = "Donald N. Allingham"
29
__version__ = "$Revision: 1.23 $"
31
#-------------------------------------------------------------------------
33
# internationalization
35
#-------------------------------------------------------------------------
36
from gettext import gettext as _
38
#-------------------------------------------------------------------------
42
#-------------------------------------------------------------------------
46
#-------------------------------------------------------------------------
50
#-------------------------------------------------------------------------
57
#-------------------------------------------------------------------------
61
#-------------------------------------------------------------------------
64
Displays the AddSpouse dialog, allowing the user to create a new
65
family with the passed person as one spouse, and another person to
68
def __init__(self,db,person,update,addperson,family=None):
70
Displays the AddSpouse dialog box.
72
db - database to which to add the new family
73
person - the current person, will be one of the parents
74
update - function that updates the family display
75
addperson - function that adds a person to the person view
80
self.addperson = addperson
81
self.active_family = family
83
self.glade = gtk.glade.XML(const.gladeFile, "spouseDialog","gramps")
85
self.rel_combo = self.glade.get_widget("rel_combo")
86
self.relation_type = self.glade.get_widget("rel_type")
87
self.spouse_list = self.glade.get_widget("spouse_list")
88
self.showall = self.glade.get_widget('showall')
90
titles = [ (_('Name'),3,200), (_('ID'),1,50), (_('Birth date'),4,50),
93
self.slist = ListModel.ListModel(self.spouse_list, titles,
96
self.relation_def = self.glade.get_widget("reldef")
97
self.ok = self.glade.get_widget('spouse_ok')
98
self.ok.set_sensitive(0)
100
self.rel_combo.set_popdown_strings(const.familyRelations)
101
title = _("Choose Spouse/Partner of %s") % GrampsCfg.nameof(person)
103
Utils.set_titles(self.glade.get_widget('spouseDialog'),
104
self.glade.get_widget('title'),title,
105
_('Choose Spouse/Partner'))
107
self.glade.signal_autoconnect({
108
"on_select_spouse_clicked" : self.select_spouse_clicked,
109
"on_spouse_help_clicked" : self.on_spouse_help_clicked,
110
"on_show_toggled" : self.on_show_toggled,
111
"on_new_spouse_clicked" : self.new_spouse_clicked,
112
"on_rel_type_changed" : self.relation_type_changed,
113
"destroy_passed_object" : Utils.destroy_passed_object
116
self.relation_type.set_text(_("Married"))
117
self.relation_type_changed(None)
119
def on_spouse_help_clicked(self,obj):
120
"""Display the relevant portion of GRAMPS manual"""
121
gnome.help_display('gramps-manual','gramps-edit-quick')
123
def select_row(self,obj):
125
Called with a row has be unselected. Used to enable the OK button
126
when a row has been selected.
129
model,iter = self.slist.get_selected()
131
self.ok.set_sensitive(1)
133
self.ok.set_sensitive(0)
135
def new_spouse_clicked(self,obj):
137
Called when the spouse to be added does not exist, and needs
138
to be created and added to the database
142
relation = const.save_frel(unicode(self.relation_type.get_text()))
143
if relation == "Partners":
144
if self.person.getGender() == RelLib.Person.male:
145
gen = RelLib.Person.male
147
gen = RelLib.Person.female
148
elif self.person.getGender() == RelLib.Person.male:
149
gen = RelLib.Person.female
151
gen = RelLib.Person.male
153
person = RelLib.Person()
154
person.setGender(gen)
155
EditPerson.EditPerson(person,self.db,self.update_list)
157
def update_list(self,epo):
159
Updates the potential spouse list after a person has been added
160
to database. Called by the QuickAdd class when the dialog has
164
if person.getId() == "":
165
self.db.addPerson(person)
167
self.db.addPersonNoMap(person,person.getId())
168
self.db.buildPersonDisplay(person.getId())
169
self.addperson(person)
170
self.update_data(person.getId())
171
self.slist.center_selected()
173
def select_spouse_clicked(self,obj):
175
Called when the spouse to be added already exists and has been
176
selected from the list.
179
model,iter = self.slist.get_selected()
183
id = self.slist.get_object(iter)
184
spouse = self.db.getPerson(id)
186
# don't do anything if the marriage already exists
187
for f in self.person.getFamilyList():
188
if spouse == f.getMother() or spouse == f.getFather():
189
Utils.destroy_passed_object(obj)
193
if not self.active_family:
194
self.active_family = self.db.newFamily()
195
self.person.addFamily(self.active_family)
196
spouse.addFamily(self.active_family)
198
if self.person.getGender() == RelLib.Person.male:
199
self.active_family.setMother(spouse)
200
self.active_family.setFather(self.person)
202
self.active_family.setFather(spouse)
203
self.active_family.setMother(self.person)
205
self.active_family.setRelationship(const.save_frel(unicode(self.relation_type.get_text())))
206
Utils.destroy_passed_object(obj)
207
self.update(self.active_family)
209
def relation_type_changed(self,obj):
212
def update_data(self,person = None):
214
Called whenever the relationship type changes. Rebuilds the
215
the potential spouse list.
218
text = unicode(self.relation_type.get_text())
219
self.relation_def.set_text(const.relationship_def(text))
221
# determine the gender of the people to be loaded into
222
# the potential spouse list. If Partners is selected, use
223
# the same gender as the current person.
224
gender = self.person.getGender()
225
bday = self.person.getBirth().getDateObj()
226
dday = self.person.getDeath().getDateObj()
228
if text == _("Partners"):
229
if gender == RelLib.Person.male:
230
sgender = const.female
234
if gender == RelLib.Person.male:
237
sgender = const.female
241
self.slist.new_model()
242
for key in self.db.sortPersonKeys():
243
data = self.db.getPersonDisplay(key)
244
if data[2] == sgender:
247
if not self.showall.get_active():
248
pdday = self.db.getPerson(key).getDeath().getDateObj()
249
pbday = self.db.getPerson(key).getBirth().getDateObj()
251
if bday.getYearValid():
252
if pbday.getYearValid():
253
# reject if person birthdate differs more than
254
# 100 years from spouse birthdate
255
if abs(pbday.getYear() - bday.getYear()) > 100:
258
if pdday.getYearValid():
259
# reject if person birthdate is after the spouse deathdate
260
if bday.getLowYear() + 10 > pdday.getHighYear():
263
# reject if person birthdate is more than 100 years
264
# before the spouse deathdate
265
if bday.getHighYear() + 100 < pdday.getLowYear():
268
if dday.getYearValid():
269
if pbday.getYearValid():
270
# reject if person deathdate was prior to
271
# the spouse birthdate
272
if dday.getHighYear() < pbday.getLowYear() + 10:
275
if pdday.getYearValid():
276
# reject if person deathdate differs more than
277
# 100 years from spouse deathdate
278
if abs(pdday.getYear() - dday.getYear()) > 100:
280
self.slist.add([data[0],data[1],data[3],data[5],data[6]],key,person==key)
281
self.slist.connect_model()
283
def on_show_toggled(self,obj):