EditName call in EditPerson

svn: r6289
This commit is contained in:
Don Allingham 2006-04-07 20:28:41 +00:00
parent 706ed650c9
commit 1439dcf535
2 changed files with 249 additions and 180 deletions

View File

@ -1,3 +1,6 @@
2006-04-07 Don Allingham <don@gramps-project.org>
* src/EditPerson.py: Fix call to EditName, pylint fixes
2006-04-06 Don Allingham <don@gramps-project.org> 2006-04-06 Don Allingham <don@gramps-project.org>
* src/glade/gramps.glade: restored addr_edit * src/glade/gramps.glade: restored addr_edit
* src/DataViews/_FamilyView.py: add select parents function * src/DataViews/_FamilyView.py: add select parents function

View File

@ -8,7 +8,7 @@
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
@ -20,15 +20,21 @@
# $Id$ # $Id$
"""
EditPerson Dialog. Provides the interface to allow the GRAMPS program
to edit information about a particular Person.
"""
__author__ = "Don Allingham"
__revision__ = "$Revision$"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Standard python modules # Standard python modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os
import locale import locale
from gettext import gettext as _ from gettext import gettext as _
from cgi import escape
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -39,6 +45,11 @@ import gtk
import gtk.glade import gtk.glade
import gtk.gdk import gtk.gdk
try:
set()
except NameError:
from sets import Set as set
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# gramps modules # gramps modules
@ -46,25 +57,13 @@ import gtk.gdk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import const import const
import Utils import Utils
import Config
import Mime import Mime
import RelLib import RelLib
import DateHandler
import NameDisplay
import DisplayState
import GrampsDisplay
import GrampsWidgets import GrampsWidgets
import AutoComp
from _EditPrimary import EditPrimary from _EditPrimary import EditPrimary
from DisplayTabs import *
from QuestionDialog import WarningDialog, ErrorDialog, QuestionDialog2 from QuestionDialog import WarningDialog, ErrorDialog, QuestionDialog2
from DdTargets import DdTargets from DisplayTabs import NoteTab, GalleryTab, WebEmbedList, LdsEmbedList
try:
set()
except:
from sets import Set as set
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -72,93 +71,125 @@ except:
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
_select_gender = ((True,False,False),(False,True,False),(False,False,True)) _select_gender = ((True, False, False),
_use_patronymic = set(["ru","RU","ru_RU","koi8r","ru_koi8r","russian","Russian"]) (False, True, False),
(False, False, True))
_use_patronymic = set(
["ru", "RU", "ru_RU", "koi8r", "ru_koi8r", "russian", "Russian"]
)
#-------------------------------------------------------------------------
#
# EditPerson class
#
#-------------------------------------------------------------------------
class EditPerson(EditPrimary): class EditPerson(EditPrimary):
"""
The EditPerson dialog is derived from the EditPrimary class. It
allos for the editing of the primary object type of Person.
"""
use_patronymic = locale.getlocale(locale.LC_TIME)[0] in _use_patronymic use_patronymic = locale.getlocale(locale.LC_TIME)[0] in _use_patronymic
def __init__(self,state,uistate,track,person,callback=None): def __init__(self, state, uistate, track, person, callback=None):
"""Creates an edit window. Associates a person with the window.""" """
Creates an EditPerson window. Associates a person with the window.
"""
EditPrimary.__init__(self, state, uistate, track, person, EditPrimary.__init__(self, state, uistate, track, person,
state.db.get_person_from_handle, callback) state.db.get_person_from_handle, callback)
def empty_object(self): def empty_object(self):
"""
Returns an empty Person object for comparison for changes. This
is used by the base class (EditPrimary)
"""
return RelLib.Person() return RelLib.Person()
def _local_init(self): def _local_init(self):
"""
Local initialization function. Performs basic initialization,
including setting up widgets and the glade interface. This is called
by the base class of EditPrimary, and overridden here.
"""
self.pname = self.obj.get_primary_name() self.pname = self.obj.get_primary_name()
self.should_guess_gender = (not self.obj.get_gramps_id() and self.should_guess_gender = (not self.obj.get_gramps_id() and
self.obj.get_gender () == self.obj.get_gender () ==
RelLib.Person.UNKNOWN) RelLib.Person.UNKNOWN)
self.load_obj = None self.load_obj = None
self.top = gtk.glade.XML(const.person_glade, "edit_person","gramps") self.top = gtk.glade.XML(const.person_glade, "edit_person", "gramps")
self.define_top_level(self.top.get_widget("edit_person"), None, self.define_top_level(self.top.get_widget("edit_person"), None,
_('Edit Person')) _('Edit Person'))
self.obj_photo = self.top.get_widget("personPix") self.obj_photo = self.top.get_widget("personPix")
self.eventbox = self.top.get_widget("eventbox1") self.eventbox = self.top.get_widget("eventbox1")
def _post_init(self): def _post_init(self):
"""
Post initalization function. Handles any initialization that
needs to be done after the interface is brought up. This called
by _EditPrimary's init routine, and overridden in the derived
class (this class)
"""
self.load_person_image() self.load_person_image()
self.surname_field.grab_focus() self.surname_field.grab_focus()
def _connect_signals(self): def _connect_signals(self):
"""
Connects any signals that need to be connected. Called by the
init routine of the base class (_EditPrimary).
"""
self.define_cancel_button(self.top.get_widget("button15")) self.define_cancel_button(self.top.get_widget("button15"))
self.define_ok_button(self.top.get_widget("ok"), self.save) self.define_ok_button(self.top.get_widget("ok"), self.save)
self.define_help_button(self.top.get_widget("button134"),'adv-pers') self.define_help_button(self.top.get_widget("button134"), 'adv-pers')
self.given.connect("focus_out_event",self.given_focus_out_event) self.given.connect("focus_out_event", self._given_focus_out_event)
self.top.get_widget("button177").connect("clicked", self.edit_name_clicked) self.top.get_widget("button177").connect("clicked",
self._edit_name_clicked)
self.eventbox.connect('button-press-event',self.image_button_press) self.eventbox.connect('button-press-event',
self._image_button_press)
def _setup_fields(self): def _setup_fields(self):
"""
Connects the GrampsWidget objects to field in the interface. This
allows the widgets to keep the data in the attached Person object
up to date at all times, eliminating a lot of need in 'save' routine.
"""
self.private = GrampsWidgets.PrivacyButton( self.private = GrampsWidgets.PrivacyButton(
self.top.get_widget('private'), self.top.get_widget('private'),
self.obj) self.obj)
self.gender = GrampsWidgets.MonitoredMenu( self.gender = GrampsWidgets.MonitoredMenu(
self.top.get_widget('gender'), self.top.get_widget('gender'),
self.obj.set_gender, self.obj.set_gender,
self.obj.get_gender, self.obj.get_gender,
( (
(_('female'),RelLib.Person.FEMALE), (_('female'), RelLib.Person.FEMALE),
(_('male'),RelLib.Person.MALE), (_('male'), RelLib.Person.MALE),
(_('unknown'),RelLib.Person.UNKNOWN) (_('unknown'), RelLib.Person.UNKNOWN)
), ),
self.db.readonly) self.db.readonly)
self.ntype_field = GrampsWidgets.MonitoredType( self.ntype_field = GrampsWidgets.MonitoredType(
self.top.get_widget("ntype"), self.top.get_widget("ntype"),
self.pname.set_type, self.pname.set_type,
self.pname.get_type, self.pname.get_type,
dict(Utils.name_types), dict(Utils.name_types),
RelLib.Name.CUSTOM, RelLib.Name.CUSTOM,
self.db.readonly) self.db.readonly)
self.marker = GrampsWidgets.MonitoredType( self.marker = GrampsWidgets.MonitoredType(
self.top.get_widget('marker'), self.top.get_widget('marker'),
self.obj.set_marker, self.obj.set_marker,
self.obj.get_marker, self.obj.get_marker,
dict(Utils.marker_types), dict(Utils.marker_types),
RelLib.PrimaryObject.MARKER_CUSTOM, RelLib.PrimaryObject.MARKER_CUSTOM,
self.db.readonly) self.db.readonly)
if self.use_patronymic: if self.use_patronymic:
self.prefix = GrampsWidgets.MonitoredEntry( self.prefix = GrampsWidgets.MonitoredEntry(
self.top.get_widget("prefix"), self.top.get_widget("prefix"),
self.pname.set_patronymic, self.pname.set_patronymic,
self.pname.get_patronymic, self.pname.get_patronymic,
self.db.readonly) self.db.readonly)
prefix_label = self.top.get_widget('prefix_label') prefix_label = self.top.get_widget('prefix_label')
@ -166,40 +197,40 @@ class EditPerson(EditPrimary):
prefix_label.set_use_underline(True) prefix_label.set_use_underline(True)
else: else:
self.prefix = GrampsWidgets.MonitoredEntry( self.prefix = GrampsWidgets.MonitoredEntry(
self.top.get_widget("prefix"), self.top.get_widget("prefix"),
self.pname.set_surname_prefix, self.pname.set_surname_prefix,
self.pname.get_surname_prefix, self.pname.get_surname_prefix,
self.db.readonly) self.db.readonly)
self.suffix = GrampsWidgets.MonitoredEntry( self.suffix = GrampsWidgets.MonitoredEntry(
self.top.get_widget("suffix"), self.top.get_widget("suffix"),
self.pname.set_suffix, self.pname.set_suffix,
self.pname.get_suffix, self.pname.get_suffix,
self.db.readonly) self.db.readonly)
self.given = GrampsWidgets.MonitoredEntry( self.given = GrampsWidgets.MonitoredEntry(
self.top.get_widget("given_name"), self.top.get_widget("given_name"),
self.pname.set_first_name, self.pname.set_first_name,
self.pname.get_first_name, self.pname.get_first_name,
self.db.readonly) self.db.readonly)
self.title = GrampsWidgets.MonitoredEntry( self.title = GrampsWidgets.MonitoredEntry(
self.top.get_widget("title"), self.top.get_widget("title"),
self.pname.set_title, self.pname.set_title,
self.pname.get_title, self.pname.get_title,
self.db.readonly) self.db.readonly)
self.surname_field = GrampsWidgets.MonitoredEntry( self.surname_field = GrampsWidgets.MonitoredEntry(
self.top.get_widget("surname"), self.top.get_widget("surname"),
self.pname.set_surname, self.pname.set_surname,
self.pname.get_surname, self.pname.get_surname,
self.db.readonly, self.db.readonly,
autolist=self.db.get_surname_list()) autolist=self.db.get_surname_list())
self.gid = GrampsWidgets.MonitoredEntry( self.gid = GrampsWidgets.MonitoredEntry(
self.top.get_widget("gid"), self.top.get_widget("gid"),
self.obj.set_gramps_id, self.obj.set_gramps_id,
self.obj.get_gramps_id, self.obj.get_gramps_id,
self.db.readonly) self.db.readonly)
def _create_tabbed_pages(self): def _create_tabbed_pages(self):
@ -211,74 +242,77 @@ class EditPerson(EditPrimary):
notebook = gtk.Notebook() notebook = gtk.Notebook()
self.event_list = self._add_tab( self.event_list = self._add_tab(
notebook, notebook,
PersonEventEmbedList(self.dbstate,self.uistate, PersonEventEmbedList(self.dbstate, self.uistate,
self.track,self.obj)) self.track, self.obj))
self.name_list = self._add_tab( self.name_list = self._add_tab(
notebook, notebook,
NameEmbedList(self.dbstate, self.uistate, self.track, NameEmbedList(self.dbstate, self.uistate, self.track,
self.obj.get_alternate_names())) self.obj.get_alternate_names()))
self.srcref_list = self._add_tab( self.srcref_list = self._add_tab(
notebook, notebook,
SourceEmbedList(self.dbstate,self.uistate, SourceEmbedList(self.dbstate, self.uistate,
self.track, self.obj.source_list)) self.track, self.obj.source_list))
self.attr_list = self._add_tab( self.attr_list = self._add_tab(
notebook, notebook,
AttrEmbedList(self.dbstate,self.uistate, self.track, AttrEmbedList(self.dbstate, self.uistate, self.track,
self.obj.get_attribute_list())) self.obj.get_attribute_list()))
self.addr_list = self._add_tab( self.addr_list = self._add_tab(
notebook, notebook,
AddrEmbedList(self.dbstate,self.uistate,self.track, AddrEmbedList(self.dbstate, self.uistate, self.track,
self.obj.get_address_list())) self.obj.get_address_list()))
self.note_tab = self._add_tab( self.note_tab = self._add_tab(
notebook, notebook,
NoteTab(self.dbstate, self.uistate, self.track, NoteTab(self.dbstate, self.uistate, self.track,
self.obj.get_note_object())) self.obj.get_note_object()))
self.gallery_tab = self._add_tab( self.gallery_tab = self._add_tab(
notebook, notebook,
GalleryTab(self.dbstate, self.uistate, self.track, GalleryTab(self.dbstate, self.uistate, self.track,
self.obj.get_media_list())) self.obj.get_media_list()))
self.web_list = self._add_tab( self.web_list = self._add_tab(
notebook, notebook,
WebEmbedList(self.dbstate,self.uistate,self.track, WebEmbedList(self.dbstate, self.uistate, self.track,
self.obj.get_url_list())) self.obj.get_url_list()))
self.lds_list = self._add_tab( self.lds_list = self._add_tab(
notebook, notebook,
LdsEmbedList(self.dbstate,self.uistate,self.track, LdsEmbedList(self.dbstate, self.uistate, self.track,
self.obj.get_lds_ord_list())) self.obj.get_lds_ord_list()))
notebook.show_all() notebook.show_all()
self.top.get_widget('vbox').pack_start(notebook,True) self.top.get_widget('vbox').pack_start(notebook, True)
def build_menu_names(self,person): def build_menu_names(self, person):
"""
Provides the information need by the base class to define the
window management menu entries.
"""
win_menu_label = self.nd.display(person) win_menu_label = self.nd.display(person)
if not win_menu_label.strip(): if not win_menu_label.strip():
win_menu_label = _("New Person") win_menu_label = _("New Person")
return (_('Edit Person'),win_menu_label) return (_('Edit Person'), win_menu_label)
# def set_list_dnd(self,obj, get, begin, receive): def _image_callback(self, ref):
# obj.drag_dest_set(gtk.DEST_DEFAULT_ALL, [DdTargets.NAME.target()], """
# gtk.gdk.ACTION_COPY) Called when a media reference had been edited. This allows fot
# obj.drag_source_set(gtk.gdk.BUTTON1_MASK,[DdTargets.NAME.target()], the updating image on the main form which has just been modified.
# gtk.gdk.ACTION_COPY) """
# obj.connect('drag_data_get', get)
# obj.connect('drag_begin', begin)
# if not self.db.readonly:
# obj.connect('drag_data_received', receive)
def image_callback(self,ref):
obj = self.db.get_object_from_handle(ref.get_reference_handle()) obj = self.db.get_object_from_handle(ref.get_reference_handle())
self.load_photo(obj) self.load_photo(obj)
def image_button_press(self,obj,event): def _image_button_press(self, obj, event):
"""
Button press event that is caught when a button has been
pressed while on the image on the main form. This does not apply
to the images in galleries, just the image on the main form.
"""
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1: if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
media_list = self.obj.get_media_list() media_list = self.obj.get_media_list()
@ -289,17 +323,19 @@ class EditPerson(EditPrimary):
object_handle = media_ref.get_reference_handle() object_handle = media_ref.get_reference_handle()
media_obj = self.db.get_object_from_handle(object_handle) media_obj = self.db.get_object_from_handle(object_handle)
EditMediaRef(self.dbstate, self.uistate, self.track, EditMediaRef(self.dbstate, self.uistate, self.track,
media_obj, media_ref, self.image_callback) media_obj, media_ref, self._image_callback)
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
media_list = self.obj.get_media_list() media_list = self.obj.get_media_list()
if media_list: if media_list:
ph = media_list[0] photo = media_list[0]
self.show_popup(ph,event) self._show_popup(photo, event)
def show_popup(self, photo, event): def _show_popup(self, photo, event):
"""Look for right-clicks on a picture and create a popup """
menu of the available actions.""" Look for right-clicks on a picture and create a popup
menu of the available actions.
"""
menu = gtk.Menu() menu = gtk.Menu()
menu.set_title(_("Media Object")) menu.set_title(_("Media Object"))
@ -308,21 +344,26 @@ class EditPerson(EditPrimary):
progname = Mime.get_application(mtype) progname = Mime.get_application(mtype)
if progname and len(progname) > 1: if progname and len(progname) > 1:
Utils.add_menuitem(menu,_("Open in %s") % progname[1], Utils.add_menuitem(menu, _("Open in %s") % progname[1],
photo,self.popup_view_photo) photo, self._popup_view_photo)
Utils.add_menuitem(menu,_("Edit Object Properties"),photo, Utils.add_menuitem(menu, _("Edit Object Properties"), photo,
self.popup_change_description) self._popup_change_description)
menu.popup(None,None,None,event.button,event.time) menu.popup(None, None, None, event.button, event.time)
def popup_view_photo(self, obj): def _popup_view_photo(self, obj):
"""Open this picture in a picture viewer""" """
Open this picture in the default picture viewer
"""
media_list = self.obj.get_media_list() media_list = self.obj.get_media_list()
if media_list: if media_list:
ph = media_list[0] photo = media_list[0]
object_handle = ph.get_reference_handle() object_handle = photo.get_reference_handle()
Utils.view_photo(self.db.get_object_from_handle(object_handle)) Utils.view_photo(self.db.get_object_from_handle(object_handle))
def popup_change_description(self,obj): def _popup_change_description(self, obj):
"""
Brings up the EditMediaRef dialog for the image on the main form.
"""
media_list = self.obj.get_media_list() media_list = self.obj.get_media_list()
if media_list: if media_list:
from Editors import EditMediaRef from Editors import EditMediaRef
@ -330,19 +371,25 @@ class EditPerson(EditPrimary):
media_ref = media_list[0] media_ref = media_list[0]
object_handle = media_ref.get_reference_handle() object_handle = media_ref.get_reference_handle()
media_obj = self.db.get_object_from_handle(object_handle) media_obj = self.db.get_object_from_handle(object_handle)
EditMediaRef(self.dbstate, self.uistate, self.track, EditMediaRef(self.dbstate, self.uistate, self.track,
media_obj, media_ref, self.image_callback) media_obj, media_ref, self._image_callback)
def given_focus_out_event (self, entry, event): def _given_focus_out_event (self, entry, event):
"""
Callback that occurs when the user leaves the given name field,
allowing us to attempt to guess the gender of the person if
so requested.
"""
if not self.should_guess_gender: if not self.should_guess_gender:
return False return False
try: try:
self.gender.force(self.db.genderStats.guess_gender(entry.get_text())) gender_type = self.db.genderStats.guess_gender(entry.get_text())
self.gender.force(gender_type)
except: except:
return False return False
return False return False
def load_photo(self,photo): def load_photo(self, photo):
"""loads, scales, and displays the person's main photo""" """loads, scales, and displays the person's main photo"""
self.load_obj = photo self.load_obj = photo
if photo == None: if photo == None:
@ -350,11 +397,11 @@ class EditPerson(EditPrimary):
else: else:
try: try:
i = gtk.gdk.pixbuf_new_from_file(photo) i = gtk.gdk.pixbuf_new_from_file(photo)
ratio = float(max(i.get_height(),i.get_width())) ratio = float(max(i.get_height(), i.get_width()))
scale = float(100.0)/ratio scale = float(100.0)/ratio
x = int(scale*(i.get_width())) x = int(scale*(i.get_width()))
y = int(scale*(i.get_height())) y = int(scale*(i.get_height()))
i = i.scale_simple(x,y,gtk.gdk.INTERP_BILINEAR) i = i.scale_simple(x, y, gtk.gdk.INTERP_BILINEAR)
self.obj_photo.set_from_pixbuf(i) self.obj_photo.set_from_pixbuf(i)
self.obj_photo.show() self.obj_photo.show()
except: except:
@ -363,12 +410,12 @@ class EditPerson(EditPrimary):
def _check_for_unknown_gender(self): def _check_for_unknown_gender(self):
if self.obj.get_gender() == RelLib.Person.UNKNOWN: if self.obj.get_gender() == RelLib.Person.UNKNOWN:
dialog = QuestionDialog2( dialog = QuestionDialog2(
_("Unknown gender specified"), _("Unknown gender specified"),
_("The gender of the person is currently unknown. " _("The gender of the person is currently unknown. "
"Usually, this is a mistake. You may choose to " "Usually, this is a mistake. You may choose to "
"either continue saving, or returning to the " "either continue saving, or returning to the "
"Edit Person dialog to fix the problem."), "Edit Person dialog to fix the problem."),
_("Continue saving"), _("Return to window"), _("Continue saving"), _("Return to window"),
self.window) self.window)
if not dialog.run(): if not dialog.run():
return True return True
@ -381,35 +428,38 @@ class EditPerson(EditPrimary):
idval = self.obj.get_gramps_id() idval = self.obj.get_gramps_id()
person = self.db.get_person_from_gramps_id(idval) person = self.db.get_person_from_gramps_id(idval)
if person: if person:
n = self.nd.display(person) name = self.nd.display(person)
msg1 = _("GRAMPS ID value was not changed.") msg1 = _("GRAMPS ID value was not changed.")
msg2 = _("You have attempted to change the GRAMPS ID to a value " msg2 = _("You have attempted to change the GRAMPS ID "
"of %(grampsid)s. This value is already used by %(person)s.") % { "to a value of %(grampsid)s. This value is "
'grampsid' : idval, "already used by %(person)s.") % {
'person' : n } 'grampsid' : idval,
WarningDialog(msg1,msg2) 'person' : name }
WarningDialog(msg1, msg2)
def _update_family_ids(self, trans): def _update_family_ids(self, trans):
# Update each of the families child lists to reflect any # Update each of the families child lists to reflect any
# change in ordering due to the new birth date # change in ordering due to the new birth date
family = self.obj.get_main_parents_family_handle() family = self.obj.get_main_parents_family_handle()
if (family): if (family):
f = self.db.find_family_from_handle(family,trans) f = self.db.find_family_from_handle(family, trans)
new_order = self.reorder_child_list(self.obj,f.get_child_handle_list()) new_order = self.reorder_child_list(self.obj,
f.get_child_handle_list())
f.set_child_handle_list(new_order) f.set_child_handle_list(new_order)
for (family, rel1, rel2) in self.obj.get_parent_family_handle_list(): for (family, rel1, rel2) in self.obj.get_parent_family_handle_list():
f = self.db.find_family_from_handle(family,trans) f = self.db.find_family_from_handle(family, trans)
new_order = self.reorder_child_list(self.obj,f.get_child_handle_list()) new_order = self.reorder_child_list(self.obj,
f.get_child_handle_list())
f.set_child_handle_list(new_order) f.set_child_handle_list(new_order)
error = False error = False
original = self.db.get_person_from_handle(self.obj.handle) original = self.db.get_person_from_handle(self.obj.handle)
if original: if original:
(female,male,unknown) = _select_gender[self.obj.get_gender()] (female, male, unknown) = _select_gender[self.obj.get_gender()]
if male and original.get_gender() != RelLib.Person.MALE: if male and original.get_gender() != RelLib.Person.MALE:
for temp_family_handle in self.obj.get_family_handle_list(): for tmp_handle in self.obj.get_family_handle_list():
temp_family = self.db.get_family_from_handle(temp_family_handle) temp_family = self.db.get_family_from_handle(tmp_handle)
if self.obj == temp_family.get_mother_handle(): if self.obj == temp_family.get_mother_handle():
if temp_family.get_father_handle() != None: if temp_family.get_father_handle() != None:
error = True error = True
@ -417,8 +467,8 @@ class EditPerson(EditPrimary):
temp_family.set_mother_handle(None) temp_family.set_mother_handle(None)
temp_family.set_father_handle(self.obj) temp_family.set_father_handle(self.obj)
elif female and original != RelLib.Person.FEMALE: elif female and original != RelLib.Person.FEMALE:
for temp_family_handle in self.obj.get_family_handle_list(): for tmp_handle in self.obj.get_family_handle_list():
temp_family = self.db.get_family_from_handle(temp_family_handle) temp_family = self.db.get_family_from_handle(tmp_handle)
if self.obj == temp_family.get_father_handle(): if self.obj == temp_family.get_father_handle():
if temp_family.get_mother_handle() != None: if temp_family.get_mother_handle() != None:
error = True error = True
@ -426,8 +476,8 @@ class EditPerson(EditPrimary):
temp_family.set_father_handle(None) temp_family.set_father_handle(None)
temp_family.set_mother_handle(self.obj) temp_family.set_mother_handle(self.obj)
elif unknown and original.get_gender() != RelLib.Person.UNKNOWN: elif unknown and original.get_gender() != RelLib.Person.UNKNOWN:
for temp_family_handle in self.obj.get_family_handle_list(): for tmp_handle in self.obj.get_family_handle_list():
temp_family = self.db.get_family_from_handle(temp_family_handle) temp_family = self.db.get_family_from_handle(tmp_handle)
if self.obj == temp_family.get_father_handle(): if self.obj == temp_family.get_father_handle():
if temp_family.get_mother_handle() != None: if temp_family.get_mother_handle() != None:
error = True error = True
@ -446,15 +496,15 @@ class EditPerson(EditPrimary):
msg = _("Changing the gender caused problems " msg = _("Changing the gender caused problems "
"with marriage information.\nPlease check " "with marriage information.\nPlease check "
"the person's marriages.") "the person's marriages.")
ErrorDialog(msg) ErrorDialog(msg2, msg)
def save(self,*obj): def save(self, *obj):
""" """
Save the data. Save the data.
""" """
if self.object_is_empty(): if self.object_is_empty():
ErrorDialog(_("Cannot save person"), ErrorDialog(_("Cannot save person"),
_("No data exists for this person. Please " _("No data exists for this person. Please "
"enter data or cancel the edit.")) "enter data or cancel the edit."))
return return
@ -462,10 +512,10 @@ class EditPerson(EditPrimary):
if self._check_for_unknown_gender(): if self._check_for_unknown_gender():
return return
(br, dr, el) = self.event_list.return_info() (birth_ref, death_ref, event_list) = self.event_list.return_info()
self.obj.set_birth_ref(br) self.obj.set_birth_ref(birth_ref)
self.obj.set_death_ref(dr) self.obj.set_death_ref(death_ref)
self.obj.set_event_ref_list(el) self.obj.set_event_ref_list(event_list)
self.window.hide() self.window.hide()
@ -481,25 +531,40 @@ class EditPerson(EditPrimary):
self.obj.set_gramps_id(self.db.find_next_person_gramps_id()) self.obj.set_gramps_id(self.db.find_next_person_gramps_id())
self.db.commit_person(self.obj, trans) self.db.commit_person(self.obj, trans)
self.db.transaction_commit(trans,_("Edit Person (%s)") % self.nd.display(self.obj)) msg = _("Edit Person (%s)") % self.nd.display(self.obj)
self.db.transaction_commit(trans, msg)
self.close() self.close()
if self.callback: if self.callback:
self.callback(self.obj) self.callback(self.obj)
def edit_name_clicked(self,obj): def _edit_name_clicked(self, obj):
NameEdit.NameEditor(self.dbstate, self.uistate, self.track, """
self.pname, self.update_name) Called when the edit name button is clicked for the primary name
on the main form (not in the names tab). Brings up the EditName
dialog for this name.
"""
from Editors import EditName
EditName(self.dbstate, self.uistate, self.track,
self.pname, self._update_name)
def update_name(self,name): def _update_name(self, name):
for obj in (self.suffix, self.prefix, self.given, self.title, """
Called when the primary name has been changed by the EditName
dialog. This allows us to update the main form in response to
any changes.
"""
for obj in (self.suffix, self.prefix, self.given, self.title,
self.ntype_field, self.surname_field): self.ntype_field, self.surname_field):
obj.update() obj.update()
def load_person_image(self): def load_person_image(self):
"""
Loads the primary image into the main form if it exists.
"""
media_list = self.obj.get_media_list() media_list = self.obj.get_media_list()
if media_list: if media_list:
ph = media_list[0] photo = media_list[0]
object_handle = ph.get_reference_handle() object_handle = photo.get_reference_handle()
obj = self.db.get_object_from_handle(object_handle) obj = self.db.get_object_from_handle(object_handle)
if self.load_obj != obj.get_path(): if self.load_obj != obj.get_path():
mime_type = obj.get_mime_type() mime_type = obj.get_mime_type()
@ -510,16 +575,17 @@ class EditPerson(EditPrimary):
else: else:
self.load_photo(None) self.load_photo(None)
def birth_dates_in_order(self,list): def birth_dates_in_order(self, child_list):
"""Check any *valid* birthdates in the list to insure that they are in """Check any *valid* birthdates in the list to insure that they are in
numerically increasing order.""" numerically increasing order."""
inorder = True inorder = True
prev_date = 0 prev_date = 0
for i in range(len(list)): for i in range(len(child_list)):
child_handle = list[i] child_handle = child_list[i]
child = self.db.get_person_from_handle(child_handle) child = self.db.get_person_from_handle(child_handle)
if child.get_birth_ref(): if child.get_birth_ref():
event = self.db.get_event_from_handle(child.get_birth_ref().ref) event_handle = child.get_birth_ref().ref
event = self.db.get_event_from_handle(event_handle)
child_date = event.get_date_object().get_sort_value() child_date = event.get_date_object().get_sort_value()
else: else:
continue continue
@ -529,13 +595,13 @@ class EditPerson(EditPrimary):
inorder = False inorder = False
return inorder return inorder
def reorder_child_list(self, person, list): def reorder_child_list(self, person, child_list):
"""Reorder the child list to put the specified person in his/her """Reorder the child list to put the specified person in his/her
correct birth order. Only check *valid* birthdates. Move the person correct birth order. Only check *valid* birthdates. Move the person
as short a distance as possible.""" as short a distance as possible."""
if (self.birth_dates_in_order(list)): if self.birth_dates_in_order(child_list):
return(list) return(child_list)
# Build the person's date string once # Build the person's date string once
event_ref = person.get_birth_ref() event_ref = person.get_birth_ref()
@ -547,10 +613,10 @@ class EditPerson(EditPrimary):
# First, see if the person needs to be moved forward in the list # First, see if the person needs to be moved forward in the list
index = list.index(person.get_handle()) index = child_list.index(person.get_handle())
target = index target = index
for i in range(index-1, -1, -1): for i in range(index-1, -1, -1):
other = self.db.get_person_from_handle(list[i]) other = self.db.get_person_from_handle(child_list[i])
event_ref = other.get_birth_ref() event_ref = other.get_birth_ref()
if event_ref: if event_ref:
event = self.db.get_event_from_handle(event_ref.ref) event = self.db.get_event_from_handle(event_ref.ref)
@ -564,8 +630,8 @@ class EditPerson(EditPrimary):
# Now try moving to a later position in the list # Now try moving to a later position in the list
if (target == index): if (target == index):
for i in range(index, len(list)): for i in range(index, len(child_list)):
other = self.db.get_person_from_handle(list[i]) other = self.db.get_person_from_handle(child_list[i])
event_ref = other.get_birth_ref() event_ref = other.get_birth_ref()
if event_ref: if event_ref:
event = self.db.get_event_from_handle(event_ref.ref) event = self.db.get_event_from_handle(event_ref.ref)
@ -579,7 +645,7 @@ class EditPerson(EditPrimary):
# Actually need to move? Do it now. # Actually need to move? Do it now.
if (target != index): if (target != index):
list.remove(person.get_handle()) child_list.remove(person.get_handle())
list.insert(target,person.get_handle()) child_list.insert(target, person.get_handle())
return list return child_list