diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index e157a9a49..7344e0b70 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,16 @@ 2004-10-07 Don Allingham + * src/AddMedia.py: pychecker fixes + * src/DbPrompter.py: pychecker fixes + * src/DisplayModels.py: pychecker fixes + * src/GrampsDbBase.py: pychecker fixes + * src/GrampsInMemDB.py: pychecker fixes + * src/RelLib.py: move probably_alive to Utils + * src/Utils.py: added probably_alive + * src/WriteGedcom.py: probably_alive fixes + * src/WriteGedcom.py: probably_alive fixes + * src/plugins/WebPage.py: probably_alive fixes + * src/plugins/WebFtree.py: probably_alive fixes + * src/plugins/WebGeneWeb.py: probably_alive fixes * src/NameEdit.py: integrate patches from Julio Sanchez to fix surname prefix * src/FamilyView.py: Handle add person post processing properly diff --git a/gramps2/src/AddMedia.py b/gramps2/src/AddMedia.py index e90b73dec..a613f880b 100644 --- a/gramps2/src/AddMedia.py +++ b/gramps2/src/AddMedia.py @@ -169,7 +169,7 @@ class AddMediaObject: self.window.destroy() return self.object elif val == gtk.RESPONSE_HELP: - self.on_help_imagesel_clicked() + self.on_help_imagesel_clicked(None) else: self.window.destroy() return None diff --git a/gramps2/src/ChooseParents.py b/gramps2/src/ChooseParents.py index eab8c95f0..6439983a1 100644 --- a/gramps2/src/ChooseParents.py +++ b/gramps2/src/ChooseParents.py @@ -548,14 +548,13 @@ class ChooseParents: self.db.transaction_commit(trans,_("Choose Parents")) self.close(obj) - def add_new_parent(self,epo,trans): + def add_new_parent(self,epo,val): """Adds a new person to either the father list or the mother list, depending on the gender of the person.""" person = epo.person handle = person.get_handle() name = person.get_primary_name().get_surname() - self.db.add_person(person,trans) self.type = self.prel.get_active() if self.type == const.FAMILY_CIVIL_UNION: diff --git a/gramps2/src/DbPrompter.py b/gramps2/src/DbPrompter.py index bae472c34..a48d7ef1f 100644 --- a/gramps2/src/DbPrompter.py +++ b/gramps2/src/DbPrompter.py @@ -185,17 +185,17 @@ class ExistingDbPrompter: msg_top = msgxml.get_widget('load_message') self.parent.read_file(filename) msg_top.destroy() - return 1 + return True elif filetype == const.app_gramps_xml: choose.destroy() self.parent.db = GrampsXMLDB.GrampsXMLDB() self.parent.read_file(filename) - return 1 + return True elif filetype == const.app_gedcom: choose.destroy() self.parent.db = GrampsGEDDB.GrampsGEDDB() self.parent.read_file(filename) - return 1 + return True # The above native formats did not work, so we need to # look up the importer for this format @@ -213,13 +213,13 @@ class ExistingDbPrompter: if prompter.chooser(): importData(self.parent.db,filename) self.parent.import_tool_callback() - return 1 + return True else: - return 0 + return False QuestionDialog.ErrorDialog( _("Could not open file: %s") % filename, _('The type "%s" is not in the list of known file types') % filetype ) choose.destroy() - return 0 + return False #------------------------------------------------------------------------- # @@ -291,7 +291,7 @@ class ImportDbPrompter: # if filetype == 'application/x-gramps': # choose.destroy() # self.parent.read_file(filename) -# return 1 +# return True (the_path,the_file) = os.path.split(filename) GrampsGconfKeys.save_last_import_dir(the_path) @@ -300,11 +300,11 @@ class ImportDbPrompter: choose.destroy() importData(self.parent.db,filename) self.parent.import_tool_callback() - return 1 + return True QuestionDialog.ErrorDialog( _("Could not open file: %s") % filename, _('The type "%s" is not in the list of known file types') % filetype ) choose.destroy() - return 0 + return False #------------------------------------------------------------------------- # @@ -373,7 +373,8 @@ class NewNativeDbPrompter: filename = filename + ".grdb" choose.destroy() self.parent.read_file(filename) - return 1 + return True else: choose.destroy() - return 0 + return False + return False diff --git a/gramps2/src/DisplayModels.py b/gramps2/src/DisplayModels.py index b206e07eb..c45d4541a 100644 --- a/gramps2/src/DisplayModels.py +++ b/gramps2/src/DisplayModels.py @@ -36,19 +36,21 @@ import gtk class BaseModel(gtk.GenericTreeModel): def __init__(self,db): - gtk.GenericTreeModel.__init__(self) self.set_property("leak_references",False) - + self.fmap = [] + self.map = {} self.db = db self.rebuild_data() + def sort_keys(self): + return [] + def rebuild_data(self): self.datalist = [] if not self.db.is_open(): return - self.datalist = self.sort_keys() def on_row_inserted(self,obj,path,node): @@ -138,6 +140,7 @@ class BaseModel(gtk.GenericTreeModel): class SourceModel(BaseModel): def __init__(self,db): + BaseModel.__init__(self,db) self.sort_keys = db.get_source_handles self.map = db.source_map self.fmap = [ @@ -149,7 +152,6 @@ class SourceModel(BaseModel): self.column_change, self.column_handle, ] - BaseModel.__init__(self,db) def on_get_n_columns(self): return len(self.fmap)+1 diff --git a/gramps2/src/GrampsDbBase.py b/gramps2/src/GrampsDbBase.py index d950536c5..955d7b565 100644 --- a/gramps2/src/GrampsDbBase.py +++ b/gramps2/src/GrampsDbBase.py @@ -85,6 +85,7 @@ class GrampsDbBase: self.open = 0 self.genderStats = GenderStats() + self.undodb = None self.id_trans = None self.fid_trans = None self.pid_trans = None diff --git a/gramps2/src/GrampsInMemDB.py b/gramps2/src/GrampsInMemDB.py index e9413f5aa..44a722141 100644 --- a/gramps2/src/GrampsInMemDB.py +++ b/gramps2/src/GrampsInMemDB.py @@ -109,39 +109,31 @@ class GrampsInMemDB(GrampsDbBase): if transaction != None: old_data = self.event_map.get(str(handle)) transaction.add(EVENT_KEY,handle,old_data) - del self.eid_trans[self.event_map[handle].get_gramps_id()] del self.event_map[str(handle)] - def remove_family(self,handle,transaction): - if transaction != None: - old_data = self.family_map.get(str(handle)) - transaction.add(EVENT_KEY,handle,old_data) - del self.fid_trans[self.family_map[handle].get_gramps_id()] - del self.family_map[str(handle)] - def commit_person(self,person,transaction,change_time=None): - id = person.get_gramps_id() - self.id_trans[id] = person.get_handle() + 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): - id = place.get_gramps_id() - self.pid_trans[id] = place.get_handle() + 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): - id = family.get_gramps_id() - self.fid_trans[id] = family.get_handle() + 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): - id = obj.get_gramps_id() - self.oid_trans[id] = obj.get_handle() + 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): - id = source.get_gramps_id() - self.sid_trans[id] = source.get_handle() + gid = source.get_gramps_id() + self.sid_trans[gid] = source.get_handle() GrampsDbBase.commit_source(self,source,transaction,change_time) def get_person_from_gramps_id(self,val): diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index 4157e4638..80e554f27 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -564,12 +564,10 @@ class Person(PrimaryObject,SourceNote): if ev.name in ["Cause Of Death", "Burial", "Cremation"]: return False - return True - if self.birth_handle: birth = db.get_event_from_handle(self.birth_handle) - if birth.get_date() != "": - return not_too_old(birth.get_date_object().get_start_date()) + if birth.get_date_object().get_start_date() != Date.EMPTY: + return not_too_old(birth.get_date_object()) # Neither birth nor death events are available. Try looking # for descendants that were born more than a lifespan ago. @@ -584,17 +582,18 @@ class Person(PrimaryObject,SourceNote): child = db.get_person_from_handle(child_handle) if child.birth_handle: child_birth = db.get_event_from_handle(child.birth_handle) - if child_birth.get_date() != "": - d = SingleDate (child_birth.get_date_object().get_start_date()) - d.set_year (d.get_year() - years) + dobj = child_birth.get_date_object() + if dobj.get_start_date() != Date.EMPTY: + d = Date(dobj) + d.set_year(d.get_year() - years) if not not_too_old (d): return True if child.death_handle: child_death = db.get_event_from_handle(child.death_handle) - if child_death.get_date() != "": - d = SingleDate (child_death.get_date_object().get_start_date()) - if not not_too_old (d): + dobj = child_death.get_date_object() + if dobj.get_start_date != Date.EMPTY: + if not not_too_old (dobj): return True if descendants_too_old (child, years + min_generation): @@ -603,6 +602,8 @@ class Person(PrimaryObject,SourceNote): if descendants_too_old (self, min_generation): return False + return False + # What about their parents? def parents_too_old (person, age_difference): family_handle = person.get_main_parents_family_handle() @@ -2350,4 +2351,8 @@ class GenderStats: return Person.unknown - +def not_too_old(date): + time_struct = time.localtime(time.time()) + current_year = time_struct[0] + year = date.get_year() + return not( year != 0 and current_year - year > 110) diff --git a/gramps2/src/Utils.py b/gramps2/src/Utils.py index f576a8184..0627267e9 100644 --- a/gramps2/src/Utils.py +++ b/gramps2/src/Utils.py @@ -550,6 +550,120 @@ def create_id(): val = int(val/36) return s + +def probably_alive(person,db): + """Returns true if the person may be alive.""" + if person.death_handle: + return False + + # Look for Cause Of Death, Burial or Cremation events. + # These are fairly good indications that someone's not alive. + for ev_handle in person.event_list: + ev = db.get_event_from_handle(ev_handle) + if ev.name in ["Cause Of Death", "Burial", "Cremation"]: + return False + + if person.birth_handle: + birth = db.get_event_from_handle(person.birth_handle) + if birth.get_date_object().get_start_date() != Date.EMPTY: + return not_too_old(birth.get_date_object()) + + # Neither birth nor death events are available. Try looking + # for descendants that were born more than a lifespan ago. + + min_generation = 13 + max_generation = 60 + max_age_difference = 60 + + def descendants_too_old (person, years): + for family_handle in person.get_family_handle_list(): + family = db.get_family_from_handle(family_handle) + for child_handle in family.get_child_handle_list(): + child = db.get_person_from_handle(child_handle) + if child.birth_handle: + child_birth = db.get_event_from_handle(child.birth_handle) + dobj = child_birth.get_date_object() + if dobj.get_start_date() != Date.EMPTY: + d = Date(dobj) + d.set_year(d.get_year() - years) + if not not_too_old (d): + return True + + if child.death_handle: + child_death = db.get_event_from_handle(child.death_handle) + dobj = child_death.get_date_object() + if dobj.get_start_date != Date.EMPTY: + if not not_too_old (dobj): + return True + + if descendants_too_old (child, years + min_generation): + return True + + if descendants_too_old (person, min_generation): + return False + + return False + + # What about their parents? + + def parents_too_old (person, age_difference): + family_handle = person.get_main_parents_family_handle() + if family_handle: + family = db.get_family_from_handle(family_handle) + for parent_id in [family.get_father_handle(), family.get_mother_handle()]: + if not parent_id: + continue + + parent = db.get_person_from_handle(parent_id) + if parent.birth_handle: + parent_birth = db.get_event_from_handle(parent.birth_handle) + if parent_birth.get_date(): + d = SingleDate (parent_birth.get_date_object().get_start_date()) + d.set_year (d.get_year() + max_generation + age_difference) + if not not_too_old (d): + return True + + if parent.death_handle: + parent_death = db.get_event_from_handle(parent.death_handle) + if parent_death.get_date() != "": + d = SingleDate (parent_death.get_date_object().get_start_date()) + d.set_year (d.get_year() + age_difference) + if not not_too_old (d): + return True + + if parents_too_old (person, 0): + return False + + # As a last resort, trying seeing if their spouse's age gives + # any clue. + for family_handle in person.get_family_handle_list(): + family = db.get_family_from_handle(family_handle) + for spouse_id in [family.get_father_handle(), family.get_mother_handle()]: + if not spouse_id or spouse_id == person.handle: + continue + spouse = db.get_person_from_handle(spouse_id) + sp_birth_handle = spouse.get_birth_handle() + sp_death_handle = spouse.get_death_handle() + if sp_birth_handle: + spouse_birth = db.get_event_from_handle(sp_birth_handle) + if spouse_birth.get_date() != "": + d = SingleDate (spouse_birth.get_date_object().get_start_date()) + d.set_year (d.get_year() + max_age_difference) + if not not_too_old (d): + return False + + if sp_death_handle: + spouse_death = db.get_event_from_handle(sp_death_handle) + if spouse_death.get_date() != "": + d = SingleDate (spouse_death.get_date_object().get_start_date()) + d.set_year (d.get_year() - min_generation) + if not not_too_old (d): + return False + + if parents_too_old (spouse, max_age_difference): + return False + return True + #------------------------------------------------------------------------- # # diff --git a/gramps2/src/WriteGedcom.py b/gramps2/src/WriteGedcom.py index 3da76b882..34966d181 100644 --- a/gramps2/src/WriteGedcom.py +++ b/gramps2/src/WriteGedcom.py @@ -670,14 +670,14 @@ class GedcomWriter: person = self.db.get_person_from_handle(person_handle) gramps_id = person.get_gramps_id() self.writeln("1 HUSB @%s@" % gramps_id) - father_alive = person.probably_alive(self.db) + father_alive = Utils.probably_alive(person,self.db) person_handle = family.get_mother_handle() if person_handle != None and self.plist.has_key(person_handle): person = self.db.get_person_from_handle(person_handle) gramps_id = person.get_gramps_id() self.writeln("1 WIFE @%s@" % gramps_id) - mother_alive = person.probably_alive(self.db) + mother_alive = Utils.probably_alive(person,self.db) if not self.restrict or ( not father_alive and not mother_alive ): self.write_ord("SLGS",family.get_lds_sealing(),1,const.lds_ssealing) @@ -750,7 +750,7 @@ class GedcomWriter: def write_person(self,person): self.writeln("0 @%s@ INDI" % person.get_gramps_id()) - restricted = self.restrict and person.probably_alive (self.db) + restricted = self.restrict and probably_alive (person,self.db) self.prefn(person) primaryname = person.get_primary_name () if restricted and self.living: diff --git a/gramps2/src/plugins/WebPage.py b/gramps2/src/plugins/WebPage.py index 376168843..97d12f4dd 100644 --- a/gramps2/src/plugins/WebPage.py +++ b/gramps2/src/plugins/WebPage.py @@ -114,7 +114,7 @@ class IndividualPage: self.id_link = idlink self.list = map self.private = private - self.alive = person.probably_alive(db) and restrict + self.alive = Utils.probably_alive(person,db) and restrict self.photos = (photos == 2) or (photos == 1 and not self.alive) self.usecomments = not uc self.dir = dir_name diff --git a/gramps2/src/plugins/WriteFtree.py b/gramps2/src/plugins/WriteFtree.py index df6b58453..f2a39bbb9 100644 --- a/gramps2/src/plugins/WriteFtree.py +++ b/gramps2/src/plugins/WriteFtree.py @@ -212,7 +212,7 @@ class FtreeWriter: death = p.get_death().get_date_object() if restrict: - alive = p.probably_alive(self.db) + alive = Utils.probably_alive(p,self.db) else: alive = 0 diff --git a/gramps2/src/plugins/WriteGeneWeb.py b/gramps2/src/plugins/WriteGeneWeb.py index 692e56973..88b72fe02 100644 --- a/gramps2/src/plugins/WriteGeneWeb.py +++ b/gramps2/src/plugins/WriteGeneWeb.py @@ -353,7 +353,7 @@ class GeneWebWriter: place = self.db.get_place_from_handle(place_handle) b_place = place.get_title() - if person.probably_alive(self.db): + if Utils.probably_alive(person,self.db): d_date = "" else: d_date = "0" @@ -407,7 +407,7 @@ class GeneWebWriter: def get_ref_name(self,person): surname = self.rem_spaces( person.get_primary_name().get_surname()) firstname = "Living" - if not (person.probably_alive(self.db) and self.restrict and self.living): + if not (Utils.probably_alive(person,self.db) and self.restrict and self.living): firstname = self.rem_spaces( person.get_primary_name().get_first_name()) if not self.person_ids.has_key(person.get_handle()): self.person_ids[person.get_handle()] = len(self.person_ids) @@ -417,7 +417,7 @@ class GeneWebWriter: def get_child_ref_name(self,person,father_lastname): surname = self.rem_spaces( person.get_primary_name().get_surname()) firstname = "Living" - if not (person.probably_alive(self.db) and self.restrict and self.living): + if not (Utils.probably_alive(person,self.db) and self.restrict and self.living): firstname = self.rem_spaces( person.get_primary_name().get_first_name()) if not self.person_ids.has_key(person.get_handle()): self.person_ids[person.get_handle()] = len(self.person_ids)