allow adding people from family editor and relview

svn: r16042
This commit is contained in:
Benny Malengier 2010-10-24 20:21:37 +00:00
parent e5f62ee933
commit 2fa5470b34
5 changed files with 106 additions and 52 deletions

View File

@ -167,6 +167,36 @@ def clearHistory_broken():
def wasHistory_broken(): def wasHistory_broken():
return _history_brokenFlag return _history_brokenFlag
#-------------------------------------------------------------------------
#
# Preset a name with a name of family member
#
#-------------------------------------------------------------------------
def preset_name(basepers, name, sibling=False):
"""Fill up name with all family common names of basepers.
If sibling=True, pa/matronymics are retained.
"""
surnlist = []
primname = basepers.get_primary_name()
prim = False
for surn in primname.get_surname_list():
if (not sibling) and (surn.get_origintype().value in
[gen.lib.NameOriginType.PATRONYMIC,
gen.lib.NameOriginType.MATRONYMIC]):
continue
surnlist.append(gen.lib.Surname(source=surn))
if surn.primary:
prim=True
if not surnlist:
surnlist = [gen.lib.Surname()]
name.set_surname_list(surnlist)
if not prim:
name.set_primary_surname(0)
name.set_family_nick_name(primname.get_family_nick_name())
name.set_group_as(primname.get_group_as())
name.set_sort_as(primname.get_sort_as())
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Short hand function to return either the person's name, or an empty # Short hand function to return either the person's name, or an empty

View File

