~rosco2/ubuntu/wily/gramps/bug-1492304

« back to all changes in this revision

Viewing changes to src/AddSpouse.py

  • Committer: Bazaar Package Importer
  • Author(s): James A. Treacy
  • Date: 2004-06-16 16:53:36 UTC
  • Revision ID: james.westby@ubuntu.com-20040616165336-kjzczqef4gnxrn2b
Tags: upstream-1.0.4
ImportĀ upstreamĀ versionĀ 1.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Gramps - a GTK+/GNOME based genealogy program
 
3
#
 
4
# Copyright (C) 2000-2003  Donald N. Allingham
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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
 
19
#
 
20
 
 
21
# $Id: AddSpouse.py,v 1.23 2003/12/17 18:38:02 dallingham Exp $
 
22
 
 
23
"""
 
24
The AddSpouse module provides the AddSpouse class that allows the user to
 
25
add a new spouse to the active person.
 
26
"""
 
27
 
 
28
__author__ = "Donald N. Allingham"
 
29
__version__ = "$Revision: 1.23 $"
 
30
 
 
31
#-------------------------------------------------------------------------
 
32
#
 
33
# internationalization
 
34
#
 
35
#-------------------------------------------------------------------------
 
36
from gettext import gettext as _
 
37
 
 
38
#-------------------------------------------------------------------------
 
39
#
 
40
# GTK/Gnome modules
 
41
#
 
42
#-------------------------------------------------------------------------
 
43
import gtk.glade
 
44
import gnome
 
45
 
 
46
#-------------------------------------------------------------------------
 
47
#
 
48
# gramps modules
 
49
#
 
50
#-------------------------------------------------------------------------
 
51
import RelLib
 
52
import const
 
53
import Utils
 
54
import GrampsCfg
 
55
import ListModel
 
56
 
 
57
#-------------------------------------------------------------------------
 
58
#
 
59
# AddSpouse
 
60
#
 
61
#-------------------------------------------------------------------------
 
62
class AddSpouse:
 
63
    """
 
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
 
66
    be selected.
 
67
    """
 
68
    def __init__(self,db,person,update,addperson,family=None):
 
69
        """
 
70
        Displays the AddSpouse dialog box.
 
71
 
 
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
 
76
        """
 
77
        self.db = db
 
78
        self.update = update
 
79
        self.person = person
 
80
        self.addperson = addperson
 
81
        self.active_family = family
 
82
 
 
83
        self.glade = gtk.glade.XML(const.gladeFile, "spouseDialog","gramps")
 
84
 
 
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')
 
89
 
 
90
        titles = [ (_('Name'),3,200), (_('ID'),1,50), (_('Birth date'),4,50),
 
91
                   ('',0,50), ('',0,0)]
 
92
        
 
93
        self.slist = ListModel.ListModel(self.spouse_list, titles,
 
94
                                         self.select_row )
 
95
        
 
96
        self.relation_def = self.glade.get_widget("reldef")
 
97
        self.ok = self.glade.get_widget('spouse_ok')
 
98
        self.ok.set_sensitive(0)
 
99
                     
 
100
        self.rel_combo.set_popdown_strings(const.familyRelations)
 
101
        title = _("Choose Spouse/Partner of %s") % GrampsCfg.nameof(person)
 
102
 
 
103
        Utils.set_titles(self.glade.get_widget('spouseDialog'),
 
104
                         self.glade.get_widget('title'),title,
 
105
                         _('Choose Spouse/Partner'))
 
106
 
 
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
 
114
            })
 
115
 
 
116
        self.relation_type.set_text(_("Married"))
 
117
        self.relation_type_changed(None)
 
118
        
 
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')
 
122
 
 
123
    def select_row(self,obj):
 
124
        """
 
125
        Called with a row has be unselected. Used to enable the OK button
 
126
        when a row has been selected.
 
127
        """
 
128
 
 
129
        model,iter = self.slist.get_selected()
 
130
        if iter:
 
131
            self.ok.set_sensitive(1)
 
132
        else:
 
133
            self.ok.set_sensitive(0)
 
