From 98e031a82509b0c61b76a648f844794352ee2ea2 Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Sun, 13 Mar 2005 22:10:40 +0000 Subject: [PATCH] * src/DateEdit.py (update_after_editor): Add method. * src/EditPerson.py: Always have birth/death events (never None); Use new update method for dates; Only commit death/birth if changed; Only add new birth/death if non-empty. * src/EventEdit.py: Translate stored event names before including in menu; Exclude birth/death from menu; Do not add birth/death to the custom event types; Only detect type change for non-birth/death. * src/GrampsDbBase.py: Do not commit objects with empty handles. * src/GrampsInMemDB.py: Do not commit objects with empty handles. * src/Utils.py (family_name): Add clause for unknown parents. svn: r4172 --- gramps2/ChangeLog | 12 +++++++ gramps2/src/DateEdit.py | 12 +++++-- gramps2/src/EditPerson.py | 66 ++++++++++++++++-------------------- gramps2/src/EventEdit.py | 15 ++++---- gramps2/src/GrampsDbBase.py | 14 ++++---- gramps2/src/GrampsInMemDB.py | 15 +++++--- gramps2/src/Utils.py | 4 ++- 7 files changed, 80 insertions(+), 58 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index df6bec983..f87f24f6c 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,15 @@ +2005-03-13 Alex Roitman + * src/DateEdit.py (update_after_editor): Add method. + * src/EditPerson.py: Always have birth/death events (never None); + Use new update method for dates; Only commit death/birth if changed; + Only add new birth/death if non-empty. + * src/EventEdit.py: Translate stored event names before including in + menu; Exclude birth/death from menu; Do not add birth/death to the + custom event types; Only detect type change for non-birth/death. + * src/GrampsDbBase.py: Do not commit objects with empty handles. + * src/GrampsInMemDB.py: Do not commit objects with empty handles. + * src/Utils.py (family_name): Add clause for unknown parents. + 2005-03-12 Martin Hawlisch * src/GenericFilter.py (Rule,GenericFilter): New methods prepare() and reset(), that are called before/after a filter is applied, to properly diff --git a/gramps2/src/DateEdit.py b/gramps2/src/DateEdit.py index f8d87c85a..b9754dd29 100644 --- a/gramps2/src/DateEdit.py +++ b/gramps2/src/DateEdit.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2002-2004 Donald N. Allingham +# Copyright (C) 2002-2005 Donald N. Allingham # # 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 @@ -156,8 +156,14 @@ class DateEdit: """ date_dialog = DateEditorDialog(self.date_obj,self.parent_window) the_date = date_dialog.return_date - if the_date: - self.date_obj.copy(the_date) + self.update_after_editor(the_date) + + def update_after_editor(self,date_obj): + """ + Update text field and LED button to reflect the given date instance. + """ + if date_obj: + self.date_obj.copy(date_obj) self.text_obj.set_text(DateHandler.displayer.display(self.date_obj)) self.check() diff --git a/gramps2/src/EditPerson.py b/gramps2/src/EditPerson.py index 56bff0220..4db5d1015 100644 --- a/gramps2/src/EditPerson.py +++ b/gramps2/src/EditPerson.py @@ -27,6 +27,7 @@ #------------------------------------------------------------------------- import pickle import os +import locale from gettext import gettext as _ #------------------------------------------------------------------------- @@ -38,8 +39,6 @@ import gtk import gtk.glade import gobject import gnome -import locale - from gtk.gdk import ACTION_COPY, BUTTON1_MASK, INTERP_BILINEAR, pixbuf_new_from_file #------------------------------------------------------------------------- @@ -260,9 +259,19 @@ class EditPerson: self.prefix_label.set_use_underline(True) birth_handle = person.get_birth_handle() + if birth_handle: + self.orig_birth = self.db.get_event_from_handle(birth_handle) + else: + self.orig_birth = RelLib.Event() + self.orig_birth.set_name("Birth") + death_handle = person.get_death_handle() - self.orig_birth = self.db.get_event_from_handle(birth_handle) - self.orig_death = self.db.get_event_from_handle(death_handle) + if death_handle: + self.orig_death = self.db.get_event_from_handle(death_handle) + else: + self.orig_death = RelLib.Event() + self.orig_death.set_name("Death") + self.death = RelLib.Event(self.orig_death) self.birth = RelLib.Event(self.orig_birth) self.pname = RelLib.Name(person.get_primary_name()) @@ -423,7 +432,6 @@ class EditPerson: self.birth_date_object = self.birth.get_date_object() self.death_date_object = self.death.get_date_object() - self.update_birth_death() self.bdate_check = DateEdit.DateEdit( self.birth_date_object, self.bdate, @@ -433,6 +441,8 @@ class EditPerson: self.death_date_object, self.ddate, self.get_widget("death_stat"), self.window) + self.update_birth_death() + self.top.signal_autoconnect({ "destroy_passed_object" : self.on_cancel_edit, "on_up_clicked" : self.on_up_clicked, @@ -717,23 +727,10 @@ class EditPerson: for fam_id in flist: index += 1 - fam = self.db.get_family_from_handle(fam_id) - if fam == None: + family = self.db.get_family_from_handle(fam_id) + if family == None: continue - f_id = fam.get_father_handle() - m_id = fam.get_mother_handle() - f = self.db.get_person_from_handle(f_id) - m = self.db.get_person_from_handle(m_id) - if f and m: - name = _("%(father)s and %(mother)s") % { - 'father' : self.name_display.display(f), - 'mother' : self.name_display.display(m) } - elif f: - name = self.name_display.display(f) - elif m: - name = self.name_display.display(m) - else: - name = _("unknown") + name = Utils.family_name(family,self.db) store.append(row=[name]) self.lds_fam_list.append(fam_id) if fam_id == self.ldsfam: @@ -1386,15 +1383,14 @@ class EditPerson: self.bplace.set_text(place_title(self.db,self.birth)) self.dplace.set_text(place_title(self.db,self.death)) - self.bdate.set_text(self.dd.display(self.birth_date_object)) - self.ddate.set_text(self.dd.display(self.death_date_object)) + self.bdate_check.update_after_editor(self.birth_date_object) + self.ddate_check.update_after_editor(self.death_date_object) def on_update_attr_clicked(self,obj): import AttrEdit store,node = self.atree.get_selected() if node: attr = self.atree.get_object(node) - print attr.get_type() pname = self.name_display.display(self.person) AttrEdit.AttributeEditor(self,attr,pname,const.personalAttributes, self.attr_edit_callback,self.window, @@ -1696,10 +1692,10 @@ class EditPerson: p = self.db.get_place_from_handle(key).get_display_info() self.pdmap[p[0]] = key - if self.orig_birth == None: - self.db.add_event(self.birth,trans) - self.person.set_birth_handle(self.birth.get_handle()) - elif not self.orig_birth.are_equal(self.birth): + if not self.orig_birth.are_equal(self.birth): + if self.orig_birth.is_empty(): + self.db.add_event(self.birth,trans) + self.person.set_birth_handle(self.birth.get_handle()) self.db.commit_event(self.birth,trans) # Update each of the families child lists to reflect any @@ -1717,10 +1713,10 @@ class EditPerson: self.death.set_date_object(self.death_date_object) self.death.set_place_handle(self.get_place(self.dplace,1)) - if self.orig_death == None: - self.db.add_event(self.death,trans) - self.person.set_death_handle(self.death.get_handle()) - elif not self.orig_death.are_equal(self.death): + if not self.orig_death.are_equal(self.death): + if self.orig_death.is_empty(): + self.db.add_event(self.death,trans) + self.person.set_death_handle(self.death.get_handle()) self.db.commit_event(self.death,trans) male = self.is_male.get_active() @@ -1905,13 +1901,11 @@ class EditPerson: self.load_photo(None) def update_birth_info(self): - self.birth_date_object.copy(self.birth.get_date_object()) - self.bdate.set_text(self.birth.get_date()) + self.bdate_check.update_after_editor(self.birth.get_date_object()) self.bplace.set_text(place_title(self.db,self.birth)) def update_death_info(self): - self.death_date_object.copy(self.death.get_date_object()) - self.ddate.set_text(self.death.get_date()) + self.ddate_check.update_after_editor(self.death.get_date_object()) self.dplace.set_text(place_title(self.db,self.death)) def on_switch_page(self,obj,a,page): diff --git a/gramps2/src/EventEdit.py b/gramps2/src/EventEdit.py index a3d1674dd..904bca46a 100644 --- a/gramps2/src/EventEdit.py +++ b/gramps2/src/EventEdit.py @@ -88,8 +88,10 @@ class EventEditor: values = {} for v in elist: values[v] = 1 - for v in self.db.get_person_event_type_list(): - values[v] = 1 + for vv in self.db.get_person_event_type_list(): + if vv not in ("Birth","Death"): + v = _(vv) + values[v] = 1 self.elist = values.keys() self.elist.sort() @@ -108,8 +110,8 @@ class EventEditor: # add the name to the list if it is not already there. This # tends to occur in translated languages with the 'Death' # event, which is a partial match to other events - if not transname in elist: - elist.append(transname) + #if not transname in elist: + # elist.append(transname) else: self.srcreflist = [] self.witnesslist = [] @@ -321,7 +323,7 @@ class EventEditor: edesc = unicode(self.descr_field.get_text()) epriv = self.priv.get_active() - if not ename in self.elist: + if ename not in self.elist + [_("Birth") , _("Death")]: WarningDialog( _('New event type created'), _('The "%s" event type has been added to this database.\n' @@ -353,7 +355,8 @@ class EventEditor: self.event.set_place_handle("") self.parent.lists_changed = 1 - if self.event.get_name() != self.trans.find_key(name): + if self.event.get_name() not in [self.trans.find_key(name), + "Birth","Death"]: self.event.set_name(self.trans.find_key(name)) self.parent.lists_changed = 1 diff --git a/gramps2/src/GrampsDbBase.py b/gramps2/src/GrampsDbBase.py index edb41aa5c..8497a00e0 100644 --- a/gramps2/src/GrampsDbBase.py +++ b/gramps2/src/GrampsDbBase.py @@ -1,7 +1,7 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2004 Donald N. Allingham +# Copyright (C) 2000-2005 Donald N. Allingham # # 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 @@ -228,7 +228,7 @@ class GrampsDbBase: Commits the specified Person to the database, storing the changes as part of the transaction. """ - if self.readonly: + if self.readonly or not person.get_handle(): return if change_time: person.change = int(change_time) @@ -246,7 +246,7 @@ class GrampsDbBase: Commits the specified MediaObject to the database, storing the changes as part of the transaction. """ - if self.readonly: + if self.readonly or not obj.get_handle(): return if change_time: obj.change = int(change_time) @@ -263,7 +263,7 @@ class GrampsDbBase: Commits the specified Source to the database, storing the changes as part of the transaction. """ - if self.readonly: + if self.readonly or not source.get_handle(): return if change_time: source.change = int(change_time) @@ -280,7 +280,7 @@ class GrampsDbBase: Commits the specified Place to the database, storing the changes as part of the transaction. """ - if self.readonly: + if self.readonly or not place.get_handle(): return if change_time: place.change = int(change_time) @@ -297,7 +297,7 @@ class GrampsDbBase: Commits the specified Event to the database, storing the changes as part of the transaction. """ - if self.readonly: + if self.readonly or not event.get_handle(): return if change_time: event.change = int(change_time) @@ -314,7 +314,7 @@ class GrampsDbBase: Commits the specified Family to the database, storing the changes as part of the transaction. """ - if self.readonly: + if self.readonly or not family.get_handle(): return if change_time: family.change = int(change_time) diff --git a/gramps2/src/GrampsInMemDB.py b/gramps2/src/GrampsInMemDB.py index e1184db4e..3b4908f88 100644 --- a/gramps2/src/GrampsInMemDB.py +++ b/gramps2/src/GrampsInMemDB.py @@ -25,6 +25,11 @@ Provides the common infrastructure for database formats that must hold all of their data in memory. """ +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- from RelLib import * from GrampsDbBase import * @@ -189,35 +194,35 @@ class GrampsInMemDB(GrampsDbBase): del self.event_map[str(handle)] def commit_person(self,person,transaction,change_time=None): - if self.readonly: + if self.readonly or not person.get_handle(): return gid = person.get_gramps_id() self.id_trans[gid] = person.get_handle() GrampsDbBase.commit_person(self,person,transaction,change_time) def commit_place(self,place,transaction,change_time=None): - if self.readonly: + if self.readonly or not place.get_handle(): return gid = place.get_gramps_id() self.pid_trans[gid] = place.get_handle() GrampsDbBase.commit_place(self,place,transaction,change_time) def commit_family(self,family,transaction,change_time=None): - if self.readonly: + if self.readonly or not family.get_handle(): return gid = family.get_gramps_id() self.fid_trans[gid] = family.get_handle() GrampsDbBase.commit_family(self,family,transaction,change_time) def commit_media_object(self,obj,transaction,change_time=None): - if self.readonly: + if self.readonly or not obj.get_handle(): return gid = obj.get_gramps_id() self.oid_trans[gid] = obj.get_handle() GrampsDbBase.commit_media_object(self,obj,transaction,change_time) def commit_source(self,source,transaction,change_time=None): - if self.readonly: + if self.readonly or not source.get_handle(): return gid = source.get_gramps_id() self.sid_trans[gid] = source.get_handle() diff --git a/gramps2/src/Utils.py b/gramps2/src/Utils.py index becb4022f..c4cf26a83 100644 --- a/gramps2/src/Utils.py +++ b/gramps2/src/Utils.py @@ -117,8 +117,10 @@ def family_name(family,db): "mother" : mname} elif father: name = NameDisplay.displayer.display(father) - else: + elif mother: name = NameDisplay.displayer.display(mother) + else: + name = _("unknown") return name def family_upper_name(family,db):