@ -75,6 +75,7 @@ from QuestionDialog import (ErrorDialog, RunDatabaseRepair, WarningDialog,
MessageHideDialog) MessageHideDialog)
from gen.utils import get_birth_or_fallback, get_death_or_fallback from gen.utils import get_birth_or_fallback, get_death_or_fallback
from gui.selectors import SelectorFactory from gui.selectors import SelectorFactory
from Utils import preset_name
SelectPerson = SelectorFactory('Person') SelectPerson = SelectorFactory('Person')
@ -217,8 +218,7 @@ class ChildEmbedList(EmbeddedList):
name = self.latin_american() name = self.latin_american()
else: else:
name = self.no_name() name = self.no_name()
person.get_primary_name().set_surname(name[1]) person.set_primary_name(name)
person.get_primary_name().set_surname_prefix(name[0])
EditPerson(self.dbstate, self.uistate, self.track, person, EditPerson(self.dbstate, self.uistate, self.track, person,
self.new_child_added) self.new_child_added)
@ -342,34 +342,54 @@ class ChildEmbedList(EmbeddedList):
self.handle_extra_type(mytype, obj) self.handle_extra_type(mytype, obj)
def north_american(self): def north_american(self):
"""
Child inherits name from father
"""
name = gen.lib.Name()
#the editor requires a surname
name.add_surname(gen.lib.Surname())
name.set_primary_surname(0)
father_handle = self.family.get_father_handle() father_handle = self.family.get_father_handle()
if father_handle: if father_handle:
father = self.dbstate.db.get_person_from_handle(father_handle) father = self.dbstate.db.get_person_from_handle(father_handle)
pname = father.get_primary_name() preset_name(father, name)
return (pname.get_surname_prefix(), pname.get_surname()) return name
return ("","")
def no_name(self): def no_name(self):
return ("","") name = gen.lib.Name()
#the editor requires a surname
name.add_surname(gen.lib.Surname())
name.set_primary_surname(0)
return name
def latin_american(self): def latin_american(self):
"""
Child inherits name from father and mother
"""
name = gen.lib.Name()
#the editor requires a surname
name.add_surname(gen.lib.Surname())
name.set_primary_surname(0)
if self.family: if self.family:
father_handle = self.family.get_father_handle() father_handle = self.family.get_father_handle()
mother_handle = self.family.get_mother_handle() mother_handle = self.family.get_mother_handle()
if not father_handle or not mother_handle:
return ("","")
father = self.dbstate.db.get_person_from_handle(father_handle) father = self.dbstate.db.get_person_from_handle(father_handle)
mother = self.dbstate.db.get_person_from_handle(mother_handle) mother = self.dbstate.db.get_person_from_handle(mother_handle)
if not father or not mother: if not father and not mother:
return ("","") return name
fsn = father.get_primary_name().get_surname() if not father:
msn = mother.get_primary_name().get_surname() preset_name(mother, name)
try: if not mother:
return ("", "%s %s" % (fsn.split()[0], msn.split()[0])) preset_name(father, name)
except: #we take first surname, and keep that
return ("", "") mothername = gen.lib.Name()
preset_name(mother, mothername)
preset_name(father, name)
name.set_surname_list(name.get_surname_list[:1].append(
mothername.get_surname_list[:1]))
return name
else: else:
return ("", "") return name
class FastMaleFilter(object): class FastMaleFilter(object):
@ -746,8 +766,7 @@ class EditFamily(EditPrimary):
name = self.latin_american_child("mother") name = self.latin_american_child("mother")
else: else:
name = self.no_name() name = self.no_name()
person.get_primary_name().set_surname(name[1]) person.set_primary_name(name)
person.get_primary_name().set_surname_prefix(name[0])
EditPerson(self.dbstate, self.uistate, self.track, person, EditPerson(self.dbstate, self.uistate, self.track, person,
self.new_mother_added) self.new_mother_added)
@ -765,8 +784,7 @@ class EditFamily(EditPrimary):
name = self.latin_american_child("father") name = self.latin_american_child("father")
else: else:
name = self.no_name() name = self.no_name()
person.get_primary_name().set_surname(name[1]) person.set_primary_name(name)
person.get_primary_name().set_surname_prefix(name[0])
EditPerson(self.dbstate, self.uistate, self.track, EditPerson(self.dbstate, self.uistate, self.track,
person, self.new_father_added) person, self.new_father_added)
@ -1088,7 +1106,11 @@ class EditFamily(EditPrimary):
""" """
Default surname guess. Default surname guess.
""" """
return ("","") name = gen.lib.Name()
#the editor requires a surname
name.add_surname(gen.lib.Surname())
name.set_primary_surname(0)
return name
def north_american_child(self): def north_american_child(self):
""" """
@ -1096,12 +1118,16 @@ class EditFamily(EditPrimary):
and return their name for the father. and return their name for the father.
""" """
# for each child, find one with a last name # for each child, find one with a last name
name = gen.lib.Name()
#the editor requires a surname
name.add_surname(gen.lib.Surname())
name.set_primary_surname(0)
for ref in self.obj.get_child_ref_list(): for ref in self.obj.get_child_ref_list():
child = self.db.get_person_from_handle(ref.ref) child = self.db.get_person_from_handle(ref.ref)
if child: if child:
pname = child.get_primary_name() preset_name(child, name)
return (pname.get_surname_prefix(), pname.get_surname()) return name
return ("", "") return name
def latin_american_child(self, parent): def latin_american_child(self, parent):
""" """
@ -1110,24 +1136,27 @@ class EditFamily(EditPrimary):
parent = "mother" | "father" parent = "mother" | "father"
""" """
name = gen.lib.Name()
#the editor requires a surname
name.add_surname(gen.lib.Surname())
name.set_primary_surname(0)
# for each child, find one with a last name # for each child, find one with a last name
for ref in self.obj.get_child_ref_list(): for ref in self.obj.get_child_ref_list():
child = self.db.get_person_from_handle(ref.ref) child = self.db.get_person_from_handle(ref.ref)
if child: if child:
pname = child.get_primary_name() pname = child.get_primary_name()
prefix, surname = (pname.get_surname_prefix(), preset_name(child, name)
pname.get_surname()) if len(name.get_surname_list()) < 2:
if " " in surname: return name
fsn, msn = surname.split(" ", 1)
else: else:
fsn, msn = surname, surname #return first for the father, and last for the mother
if parent == "father": if parent == 'father':
return prefix, fsn name.set_surname_list(name.get_surname_list()[0])
elif parent == "mother": return name
return prefix, msn else:
else: name.set_surname_list(name.get_surname_list()[-1])
return ("", "") return name
return ("", "") return name
def button_activated(event, mouse_button): def button_activated(event, mouse_button):
if (event.type == gtk.gdk.BUTTON_PRESS and \ if (event.type == gtk.gdk.BUTTON_PRESS and \
@ -1137,4 +1166,3 @@ def button_activated(event, mouse_button):
return True return True
else: else:
return False return False

View File

@ -36,7 +36,6 @@ from libpersonview import BasePersonView
from gui.views.treemodels.peoplemodel import PersonListModel from gui.views.treemodels.peoplemodel import PersonListModel
import gen.lib import gen.lib
import Errors import Errors
from gui.editors import EditPerson
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -37,6 +37,7 @@ from gui.views.treemodels.peoplemodel import PersonTreeModel
import gen.lib import gen.lib
import Errors import Errors
from gui.editors import EditPerson from gui.editors import EditPerson
from Utils import preset_name
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -171,17 +172,9 @@ class PersonTreeView(BasePersonView):
handle = model.get_value(node, self.handle_col) handle = model.get_value(node, self.handle_col)
basepers = self.dbstate.db.get_person_from_handle(handle) basepers = self.dbstate.db.get_person_from_handle(handle)
if basepers: if basepers:
surnlist = [] preset_name(basepers, name)
primname = basepers.get_primary_name() person.set_primary_name(name)
for surn in primname.get_surname_list():
surnlist.append(gen.lib.Surname(source=surn))
name.set_surname_list(surnlist)
name.set_family_nick_name(primname.get_family_nick_name())
name.set_group_as(primname.get_group_as())
name.set_sort_as(primname.get_sort_as())
try: try:
person.set_primary_name(name)
EditPerson(self.dbstate, self.uistate, [], person) EditPerson(self.dbstate, self.uistate, [], person)
except Errors.WindowActiveError: except Errors.WindowActiveError:
pass pass

View File

@ -60,7 +60,7 @@ from gui.selectors import SelectorFactory
import Errors import Errors
import Bookmarks import Bookmarks
import const import const
from Utils import preset_name
from gen.utils import get_birth_or_fallback, get_death_or_fallback from gen.utils import get_birth_or_fallback, get_death_or_fallback
_GenderCode = { _GenderCode = {
@ -1477,12 +1477,16 @@ class RelationshipView(NavigationView):
if button_activated(event, _LEFT_BUTTON): if button_activated(event, _LEFT_BUTTON):
callback = lambda x: self.callback_add_child(x, handle) callback = lambda x: self.callback_add_child(x, handle)
person = gen.lib.Person() person = gen.lib.Person()
name = gen.lib.Name()
#the editor requires a surname
name.add_surname(gen.lib.Surname())
name.set_primary_surname(0)
family = self.dbstate.db.get_family_from_handle(handle) family = self.dbstate.db.get_family_from_handle(handle)
father = self.dbstate.db.get_person_from_handle( father = self.dbstate.db.get_person_from_handle(
family.get_father_handle()) family.get_father_handle())
if father: if father:
name = father.get_primary_name().get_surname() preset_name(father, name)
person.get_primary_name().set_surname(name) person.set_primary_name(name)
try: try:
EditPerson(self.dbstate, self.uistate, [], person, EditPerson(self.dbstate, self.uistate, [], person,
callback=callback) callback=callback)