134
        
 
135
    def new_spouse_clicked(self,obj):
 
136
        """
 
137
        Called when the spouse to be added does not exist, and needs
 
138
        to be created and added to the database
 
139
        """
 
140
        import EditPerson
 
141
 
 
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
 
146
            else:
 
147
                gen = RelLib.Person.female
 
148
        elif self.person.getGender() == RelLib.Person.male:
 
149
            gen = RelLib.Person.female
 
150
        else:
 
151
            gen = RelLib.Person.male
 
152
 
 
153
        person = RelLib.Person()
 
154
        person.setGender(gen)
 
155
        EditPerson.EditPerson(person,self.db,self.update_list)
 
156
 
 
157
    def update_list(self,epo):
 
158
        """
 
159
        Updates the potential spouse list after a person has been added
 
160
        to database. Called by the QuickAdd class when the dialog has
 
161
        been closed.
 
162
        """
 
163
        person = epo.person
 
164
        if person.getId() == "":
 
165
            self.db.addPerson(person)
 
166
        else:
 
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()
 
172
 
 
173
    def select_spouse_clicked(self,obj):
 
174
        """
 
175
        Called when the spouse to be added already exists and has been
 
176
        selected from the list.
 
177
        """
 
178
 
 
179
        model,iter = self.slist.get_selected()
 
180
        if not iter:
 
181
            return
 
182
        
 
183
        id = self.slist.get_object(iter)
 
184
        spouse = self.db.getPerson(id)
 
185
 
 
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)
 
190
                return
 
191
 
 
192
        Utils.modified()
 
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)
 
197
 
 
198
        if self.person.getGender() == RelLib.Person.male:
 
199
            self.active_family.setMother(spouse)
 
200
            self.active_family.setFather(self.person)
 
201
        else:   
 
202
            self.active_family.setFather(spouse)
 
203
            self.active_family.setMother(self.person)
 
204
 
 
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)
 
208
 
 
209
    def relation_type_changed(self,obj):
 
210
        self.update_data()
 
211
 
 
212
    def update_data(self,person = None):
 
213
        """
 
214
        Called whenever the relationship type changes. Rebuilds the
 
215
        the potential spouse list.
 
216
        """
 
217
 
 
218
        text = unicode(self.relation_type.get_text())
 
219
        self.relation_def.set_text(const.relationship_def(text))
 
220
    
 
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()
 
227
 
 
228
        if text == _("Partners"):
 
229
            if gender == RelLib.Person.male:
 
230
                sgender = const.female
 
231
            else:
 
232
                sgender = const.male
 
233
        else:
 
234
            if gender == RelLib.Person.male:
 
235
                sgender = const.male
 
236
            else:
 
237
                sgender = const.female
 
238
 
 
239
        self.entries = []
 
240
        self.slist.clear()
 
241
        self.slist.new_model()
 
242
        for key in self.db.sortPersonKeys():
 
243
            data = self.db.getPersonDisplay(key)
 
244
            if data[2] == sgender:
 
245
                continue
 
246
 
 
247
            if not self.showall.get_active():
 
248
                pdday = self.db.getPerson(key).getDeath().getDateObj()
 
249
                pbday = self.db.getPerson(key).getBirth().getDateObj()
 
250
 
 
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:
 
256
                            continue
 
257
 
 
258
                    if pdday.getYearValid():
 
259
                        # reject if person birthdate is after the spouse deathdate 
 
260
                        if bday.getLowYear() + 10 > pdday.getHighYear():
 
261
                            continue
 
262
                
 
263
                        # reject if person birthdate is more than 100 years 
 
264
                        # before the spouse deathdate
 
265
                        if bday.getHighYear() + 100 < pdday.getLowYear():
 
266
                            continue
 
267
 
 
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:
 
273
                            continue
 
274
 
 
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:
 
279
                            continue
 
280
            self.slist.add([data[0],data[1],data[3],data[5],data[6]],key,person==key)
 
281
        self.slist.connect_model()
 
282
 
 
283
    def on_show_toggled(self,obj):
 
284
        self.update_data()