2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2004-02-15 12:51:29 +05:30
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2003-11-19 08:44:14 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
ChooseParents interface allows users to select the paretns of an
|
|
|
|
individual.
|
|
|
|
"""
|
|
|
|
|
|
|
|
__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
|
2003-11-19 08:44:14 +05:30
|
|
|
import gnome
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import RelLib
|
|
|
|
import const
|
|
|
|
import Utils
|
|
|
|
import GrampsCfg
|
2003-01-20 04:29:38 +05:30
|
|
|
import ListModel
|
|
|
|
|
2003-03-03 10:02:53 +05:30
|
|
|
_titles = [(_('Name'),3,200),(_('ID'),1,50),(_('Birth date'),4,50),('',0,50),('',0,0)]
|
2003-01-20 04:29:38 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ChooseParents
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class ChooseParents:
|
|
|
|
"""
|
|
|
|
Displays the Choose Parents dialog box, allowing the parents
|
|
|
|
to be edited.
|
|
|
|
"""
|
2004-02-21 12:10:44 +05:30
|
|
|
def __init__(self,parent,db,person,family,family_update,full_update):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Creates a ChoosePerson dialog box.
|
|
|
|
|
|
|
|
db - database associated the person
|
|
|
|
person - person whose parents we are selecting
|
|
|
|
family - current family
|
|
|
|
family_update - task that updates the family display
|
|
|
|
full_update - task that updates the main display
|
|
|
|
"""
|
2004-02-21 12:10:44 +05:30
|
|
|
self.parent = parent
|
2002-10-20 19:55:16 +05:30
|
|
|
self.db = db
|
2004-02-25 08:50:53 +05:30
|
|
|
self.child_windows = {}
|
2002-10-20 19:55:16 +05:30
|
|
|
self.person = person
|
|
|
|
self.family = family
|
|
|
|
self.family_update = family_update
|
|
|
|
self.full_update = full_update
|
|
|
|
self.old_type = ""
|
|
|
|
self.type = ""
|
2003-10-14 09:52:24 +05:30
|
|
|
self.parent_selected = 0
|
2003-01-20 09:04:42 +05:30
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
birth_event = self.db.find_event_from_id(person.get_birth_id())
|
|
|
|
if birth_event:
|
|
|
|
self.date = birth_event.get_date_object()
|
|
|
|
else:
|
|
|
|
self.date = None
|
2003-01-20 09:04:42 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.family:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.father = self.family.get_father_id()
|
|
|
|
self.mother = self.family.get_mother_id()
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.mother = None
|
|
|
|
self.father = None
|
|
|
|
|
2003-08-17 07:44:33 +05:30
|
|
|
self.glade = gtk.glade.XML(const.gladeFile,"familyDialog","gramps")
|
2003-03-06 11:42:51 +05:30
|
|
|
self.top = self.glade.get_widget("familyDialog")
|
2003-03-05 11:31:31 +05:30
|
|
|
|
2004-02-25 08:50:53 +05:30
|
|
|
self.title_text = _("Choose the Parents of %s") % GrampsCfg.nameof(self.person)
|
2003-03-06 11:42:51 +05:30
|
|
|
Utils.set_titles(self.top,self.glade.get_widget('title'),
|
2004-02-25 08:50:53 +05:30
|
|
|
self.title_text,_('Choose Parents'))
|
2003-03-06 11:42:51 +05:30
|
|
|
|
2004-02-15 12:51:29 +05:30
|
|
|
self.mother_rel = self.glade.get_widget("mrel")
|
|
|
|
self.father_rel = self.glade.get_widget("frel")
|
2002-10-20 19:55:16 +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("father_list")
|
|
|
|
self.mother_list = self.glade.get_widget("mother_list")
|
|
|
|
self.flabel = self.glade.get_widget("flabel")
|
|
|
|
self.mlabel = self.glade.get_widget("mlabel")
|
2003-05-22 02:22:53 +05:30
|
|
|
self.showallf = self.glade.get_widget('showallf')
|
2003-03-03 10:02:53 +05:30
|
|
|
self.showallm = self.glade.get_widget('showallm')
|
2003-01-20 09:04:42 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
self.fcombo.set_popdown_strings(const.familyRelations)
|
|
|
|
|
2003-01-20 04:29:38 +05:30
|
|
|
self.fmodel = ListModel.ListModel(self.father_list, _titles,
|
|
|
|
self.father_list_select_row)
|
|
|
|
self.mmodel = ListModel.ListModel(self.mother_list, _titles,
|
|
|
|
self.mother_list_select_row)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
for (f,mr,fr) in self.person.get_parent_family_id_list():
|
2002-10-20 19:55:16 +05:30
|
|
|
if f == self.family:
|
|
|
|
self.mother_rel.set_text(_(mr))
|
|
|
|
self.father_rel.set_text(_(fr))
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
self.mother_rel.set_text(_("Birth"))
|
|
|
|
self.father_rel.set_text(_("Birth"))
|
|
|
|
|
|
|
|
if self.family:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.type = self.family.get_relationship()
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.type = "Married"
|
|
|
|
|
|
|
|
self.prel.set_text(_(self.type))
|
2003-05-22 02:22:53 +05:30
|
|
|
self.redrawf()
|
|
|
|
self.redrawm()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.glade.signal_autoconnect({
|
2003-11-24 02:02:40 +05:30
|
|
|
"on_save_parents_clicked" : self.save_parents_clicked,
|
2002-10-20 19:55:16 +05:30
|
|
|
"on_add_parent_clicked" : self.add_parent_clicked,
|
|
|
|
"on_prel_changed" : self.parent_relation_changed,
|
2003-05-22 02:22:53 +05:30
|
|
|
"on_showallf_toggled" : self.showallf_toggled,
|
|
|
|
"on_showallm_toggled" : self.showallm_toggled,
|
2004-02-25 08:50:53 +05:30
|
|
|
"destroy_passed_object" : self.close,
|
2003-11-19 08:44:14 +05:30
|
|
|
"on_help_familyDialog_clicked" : self.on_help_clicked,
|
2004-02-25 08:50:53 +05:30
|
|
|
"on_familyDialog_delete_event" : self.on_delete_event,
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
|
|
|
|
2004-02-25 08:50:53 +05:30
|
|
|
self.add_itself_to_menu()
|
|
|
|
self.top.show()
|
|
|
|
|
|
|
|
def on_delete_event(self,obj,b):
|
|
|
|
self.close_child_windows()
|
|
|
|
self.remove_itself_from_menu()
|
|
|
|
|
|
|
|
def close(self,obj):
|
|
|
|
self.close_child_windows()
|
|
|
|
self.remove_itself_from_menu()
|
|
|
|
self.top.destroy()
|
|
|
|
|
|
|
|
def close_child_windows(self):
|
|
|
|
for child_window in self.child_windows.values():
|
|
|
|
child_window.close(None)
|
|
|
|
self.child_windows = {}
|
|
|
|
|
|
|
|
def add_itself_to_menu(self):
|
|
|
|
self.parent.child_windows[self] = self
|
|
|
|
self.win_menu_item = gtk.MenuItem(self.title_text)
|
|
|
|
self.win_menu_item.set_submenu(gtk.Menu())
|
|
|
|
self.win_menu_item.show()
|
|
|
|
self.parent.winsmenu.append(self.win_menu_item)
|
|
|
|
self.winsmenu = self.win_menu_item.get_submenu()
|
|
|
|
self.menu_item = gtk.MenuItem(_('Choose Parents'))
|
|
|
|
self.menu_item.connect("activate",self.present)
|
|
|
|
self.menu_item.show()
|
|
|
|
self.winsmenu.append(self.menu_item)
|
|
|
|
|
|
|
|
def remove_itself_from_menu(self):
|
|
|
|
del self.parent.child_windows[self]
|
|
|
|
self.menu_item.destroy()
|
|
|
|
self.winsmenu.destroy()
|
|
|
|
self.win_menu_item.destroy()
|
|
|
|
|
|
|
|
def present(self,obj):
|
|
|
|
self.top.present()
|
|
|
|
|
2003-11-19 08:44:14 +05:30
|
|
|
def on_help_clicked(self,obj):
|
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
2003-12-02 09:57:23 +05:30
|
|
|
gnome.help_display('gramps-manual','gramps-edit-quick')
|
2003-11-19 08:44:14 +05:30
|
|
|
|
2003-05-22 02:22:53 +05:30
|
|
|
def redrawf(self):
|
|
|
|
"""Redraws the potential father list"""
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
self.fmodel.clear()
|
2003-05-22 01:45:50 +05:30
|
|
|
self.fmodel.new_model()
|
2003-05-22 02:22:53 +05:30
|
|
|
|
2004-02-16 02:19:34 +05:30
|
|
|
person_id = self.person.get_id()
|
2003-05-22 02:22:53 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.father:
|
2004-02-16 02:19:34 +05:30
|
|
|
father_id = self.father.get_id()
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2004-02-16 02:19:34 +05:30
|
|
|
father_id = None
|
2003-05-22 02:22:53 +05:30
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
birth_event = self.db.find_event_from_id(self.person.get_birth_id())
|
|
|
|
if birth_event:
|
|
|
|
bday = birth_event.get_date_object()
|
|
|
|
else:
|
|
|
|
bday = None
|
|
|
|
death_event = self.db.find_event_from_id(self.person.get_death_id())
|
|
|
|
if death_event:
|
|
|
|
dday = death_event.get_date_object()
|
|
|
|
else:
|
|
|
|
dday = None
|
2003-05-22 02:22:53 +05:30
|
|
|
|
|
|
|
person_list = []
|
2004-02-14 11:10:30 +05:30
|
|
|
for key in self.db.sort_person_keys():
|
2004-02-16 02:19:34 +05:30
|
|
|
if person_id == key:
|
2003-05-22 02:22:53 +05:30
|
|
|
continue
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
person = self.db.get_person(key)
|
2004-02-16 02:19:34 +05:30
|
|
|
if person.get_gender() != RelLib.Person.male:
|
2003-05-22 02:22:53 +05:30
|
|
|
continue
|
|
|
|
|
|
|
|
if not self.showallf.get_active():
|
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
birth_event = self.db.find_event_from_id(person.get_birth_id())
|
|
|
|
if birth_event:
|
|
|
|
pbday = birth_event.get_date_object()
|
|
|
|
else:
|
|
|
|
pbday = None
|
|
|
|
|
|
|
|
death_event = self.db.find_event_from_id(person.get_death_id())
|
|
|
|
if death_event:
|
|
|
|
pdday = death_event.get_date_object()
|
|
|
|
else:
|
|
|
|
pdday = None
|
|
|
|
|
|
|
|
if bday and bday.getYearValid():
|
|
|
|
if pbday and pbday.getYearValid():
|
2003-05-22 02:22:53 +05:30
|
|
|
# reject if parents birthdate + 10 > child birthdate
|
|
|
|
if pbday.getLowYear()+10 > bday.getHighYear():
|
|
|
|
continue
|
|
|
|
|
|
|
|
# reject if parents birthdate + 90 < child birthdate
|
|
|
|
if pbday.getHighYear()+90 < bday.getLowYear():
|
|
|
|
continue
|
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
if pdday and pdday.getYearValid():
|
2003-05-22 02:22:53 +05:30
|
|
|
# reject if parents birthdate + 10 > child deathdate
|
2004-02-21 12:10:44 +05:30
|
|
|
if dday and pbday.getLowYear()+10 > dday.getHighYear():
|
2003-05-22 02:22:53 +05:30
|
|
|
continue
|
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
if dday and dday.getYearValid():
|
|
|
|
if pbday and pbday.getYearValid():
|
2003-05-22 02:22:53 +05:30
|
|
|
# reject if parents deathday + 3 < childs birth date
|
2004-02-21 12:10:44 +05:30
|
|
|
if pdday and bday and pdday.getHighYear()+3 < bday.getLowYear():
|
2003-05-22 02:22:53 +05:30
|
|
|
continue
|
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
if pdday and pdday.getYearValid():
|
2003-05-22 02:22:53 +05:30
|
|
|
# reject if parents deathday + 150 < childs death date
|
|
|
|
if pdday.getHighYear() + 150 < dday.getLowYear():
|
|
|
|
continue
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
person_list.append(person.get_id())
|
2003-05-22 02:22:53 +05:30
|
|
|
|
|
|
|
for idval in person_list:
|
2004-02-14 11:10:30 +05:30
|
|
|
d = self.db.get_person_display(idval)
|
2003-05-22 02:22:53 +05:30
|
|
|
info = [d[0],d[1],d[3],d[5],d[6]]
|
|
|
|
if self.type == "Partners":
|
2004-02-16 02:19:34 +05:30
|
|
|
self.fmodel.add(info,d[1],father_id==d[1])
|
2003-05-22 02:22:53 +05:30
|
|
|
elif d[2] == const.male:
|
2004-02-16 02:19:34 +05:30
|
|
|
self.fmodel.add(info,d[1],father_id==d[1])
|
2003-05-22 02:22:53 +05:30
|
|
|
|
|
|
|
if self.type == "Partners":
|
2003-12-14 10:19:43 +05:30
|
|
|
self.flabel.set_label("<b>%s</b>" % _("Par_ent"))
|
2003-05-22 02:22:53 +05:30
|
|
|
else:
|
2003-12-14 10:19:43 +05:30
|
|
|
self.flabel.set_label("<b>%s</b>" % _("Fath_er"))
|
2003-05-22 02:22:53 +05:30
|
|
|
|
|
|
|
self.fmodel.connect_model()
|
|
|
|
|
|
|
|
|
|
|
|
def redrawm(self):
|
|
|
|
"""Redraws the potential mother list"""
|
|
|
|
|
|
|
|
self.mmodel.clear()
|
|
|
|
self.mmodel.new_model()
|
|
|
|
|
2004-02-16 02:19:34 +05:30
|
|
|
person_id = self.person.get_id()
|
2003-05-22 02:22:53 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.mother:
|
2004-02-14 11:10:30 +05:30
|
|
|
mid = self.mother.get_id()
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
mid = None
|
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
birth_event = self.db.find_event_from_id(self.person.get_birth_id())
|
|
|
|
if birth_event:
|
|
|
|
bday = birth_event.get_date_object()
|
|
|
|
else:
|
|
|
|
bday = None
|
|
|
|
death_event = self.db.find_event_from_id(self.person.get_death_id())
|
|
|
|
if death_event:
|
|
|
|
dday = death_event.get_date_object()
|
|
|
|
else:
|
|
|
|
dday = None
|
2003-05-22 02:22:53 +05:30
|
|
|
|
|
|
|
person_list = []
|
2004-02-14 11:10:30 +05:30
|
|
|
for key in self.db.sort_person_keys():
|
2004-02-16 02:19:34 +05:30
|
|
|
if person_id == key:
|
2002-10-20 19:55:16 +05:30
|
|
|
continue
|
2003-05-22 02:22:53 +05:30
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
person = self.db.get_person(key)
|
2004-02-16 02:19:34 +05:30
|
|
|
if person.get_gender() != RelLib.Person.female:
|
2002-10-20 19:55:16 +05:30
|
|
|
continue
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
person = self.db.get_person(key)
|
2003-05-22 02:22:53 +05:30
|
|
|
|
|
|
|
if not self.showallm.get_active():
|
2003-01-20 09:04:42 +05:30
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
birth_event = self.db.find_event_from_id(person.get_birth_id())
|
|
|
|
if birth_event:
|
|
|
|
pbday = birth_event.get_date_object()
|
|
|
|
else:
|
|
|
|
pbday = None
|
|
|
|
|
|
|
|
death_event = self.db.find_event_from_id(person.get_death_id())
|
|
|
|
if death_event:
|
|
|
|
pdday = death_event.get_date_object()
|
|
|
|
else:
|
|
|
|
pdday = None
|
|
|
|
|
|
|
|
if bday and bday.getYearValid():
|
|
|
|
if pbday and pbday.getYearValid():
|
2003-05-22 02:22:53 +05:30
|
|
|
# reject if parents birthdate + 10 > child birthdate
|
|
|
|
if pbday.getLowYear()+10 > bday.getHighYear():
|
|
|
|
continue
|
|
|
|
|
|
|
|
# reject if parents birthdate + 90 < child birthdate
|
|
|
|
if pbday.getHighYear()+90 < bday.getLowYear():
|
|
|
|
continue
|
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
if pdday and pdday.getYearValid():
|
2003-05-22 02:22:53 +05:30
|
|
|
# reject if parents birthdate + 10 > child deathdate
|
|
|
|
if pbday.getLowYear()+10 > dday.getHighYear():
|
|
|
|
continue
|
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
if dday and dday.getYearValid():
|
|
|
|
if pbday and pbday.getYearValid():
|
2003-05-22 02:22:53 +05:30
|
|
|
# reject if parents deathday + 3 < childs birth date
|
2004-02-21 12:10:44 +05:30
|
|
|
if pdday and bday and pdday.getHighYear()+3 < bday.getLowYear():
|
2003-05-22 02:22:53 +05:30
|
|
|
continue
|
|
|
|
|
2004-02-21 12:10:44 +05:30
|
|
|
if pdday and pdday.getYearValid():
|
2003-05-22 02:22:53 +05:30
|
|
|
# reject if parents deathday + 150 < childs death date
|
|
|
|
if pdday.getHighYear() + 150 < dday.getLowYear():
|
|
|
|
continue
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
person_list.append(person.get_id())
|
2003-05-22 02:22:53 +05:30
|
|
|
|
|
|
|
for idval in person_list:
|
2004-02-14 11:10:30 +05:30
|
|
|
d = self.db.get_person_display(idval)
|
2003-01-20 04:29:38 +05:30
|
|
|
info = [d[0],d[1],d[3],d[5],d[6]]
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.type == "Partners":
|
2003-10-14 09:52:24 +05:30
|
|
|
self.mmodel.add(info,d[1],mid==d[1])
|
2003-05-22 02:22:53 +05:30
|
|
|
elif d[2] == const.female:
|
2003-10-14 09:52:24 +05:30
|
|
|
self.mmodel.add(info,d[1],mid==d[1])
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if self.type == "Partners":
|
2003-12-14 10:19:43 +05:30
|
|
|
self.mlabel.set_label("<b>%s</b>" % _("Pa_rent"))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2003-12-14 10:19:43 +05:30
|
|
|
self.mlabel.set_label("<b>%s</b>" % _("Mothe_r"))
|
2003-05-22 01:45:50 +05:30
|
|
|
self.mmodel.connect_model()
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def parent_relation_changed(self,obj):
|
|
|
|
"""Called everytime the parent relationship information is changegd"""
|
|
|
|
self.old_type = self.type
|
2003-12-17 10:53:16 +05:30
|
|
|
self.type = const.save_frel(unicode(obj.get_text()))
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.old_type == "Partners" or self.type == "Partners":
|
2003-05-22 02:22:53 +05:30
|
|
|
self.redrawf()
|
|
|
|
self.redrawm()
|
|
|
|
|
|
|
|
def showallf_toggled(self,obj):
|
|
|
|
self.redrawf()
|
2003-01-20 09:04:42 +05:30
|
|
|
|
2003-05-22 02:22:53 +05:30
|
|
|
def showallm_toggled(self,obj):
|
|
|
|
self.redrawm()
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-02-16 02:19:34 +05:30
|
|
|
def find_family(self,father_id,mother_id):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Finds the family associated with the father and mother.
|
|
|
|
If one does not exist, it is created.
|
|
|
|
"""
|
2004-02-16 02:19:34 +05:30
|
|
|
if not father_id and not mother_id:
|
2002-10-20 19:55:16 +05:30
|
|
|
return None
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
families = self.db.get_family_id_map().values()
|
2002-10-20 19:55:16 +05:30
|
|
|
for family in families:
|
2004-02-16 02:19:34 +05:30
|
|
|
if family.get_father_id() == father_id and family.get_mother_id() == mother_id:
|
2002-10-20 19:55:16 +05:30
|
|
|
return family
|
2004-02-16 02:19:34 +05:30
|
|
|
elif family.get_father_id() == mother_id and family.get_mother_id() == father_id:
|
2002-10-20 19:55:16 +05:30
|
|
|
return family
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
family = self.db.new_family()
|
2004-02-16 02:19:34 +05:30
|
|
|
family.set_father_id(father_id)
|
|
|
|
family.set_mother_id(mother_id)
|
|
|
|
family.add_child_id(self.person.get_id())
|
|
|
|
|
|
|
|
if father_id:
|
|
|
|
father = self.db.find_person_from_id(father_id)
|
2004-02-14 11:10:30 +05:30
|
|
|
father.add_family_id(family.get_id())
|
2002-10-20 19:55:16 +05:30
|
|
|
if mother:
|
2004-02-16 02:19:34 +05:30
|
|
|
mother = self.db.find_person_from_id(mother_id)
|
2004-02-14 11:10:30 +05:30
|
|
|
mother.add_family_id(family.get_id())
|
2004-02-16 02:19:34 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
return family
|
|
|
|
|
|
|
|
def mother_list_select_row(self,obj):
|
|
|
|
"""Called when a row is selected in the mother list. Sets the
|
|
|
|
active mother based off the id associated with the row."""
|
|
|
|
|
2003-01-20 04:29:38 +05:30
|
|
|
model, iter = self.mmodel.get_selected()
|
2002-10-20 19:55:16 +05:30
|
|
|
if iter:
|
|
|
|
id = model.get_value(iter,1)
|
2004-02-14 11:10:30 +05:30
|
|
|
self.mother = self.db.get_person(id)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.mother = None
|
|
|
|
|
2003-10-14 09:52:24 +05:30
|
|
|
if not self.parent_selected and self.mother:
|
|
|
|
self.parent_selected = 1
|
2004-02-16 02:19:34 +05:30
|
|
|
family_id_list = self.mother.get_family_id_list()
|
|
|
|
if len(family_id_list) >= 1:
|
|
|
|
family = self.db.find_family_from_id(family_id_list[0])
|
|
|
|
father_id = family.get_father_id()
|
|
|
|
self.fmodel.find(father_id)
|
2003-10-14 09:52:24 +05:30
|
|
|
self.fmodel.center_selected()
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def father_list_select_row(self,obj):
|
|
|
|
"""Called when a row is selected in the father list. Sets the
|
|
|
|
active father based off the id associated with the row."""
|
2003-01-20 04:29:38 +05:30
|
|
|
model, iter = self.fmodel.get_selected()
|
2002-10-20 19:55:16 +05:30
|
|
|
if iter:
|
|
|
|
id = model.get_value(iter,1)
|
2004-02-14 11:10:30 +05:30
|
|
|
self.father = self.db.get_person(id)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.father = None
|
|
|
|
|
2003-10-14 09:52:24 +05:30
|
|
|
if not self.parent_selected and self.father:
|
|
|
|
self.parent_selected = 1
|
2004-02-16 02:19:34 +05:30
|
|
|
family_id_list = self.father.get_family_id_list()
|
|
|
|
if len(family_id_list) >= 1:
|
|
|
|
family = self.db.find_family_from_id(family_id_list[0])
|
|
|
|
mother_id = family.get_mother_id()
|
|
|
|
self.mmodel.find(mother_id)
|
2003-10-14 09:52:24 +05:30
|
|
|
self.mmodel.center_selected()
|
|
|
|
|
2003-11-24 02:02:40 +05:30
|
|
|
def save_parents_clicked(self,obj):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Called with the OK button nis pressed. Saves the selected people as parents
|
|
|
|
of the main perosn.
|
|
|
|
"""
|
2003-04-20 09:22:54 +05:30
|
|
|
try:
|
2004-02-15 12:51:29 +05:30
|
|
|
mother_rel = const.child_relations.find_value(self.mother_rel.get_text())
|
2003-04-20 09:22:54 +05:30
|
|
|
except KeyError:
|
2004-02-15 12:51:29 +05:30
|
|
|
mother_rel = const.child_relations.find_value("Birth")
|
2003-04-20 09:22:54 +05:30
|
|
|
|
|
|
|
try:
|
2004-02-15 12:51:29 +05:30
|
|
|
father_rel = const.child_relations.find_value(self.father_rel.get_text())
|
2003-04-20 09:22:54 +05:30
|
|
|
except KeyError:
|
2004-02-15 12:51:29 +05:30
|
|
|
father_rel = const.child_relations.find_value("Birth")
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if self.father or self.mother:
|
|
|
|
if self.mother and not self.father:
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.mother.get_gender() == RelLib.Person.male:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.father = self.mother
|
|
|
|
self.mother = None
|
2004-02-16 02:19:34 +05:30
|
|
|
self.family = self.find_family(self.father.get_id(),self.mother.get_id())
|
2002-10-20 19:55:16 +05:30
|
|
|
elif self.father and not self.mother:
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.father.get_gender() == RelLib.Person.female:
|
2002-10-20 19:55:16 +05:30
|
|
|
self.mother = self.father
|
|
|
|
self.father = None
|
2004-02-16 02:19:34 +05:30
|
|
|
self.family = self.find_family(self.father.get_id(),self.mother.get_id())
|
2004-02-14 11:10:30 +05:30
|
|
|
elif self.mother.get_gender() != self.father.get_gender():
|
2002-10-20 19:55:16 +05:30
|
|
|
if self.type == "Partners":
|
|
|
|
self.type = "Unknown"
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.father.get_gender() == RelLib.Person.female:
|
2004-02-16 02:19:34 +05:30
|
|
|
self.father, self.mother = self.mother, self.father
|
|
|
|
self.family = self.find_family(self.father.get_id(),self.mother.get_id())
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.type = "Partners"
|
2004-02-16 02:19:34 +05:30
|
|
|
self.family = self.find_family(self.father.get_id(),self.mother.get_id())
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
|
|
|
self.family = None
|
|
|
|
|
|
|
|
if self.family:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.family.set_relationship(self.type)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.change_family_type(self.family,mother_rel,father_rel)
|
|
|
|
self.family_update(None)
|
2004-02-25 08:50:53 +05:30
|
|
|
self.close(obj)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-12-18 00:08:02 +05:30
|
|
|
def add_new_parent(self,epo):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""Adds a new person to either the father list or the mother list,
|
|
|
|
depending on the gender of the person."""
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
person = epo.person
|
2004-02-14 11:10:30 +05:30
|
|
|
id = person.get_id()
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
if id == "":
|
2004-02-14 11:10:30 +05:30
|
|
|
id = self.db.add_person(person)
|
2003-07-31 17:28:08 +05:30
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.db.add_person_no_map(person,id)
|
|
|
|
self.db.build_person_display(id)
|
2003-07-31 17:28:08 +05:30
|
|
|
|
2003-12-17 10:53:16 +05:30
|
|
|
self.type = const.save_frel(unicode(self.prel.get_text()))
|
2004-02-14 11:10:30 +05:30
|
|
|
dinfo = self.db.get_person_display(id)
|
2003-01-20 04:29:38 +05:30
|
|
|
rdata = [dinfo[0],dinfo[1],dinfo[3],dinfo[5],dinfo[6]]
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if self.type == "Partners":
|
|
|
|
self.parent_relation_changed(self.prel)
|
2004-02-14 11:10:30 +05:30
|
|
|
elif person.get_gender() == RelLib.Person.male:
|
2003-01-20 04:29:38 +05:30
|
|
|
self.fmodel.add(rdata,None,1)
|
2003-06-02 04:18:27 +05:30
|
|
|
self.fmodel.center_selected()
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2003-01-20 04:29:38 +05:30
|
|
|
self.mmodel.add(rdata,None,1)
|
2003-06-02 04:18:27 +05:30
|
|
|
self.mmodel.center_selected()
|
2002-10-20 19:55:16 +05:30
|
|
|
self.full_update()
|
|
|
|
|
|
|
|
def add_parent_clicked(self,obj):
|
|
|
|
"""Called with the Add New Person button is pressed. Calls the QuickAdd
|
|
|
|
class to create a new person."""
|
|
|
|
|
2003-07-31 17:28:08 +05:30
|
|
|
person = RelLib.Person()
|
2004-02-14 11:10:30 +05:30
|
|
|
person.set_gender(RelLib.Person.male)
|
2003-07-31 17:28:08 +05:30
|
|
|
|
|
|
|
try:
|
|
|
|
import EditPerson
|
2004-02-25 08:50:53 +05:30
|
|
|
EditPerson.EditPerson(self, person,self.db,self.add_new_parent)
|
2003-07-31 17:28:08 +05:30
|
|
|
except:
|
|
|
|
import DisplayTrace
|
|
|
|
DisplayTrace.DisplayTrace()
|
2002-10-20 19:55:16 +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.
|
|
|
|
"""
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.person not in family.get_child_id_list():
|
2004-02-16 02:19:34 +05:30
|
|
|
family.add_child_id(self.person.get_id())
|
2004-02-14 11:10:30 +05:30
|
|
|
for fam in self.person.get_parent_family_id_list():
|
2002-10-20 19:55:16 +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]:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.person.remove_parent_family_id(family.get_id())
|
|
|
|
self.person.add_parent_family_id(family.get_id(),mother_rel,father_rel)
|
2002-10-20 19:55:16 +05:30
|
|
|
break
|
|
|
|
else:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.person.add_parent_family_id(family.get_id(),mother_rel,father_rel)
|
2004-02-21 11:41:59 +05:30
|
|
|
self.db.commit_person(self.person)
|
|
|
|
self.db.commit_family(family)
|
|
|
|
if self.father:
|
|
|
|
self.db.commit_person(self.father)
|
|
|
|
if self.mother:
|
|
|
|
self.db.commit_person(self.mother)
|
2002-10-20 19:55:16 +05:30
|
|
|
Utils.modified()
|
|
|
|
|
|
|
|
|
|
|
|
class ModifyParents:
|
2004-02-16 04:40:12 +05:30
|
|
|
def __init__(self,db,person,family_id,family_update,full_update,parent_window=None):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Creates a ChoosePerson dialog box.
|
|
|
|
|
|
|
|
db - database associated the person
|
|
|
|
person - person whose parents we are selecting
|
|
|
|
family - current family
|
|
|
|
family_update - task that updates the family display
|
|
|
|
full_update - task that updates the main display
|
|
|
|
"""
|
|
|
|
self.db = db
|
|
|
|
self.person = person
|
2004-02-16 04:40:12 +05:30
|
|
|
self.family = self.db.find_family_from_id(family_id)
|
2002-10-20 19:55:16 +05:30
|
|
|
self.family_update = family_update
|
|
|
|
self.full_update = full_update
|
|
|
|
|
2004-02-16 04:40:12 +05:30
|
|
|
self.father = self.db.find_person_from_id(self.family.get_father_id())
|
|
|
|
self.mother = self.db.find_person_from_id(self.family.get_mother_id())
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-08-17 07:44:33 +05:30
|
|
|
self.glade = gtk.glade.XML(const.gladeFile,"modparents","gramps")
|
2003-03-06 11:42:51 +05:30
|
|
|
self.top = self.glade.get_widget("modparents")
|
|
|
|
self.title = self.glade.get_widget("title")
|
2003-03-05 11:31:31 +05:30
|
|
|
|
2003-03-06 11:42:51 +05:30
|
|
|
title = _("Modify the Parents of %s") % GrampsCfg.nameof(self.person)
|
|
|
|
Utils.set_titles(self.top, self.title, title, _("Modify Parents"))
|
2003-03-05 11:31:31 +05:30
|
|
|
|
2004-02-15 12:51:29 +05:30
|
|
|
self.mother_rel = self.glade.get_widget("mrel")
|
|
|
|
self.father_rel = self.glade.get_widget("frel")
|
2002-10-20 19:55:16 +05:30
|
|
|
self.flabel = self.glade.get_widget("flabel")
|
|
|
|
self.mlabel = self.glade.get_widget("mlabel")
|
|
|
|
|
|
|
|
self.orig_mrel = _("Birth")
|
|
|
|
self.orig_frel = _("Birth")
|
2004-02-14 11:10:30 +05:30
|
|
|
for (f,mr,fr) in self.person.get_parent_family_id_list():
|
2004-02-16 04:40:12 +05:30
|
|
|
if f == self.family.get_id():
|
2002-10-20 19:55:16 +05:30
|
|
|
self.orig_mrel = _(mr)
|
|
|
|
self.orig_frel = _(fr)
|
|
|
|
|
|
|
|
self.mother_rel.set_text(self.orig_mrel)
|
|
|
|
self.father_rel.set_text(self.orig_frel)
|
|
|
|
|
|
|
|
self.glade.signal_autoconnect({
|
2003-11-19 08:44:14 +05:30
|
|
|
"on_parents_help_clicked" : self.on_help_clicked,
|
2002-10-20 19:55:16 +05:30
|
|
|
})
|
|
|
|
|
|
|
|
self.title.set_use_markup(gtk.TRUE)
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
if self.family.get_relationship() == "Partners":
|
2003-03-05 11:31:31 +05:30
|
|
|
self.mlabel.set_label('<b>%s</b>' % _("Parent"))
|
|
|
|
self.flabel.set_label('<b>%s</b>' % _("Parent"))
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2003-03-05 11:31:31 +05:30
|
|
|
self.mlabel.set_label('<b>%s</b>' % _("Mother"))
|
|
|
|
self.flabel.set_label('<b>%s</b>' % _("Father"))
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
|
|
|
|
if self.father:
|
2004-02-14 11:10:30 +05:30
|
|
|
fname = self.father.get_primary_name().get_name()
|
2002-10-27 09:13:12 +05:30
|
|
|
self.glade.get_widget("fname").set_text(fname)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2002-11-27 19:06:11 +05:30
|
|
|
self.father_rel.set_sensitive(0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-10-27 09:13:12 +05:30
|
|
|
if self.mother:
|
2004-02-14 11:10:30 +05:30
|
|
|
mname = self.mother.get_primary_name().get_name()
|
2002-10-27 09:13:12 +05:30
|
|
|
self.glade.get_widget("mname").set_text(mname)
|
2002-10-20 19:55:16 +05:30
|
|
|
else:
|
2002-11-27 19:06:11 +05:30
|
|
|
self.mother_rel.set_sensitive(0)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2003-07-21 05:39:12 +05:30
|
|
|
self.pref = self.glade.get_widget('preferred')
|
2004-02-14 11:10:30 +05:30
|
|
|
if len(self.person.get_parent_family_id_list()) > 1:
|
2003-07-21 05:39:12 +05:30
|
|
|
self.glade.get_widget('pref_label').show()
|
|
|
|
self.pref.show()
|
2004-02-14 11:10:30 +05:30
|
|
|
if family == self.person.get_parent_family_id_list()[0]:
|
2003-07-21 05:39:12 +05:30
|
|
|
self.pref.set_active(1)
|
|
|
|
else:
|
|
|
|
self.pref.set_active(0)
|
|
|
|
|
2003-11-19 08:44:14 +05:30
|
|
|
if parent_window:
|
|
|
|
self.top.set_transient_for(parent_window)
|
|
|
|
self.val = self.top.run()
|
|
|
|
if self.val == gtk.RESPONSE_OK:
|
|
|
|
self.save_parents_clicked()
|
|
|
|
self.top.destroy()
|
2003-07-21 05:39:12 +05:30
|
|
|
|
|
|
|
|
2003-11-19 08:44:14 +05:30
|
|
|
def on_help_clicked(self,obj):
|
|
|
|
"""Display the relevant portion of GRAMPS manual"""
|
|
|
|
gnome.help_display('gramps-manual','gramps-spec-par')
|
|
|
|
self.val = self.top.run()
|
|
|
|
|
|
|
|
def save_parents_clicked(self):
|
2002-10-20 19:55:16 +05:30
|
|
|
"""
|
|
|
|
Called with the OK button nis pressed. Saves the selected people as parents
|
|
|
|
of the main perosn.
|
|
|
|
"""
|
2004-02-15 12:51:29 +05:30
|
|
|
mother_rel = const.child_relations.find_value(self.mother_rel.get_text())
|
|
|
|
father_rel = const.child_relations.find_value(self.father_rel.get_text())
|
2003-07-21 05:39:12 +05:30
|
|
|
mod = 0
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
if mother_rel != self.orig_mrel or father_rel != self.orig_frel:
|
2004-02-16 04:40:12 +05:30
|
|
|
self.person.remove_parent_family_id(self.family.get_id())
|
|
|
|
self.person.add_parent_family_id(self.family.get_id(),mother_rel,father_rel)
|
2003-07-21 05:39:12 +05:30
|
|
|
mod = 1
|
2002-10-20 19:55:16 +05:30
|
|
|
Utils.modified()
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
if len(self.person.get_parent_family_id_list()):
|
2003-07-21 05:39:12 +05:30
|
|
|
make_pref = self.pref.get_active()
|
|
|
|
|
2004-02-14 11:10:30 +05:30
|
|
|
plist = self.person.get_parent_family_id_list()
|
2003-07-21 05:39:12 +05:30
|
|
|
if make_pref:
|
|
|
|
if self.family != plist[0]:
|
2004-02-16 04:40:12 +05:30
|
|
|
self.person.set_main_parent_family_id(self.family.get_id())
|
2003-07-21 05:39:12 +05:30
|
|
|
Utils.modified()
|
|
|
|
mod = 1
|
|
|
|
else:
|
|
|
|
if self.family == plist[0]:
|
2004-02-14 11:10:30 +05:30
|
|
|
self.person.set_main_parent_family_id(plist[0])
|
2003-07-21 05:39:12 +05:30
|
|
|
Utils.modified()
|
|
|
|
mod = 1
|
|
|
|
|
|
|
|
if mod:
|
|
|
|
self.family_update(None)
|