diff --git a/ChangeLog b/ChangeLog index ce3ec74dd..13f824b58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2004-08-12 Don Allingham + * various: Updated cleaned up API + 2004-08-11 Don Allingham * src/GenericFilter.py: fixed find/get_family_from_handle * src/WriteGedcom.py: fixed find/get_family_from_handle diff --git a/src/AddMedia.py b/src/AddMedia.py index 273b95909..c76edca76 100644 --- a/src/AddMedia.py +++ b/src/AddMedia.py @@ -124,7 +124,7 @@ class AddMediaObject: mobj.set_description(description) mobj.set_mime_type(mtype) - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.add_object(mobj,trans) name = filename @@ -132,7 +132,7 @@ class AddMediaObject: self.object = mobj self.db.commit_media_object(mobj,trans) - self.db.add_transaction(trans,_("Add Media Object")) + self.db.transaction_commit(trans,_("Add Media Object")) if self.update: self.update() diff --git a/src/AddSpouse.py b/src/AddSpouse.py index 51f928818..3bcb0dffa 100644 --- a/src/AddSpouse.py +++ b/src/AddSpouse.py @@ -212,11 +212,11 @@ class AddSpouse: been closed. """ person = epo.person - trans = self.db.start_transaction() + trans = self.db.transaction_begin() handle = self.db.add_person(person,trans) n = person.get_primary_name().get_name() - self.db.add_transaction(trans,_('Add Person (%s)' % n)) + self.db.transaction_commit(trans,_('Add Person (%s)' % n)) self.addperson(person) self.update_data(handle) @@ -252,10 +252,11 @@ class AddSpouse: Utils.destroy_passed_object(obj) return - trans = self.db.start_transaction() + trans = self.db.transaction_begin() if not self.active_family: - self.active_family = self.db.new_family(trans) + self.active_family = RelLib.Family() + self.db.add_family(family,trans) self.person.add_family_handle(self.active_family.get_handle()) self.db.commit_person(self.person,trans) @@ -272,7 +273,7 @@ class AddSpouse: rtype = self.rel_combo.get_active() self.active_family.set_relationship(rtype) self.db.commit_family(self.active_family,trans) - self.db.add_transaction(trans,_("Add Spouse")) + self.db.transaction_commit(trans,_("Add Spouse")) Utils.destroy_passed_object(obj) self.update(self.active_family) diff --git a/src/ArgHandler.py b/src/ArgHandler.py index 97e120754..a1e68b26b 100644 --- a/src/ArgHandler.py +++ b/src/ArgHandler.py @@ -414,7 +414,7 @@ class ArgHandler: try: # Write media files first, since the database may be modified # during the process (i.e. when removing object) - for m_id in self.parent.db.get_object_keys(): + for m_id in self.parent.db.get_media_object_handles(): mobject = self.parent.db.get_object_from_handle(m_id) oldfile = mobject.get_path() base = os.path.basename(oldfile) diff --git a/src/ChooseParents.py b/src/ChooseParents.py index 764ff847c..2454fc72b 100644 --- a/src/ChooseParents.py +++ b/src/ChooseParents.py @@ -316,7 +316,7 @@ class ChooseParents: self.father_nsort.reset_visible() self.build_exclude_list() - for pid in self.db.get_person_keys(): + for pid in self.db.get_person_handles(sort_handles=False): person = self.db.get_person_from_handle(pid) visible = self.father_filter(person) if visible: @@ -339,7 +339,7 @@ class ChooseParents: self.mother_nsort.reset_visible() self.build_exclude_list() - for pid in self.db.get_person_keys(): + for pid in self.db.get_person_handles(sort_handles=False): person = self.db.get_person_from_handle(pid) visible = self.mother_filter(person) if visible: @@ -385,7 +385,7 @@ class ChooseParents: if not father_handle and not mother_handle: return None - for family_handle in self.db.get_family_keys(): + for family_handle in self.db.get_family_handles(): family = self.db.find_family_from_handle(family_handle) if family.get_father_handle() == father_handle and family.get_mother_handle() == mother_handle: family.add_child_handle(self.person.get_handle()) @@ -396,10 +396,11 @@ class ChooseParents: self.db.commit_family(family,trans) return family - family = self.db.new_family(trans) + family = RelLib.Family() family.set_father_handle(father_handle) family.set_mother_handle(mother_handle) family.add_child_handle(self.person.get_handle()) + self.db.add_family(family,trans) if father_handle: self.father = self.db.get_person_from_handle(father_handle) @@ -515,7 +516,7 @@ class ChooseParents: except KeyError: father_rel = const.child_relations.find_value("Birth") - trans = self.db.start_transaction() + trans = self.db.transaction_begin() if self.father or self.mother: if self.mother and not self.father: if self.mother.get_gender() == RelLib.Person.male: @@ -561,7 +562,7 @@ class ChooseParents: self.change_family_type(self.family,mother_rel,father_rel) self.db.commit_family(self.family,trans) self.family_update(None) - self.db.add_transaction(trans,_("Choose Parents")) + self.db.transaction_commit(trans,_("Choose Parents")) self.close(obj) def add_new_parent(self,epo,trans): @@ -625,14 +626,14 @@ class ChooseParents: else: self.person.add_parent_family_handle(family.get_handle(),mother_rel,father_rel) - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.commit_person(self.person,trans) self.db.commit_family(family,trans) if self.father: self.db.commit_person(self.father,trans) if self.mother: self.db.commit_person(self.mother,trans) - self.db.add_transaction(trans,_("Choose Parents")) + self.db.transaction_commit(trans,_("Choose Parents")) class ModifyParents: def __init__(self,db,person,family_handle,family_update,full_update,parent_window=None): @@ -752,7 +753,7 @@ class ModifyParents: mod = 1 if mod: - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.commit_person(self.person,trans) - self.db.add_transaction(trans,_("Modify Parents")) + self.db.transaction_commit(trans,_("Modify Parents")) self.family_update(None) diff --git a/src/DisplayModels.py b/src/DisplayModels.py index 327f6d837..5baf47413 100644 --- a/src/DisplayModels.py +++ b/src/DisplayModels.py @@ -125,7 +125,7 @@ class BaseModel(gtk.GenericTreeModel): class SourceModel(BaseModel): def __init__(self,db): - self.sort_keys = db.sort_source_keys + self.sort_keys = db.get_source_handles self.map = db.source_map self.fmap = [ self.column_title, @@ -163,7 +163,7 @@ class SourceModel(BaseModel): class PlaceModel(BaseModel): def __init__(self,db): - self.sort_keys = db.sort_place_keys + self.sort_keys = db.get_place_handles self.map = db.place_map self.fmap = [ self.column_name, @@ -232,7 +232,7 @@ class PlaceModel(BaseModel): class MediaModel(BaseModel): def __init__(self,db): - self.sort_keys = db.sort_media_keys + self.sort_keys = db.get_media_object_handles self.map = db.media_map self.fmap = [ diff --git a/src/EditPerson.py b/src/EditPerson.py index e7395a23e..21626afb7 100644 --- a/src/EditPerson.py +++ b/src/EditPerson.py @@ -61,6 +61,14 @@ from QuestionDialog import QuestionDialog, WarningDialog, ErrorDialog, SaveDialo from gettext import gettext as _ +#------------------------------------------------------------------------- +# +# Constants +# +#------------------------------------------------------------------------- + +_PICTURE_WIDTH = 200.0 + _temple_names = const.lds_temple_codes.keys() _temple_names.sort() _temple_names = [""] + _temple_names @@ -102,8 +110,8 @@ class EditPerson: person.get_gender () == RelLib.Person.unknown) - for key in db.get_place_handle_keys(): - p = db.get_place_display(key) + for key in db.get_place_handles(): + p = db.get_place_from_handle(key).get_display_info() self.pdmap[p[0]] = key self.load_obj = None @@ -287,7 +295,7 @@ class EditPerson: build_dropdown(self.bplace,self.place_list) build_dropdown(self.dplace,self.place_list) - build_dropdown(self.surname,self.db.get_surnames()) + build_dropdown(self.surname,self.db.get_surname_list()) self.gid.set_text(person.get_gramps_id()) self.gid.set_editable(1) @@ -418,7 +426,7 @@ class EditPerson: self.top.get_widget('edit_src'), self.top.get_widget('del_src')) - if self.person.get_complete(): + if self.person.get_complete_flag(): self.complete.set_active(1) self.redraw_event_list() @@ -1092,7 +1100,7 @@ class EditPerson: changed = 0 name = self.person.get_primary_name() - if self.complete.get_active() != self.person.get_complete(): + if self.complete.get_active() != self.person.get_complete_flag(): changed = 1 if self.person.get_gramps_id() != idval: @@ -1412,7 +1420,7 @@ class EditPerson: try: i = pixbuf_new_from_file(photo) ratio = float(max(i.get_height(),i.get_width())) - scale = float(const.picWidth)/ratio + scale = float(_PICTURE_WIDTH)/ratio x = int(scale*(i.get_width())) y = int(scale*(i.get_height())) i = i.scale_simple(x,y,INTERP_BILINEAR) @@ -1434,7 +1442,7 @@ class EditPerson: def on_apply_person_clicked(self,obj): - trans = self.db.start_transaction() + trans = self.db.transaction_begin() surname = unicode(self.surname.get_text()) suffix = unicode(self.suffix.get_text()) @@ -1495,8 +1503,8 @@ class EditPerson: self.person.set_nick_name(nick) self.pdmap.clear() - for key in self.db.get_place_handle_keys(): - p = self.db.get_place_display(key) + for key in self.db.get_place_handles(): + p = self.db.get_place_from_handle(key).get_display_info() self.pdmap[p[0]] = key if self.orig_birth == None: @@ -1581,8 +1589,8 @@ class EditPerson: if format != self.person.get_note_format(): self.person.set_note_format(format) - if self.complete.get_active() != self.person.get_complete(): - self.person.set_complete(self.complete.get_active()) + if self.complete.get_active() != self.person.get_complete_flag(): + self.person.set_complete_flag(self.complete.get_active()) if self.lds_not_loaded == 0: self.check_lds() @@ -1607,7 +1615,7 @@ class EditPerson: self.db.commit_person(self.person, trans) n = self.person.get_primary_name().get_regular_name() - self.db.add_transaction(trans,_("Edit Person (%s)") % n) + self.db.transaction_commit(trans,_("Edit Person (%s)") % n) self.close() def get_place(self,field,makenew=0): @@ -1618,9 +1626,9 @@ class EditPerson: elif makenew: place = RelLib.Place() place.set_title(text) - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.add_place(place,trans) - self.db.add_transaction(trans,_('Add Place (%s)' % text)) + self.db.transaction_commit(trans,_('Add Place (%s)' % text)) self.pdmap[text] = place.get_handle() self.add_places.append(place) return place.get_handle() diff --git a/src/EditPlace.py b/src/EditPlace.py index 9a8185677..76a08ef8a 100644 --- a/src/EditPlace.py +++ b/src/EditPlace.py @@ -201,7 +201,7 @@ class EditPlace: self.top_window.get_widget('edit_src'), self.top_window.get_widget('del_src')) - if self.place.get_handle() == "": + if self.place.get_handle() == None: self.top_window.get_widget("add_photo").set_sensitive(0) self.top_window.get_widget("delete_photo").set_sensitive(0) @@ -368,9 +368,9 @@ class EditPlace: self.update_lists() - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.commit_place(self.place,trans) - self.db.add_transaction(trans,_("Edit Place (%s)") % self.place.get_title()) + self.db.transaction_commit(trans,_("Edit Place (%s)") % self.place.get_title()) if self.callback: self.callback(self.place) @@ -477,13 +477,13 @@ class EditPlace: pevent = [] fevent = [] msg = "" - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) for event_handle in [p.get_birth_handle(), p.get_death_handle()] + p.get_event_list(): event = self.db.find_event_from_handle(event_handle) if event and event.get_place_handle() == self.place: pevent.append((p,event)) - for family_handle in self.db.get_family_keys(): + for family_handle in self.db.get_family_handles(): f = self.db.get_family_from_handle(family_handle) for event_handle in f.get_event_list(): event = self.db.find_event_from_handle(event_handle) @@ -555,11 +555,11 @@ class DeletePlaceQuery: self.update = update def query_response(self): - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.remove_place(self.place.get_handle(),trans) - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) for event_handle in [p.get_birth_handle(), p.get_death_handle()] + p.get_event_list(): event = self.db.find_event_from_handle(event_handle) @@ -567,7 +567,7 @@ class DeletePlaceQuery: event.set_place_handle(None) self.db.commit_event(event,trans) - for fid in self.db.get_family_keys(): + for fid in self.db.get_family_handles(): f = self.db.get_family_from_handle(fid) for event_handle in f.get_event_list(): event = self.db.find_event_from_handle(event_handle) @@ -575,5 +575,5 @@ class DeletePlaceQuery: event.set_place_handle(None) self.db.commit_event(event,trans) - self.db.add_transaction(trans,_("Delete Place (%s)") % self.place.get_title()) + self.db.transaction_commit(trans,_("Delete Place (%s)") % self.place.get_title()) self.update(None) diff --git a/src/EditSource.py b/src/EditSource.py index ca3da863c..04dfb5eb5 100644 --- a/src/EditSource.py +++ b/src/EditSource.py @@ -121,7 +121,7 @@ class EditSource: "on_sourceEditor_delete_event" : self.on_delete_event, }) - if self.source.get_handle() == "": + if self.source.get_handle() == None: self.top_window.get_widget("edit_photo").set_sensitive(0) self.top_window.get_widget("delete_photo").set_sensitive(0) @@ -190,13 +190,13 @@ class EditSource: f_event_list = [] f_attr_list = [] p_list = [] - for key in self.db.get_place_handle_keys(): + for key in self.db.get_place_handles(): p = self.db.get_place_from_handle(key) name = p.get_title() for sref in p.get_source_references(): if sref.get_base_handle() == self.source.get_handle(): p_list.append(name) - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) name = GrampsCfg.get_nameof()(p) for event_handle in p.get_event_list() + [p.get_birth_handle(), p.get_death_handle()]: @@ -217,13 +217,13 @@ class EditSource: for sref in v.get_source_references(): if sref.get_base_handle() == self.source.get_handle(): p_addr_list.append((name,v.get_street())) - for object_handle in self.db.get_object_keys(): + for object_handle in self.db.get_media_object_handles(): object = self.db.get_object_from_handle(object_handle) name = object.get_description() for sref in object.get_source_references(): if sref.get_base_handle() == self.source.get_handle(): m_list.append(name) - for family_handle in self.db.get_family_keys(): + for family_handle in self.db.get_family_handles(): family = self.db.get_family_from_handle(family_handle) f_id = family.get_father_handle() m_id = family.get_mother_handle() @@ -327,9 +327,9 @@ class EditSource: self.gallery_ok = 1 - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.commit_source(self.source,trans) - self.db.add_transaction(trans,_("Edit Source (%s)") % title) + self.db.transaction_commit(trans,_("Edit Source (%s)") % title) if self.callback: self.callback(self.source) @@ -369,9 +369,9 @@ class DelSrcQuery: return m def query_response(self): - trans = self.db.start_transaction() + trans = self.db.transaction_begin() - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): commit = 0 p = self.db.get_person_from_handle(key) for v_id in p.get_event_list() + [p.get_birth_handle(), p.get_death_handle()]: @@ -390,7 +390,7 @@ class DelSrcQuery: if commit > 0: self.db.commit_person(p,trans) - for p_id in self.db.get_family_keys(): + for p_id in self.db.get_family_handles(): commit = 0 p = self.db.find_family_from_handle(p_id) for v_id in p.get_event_list(): @@ -403,16 +403,16 @@ class DelSrcQuery: if commit > 0: self.db.commit_family(p,trans) - for p_id in self.db.get_object_keys(): + for p_id in self.db.get_media_object_handles(): p = self.db.get_object_from_handle(p_id,trans) if self.delete_source(p): self.db.commit_media_object(p,trans) - for key in self.db.get_place_handle_keys(): + for key in self.db.get_place_handles(): p = self.db.get_place_from_handle(key) if self.delete_source(self.db.get_place_from_handle(key)): self.db.commit_place(p,trans) - self.db.remove_source_handle(self.source.get_handle(),trans) - self.db.add_transaction(trans,_("Delete Source (%s)") % self.source.get_title()) + self.db.remove_source(self.source.get_handle(),trans) + self.db.transaction_commit(trans,_("Delete Source (%s)") % self.source.get_title()) self.update() diff --git a/src/EventEdit.py b/src/EventEdit.py index ea0273dbf..f6f339e75 100644 --- a/src/EventEdit.py +++ b/src/EventEdit.py @@ -81,14 +81,14 @@ class EventEditor: values = {} for v in elist: values[v] = 1 - for v in self.db.get_eventnames(): + for v in self.db.get_person_event_type_list(): values[v] = 1 self.elist = values.keys() self.elist.sort() - for key in self.parent.db.get_place_handle_keys(): - p = self.parent.db.get_place_display(key) + for key in self.parent.db.get_place_handles(): + p = self.parent.db.get_place_from_handle(key).get_display_info() self.pmap[p[0]] = key if event: @@ -302,7 +302,7 @@ class EventEditor: def on_event_edit_ok_clicked(self,obj): - trans = self.db.start_transaction() + trans = self.db.transaction_begin() ename = unicode(self.event_menu.child.get_text()) self.date.set(unicode(self.date_field.get_text())) @@ -331,7 +331,7 @@ class EventEditor: self.update_event(ename,self.date,eplace_obj,edesc,enote,eformat, epriv,ecause,trans) - self.db.add_transaction(trans,_("Edit Event")) + self.db.transaction_commit(trans,_("Edit Event")) self.close(obj) self.parent.redraw_event_list() self.callback(self.event) diff --git a/src/FamilyView.py b/src/FamilyView.py index b9489a078..90a920383 100644 --- a/src/FamilyView.py +++ b/src/FamilyView.py @@ -550,10 +550,10 @@ class FamilyView: def set_preferred_spouse(self,obj): if self.selected_spouse: self.person.set_preferred_family_handle(self.family) - trans = self.parent.db.start_transaction() + trans = self.parent.db.transaction_begin() self.parent.db.commit_person(self.person,trans) n = self.person.get_primary_name().get_regular_name() - self.parent.db.add_transaction(trans,_("Set Preferred Spouse (%s)") % n) + self.parent.db.transaction_commit(trans,_("Set Preferred Spouse (%s)") % n) self.load_family() def edit_spouse_callback(self,obj): @@ -622,7 +622,7 @@ class FamilyView: if epo: self.parent.db.commit_person(epo.person,trans) n = epo.person.get_primary_name().get_regular_name() - self.parent.db.add_transaction(trans,_("Add Person (%s)") % n) + self.parent.db.transaction_commit(trans,_("Add Person (%s)") % n) self.parent.people_view.remove_from_person_list(epo.person) self.parent.people_view.redisplay_person_list(epo.person) @@ -632,7 +632,8 @@ class FamilyView: def new_spouse_after_edit(self,epo,trans): self.parent.db.add_person(epo.person,trans) - self.family = self.parent.db.new_family(trans) + self.family = RelLib.Family() + self.parent.db.add_family(self.family,trans) self.parent.people_view.add_to_person_list(epo.person,0) self.person.add_family_handle(self.family.get_handle()) @@ -681,8 +682,11 @@ class FamilyView: DisplayTrace.DisplayTrace() def update_person_list(self,person): + trans = self.db.transaction_begin() + if not self.family: - self.family = self.parent.db.new_family() + self.family = RelLib.Family() + self.parent.db.add_family(self.family,trans) person.add_family_handle(self.family.get_handle()) if person.get_gender() == RelLib.Person.male: self.family.set_father_handle(person) @@ -693,6 +697,9 @@ class FamilyView: person.add_parent_family_handle(self.family.get_handle(),"Birth","Birth") self.parent.update_person_list(person) self.load_family(self.family) + self.db.commit_person(person,trans) + self.db.commit_family(self.family,trans) + self.db.transaction_commit(trans,_("Modify family")) def new_child_after_edit(self,epo,trans): @@ -700,7 +707,8 @@ class FamilyView: self.parent.people_view.add_to_person_list(epo.person,0) if not self.family: - self.family = self.parent.db.new_family() + self.family = RelLib.Family() + self.parent.db.add_family(self.family,trans) self.person.add_family_handle(self.family.get_handle()) if self.person.get_gender() == RelLib.Person.male: self.family.set_father_handle(self.person.get_handle()) @@ -734,7 +742,7 @@ class FamilyView: id = self.child_model.get_value(iter,7) child = self.parent.db.get_person_from_handle(id) - trans = self.parent.db.start_transaction() + trans = self.parent.db.transaction_begin() self.family.remove_child_handle(child.get_handle()) child.remove_parent_family_handle(self.family.get_handle()) @@ -748,7 +756,7 @@ class FamilyView: self.parent.db.commit_person(child,trans) self.parent.db.commit_family(self.family,trans) n = child.get_primary_name().get_regular_name() - self.parent.db.add_transaction(trans,_("Remove Child (%s)") % n) + self.parent.db.transaction_commit(trans,_("Remove Child (%s)") % n) self.load_family() @@ -775,7 +783,7 @@ class FamilyView: else: self.family.set_mother_handle(None) - trans = self.parent.db.start_transaction() + trans = self.parent.db.transaction_begin() if self.selected_spouse: self.selected_spouse.remove_family_handle(self.family.get_handle()) @@ -796,7 +804,7 @@ class FamilyView: else: self.load_family(self.family) n = self.person.get_primary_name().get_regular_name() - self.parent.db.add_transaction(trans,_("Remove Spouse (%s)") % n) + self.parent.db.transaction_commit(trans,_("Remove Spouse (%s)") % n) if len(self.person.get_family_handle_list()) <= 1: self.spouse_selection.set_mode(gtk.SELECTION_NONE) @@ -825,7 +833,7 @@ class FamilyView: model, iter = self.ap_selection.get_selected() path = model.get_path(iter) family_handle,m,r = plist[path[0]] - family = self.parent.db.find_family_from_handle(family_handle) + family = self.parent.db.get_family_from_handle(family_handle) if family.get_father_handle(): person_handle = family.get_father_handle() @@ -835,9 +843,9 @@ class FamilyView: self.parent.change_active_person(person) n = person.get_primary_name().get_name() - trans = self.parent.db.start_transaction() + trans = self.parent.db.transaction_begin() self.parent.db.commit_family(family,trans) - self.parent.db.add_transaction(trans,_("Select Parents (%s)") % n) + self.parent.db.transaction_commit(trans,_("Select Parents (%s)") % n) self.load_family(family) def clear(self): @@ -899,7 +907,7 @@ class FamilyView: for f in splist: if not f: continue - fm = self.parent.db.find_family_from_handle(f,None) + fm = self.parent.db.get_family_from_handle(f) if fm.get_father_handle() == self.person.get_handle(): sp_id = fm.get_mother_handle() @@ -982,7 +990,7 @@ class FamilyView: return _("%s: unknown") % (l) def delete_family_from(self,person): - trans = self.parent.db.start_transaction() + trans = self.parent.db.transaction_begin() person.remove_family_handle(self.family.get_handle(),trans) self.parent.db.delete_family(self.family.get_handle(),trans) flist = self.person.get_family_handle_list() @@ -991,7 +999,7 @@ class FamilyView: else: self.family = None n = person.get_primary_name().get_name() - self.parent.db.add_transaction(trans,_("Remove from family (%s)") % n) + self.parent.db.transaction_commit(trans,_("Remove from family (%s)") % n) def display_marriage(self,family): self.child_model.clear() @@ -1040,7 +1048,7 @@ class FamilyView: if fiter == None: fiter = self.child_model.get_path(iter) - val = self.parent.db.get_person_display(child.get_handle()) + val = child.get_display_info() i += 1 event = self.parent.db.find_event_from_handle(val[3]) @@ -1267,7 +1275,7 @@ class FamilyView: if not person: return - trans = self.parent.db.start_transaction() + trans = self.parent.db.transaction_begin() plist = person.get_parent_family_handle_list() if len(plist) == 0: @@ -1300,7 +1308,7 @@ class FamilyView: self.parent.db.commit_person(person,trans) n = person.get_primary_name().get_regular_name() - self.parent.db.add_transaction(trans,_("Remove Parents (%s)") % n) + self.parent.db.transaction_commit(trans,_("Remove Parents (%s)") % n) self.load_family() @@ -1336,9 +1344,9 @@ class FamilyView: _("Children must be ordered by their birth dates.")) return self.family.set_child_handle_list(list) - trans = self.parent.db.start_transaction() + trans = self.parent.db.transaction_begin() self.parent.db.commit_family(self.family,trans) - self.parent.db.add_transaction(trans,_('Reorder children')) + self.parent.db.transaction_commit(trans,_('Reorder children')) self.display_marriage(self.family) def drag_data_get(self,widget, context, sel_data, info, time): diff --git a/src/Find.py b/src/Find.py deleted file mode 100644 index 708346501..000000000 --- a/src/Find.py +++ /dev/null @@ -1,219 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000 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 -# 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 -# - -"""interface for opening a find person dialog for gramps -""" - -__author__ = 'Don Allingham' - -#------------------------------------------------------------------------- -# -# python modules -# -#------------------------------------------------------------------------- -import string - -#------------------------------------------------------------------------- -# -# Gnome modules -# -#------------------------------------------------------------------------- -import gtk -import gtk.glade - -#------------------------------------------------------------------------- -# -# gramps modules -# -#------------------------------------------------------------------------- -import const -import Utils -from gettext import gettext as _ - -#------------------------------------------------------------------------- -# -# FindBase -# -#------------------------------------------------------------------------- -class FindBase: - """Opens find person dialog for gramps""" - - def __init__(self,task,name,db,valid_map=None): - """Opens a dialog box instance that allows users to - search for a person. - task - function to call to change the active person""" - - self.t = type(u' ') - self.db = db - self.task = task - self.glade = gtk.glade.XML(const.gladeFile,"find","gramps") - self.glade.signal_autoconnect({ - 'on_next_clicked' : self.on_next_clicked, - 'on_back_clicked' : self.on_prev_clicked, - 'on_close_clicked' : self.on_close_clicked, - }) - self.top = self.glade.get_widget('find') - self.top.connect('delete_event',self.on_destroy) - - self.entry = self.glade.get_widget('entry') - self.forward_button = self.glade.get_widget('forward') - self.back_button = self.glade.get_widget('back') - Utils.set_titles(self.top, self.glade.get_widget('title'), name) - self.list = None - self.index = 0 - self.visible = 1 - self.valid = valid_map - - def get_value(self,id): - return id - - def advance(self,func): - text = unicode(self.entry.get_text().upper()) - orow = self.index - func() - while self.index != orow: - vals = self.list[self.index] - id = vals[1] - name = vals[0] - if id == None: - func() - continue - if self.valid and not self.valid.has_key(id): - func() - continue - if string.find(name.upper(),text) >= 0: - self.back_button.set_sensitive(0) - self.forward_button.set_sensitive(0) - self.task(self.get_value(id)) - self.back_button.set_sensitive(1) - self.forward_button.set_sensitive(1) - return - func() - - def forward(self): - self.index = self.index + 1 - if self.index == len(self.list): - self.index = 0 - - def backward(self): - self.index = self.index - 1 - if self.index < 0: - self.index = len(self.list)-1 - - def on_close_clicked(self,obj): - """Destroys the window in response to a close window button press""" - self.visible = 0 - self.top.hide() - - def on_destroy(self,obj,event): - self.on_close_clicked(obj) - return 1 - - def show(self): - self.top.window.raise_() - self.top.show() - self.entry.grab_focus () - - def on_next_clicked(self,obj): - """Advances to the next person that matches the dialog text""" - self.advance(self.forward) - - def on_prev_clicked(self,obj): - """Advances to the previous person that matches the dialog text""" - self.advance(self.backward) - -#------------------------------------------------------------------------- -# -# FindPerson -# -#------------------------------------------------------------------------- -class FindPerson(FindBase): - """Opens a Find Person dialog for GRAMPS""" - - def __init__(self,task,db,valid_map): - """Opens a dialog box instance that allows users to - search for a person. - - task - function to call to change the active person""" - - FindBase.__init__(self,task,_("Find Person"),db,valid_map) - self.list = [] - for val in db.sort_person_keys(): - self.list.append(db.get_person_display(val)) - - def get_value(self,id): - return self.db.get_person_from_handle(id) - -#------------------------------------------------------------------------- -# -# FindPlace -# -#------------------------------------------------------------------------- -class FindPlace(FindBase): - """Opens a Find Place dialog for GRAMPS""" - - def __init__(self,task,db): - """Opens a dialog box instance that allows users to - search for a place. - - task - function to call to change the active person""" - - FindBase.__init__(self,task,_("Find Place"),db) - self.list = db.placeTable.values() - self.list.sort() - -#------------------------------------------------------------------------- -# -# FindSource -# -#------------------------------------------------------------------------- -class FindSource(FindBase): - """Opens a Find Place dialog for GRAMPS""" - - def __init__(self,task,db): - """Opens a dialog box instance that allows users to - search for a place. - - task - function to call to change the active person""" - - FindBase.__init__(self,task,_("Find Source"),db) - self.list = db.sourceTable.values() - self.list.sort() - -#------------------------------------------------------------------------- -# -# FindMedia -# -#------------------------------------------------------------------------- -class FindMedia(FindBase): - """Opens a Find Media Object dialog for GRAMPS""" - - def __init__(self,task,db): - """Opens a dialog box instance that allows users to - search for a place. - - task - function to call to change the active person""" - - FindBase.__init__(self,task,_("Find Media Object"),db) - self.list = [] - for n in self.db.get_object_map().values(): - self.list.append((n.get_description(),n.get_handle())) - self.list.sort() - diff --git a/src/GenericFilter.py b/src/GenericFilter.py index 3b41342d0..df014e8c6 100644 --- a/src/GenericFilter.py +++ b/src/GenericFilter.py @@ -279,7 +279,7 @@ class HasCompleteRecord(Rule): return _('Matches all people whose records are complete') def apply(self,db,p_id): - return db.get_person_from_handle(p_id).get_complete() == 1 + return db.get_person_from_handle(p_id).get_complete_flag() == 1 #------------------------------------------------------------------------- # @@ -393,7 +393,7 @@ class IsDescendantOfFilterMatch(IsDescendantOf): if not self.init: self.init = 1 filter = MatchesFilter(self.list) - for person_handle in db.get_person_keys(): + for person_handle in db.get_person_handles(sort_handles=False): if filter.apply (db, person_handle): self.init_list (person_handle, first) return self.map.has_key(p_id) @@ -524,7 +524,7 @@ class IsChildOfFilterMatch(Rule): if not self.init: self.init = 1 filter = MatchesFilter(self.list) - for person_handle in db.get_person_keys(): + for person_handle in db.get_person_handles(sort_handles=False): if filter.apply (db, person_handle): self.init_list (person_handle) return self.map.has_key(p_id) @@ -682,7 +682,7 @@ class IsAncestorOfFilterMatch(IsAncestorOf): if not self.init: self.init = 1 filter = MatchesFilter(self.list[0]) - for person_handle in db.get_person_keys(): + for person_handle in db.get_person_handles(sort_handles=False): if filter.apply (db, person_handle): self.init_ancestor_list (person_handle,first) return self.map.has_key(p_id) @@ -827,7 +827,7 @@ class IsParentOfFilterMatch(Rule): if not self.init: self.init = 1 filter = MatchesFilter(self.list) - for person_handle in db.get_person_keys(): + for person_handle in db.get_person_handles(sort_handles=False): if filter.apply (db, person_handle): self.init_list (person_handle) return self.map.has_key(p_id) @@ -912,7 +912,7 @@ class HasCommonAncestorWithFilterMatch(HasCommonAncestorWith): def init_ancestor_cache(self,db): filter = MatchesFilter(self.list) def init(self,pid): self.ancestor_cache[pid] = 1 - for p_id in db.get_person_keys(): + for p_id in db.get_person_handles(sort_handles=False): if (not self.ancestor_cache.has_key (p_id) and filter.apply (db, p_id)): for_each_ancestor([p_id],init,self) diff --git a/src/GrampsBSDDB.py b/src/GrampsBSDDB.py index f3f53c63c..f1f592670 100644 --- a/src/GrampsBSDDB.py +++ b/src/GrampsBSDDB.py @@ -124,7 +124,7 @@ class GrampsBSDDB(GrampsDbBase): self.env = None self.metadata = None - def get_surnames(self): + def get_surname_list(self): names = self.surnames.keys() a = {} for name in names: @@ -133,7 +133,7 @@ class GrampsBSDDB(GrampsDbBase): vals.sort() return vals - def get_eventnames(self): + def get_person_event_type_list(self): names = self.eventnames.keys() a = {} for name in names: @@ -142,20 +142,26 @@ class GrampsBSDDB(GrampsDbBase): vals.sort() return vals - def remove_person_handle(self,handle,transaction): + def remove_person(self,handle,transaction): self.genderStats.uncount_person (self.person_map[handle]) if transaction != None: old_data = self.person_map.get(handle) transaction.add(PERSON_KEY,handle,old_data) self.person_map.delete(handle) - def remove_source_handle(self,handle,transaction): + def remove_source(self,handle,transaction): if transaction != None: old_data = self.source_map.get(str(handle)) transaction.add(SOURCE_KEY,handle,old_data) self.source_map.delete(str(handle)) - def remove_event_handle(self,handle,transaction): + def remove_family_handle(self,handle,transaction): + if transaction != None: + old_data = self.family_map.get(str(handle)) + transaction.add(FAMILY_KEY,handle,old_data) + self.family_map.delete(str(handle)) + + def remove_event(self,handle,transaction): if transaction != None: old_data = self.event_map.get(str(handle)) transaction.add(EVENT_KEY,handle,old_data) diff --git a/src/GrampsCfg.py b/src/GrampsCfg.py index 070ec6185..1db79fced 100644 --- a/src/GrampsCfg.py +++ b/src/GrampsCfg.py @@ -265,22 +265,22 @@ def save_usetips(val): set_bool("/apps/gramps/behavior/use-tips",val) # preferences keys -def get_iprefix(): +def get_person_id_prefix(): return get_string("/apps/gramps/preferences/iprefix") -def get_eprefix(): +def get_event_id_prefix(): return get_string("/apps/gramps/preferences/iprefix") def save_iprefix(val): set_string_as_id_prefix("/apps/gramps/preferences/iprefix",val) -def get_oprefix(): +def get_object_id_prefix(): return get_string("/apps/gramps/preferences/oprefix") def save_oprefix(val): set_string_as_id_prefix("/apps/gramps/preferences/oprefix",val) -def get_sprefix(): +def get_source_id_prefix(): return get_string("/apps/gramps/preferences/sprefix") def save_sprefix(val): @@ -289,13 +289,13 @@ def save_sprefix(val): def save_eprefix(val): set_string_as_id_prefix("/apps/gramps/preferences/eprefix",val) -def get_pprefix(): +def get_place_id_prefix(): return get_string("/apps/gramps/preferences/pprefix") def save_pprefix(val): set_string_as_id_prefix("/apps/gramps/preferences/pprefix",val) -def get_fprefix(): +def get_family_id_prefix(): return get_string("/apps/gramps/preferences/fprefix") def save_fprefix(val): @@ -741,19 +741,19 @@ class GrampsPreferences: index_vis.connect('toggled',lambda obj: save_index_visible(obj.get_active())) ipr = self.top.get_widget("iprefix") - ipr.set_text(get_iprefix()) + ipr.set_text(get_person_id_prefix()) ipr.connect('changed',lambda obj: save_iprefix(obj.get_text())) opr = self.top.get_widget("oprefix") - opr.set_text(get_oprefix()) + opr.set_text(get_object_id_prefix()) opr.connect('changed',lambda obj: save_oprefix(obj.get_text())) fpr = self.top.get_widget("fprefix") - fpr.set_text(get_fprefix()) + fpr.set_text(get_family_id_prefix()) fpr.connect('changed',lambda obj: save_fprefix(obj.get_text())) spr = self.top.get_widget("sprefix") - spr.set_text(get_sprefix()) + spr.set_text(get_source_id_prefix()) spr.connect('changed',lambda obj: save_sprefix(obj.get_text())) ppr = self.top.get_widget("pprefix") - ppr.set_text(get_pprefix()) + ppr.set_text(get_place_id_prefix()) ppr.connect('changed',lambda obj: save_pprefix(obj.get_text())) sb2 = self.top.get_widget("stat2") diff --git a/src/GrampsDbBase.py b/src/GrampsDbBase.py index a3bd14d90..7bcca3546 100644 --- a/src/GrampsDbBase.py +++ b/src/GrampsDbBase.py @@ -1,4 +1,4 @@ -# + # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2004 Donald N. Allingham @@ -20,6 +20,11 @@ # $Id$ +""" +Base class for the GRAMPS databases. All database interfaces should inherit +from this class. +""" + #------------------------------------------------------------------------- # # libraries @@ -44,27 +49,34 @@ EVENT_KEY = 3 MEDIA_KEY = 4 PLACE_KEY = 5 -#------------------------------------------------------------------------- -# -# GrampsDbBase -# -#------------------------------------------------------------------------- class GrampsDbBase: - """GRAMPS database object. This object is a base class for other - objects.""" + """ + GRAMPS database object. This object is a base class for all + database interfaces. + """ def __init__(self): - """creates a new GrampsDB""" + """ + Creates a new GrampsDbBase instance. A new GrampDbBase class should + never be directly created. Only classes derived from this class should + be created. + """ + + self.smap_index = 0 + self.emap_index = 0 + self.pmap_index = 0 + self.fmap_index = 0 + self.lmap_index = 0 + self.omap_index = 0 + + self.set_person_id_prefix(GrampsCfg.get_person_id_prefix()) + self.set_object_id_prefix(GrampsCfg.get_object_id_prefix()) + self.set_family_id_prefix(GrampsCfg.get_family_id_prefix()) + self.set_source_id_prefix(GrampsCfg.get_source_id_prefix()) + self.set_place_id_prefix(GrampsCfg.get_place_id_prefix()) + self.set_event_id_prefix(GrampsCfg.get_event_id_prefix()) - self.set_iprefix(GrampsCfg.get_iprefix()) - self.set_oprefix(GrampsCfg.get_oprefix()) - self.set_fprefix(GrampsCfg.get_fprefix()) - self.set_sprefix(GrampsCfg.get_sprefix()) - self.set_pprefix(GrampsCfg.get_pprefix()) - self.set_eprefix(GrampsCfg.get_eprefix()) self.open = 0 - self.new() - self.added_files = [] self.genderStats = GenderStats() self.id_trans = None @@ -77,38 +89,43 @@ class GrampsDbBase: self.event_map = None self.eventnames = None self.metadata = None - self.undolabel = None - self.redolabel = None + self.undo_callback = None + self.redo_callback = None self.modified = 0 - def new(self): - """initializes the GrampsDB to empty values""" - self.undoindex = -1 self.translist = [None] * _UNDO_SIZE - self.smap_index = 0 - self.emap_index = 0 - self.pmap_index = 0 - self.fmap_index = 0 - self.lmap_index = 0 - self.omap_index = 0 self.default = None self.owner = Researcher() self.bookmarks = [] self.path = "" self.place2title = {} - self.genderStats = GenderStats() def load(self,name,callback): + """ + Opens the specified database. The method needs to be overridden + in the derived class. + """ assert(0,"Needs to be overridden in the derived class") def close(self): + """ + Closes the specified database. The method needs to be overridden + in the derived class. + """ assert(0,"Needs to be overridden in the derived class") def is_open(self): + """ + Returns 1 if the database has been opened. + """ return self.person_map != None def commit_person(self,person,transaction): + """ + Commits the specified Person to the database, storing the changes + as part of the transaction. + """ handle = person.get_handle() if transaction != None: old_data = self.person_map.get(handle) @@ -116,6 +133,10 @@ class GrampsDbBase: self.person_map[handle] = person.serialize() def commit_media_object(self,obj,transaction): + """ + Commits the specified MediaObject to the database, storing the changes + as part of the transaction. + """ handle = str(obj.get_handle()) if transaction != None: old_data = self.media_map.get(handle) @@ -123,6 +144,10 @@ class GrampsDbBase: self.media_map[str(obj.get_handle())] = obj.serialize() def commit_source(self,source,transaction): + """ + Commits the specified Source to the database, storing the changes + as part of the transaction. + """ handle = str(source.get_handle()) if transaction != None: old_data = self.source_map.get(handle) @@ -130,6 +155,10 @@ class GrampsDbBase: self.source_map[str(source.get_handle())] = source.serialize() def commit_place(self,place,transaction): + """ + Commits the specified Place to the database, storing the changes + as part of the transaction. + """ handle = str(place.get_handle()) if transaction != None: old_data = self.place_map.get(handle) @@ -137,6 +166,10 @@ class GrampsDbBase: self.place_map[str(place.get_handle())] = place.serialize() def commit_event(self,event,transaction): + """ + Commits the specified Event to the database, storing the changes + as part of the transaction. + """ handle = str(event.get_handle()) if transaction != None: old_data = self.event_map.get(handle) @@ -144,13 +177,21 @@ class GrampsDbBase: self.event_map[str(event.get_handle())] = event.serialize() def commit_family(self,family,transaction): + """ + Commits the specified Family to the database, storing the changes + as part of the transaction. + """ handle = str(family.get_handle()) if transaction != None: old_data = self.family_map.get(handle) transaction.add(FAMILY_KEY,handle,old_data) self.family_map[str(family.get_handle())] = family.serialize() - def find_next_gramps_id(self): + def find_next_person_gramps_id(self): + """ + Returns the next available GRAMPS' ID for a Person object based + off the person ID prefix. + """ index = self.iprefix % self.pmap_index while self.id_trans.get(str(index)): self.pmap_index += 1 @@ -159,6 +200,10 @@ class GrampsDbBase: return index def find_next_place_gramps_id(self): + """ + Returns the next available GRAMPS' ID for a Place object based + off the person ID prefix. + """ index = self.pprefix % self.lmap_index while self.id_trans.get(str(index)): self.lmap_index += 1 @@ -167,6 +212,10 @@ class GrampsDbBase: return index def find_next_event_gramps_id(self): + """ + Returns the next available GRAMPS' ID for a Event object based + off the person ID prefix. + """ index = self.eprefix % self.emap_index while self.id_trans.get(str(index)): self.emap_index += 1 @@ -175,6 +224,10 @@ class GrampsDbBase: return index def find_next_object_gramps_id(self): + """ + Returns the next available GRAMPS' ID for a MediaObject object based + off the person ID prefix. + """ index = self.oprefix % self.omap_index while self.id_trans.get(str(index)): self.omap_index += 1 @@ -183,6 +236,10 @@ class GrampsDbBase: return index def find_next_source_gramps_id(self): + """ + Returns the next available GRAMPS' ID for a Source object based + off the person ID prefix. + """ index = self.sprefix % self.smap_index while self.source_map.get(str(index)): self.smap_index += 1 @@ -191,6 +248,10 @@ class GrampsDbBase: return index def find_next_family_gramps_id(self): + """ + Returns the next available GRAMPS' ID for a Family object based + off the person ID prefix. + """ index = self.fprefix % self.fmap_index while self.family_map.get(str(index)): self.fmap_index += 1 @@ -262,40 +323,44 @@ class GrampsDbBase: return family return None - def find_person_from_handle(self,val,trans): - """finds a Person in the database from the passed gramps' ID. - If no such Person exists, a new Person is added to the database.""" - + def find_person_from_handle(self,val,transaction): + """ + Finds a Person in the database from the passed GRAMPS ID. + If no such Person exists, a new Person is added to the database. + """ person = Person() data = self.person_map.get(str(val)) if data: person.unserialize(data) else: person.set_handle(val) - if trans != None: - trans.add(PERSON_KEY, val, None) + if transaction != None: + transaction.add(PERSON_KEY, val, None) self.person_map[val] = person.serialize() self.genderStats.count_person (person, self) return person - def find_source_from_handle(self,val,trans): - """finds a Source in the database from the passed gramps' ID. - If no such Source exists, a new Source is added to the database.""" - + def find_source_from_handle(self,val,transaction): + """ + Finds a Source in the database from the passed GRAMPS ID. + If no such Source exists, a new Source is added to the database. + """ source = Source() if self.source_map.get(str(val)): source.unserialize(self.source_map.get(str(val))) else: source.set_handle(val) - if trans != None: - trans.add(SOURCE_KEY,val,None) + if transaction != None: + transaction.add(SOURCE_KEY,val,None) self.source_map[str(val)] = source.serialize() self.smap_index = self.smap_index + 1 return source def find_event_from_handle(self,val): - """finds a Family in the database from the passed gramps' ID. - If no such Family exists, a new Family is added to the database.""" + """ + Finds a Family in the database from the passed GRAMPS ID. + If no such Family exists, a new Family is added to the database. + """ data = self.event_map.get(str(val)) if data: event = Event() @@ -304,35 +369,37 @@ class GrampsDbBase: else: return None - def find_object_from_handle(self,handle,trans): - """finds an Object in the database from the passed gramps' ID. - If no such Object exists, a new Object is added to the database.""" + def find_object_from_handle(self,handle,transaction): + """ + Finds an MediaObject in the database from the passed GRAMPS ID. + If no such MediaObject exists, a new Object is added to the database.""" obj = MediaObject() if self.media_map.get(str(handle)): obj.unserialize(self.media_map.get(str(handle))) else: obj.set_handle(handle) - self.add_object(obj,trans) + self.add_object(obj,transaction) return obj - def find_place_from_handle(self,handle,trans): - """finds a Place in the database from the passed gramps' ID. - If no such Place exists, a new Place is added to the database.""" - + def find_place_from_handle(self,handle,transaction): + """ + Finds a Place in the database from the passed GRAMPS ID. + If no such Place exists, a new Place is added to the database. + """ data = self.place_map.get(str(handle)) place = Place() if not data: place.handle = handle - if trans != None: - trans.add(PLACE_KEY,handle,None) + if transaction != None: + transaction.add(PLACE_KEY,handle,None) self.place_map[str(handle)] = place.serialize() self.lmap_index = self.lmap_index + 1 else: place.unserialize(data) return place - def find_family_from_handle(self,val,trans): + def find_family_from_handle(self,val,transaction): """finds a Family in the database from the passed gramps' ID. If no such Family exists, a new Family is added to the database.""" @@ -342,90 +409,93 @@ class GrampsDbBase: family.unserialize(data) else: family.handle = val - if trans: - trans.add(FAMILY_KEY,val,None) + if transaction: + transaction.add(FAMILY_KEY,val,None) self.family_map[str(val)] = family.serialize() self.fmap_index = self.fmap_index + 1 return family - def add_person(self,person,trans): - """adds a Person to the database, assigning a gramps' ID""" - if person.get_gramps_id() == "": - person.set_gramps_id(self.find_next_gramps_id()) - if person.get_handle() == "": + def add_person(self,person,transaction): + """ + Adds a Person to the database, assigning internal IDs if they have + not already been defined. + """ + if person.get_gramps_id() == None: + person.set_gramps_id(self.find_next_person_gramps_id()) + if person.get_handle() == None: person.set_handle(Utils.create_id()) - if trans != None: - trans.add(PERSON_KEY, person.get_handle(),None) - self.person_map[person.get_handle()] = person.serialize() + self.commit_person(person,transaction) self.genderStats.count_person (person, self) return person.get_handle() - def add_family(self,family,trans): - """adds a Person to the database, assigning a gramps' ID""" - if family.get_gramps_id() == "": + def add_family(self,family,transaction): + """ + Adds a Family to the database, assigning internal IDs if they have + not already been defined. + """ + if family.get_gramps_id() == None: family.set_gramps_id(self.find_next_family_gramps_id()) - if family.get_handle() == "": + if family.get_handle() == None: family.set_handle(Utils.create_id()) - if trans != None: - trans.add(FAMILY_KEY, family.get_handle(),None) - self.family_map[str(family.get_handle())] = family.serialize() + self.commit_family(family,transaction) return family.get_handle() - def add_source(self,source,trans): - """adds a Source instance to the database, assigning it a gramps' - ID number""" - if source.get_handle() == "": + def add_source(self,source,transaction): + """ + Adds a Source to the database, assigning internal IDs if they have + not already been defined. + """ + if source.get_handle() == None: source.set_handle(Utils.create_id()) - if source.get_gramps_id() == "": + if source.get_gramps_id() == None: source.set_gramps_id(self.find_next_source_gramps_id()) - if trans != None: - trans.add(SOURCE_KEY,source.get_handle(),None) - self.source_map[str(source.get_handle())] = source.serialize() + self.commit_source(source,transaction) return source.get_handle() - def add_event(self,event,trans): - """adds a Event instance to the database, assigning it a gramps' - ID number""" - if event.get_handle() == "": + def add_event(self,event,transaction): + """ + Adds an Event to the database, assigning internal IDs if they have + not already been defined. + """ + if event.get_handle() == None: event.set_handle(Utils.create_id()) - if event.get_gramps_id() == "": + if event.get_gramps_id() == None: event.set_gramps_id(self.find_next_event_gramps_id()) - if trans != None: - trans.add(EVENT_KEY,event.get_handle(),None) - self.event_map[str(event.get_handle())] = event.serialize() + self.commit_event(event,transaction) return event.get_handle() - def add_place(self,place,trans): - """adds a Place instance to the database, assigning it a gramps' - ID number""" - - if place.get_handle() == "": + def add_place(self,place,transaction): + """ + Adds a Place to the database, assigning internal IDs if they have + not already been defined. + """ + if place.get_handle() == None: index = Utils.create_id() place.set_handle(index) - if place.get_gramps_id() == "": + if place.get_gramps_id() == None: place.set_gramps_id(self.find_next_place_gramps_id()) - if trans != None: - trans.add(PLACE_KEY,place.get_handle(),None) - self.place_map[place.get_handle()] = place.serialize() + self.commit_place(place,transaction) return place.get_handle() - def add_object(self,obj,trans): - """adds an Object instance to the database, assigning it a gramps' - ID number""" - + def add_object(self,obj,transaction): + """ + Adds a MediaObject to the database, assigning internal IDs if they have + not already been defined. + """ index = obj.get_handle() - if index == "": + if index == None: index = Utils.create_id() obj.set_handle(index) - if obj.get_gramps_id() == "": + if obj.get_gramps_id() == None: obj.set_gramps_id(self.find_next_object_gramps_id()) - if trans != None: - trans.add(MEDIA_KEY,index,None) - self.media_map[str(index)] = obj.serialize() - self.added_files.append(obj) + self.commit_media_object(obj,transaction) return index def get_people_view_maps(self): + """ + Allows the saving people display data into the database metadata. + This allows faster display of the treeview. + """ if self.metadata: return (self.metadata.get('tp_iter'), self.metadata.get('tp_path'), @@ -436,6 +506,10 @@ class GrampsDbBase: return (None,None,None,None,None) def set_people_view_maps(self,maps): + """ + Allows the retreiving people display data into the database metadata. + This allows faster display of the treeview. + """ if self.metadata: self.metadata['tp_iter'] = maps[0] self.metadata['tp_path'] = maps[1] @@ -443,58 +517,86 @@ class GrampsDbBase: self.metadata['p_path'] = maps[3] self.metadata['sname'] = maps[4] - def get_added_media_objects(self): - return self.added_files - - def clear_added_media_objects(self): - self.added_files = [] - def get_number_of_people(self): + """ + Returns the number of people currently in the databse. + """ return len(self.person_map) - def get_person_keys(self): + def get_person_handles(self,sort_handles=True): + """ + Returns a list of database handles, one handle for each Person in + the database. If sort_handles is True, the list is sorted by surnames + """ if self.person_map: - return self.person_map.keys() + handle_list = self.person_map.keys() + if sort_handles: + handle_list.sort(self._sortbyname) + return handle_list return [] - def get_family_keys(self): + def get_place_handles(self,sort_handles=True): + """ + Returns a list of database handles, one handle for each Place in + the database. If sort_handles is True, the list is sorted by + Place title. + """ + if self.place_map: + handle_list = self.place_map.keys() + if sort_handles: + handle_list.sort(self._sortbyplace) + return handle_list + return [] + + def get_source_handles(self,sort_handles=True): + """ + Returns a list of database handles, one handle for each Source in + the database. If sort_handles is True, the list is sorted by + Source title. + """ + if self.source_map: + handle_list = self.source_map.keys() + if sort_handles: + handle_list.sort(self._sortbysource) + return handle_list + return [] + + def get_media_object_handles(self,sort_handles=True): + """ + Returns a list of database handles, one handle for each MediaObject in + the database. If sort_handles is True, the list is sorted by title. + """ + if self.media_map: + handle_list = self.media_map.keys() + if sort_handles: + handle_list.sort(self._sortbymedia) + return handle_list + return [] + + def get_event_handles(self): + """ + Returns a list of database handles, one handle for each Event in + the database. + """ + if self.event_map: + return self.event_map.keys() + return [] + + def get_family_handles(self): + """ + Returns a list of database handles, one handle for each Family in + the database. + """ if self.family_map: return self.family_map.keys() return [] - def sort_by_name(self,f,s): - n1 = self.person_map.get(f)[2].sname - n2 = self.person_map.get(s)[2].sname - return cmp(n1,n2) - - def sort_person_keys(self): - if self.person_map: - keys = self.person_map.keys() - keys.sort(self.sort_by_name) - return keys - return [] - - def get_person_display(self,key): - data = self.person_map.get(key) - - if data[2] == Person.male: - gender = const.male - elif data[2] == Person.female: - gender = const.female - else: - gender = const.unknown - - return [ data[3].get_name(), - data[1], - gender, - data[7], - data[6], - data[3].get_sort_name(), - data[7], - data[6], - GrampsCfg.get_display_surname()(data[3])] - - def set_iprefix(self,val): + def set_person_id_prefix(self,val): + """ + Sets the naming template for GRAMPS Person ID values. The string is expected + to be in the form of a simple text string, or in a format that contains + a C/Python style format string using %d, such as I%d or I%04d. + """ if val: if _id_reg.search(val): self.iprefix = val @@ -503,7 +605,12 @@ class GrampsDbBase: else: self.iprefix = "I%04d" - def set_sprefix(self,val): + def set_source_id_prefix(self,val): + """ + Sets the naming template for GRAMPS Source ID values. The string is expected + to be in the form of a simple text string, or in a format that contains + a C/Python style format string using %d, such as S%d or S%04d. + """ if val: if _id_reg.search(val): self.sprefix = val @@ -512,7 +619,12 @@ class GrampsDbBase: else: self.sprefix = "S%04d" - def set_oprefix(self,val): + def set_object_id_prefix(self,val): + """ + Sets the naming template for GRAMPS MediaObject ID values. The string is expected + to be in the form of a simple text string, or in a format that contains + a C/Python style format string using %d, such as O%d or O%04d. + """ if val: if _id_reg.search(val): self.oprefix = val @@ -521,7 +633,12 @@ class GrampsDbBase: else: self.oprefix = "O%04d" - def set_pprefix(self,val): + def set_place_id_prefix(self,val): + """ + Sets the naming template for GRAMPS Place ID values. The string is expected + to be in the form of a simple text string, or in a format that contains + a C/Python style format string using %d, such as P%d or P%04d. + """ if val: if _id_reg.search(val): self.pprefix = val @@ -530,7 +647,12 @@ class GrampsDbBase: else: self.pprefix = "P%04d" - def set_fprefix(self,val): + def set_family_id_prefix(self,val): + """ + Sets the naming template for GRAMPS Family ID values. The string is expected + to be in the form of a simple text string, or in a format that contains + a C/Python style format string using %d, such as F%d or F%04d. + """ if val: if _id_reg.search(val): self.fprefix = val @@ -539,7 +661,12 @@ class GrampsDbBase: else: self.fprefix = "F%04d" - def set_eprefix(self,val): + def set_event_id_prefix(self,val): + """ + Sets the naming template for GRAMPS Event ID values. The string is expected + to be in the form of a simple text string, or in a format that contains + a C/Python style format string using %d, such as E%d or E%04d. + """ if val: if _id_reg.search(val): self.eprefix = val @@ -548,10 +675,18 @@ class GrampsDbBase: else: self.eprefix = "E%04d" - def start_transaction(self,msg=""): + def transaction_begin(self,msg=""): + """ + Creates a new Transaction tied to the current UNDO database. The transaction + has no effect until it is committed using the transaction_commit function of + the this database object. + """ return Transaction(msg,self.undodb) - def add_transaction(self,transaction,msg): + def transaction_commit(self,transaction,msg): + """ + Commits the transaction to the assocated UNDO database. + """ if not len(transaction): return transaction.set_description(msg) @@ -561,13 +696,14 @@ class GrampsDbBase: else: self.translist[self.undoindex] = transaction - if self.undolabel: - self.undolabel.set_sensitive(1) - label = self.undolabel.get_children()[0] - label.set_text(_("_Undo %s") % transaction.get_description()) - label.set_use_underline(1) + if self.undo_callback: + self.undo_callback(_("_Undo %s") % transaction.get_description()) def undo(self): + """ + Accesses the last committed transaction, and reverts the data to + the state before the transaction was committed. + """ if self.undoindex == -1: return transaction = self.translist[self.undoindex] @@ -608,42 +744,47 @@ class GrampsDbBase: else: self.media_map[str(handle)] = data - if self.undolabel: - label = self.undolabel.get_children()[0] + if self.undo_callback: if self.undoindex == -1: - label.set_text(_("_Undo")) - self.undolabel.set_sensitive(0) + self.undo_callback(None) else: transaction = self.translist[self.undoindex] - label.set_text(_("_Undo %s") % transaction.get_description()) - self.undolabel.set_sensitive(1) - label.set_use_underline(1) + self.undo_callback(_("_Undo %s") % transaction.get_description()) - def set_undo_label(self,label): - self.undolabel = label - self.undolabel.set_sensitive(0) + def set_undo_callback(self,callback): + """ + Defines the callback function that is called whenever an undo operation + is executed. The callback function recieves a single argument that is a + text string that defines the operation. + """ + self.undo_callback = callback - def set_redo_label(self,label): - self.redolabel = label - self.redolabel.set_sensitive(0) + def set_redo_callback(self,callback): + """ + Defines the callback function that is called whenever an redo operation + is executed. The callback function recieves a single argument that is a + text string that defines the operation. + """ + self.redo_callback = callback - def get_surnames(self): - assert(0,"Needs to be overridden in the derived class") + def get_surname_list(self): + """ + Returns the list of surnames contained within the database. + The function must be overridden in the derived class. + """ + assert(False,"Needs to be overridden in the derived class") - def get_eventnames(self): - assert(0,"Needs to be overridden in the derived class") + def get_person_event_type_list(self): + """ + Returns the list of personal event types contained within the + database. The function must be overridden in the derived class. + """ + assert(False,"Needs to be overridden in the derived class") def get_bookmarks(self): - """returns the list of Person instances in the bookmarks""" + """returns the list of Person handles in the bookmarks""" return self.bookmarks - def clean_bookmarks(self): - """cleans up the bookmark list, removing empty slots""" - new_bookmarks = [] - for person_handle in self.bookmarks: - new_bookmarks.append(person_handle) - self.bookmarks = new_bookmarks - def set_researcher(self,owner): """sets the information about the owner of the database""" self.owner.set(owner.get_name(),owner.get_address(),owner.get_city(), @@ -655,14 +796,6 @@ class GrampsDbBase: the owner of the database""" return self.owner - def set_default_person(self,person): - """sets the default Person to the passed instance""" -# if (self.default): -# self.default.set_ancestor(0) - self.metadata['default'] = person.get_handle() -# if person: -# self.default.set_ancestor(1) - def set_default_person_handle(self,handle): """sets the default Person to the passed instance""" self.metadata['default'] = handle @@ -677,25 +810,6 @@ class GrampsDbBase: return person return None - def get_person(self,handle): - """returns a Person from a GRAMPS's ID""" - p = Person() - data = self.person_map.get(str(handle)) - p.unserialize(data) - return p - - def get_place_handle_map(self): - """returns a map of gramps's IDs to Place instances""" - return self.place_map - - def set_place_handle_map(self,map): - """sets the map of gramps's IDs to Place instances""" - self.place_map = map - - def get_family_handle(self,handle): - """returns a map of gramps's IDs to Family instances""" - return self.family_map.get(str(handle)) - def get_save_path(self): """returns the save path of the file, or "" if one does not exist""" return self.path @@ -729,29 +843,68 @@ class GrampsDbBase: instances in the database""" return [] - def get_place_handles(self): - """returns a list of Place instances""" - return self.place_map.keys() - def get_family_relation_types(self): """returns a list of all relationship types assocated with Family instances in the database""" return [] - def remove_person_handle(self,handle,transaction): - assert(0,"Needs to be overridden in the derived class") + def remove_person(self,handle,transaction): + """ + Removes the Person specified by the database handle from the + database, preserving the change in the passed transaction. This + method must be overridden in the derived class. + """ + assert(False,"Needs to be overridden in the derived class") - def remove_source_handle(self,handle,transaction): - assert(0,"Needs to be overridden in the derived class") + def remove_source(self,handle,transaction): + """ + Removes the Source specified by the database handle from the + database, preserving the change in the passed transaction. This + method must be overridden in the derived class. + """ + assert(False,"Needs to be overridden in the derived class") - def remove_event_handle(self,handle,transaction): - assert(0,"Needs to be overridden in the derived class") + def remove_event(self,handle,transaction): + """ + Removes the Event specified by the database handle from the + database, preserving the change in the passed transaction. This + method must be overridden in the derived class. + """ + assert(False,"Needs to be overridden in the derived class") - def has_person_handle(self,val): - return self.person_map.has_key(str(val)) + def remove_object(self,handle,transaction): + """ + Removes the MediaObjectPerson specified by the database handle from the + database, preserving the change in the passed transaction. This + method must be overridden in the derived class. + """ + assert(False,"Needs to be overridden in the derived class") - def has_family_handle(self,val): - return self.family_map.has_key(str(val)) + def remove_place(self,handle,transaction): + """ + Removes the Place specified by the database handle from the + database, preserving the change in the passed transaction. This + method must be overridden in the derived class. + """ + assert(False,"Needs to be overridden in the derived class") + + def has_person_handle(self,handle): + """ + returns True if the handle exists in the current Person database. + """ + return self.person_map.has_key(str(handle)) + + def has_family_handle(self,handle): + """ + returns True if the handle exists in the current Family database. + """ + return self.family_map.has_key(str(handle)) + + def has_object_handle(self,handle): + """ + returns True if the handle exists in the current MediaObjectdatabase. + """ + return self.media_map.has_key(str(handle)) != None def get_person_from_gramps_id(self,val): """finds a Person in the database from the passed gramps' ID. @@ -765,7 +918,7 @@ class GrampsDbBase: else: return None - def find_person_from_gramps_id(self,val,trans): + def find_person_from_gramps_id(self,val,transaction): """finds a Person in the database from the passed gramps' ID. If no such Person exists, a new Person is added to the database.""" @@ -777,153 +930,64 @@ class GrampsDbBase: intid = Utils.create_id() person.set_handle(intid) person.set_gramps_id(val) - self.add_person(person,trans) + self.add_person(person,transaction) return person - def has_object_handle(self,handle): - """finds an Object in the database from the passed gramps' ID. - If no such Source exists, a new Source is added to the database.""" + def _sortbyname(self,f,s): + n1 = self.person_map.get(f)[2].sname + n2 = self.person_map.get(s)[2].sname + return cmp(n1,n2) - return self.media_map.get(str(handle)) != None + def _sortbyplace(self,f,s): + return cmp(self.place_map.get(f)[2].upper(), self.place_map.get(s)[2].upper()) - def remove_object(self,handle,transaction): - assert(0,"Needs to be overridden in the derived class") - - def remove_place(self,handle,transaction): - assert(0,"Needs to be overridden in the derived class") - - def add_place_as(self,place,trans): - if trans != None: - trans.add(PLACE_KEY,place.get_handle(),None) - self.place_map[str(place.get_handle())] = place.serialize() - return place.get_handle() - - def sortbyplace(self,f,s): - return cmp(self.placesortmap[f], self.placesortmap[s]) - - def sortbysource(self,f,s): + def _sortbysource(self,f,s): fp = self.source_map[f][2].upper() sp = self.source_map[s][2].upper() return cmp(fp,sp) - def sortbymedia(self,f,s): + def _sortbymedia(self,f,s): fp = self.media_map[f][4].upper() sp = self.media_map[s][4].upper() return cmp(fp,sp) - def sort_place_keys(self): - if self.place_map: - self.placesortmap = {} - for key in self.place_map.keys(): - self.placesortmap[key] = self.place_map[key][2].upper() - keys = self.placesortmap.keys() - keys.sort(self.sortbyplace) - del self.placesortmap - return keys - return [] - - def sort_media_keys(self): - if self.media_map: - keys = self.media_map.keys() - keys.sort(self.sortbymedia) - return keys - else: - return [] - - def sort_source_keys(self): - if self.source_map: - keys = self.source_map.keys() - keys.sort(self.sortbysource) - return keys - else: - return [] - - def get_place_handle_keys(self): - if self.place_map: - return self.place_map.keys() - else: - return [] - - def get_place_display(self,key): - # fix this up better - place = Place() - place.unserialize(self.place_map[str(key)]) - return place.get_display_info() - - def get_source_keys(self): - if self.source_map: - return self.source_map.keys() - return [] - - def get_object_keys(self): - if self.media_map: - return self.media_map.keys() - return [] - - def get_event_keys(self): - if self.event_map: - return self.event_map.keys() - return [] - - def sortbysource(self,f,s): - f1 = self.source_map[f][1].upper() - s1 = self.source_map[s][1].upper() - return cmp(f1,s1) - - def set_source_keys(self): - keys = self.source_map.keys() - if type(keys) == type([]): - keys.sort(self.sortbyplace) - return keys - - def get_source_display(self,key): - source = Source() - source.unserialize(self.source_map.get(str(key))) - return source.get_display_info() - - def build_source_display(self,nkey,okey=None): - pass - - def new_family(self,trans): - """adds a Family to the database, assigning a gramps' ID""" - - index = self.fprefix % self.fmap_index - while self.family_map.get(str(index)): - self.fmap_index = self.fmap_index + 1 - index = self.fprefix % self.fmap_index - self.fmap_index = self.fmap_index + 1 - family = Family() - family.set_handle(index) - if trans != None: - trans.add(FAMILY_KEY, index, None) - self.family_map[str(index)] = family.serialize() - return family - - def delete_family(self,family_handle,trans): - """deletes the Family instance from the database""" - if self.family_map.get(str(family_handle)): - if trans != None: - old_data = self.family_map.get(str(family_handle)) - trans.add(FAMILY_KEY,family_handle,old_data) - del self.family_map[str(family_handle)] - - def set_column_order(self,list): + def set_person_column_order(self,list): + """ + Stores the Person display common information in the + database's metadata. + """ if self.metadata != None: self.metadata['columns'] = list def set_place_column_order(self,list): + """ + Stores the Place display common information in the + database's metadata. + """ if self.metadata != None: self.metadata['place_columns'] = list def set_source_column_order(self,list): + """ + Stores the Source display common information in the + database's metadata. + """ if self.metadata != None: self.metadata['source_columns'] = list def set_media_column_order(self,list): + """ + Stores the Media display common information in the + database's metadata. + """ if self.metadata != None: self.metadata['media_columns'] = list - def get_column_order(self): + def get_person_column_order(self): + """ + Returns the Person display common information stored in the + database's metadata. + """ default = [(1,1),(1,2),(1,3),(0,4),(1,5),(0,6),(0,7)] if self.metadata == None: return default @@ -935,6 +999,10 @@ class GrampsDbBase: return cols def get_place_column_order(self): + """ + Returns the Place display common information stored in the + database's metadata. + """ default = [(1,1),(1,2),(0,3),(1,4),(0,5),(1,6),(0,7),(0,8)] if self.metadata == None: return default @@ -946,6 +1014,10 @@ class GrampsDbBase: return cols def get_source_column_order(self): + """ + Returns the Source display common information stored in the + database's metadata. + """ default = [(1,1),(1,2),(1,3),(0,4)] if self.metadata == None: return default @@ -957,6 +1029,10 @@ class GrampsDbBase: return cols def get_media_column_order(self): + """ + Returns the MediaObject display common information stored in the + database's metadata. + """ default = [(1,1),(1,2),(1,3)] if self.metadata == None: return default @@ -966,72 +1042,70 @@ class GrampsDbBase: return cols + default[len(cols):] else: return cols -#------------------------------------------------------------------------- -# -# Transaction -# -#------------------------------------------------------------------------- + class Transaction: - + """ + Defines a group of database commits that define a single logical + operation. + """ def __init__(self,msg,db): + """ + Creates a new transaction. A Transaction instance should not be created + directly, but by the GrampsDbBase class or classes derived from + GrampsDbBase. The db parameter is a list-like interface that stores + the commit data. This could be a simple list, or a RECNO-style database + object. + """ self.db = db self.first = None self.last = None def get_description(self): + """ + Returns the text string that describes the logical operation + performed by the Transaction. + """ return self.msg def set_description(self,msg): + """ + Sets the text string that describes the logical operation + performed by the Transaction. + """ self.msg = msg def add(self, type, handle, data): + """ + Adds a commit operation to the Transaction. The type is a constant + that indicates what type of PrimaryObject is being added. The handle + is the object's database handle, and the data is the tuple returned + by the object's serialize method. + """ self.last = self.db.append(cPickle.dumps((type,handle,data),1)) if self.first == None: self.first = self.last def get_recnos(self): + """ + Returns a list of record numbers associated with the transaction. + While the list is an arbitrary index of integers, it can be used + to indicate record numbers for a database. + """ return range (self.first, self.last+1) - def get_record(self,id): - return cPickle.loads(self.db[id]) + def get_record(self,recno): + """ + Returns a tuple representing the PrimaryObject type, database handle + for the PrimaryObject, and a tuple representing the data created by + the object's serialize method. + """ + return cPickle.loads(self.db[recno]) def __len__(self): + """ + Returns the number of commits associated with the Transaction. + """ if self.last and self.first: return self.last - self.first + 1 return 0 - def display(self): - for record in self.get_recnos(): - (key,handle,val) = self.get_record(record) - if key == PERSON_KEY: - if val: - print "PERSON %s change" % handle - else: - print "PERSON %s remove" % handle - elif key == FAMILY_KEY: - if val: - print "FAMILY %s change" % handle - else: - print "FAMILY %s remove" % handle - elif key == EVENT_KEY: - if val: - print "EVENT %s change" % handle - else: - print "EVENT %s remove" % handle - elif key == SOURCE_KEY: - if val: - print "SOURCE %s change" % handle - else: - print "SOURCE %s remove" % handle - elif key == MEDIA_KEY: - if val: - print "MEDIA %s change" % handle - else: - print "MEDIA %s remove" % handle - elif key == PLACE_KEY: - if val: - print "PLACE %s change" % handle - else: - print "PLACE %s remove" % handle - - diff --git a/src/GrampsGEDDB.py b/src/GrampsGEDDB.py index d81b8b1d0..f5a39dbd2 100644 --- a/src/GrampsGEDDB.py +++ b/src/GrampsGEDDB.py @@ -63,16 +63,16 @@ class GrampsGEDDB(GrampsDbBase): writer = WriteGedcom.GedcomWriter(self,self.get_default_person()) writer.export_data(self.filename) - def get_surnames(self): + def get_surname_list(self): a = {} - for person_id in self.get_person_keys(): + for person_id in self.get_person_handles(sort_handles=False): p = self.get_person_from_handle(person_id) a[p.get_primary_name().get_surname()] = 1 vals = a.keys() vals.sort() return vals - def get_eventnames(self): + def get_person_event_type_list(self): names = self.eventnames.keys() a = {} for name in names: @@ -81,20 +81,26 @@ class GrampsGEDDB(GrampsDbBase): vals.sort() return vals - def remove_person_handle(self,handle,transaction): + def remove_person(self,handle,transaction): self.genderStats.uncount_person (self.person_map[handle]) if transaction != None: old_data = self.person_map.get(handle) transaction.add(PERSON_KEY,handle,old_data) del self.person_map[handle] - def remove_source_handle(self,handle,transaction): + def remove_source(self,handle,transaction): if transaction != None: old_data = self.source_map.get(str(handle)) transaction.add(SOURCE_KEY,handle,old_data) del self.source_map[str(handle)] - def remove_event_handle(self,handle,transaction): + def remove_family_handle(self,handle,transaction): + if transaction != None: + old_data = self.family_map.get(str(handle)) + transaction.add(FAMILY_KEY,handle,old_data) + del self.family_map[str(handle)] + + def remove_event(self,handle,transaction): if transaction != None: old_data = self.event_map.get(str(handle)) transaction.add(EVENT_KEY,handle,old_data) diff --git a/src/GrampsXMLDB.py b/src/GrampsXMLDB.py index 090d785b0..caf4b40ca 100644 --- a/src/GrampsXMLDB.py +++ b/src/GrampsXMLDB.py @@ -71,16 +71,16 @@ class GrampsXMLDB(GrampsDbBase): def close(self): WriteXML.quick_write(self,self.filename) - def get_surnames(self): + def get_surname_list(self): a = {} - for person_id in self.get_person_keys(): + for person_id in self.get_person_handles(sort_handles=False): p = self.get_person_from_handle(person_id) a[p.get_primary_name().get_surname()] = 1 vals = a.keys() vals.sort() return vals - def get_eventnames(self): + def get_person_event_type_list(self): names = self.eventnames.keys() a = {} for name in names: @@ -89,20 +89,26 @@ class GrampsXMLDB(GrampsDbBase): vals.sort() return vals - def remove_person_handle(self,handle,transaction): + def remove_person(self,handle,transaction): self.genderStats.uncount_person (self.person_map[handle]) if transaction != None: old_data = self.person_map.get(handle) transaction.add(PERSON_KEY,handle,old_data) del self.person_map[handle] - def remove_source_handle(self,handle,transaction): + def remove_source(self,handle,transaction): if transaction != None: old_data = self.source_map.get(str(handle)) transaction.add(SOURCE_KEY,handle,old_data) del self.source_map[str(handle)] - def remove_event_handle(self,handle,transaction): + def remove_family_handle(self,handle,transaction): + if transaction != None: + old_data = self.family_map.get(str(handle)) + transaction.add(FAMILY_KEY,handle,old_data) + del self.family_map[str(handle)] + + def remove_event(self,handle,transaction): if transaction != None: old_data = self.event_map.get(str(handle)) transaction.add(EVENT_KEY,handle,old_data) diff --git a/src/ImageSelect.py b/src/ImageSelect.py index da1bcfe5a..ad8547135 100644 --- a/src/ImageSelect.py +++ b/src/ImageSelect.py @@ -168,8 +168,8 @@ class ImageSelect: already_imported = None - trans = self.db.start_transaction() - for o_id in self.db.get_object_keys(): + trans = self.db.transaction_begin() + for o_id in self.db.get_media_object_handles(): o = self.db.get_object_from_handle(o_id) if o.get_path() == filename: already_imported = o @@ -194,7 +194,7 @@ class ImageSelect: mobj.set_path(filename) self.db.commit_media_object(mobj,trans) - self.db.add_transaction(trans,'Edit Media Objects') + self.db.transaction_commit(trans,'Edit Media Objects') self.parent.lists_changed = 1 self.load_images() @@ -819,9 +819,9 @@ class LocalMediaProperties: self.parent.lists_changed = 1 self.parent.parent.lists_changed = 1 - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.commit_media_object(self.object,trans) - self.db.add_transaction(trans,_("Edit Media Object")) + self.db.transaction_commit(trans,_("Edit Media Object")) def on_help_clicked(self, obj): """Display the relevant portion of GRAMPS manual""" @@ -1056,25 +1056,25 @@ class GlobalMediaProperties: self.refmodel = ListModel.ListModel(self.change_dialog.get_widget("refinfo"), titles,event_func=self.button_press) any = 0 - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) for o in p.get_media_list(): if o.get_reference_handle() == self.object.get_handle(): self.refmodel.add([_("Person"),p.get_handle(),GrampsCfg.get_nameof()(p)]) any = 1 - for key in self.db.get_family_keys(): + for key in self.db.get_family_handles(): p = self.db.find_family_from_handle(key) for o in p.get_media_list(): if o.get_reference_handle() == self.object.get_handle(): self.refmodel.add([_("Family"),p.get_handle(),Utils.family_name(p,self.db)]) any = 1 - for key in self.db.get_source_keys(): + for key in self.db.get_source_handles(): p = self.db.get_source_from_handle(key) for o in p.get_media_list(): if o.get_reference_handle() == self.object.get_handle(): self.refmodel.add([_("Source"),p.get_handle(),p.get_title()]) any = 1 - for key in self.db.get_place_handle_keys(): + for key in self.db.get_place_handles(): p = self.db.get_place_from_handle(key) for o in p.get_media_list(): if o.get_reference_handle() == self.object.get_handle(): @@ -1111,9 +1111,9 @@ class GlobalMediaProperties: self.object.set_source_reference_list(self.srcreflist) if self.update != None: self.update() - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.commit_media_object(self.object,trans) - self.db.add_transaction(trans,_("Edit Media Object")) + self.db.transaction_commit(trans,_("Edit Media Object")) def on_help_clicked(self, obj): """Display the relevant portion of GRAMPS manual""" @@ -1167,9 +1167,9 @@ class DeleteMediaQuery: self.update = update def query_response(self): - trans = self.db.start_transaction() + trans = self.db.transaction_begin() - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) nl = [] change = 0 @@ -1182,7 +1182,7 @@ class DeleteMediaQuery: p.set_media_list(nl) self.db.commit_person(p,trans) - for fid in self.db.get_family_keys(): + for fid in self.db.get_family_handles(): p = self.db.find_family_from_handle(fid) nl = [] change = 0 @@ -1195,7 +1195,7 @@ class DeleteMediaQuery: p.set_media_list(nl) self.db.commit_family(p,trans) - for key in self.db.get_source_keys(): + for key in self.db.get_source_handles(): sid = self.db.get_source_from_handle(key) nl = [] change = 0 @@ -1208,7 +1208,7 @@ class DeleteMediaQuery: p.set_media_list(nl) self.db.commit_source(p,trans) - for key in self.db.get_place_handle_keys(): + for key in self.db.get_place_handles(): p = self.db.get_place_from_handle(key) nl = [] change = 0 @@ -1222,7 +1222,7 @@ class DeleteMediaQuery: self.db.commit_place(p,trans) self.db.remove_object(self.media.get_handle(),trans) - self.db.add_transaction(trans,_("Remove Media Object")) + self.db.transaction_commit(trans,_("Remove Media Object")) if self.update: self.update() diff --git a/src/Makefile.in b/src/Makefile.in index 9de2b020e..6301cec01 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -154,7 +154,6 @@ gdir_PYTHON = \ Errors.py\ EventEdit.py\ FamilyView.py\ - Find.py\ FontScale.py\ FrenchRepublic.py\ GedcomInfo.py\ diff --git a/src/Marriage.py b/src/Marriage.py index b63d4d884..c5c4fa521 100644 --- a/src/Marriage.py +++ b/src/Marriage.py @@ -89,8 +89,8 @@ class Marriage: else: self.srcreflist = [] - for key in db.get_place_handle_keys(): - p = db.get_place_display(key) + for key in db.get_place_handles(): + p = db.get_place_from_handle(key).get_display_info() self.pmap[p[0]] = key self.top = gtk.glade.XML(const.marriageFile,"marriageEditor","gramps") @@ -224,7 +224,7 @@ class Marriage: self.lds_place.child.set_text("") self.seal_stat = 0 - if self.family.get_complete(): + if self.family.get_complete_flag(): self.complete.set_active(1) self.build_seal_menu() @@ -498,7 +498,7 @@ class Marriage: if self.type_field.get_active() != self.family.get_relationship(): changed = 1 - if self.complete.get_active() != self.family.get_complete(): + if self.complete.get_active() != self.family.get_complete_flag(): changed = 1 text = unicode(self.notes_buffer.get_text(self.notes_buffer.get_start_iter(), @@ -561,7 +561,7 @@ class Marriage: def on_close_marriage_editor(self,*obj): - trans = self.db.start_transaction() + trans = self.db.transaction_begin() idval = unicode(self.gid.get_text()) family = self.family @@ -591,8 +591,8 @@ class Marriage: if format != self.family.get_note_format(): self.family.set_note_format(format) - if self.complete.get_active() != self.family.get_complete(): - self.family.set_complete(self.complete.get_active()) + if self.complete.get_active() != self.family.get_complete_flag(): + self.family.set_complete_flag(self.complete.get_active()) date = unicode(self.lds_date.get_text()) temple = unicode(self.lds_temple.child.get_text()) @@ -628,7 +628,7 @@ class Marriage: self.update_lists() self.db.commit_family(self.family,trans) - self.db.add_transaction(trans,_("Edit Marriage")) + self.db.transaction_commit(trans,_("Edit Marriage")) self.update_fv(self.family) self.close(1) diff --git a/src/MediaView.py b/src/MediaView.py index f767dd5d8..13f1f5523 100644 --- a/src/MediaView.py +++ b/src/MediaView.py @@ -87,10 +87,7 @@ class MediaView: self.topWindow = glade.get_widget("gramps") self.renderer = gtk.CellRendererText() - if const.nosort_tree: - self.model = DisplayModels.MediaModel(self.db) - else: - self.model = gtk.TreeModelSort(DisplayModels.MediaModel(self.db)) + self.model = gtk.TreeModelSort(DisplayModels.MediaModel(self.db)) self.selection = self.list.get_selection() @@ -132,9 +129,8 @@ class MediaView: column = gtk.TreeViewColumn(_('Title'), self.renderer,text=0) column.set_resizable(gtk.TRUE) - if not const.nosort_tree: - column.set_clickable(gtk.TRUE) - column.set_sort_column_id(0) + column.set_clickable(gtk.TRUE) + column.set_sort_column_id(0) column.set_min_width(225) self.list.append_column(column) self.columns = [column] @@ -146,9 +142,8 @@ class MediaView: name = column_names[pair[1]] column = gtk.TreeViewColumn(name, self.renderer, text=pair[1]) column.set_resizable(gtk.TRUE) - if not const.nosort_tree: - column.set_clickable(gtk.TRUE) - column.set_sort_column_id(index) + column.set_clickable(gtk.TRUE) + column.set_sort_column_id(index) column.set_min_width(75) self.columns.append(column) self.list.append_column(column) @@ -161,10 +156,7 @@ class MediaView: def build_tree(self): self.list.set_model(None) - if const.nosort_tree: - self.model = DisplayModels.MediaModel(self.parent.db) - else: - self.model = gtk.TreeModelSort(DisplayModels.MediaModel(self.parent.db)) + self.model = gtk.TreeModelSort(DisplayModels.MediaModel(self.parent.db)) self.list.set_model(self.model) self.selection = self.list.get_selection() @@ -313,28 +305,28 @@ class MediaView: _('_Delete Media Object'), ans.query_response) else: - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.remove_object(mobj.get_handle(),trans) - self.db.add_transaction(trans,_("Remove Media Object")) + self.db.transaction_commit(trans,_("Remove Media Object")) self.build_tree() def is_object_used(self,mobj): - for family_handle in self.db.get_family_keys(): + for family_handle in self.db.get_family_handles(): p = self.db.find_family_from_handle(family_handle) for o in p.get_media_list(): if o.get_reference_handle() == mobj.get_handle(): return 1 - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) for o in p.get_media_list(): if o.get_reference_handle() == mobj.get_handle(): return 1 - for key in self.db.get_source_keys(): + for key in self.db.get_source_handles(): p = self.db.get_source_from_handle(key) for o in p.get_media_list(): if o.get_reference_handle() == mobj.get_handle(): return 1 - for key in self.db.get_place_handle_keys(): + for key in self.db.get_place_handles(): p = self.db.get_place_handle(key) for o in p.get_media_list(): if o.get_reference_handle() == mobj.get_handle(): @@ -376,7 +368,7 @@ class MediaView: photo.set_mime_type(mime) description = os.path.basename(name) photo.set_description(description) - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.add_object(photo,trans) self.load_media() if GrampsCfg.get_media_reference() == 0: @@ -387,7 +379,7 @@ class MediaView: photo.set_path(name) self.db.commit_media_object(photo,trans) - self.db.add_transaction(trans,_("Add Media Object")) + self.db.transaction_commit(trans,_("Add Media Object")) if GrampsCfg.get_media_global(): ImageSelect.GlobalMediaProperties(self.db,photo,self.load_media, @@ -405,7 +397,7 @@ class MediaView: photo.set_mime_type(mime) photo.set_description(d) photo.set_path(tfile) - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.add_object(photo,trans) oref = RelLib.MediaRef() oref.set_reference_handle(photo.get_handle()) @@ -420,7 +412,7 @@ class MediaView: return self.db.commit_media_object(photo,trans) - self.db.add_transaction(trans,_("Add Media Object")) + self.db.transaction_commit(trans,_("Add Media Object")) if GrampsCfg.get_media_global(): ImageSelect.GlobalMediaProperties(self.db,photo,None, diff --git a/src/MergeData.py b/src/MergeData.py index a64d78775..5a449307b 100644 --- a/src/MergeData.py +++ b/src/MergeData.py @@ -315,7 +315,7 @@ class MergePeople: orig_family.remove_child_handle(self.p1) self.p1.remove_parent_family_handle(orig_family) - (source_family,mrel,frel) = self.p2.get_main_parents_family_handleRel() + (source_family,mrel,frel) = self.p2.get_main_parents_family_handle() self.p1.set_main_parent_family_handle(source_family) if source_family: @@ -346,7 +346,7 @@ class MergePeople: self.p1.set_note(old_note + self.p2.get_note()) try: - self.db.remove_person_handle(self.p2.get_handle()) + self.db.remove_person(self.p2.get_handle()) self.db.personMap[self.p1.get_handle()] = self.p1 except: print "%s is not in the person map!" % (GrampsCfg.get_nameof()(self.p2)) @@ -361,7 +361,7 @@ class MergePeople: father = family.get_father_handle() mother = self.p1.get_handle() - for myfamily_handle in self.db.get_family_keys(): + for myfamily_handle in self.db.get_family_handles(): myfamily = self.db.find_family_from_handle(myfamily_handle) if myfamily.get_father_handle() == father and myfamily.get_mother_handle() == mother: return myfamily @@ -887,7 +887,7 @@ class MergePlaces: self.p1.add_alternate_locations(l) # loop through people, changing event references to P2 to P1 - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) for event in [p.get_birth(), p.get_death()] + p.get_event_list(): if event.get_place_handle() == self.p2: diff --git a/src/NameEdit.py b/src/NameEdit.py index d35aa94a3..fabf2deb9 100644 --- a/src/NameEdit.py +++ b/src/NameEdit.py @@ -70,7 +70,7 @@ class NameEditor: self.combo = self.top.get_widget("alt_surname_list") self.surname_field = self.top.get_widget("alt_last") - AutoComp.fill_combo(self.combo,self.parent.db.get_surnames()) + AutoComp.fill_combo(self.combo,self.parent.db.get_surname_list()) self.type_field = self.top.get_widget("name_type") self.note_field = self.top.get_widget("alt_note") diff --git a/src/PedView.py b/src/PedView.py index 408fff5bc..89c460f4e 100644 --- a/src/PedView.py +++ b/src/PedView.py @@ -485,7 +485,7 @@ class PedigreeView: if depth > 5 or person == None: return - (family_handle,m,f) = person.get_main_parents_family_handleRel() + (family_handle,m,f) = person.get_main_parents_family_handle() if family_handle: mrel = (m != "Birth") frel = (f != "Birth") diff --git a/src/PeopleModel.py b/src/PeopleModel.py index fa07fce3c..15ced0c2b 100644 --- a/src/PeopleModel.py +++ b/src/PeopleModel.py @@ -136,7 +136,7 @@ class PeopleModel(gtk.GenericTreeModel): if not self.db.is_open(): return - for person_handle in self.db.get_person_keys(): + for person_handle in self.db.get_person_handles(sort_handles=False): person = self.db.get_person_from_handle(person_handle) surname = unicode(person.get_primary_name().get_surname()) @@ -147,7 +147,7 @@ class PeopleModel(gtk.GenericTreeModel): self.sname_sub[surname] = [person_handle] sval = 0 - name_list = self.db.get_surnames() + name_list = self.db.get_surname_list() for name in name_list: if self.sname_sub.has_key(name): self.top_iter2path[name] = (sval,) @@ -181,7 +181,7 @@ class PeopleModel(gtk.GenericTreeModel): inscol = 0 sval = 0 - name_list = self.db.get_surnames() + name_list = self.db.get_surname_list() for name in name_list: if self.sname_sub.has_key(name): self.top_iter2path[name] = (sval,) diff --git a/src/PeopleView.py b/src/PeopleView.py index fa4aab735..3702a9c6e 100644 --- a/src/PeopleView.py +++ b/src/PeopleView.py @@ -102,7 +102,7 @@ class PeopleView: self.columns = [column] index = 1 - for pair in self.parent.db.get_column_order(): + for pair in self.parent.db.get_person_column_order(): if not pair[0]: continue name = column_names[pair[1]] @@ -210,7 +210,7 @@ class PeopleView: self.person_model.rebuild_data() self.parent.status_text(_('Updating display...')) keys = self.DataFilter.apply(self.parent.db, - self.parent.db.get_person_keys()) + self.parent.db.get_person_handles(sort_handles=False)) self.person_model.reset_visible() for person_handle in keys: self.person_model.set_visible(person_handle,1) diff --git a/src/PlaceView.py b/src/PlaceView.py index 2593117ba..d3b9ed4f7 100644 --- a/src/PlaceView.py +++ b/src/PlaceView.py @@ -186,11 +186,11 @@ class PlaceView: mlist = [] self.selection.selected_foreach(self.blist,mlist) - trans = self.parent.db.start_transaction() + trans = self.parent.db.transaction_begin() for place in mlist: used = 0 - for key in self.parent.db.get_person_keys(): + for key in self.parent.db.get_person_handles(sort_handles=False): p = self.parent.db.get_person_from_handle(key) event_list = [] for e in [p.get_birth_handle(),p.get_death_handle()] + p.get_event_list(): @@ -207,7 +207,7 @@ class PlaceView: if event.get_place_handle() == place.get_handle(): used = 1 - for fid in self.parent.db.get_family_keys(): + for fid in self.parent.db.get_family_handles(): f = self.parent.db.find_family_from_handle(fid) event_list = [] for e in f.get_event_list(): @@ -230,9 +230,9 @@ class PlaceView: _('_Delete Place'), ans.query_response) else: - trans = self.parent.db.start_transaction() + trans = self.parent.db.transaction_begin() self.parent.db.remove_place(place.get_handle(),trans) - self.parent.db.add_transaction(trans,_("Delete Place (%s)") % place.title()) + self.parent.db.transaction_commit(trans,_("Delete Place (%s)") % place.title()) self.build_tree() def on_edit_clicked(self,obj): diff --git a/src/ReadGedcom.py b/src/ReadGedcom.py index 76fe767c1..ebfc9a889 100644 --- a/src/ReadGedcom.py +++ b/src/ReadGedcom.py @@ -389,7 +389,7 @@ class GedcomParser: def parse_gedcom_file(self): - self.trans = self.db.start_transaction() + self.trans = self.db.transaction_begin() t = time.time() self.index = 0 self.fam_count = 0 @@ -410,7 +410,7 @@ class GedcomParser: t = time.time() - t msg = _('Import Complete: %d seconds') % t - self.db.add_transaction(self.trans,_("GEDCOM import")) + self.db.transaction_commit(self.trans,_("GEDCOM import")) if self.window: self.infomsg("\n%s" % msg) @@ -1773,7 +1773,7 @@ class GedcomParser: # new ID is not used if not self.db.has_person_handle(new_key): - self.db.remove_person_handle(pid,self.trans) + self.db.remove_person(pid,self.trans) person.set_handle(new_key) person.set_gramps_id(new_key) self.db.add_person(person,self.trans) @@ -1781,7 +1781,7 @@ class GedcomParser: tp = self.db.get_person_from_handle(new_key,self.trans) # same person, just change it if person == tp: - self.db.remove_person_handle(pid,self.trans) + self.db.remove_person(pid,self.trans) person.set_handle(new_key) person.set_gramps_id(new_key) self.db.add_person(person,self.trans) diff --git a/src/ReadXML.py b/src/ReadXML.py index 2f3217cb2..3c35b0687 100644 --- a/src/ReadXML.py +++ b/src/ReadXML.py @@ -152,7 +152,7 @@ def importData(database, filename, callback=None,cl=0): img_dir = "%s/%s.images" % (db_dir,db_base) first = not os.path.exists(img_dir) - for m_id in database.get_object_keys(): + for m_id in database.get_media_object_handles(): mobject = database.get_object_from_handle(m_id) oldfile = mobject.get_path() if oldfile[0] != '/': @@ -176,28 +176,28 @@ def importData(database, filename, callback=None,cl=0): # def remove_clicked(): # # File is lost => remove all references and the object itself # mobj = database.find_object_from_handle(NewMediaID) -# for fid in database.get_family_keys(): +# for fid in database.get_family_handles(): # p = database.find_family_from_handle(fid) # nl = p.get_media_list() # for o in nl: # if o.get_reference() == mobj: # nl.remove(o) # p.set_media_list(nl) -# for key in database.get_person_keys(): +# for key in database.get_person_handles(sort_handles=False): # p = database.find_person_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == mobj.get_handle(): # nl.remove(o) # p.set_media_list(nl) -# for key in database.get_source_keys(): +# for key in database.get_source_handles(): # p = database.find_source_from_handle(key) # nl = p.get_media_list() # for o in nl: # if o.get_reference_handle() == mobj.get_handle(): # nl.remove(o) # p.set_media_list(nl) -# for key in database.get_place_handle_keys(): +# for key in database.get_place_handles(): # p = database.find_place_from_handle(key) # nl = p.get_media_list() # for o in nl: @@ -429,13 +429,13 @@ class GrampsParser: def map_gid(self,id): if not self.idswap.get(id): if self.db.id_trans.get(str(id)): - self.idswap[id] = self.db.find_next_gramps_id() + self.idswap[id] = self.db.find_next_person_gramps_id() else: self.idswap[id] = id return self.idswap[id] def parse(self,file): - self.trans = self.db.start_transaction() + self.trans = self.db.transaction_begin() p = xml.parsers.expat.ParserCreate() p.StartElementHandler = self.startElement p.EndElementHandler = self.endElement @@ -454,7 +454,7 @@ class GrampsParser: del self.func_map del self.func_list del p - self.db.add_transaction(self.trans,_("GRAMPS XML import")) + self.db.transaction_commit(self.trans,_("GRAMPS XML import")) def start_lds_ord(self,attrs): type = attrs['type'] @@ -590,9 +590,9 @@ class GrampsParser: self.person = self.find_person_by_gramps_id(new_id) if attrs.has_key("complete"): - self.person.set_complete(int(attrs['complete'])) + self.person.set_complete_flag(int(attrs['complete'])) else: - self.person.set_complete(0) + self.person.set_complete_flag(0) def start_people(self,attrs): if attrs.has_key("default"): @@ -641,9 +641,9 @@ class GrampsParser: self.family.set_relationship(_FAMILY_TRANS.get(attrs["type"], const.FAMILY_UNKNOWN)) if attrs.has_key("complete"): - self.family.set_complete(int(attrs['complete'])) + self.family.set_complete_flag(int(attrs['complete'])) else: - self.family.set_complete(0) + self.family.set_complete_flag(0) def start_childof(self,attrs): family = self.db.find_family_from_handle(attrs["ref"],self.trans) diff --git a/src/RelLib.py b/src/RelLib.py index 02fde0e3e..ec3b4a368 100644 --- a/src/RelLib.py +++ b/src/RelLib.py @@ -1,4 +1,4 @@ -# + # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2004 Donald N. Allingham @@ -60,41 +60,47 @@ CONF_VERY_LOW = 0 #------------------------------------------------------------------------- # -# Primary Object +# Class definitions # #------------------------------------------------------------------------- class PrimaryObject: + """ + The base class for all primary objects in the database. Primary objects + are the core objects in the database. Each object has a database handle + and a GRAMPS ID value. The database handle is used as the record number + for the database, and the GRAMPS ID is the user visible version. + """ def __init__(self,source=None): + """ + Initialize a PrimaryObject. If source is None, both the ID and handle + are assigned as empty strings. If source is not None, then object + is initialized from values of the source object. + """ if source: self.gramps_id = source.gramps_id self.handle = source.handle else: - self.gramps_id = "" - self.handle = "" + self.gramps_id = None + self.handle = None def set_handle(self,handle): - """Sets the database handle for the place object""" + """Sets the database handle for the primary object""" self.handle = handle def get_handle(self): - """Returns the database handle for the place object""" + """Returns the database handle for the primary object""" return self.handle def set_gramps_id(self,gramps_id): - """Sets the GRAMPS ID for the place object""" + """Sets the GRAMPS ID for the primary object""" self.gramps_id = gramps_id def get_gramps_id(self): - """Returns the GRAMPS ID for the place object""" + """Returns the GRAMPS ID for the primary object""" return self.gramps_id -#------------------------------------------------------------------------- -# -# SourceNote -# -#------------------------------------------------------------------------- class SourceNote: """Base class for storing source references and notes""" @@ -102,16 +108,13 @@ class SourceNote: """Create a new SourceNote, copying from source if not None""" self.source_list = [] + self.note = None if source: for sref in source.source_list: self.source_list.append(SourceRef(sref)) if source.note: self.note = Note(source.note.get()) - else: - self.note = None - else: - self.note = None def add_source_reference(self,handle) : """Set the source reference""" @@ -162,126 +165,6 @@ class SourceNote: """Creates a unique instance of the current note""" self.note = Note(self.note.get()) -#------------------------------------------------------------------------- -# -# LdsOrd -# -#------------------------------------------------------------------------- -class LdsOrd(SourceNote): - """LDS Ordinance support""" - def __init__(self,source=None): - """Creates a LDS Ordinance instance""" - SourceNote.__init__(self,source) - if source: - self.famc = source.famc - self.date = Date(source.date) - self.temple = source.temple - self.status = source.status - self.place = source.place - else: - self.famc = None - self.date = None - self.temple = "" - self.status = 0 - self.place = None - - def get_place_name(self): - """returns the title of the Place associated with the Ordinance""" - if self.place: - return self.place.get_title() - else: - return "" - - def set_place_handle(self,place): - """sets the Place instance of the Event""" - self.place = place - - def get_place_handle(self): - """returns the Place instance of the Event""" - return self.place - - def set_family_handle(self,family): - """Sets the family associated with the LDS ordinance""" - self.famc = family - - def get_family_handle(self): - """Gets the family associated with the LDS ordinance""" - return self.famc - - def set_status(self,val): - """Sets the status of the LDS ordinance""" - self.status = val - - def get_status(self): - """Gets the status of the LDS ordinance""" - return self.status - - def set_date(self, date) : - """attempts to sets the date of the LdsOrd instance""" - if not self.date: - self.date = Date() - self.date.set(date) - - def get_date(self) : - """returns a string representation of the date of the LdsOrd instance""" - if self.date: - return self.date.get_date() - return "" - - def get_date_object(self): - """returns the Date object associated with the LdsOrd""" - if not self.date: - self.date = Date() - return self.date - - def set_date_object(self,date): - """sets the Date object associated with the LdsOrd""" - self.date = date - - def set_temple(self,temple): - """Sets the temple assocated with the LDS ordinance""" - self.temple = temple - - def get_temple(self): - """Gets the temple assocated with the LDS ordinance""" - return self.temple - - def is_empty(self): - """Returns 1 if the LDS ordidance is actually empty""" - if (self.famc or - (self.date and not self.date.is_empty()) or - self.temple or - self.status or - self.place): - return 0 - else: - return 1 - - def are_equal(self,other): - """returns 1 if the specified ordinance is the same as the instance""" - if other == None: - return self.is_empty() - if (self.famc != other.famc or - self.place != other.place or - self.status != other.status or - self.temple != other.temple or - compare_dates(self.get_date_object(),other.get_date_object()) or - len(self.get_source_references()) != len(other.get_source_references())): - return 0 - - index = 0 - olist = other.get_source_references() - for a in self.get_source_references(): - if not a.are_equal(olist[index]): - return 0 - index = index + 1 - return 1 - -#------------------------------------------------------------------------- -# -# DataObj -# -#------------------------------------------------------------------------- class DataObj(SourceNote): """Base class for data elements, providing source, note, and privacy data""" @@ -302,11 +185,821 @@ class DataObj(SourceNote): """Returns the privacy level of the data""" return self.private -#------------------------------------------------------------------------- -# -# Place -# -#------------------------------------------------------------------------- +class Person(PrimaryObject,SourceNote): + """ + GRAMPS Person record. Represents an individual person. Contains all + information about the person, including names, events, attributes, + and other information. + """ + + unknown = 2 + male = 1 + female = 0 + + def __init__(self,handle=""): + """creates a new Person instance""" + PrimaryObject.__init__(self) + SourceNote.__init__(self) + self.primary_name = Name() + self.event_list = [] + self.family_list = [] + self.parent_family_list = [] + self.media_list = [] + self.nickname = "" + self.alternate_names = [] + self.gender = Person.unknown + self.death_handle = None + self.birth_handle = None + self.address_list = [] + self.attribute_list = [] + self.urls = [] + self.lds_bapt = None + self.lds_endow = None + self.lds_seal = None + self.complete = 0 + + # We hold a reference to the GrampsDB so that we can maintain + # its genderStats. It doesn't get set here, but from + # GenderStats.count_person. + self.db = None + + def serialize(self): + """ + Converts the data held in the event to a Python tuple that + represents all the data elements. This method is used to convert + the object into a form that can easily be saved to a database. + + These elements may be primative Python types (string, integers), + complex Python types (lists or tuples, or Python objects. If the + target database cannot handle complex types (such as objectes or + lists), the database is responsible for converting the data into + a form that it can use. + """ + return (self.handle, self.gramps_id, self.gender, + self.primary_name, self.alternate_names, self.nickname, + self.death_handle, self.birth_handle, self.event_list, + self.family_list, self.parent_family_list, + self.media_list, self.address_list, self.attribute_list, + self.urls, self.lds_bapt, self.lds_endow, self.lds_seal, + self.complete, self.source_list, self.note) + + def unserialize(self,data): + """ + Converts the data held in a tuple created by the serialize method + back into the data in an Event structure. + """ + (self.handle, self.gramps_id, self.gender, self.primary_name, + self.alternate_names, self.nickname, self.death_handle, + self.birth_handle, self.event_list, self.family_list, + self.parent_family_list, self.media_list, self.address_list, + self.attribute_list, self.urls, self.lds_bapt, self.lds_endow, + self.lds_seal, self.complete, self.source_list, self.note) = data + + def set_complete_flag(self,val): + """ + Sets or clears the complete flag, which is used to indicate that the + Person's data is considered to be complete. + """ + self.complete = val + + def get_complete_flag(self): + """ + Gets the complete flag, which is used to indicate that the + Person's data is considered to be complete. + """ + return self.complete + + def get_display_info(self): + """ + Returns a list consisting of the information typically used for a display. + The data consists of: Display Name, ID, Gender, Date of Birth, + Date of Death, sort name, etc. + """ + if self.gender == Person.male: + gender = const.male + elif self.gender == Person.female: + gender = const.female + else: + gender = const.unknown + bday = self.birth_handle + dday = self.death_handle + return [ GrampsCfg.get_display_name()(self), self.gramps_id, + gender, bday, dday, self.get_primary_name().get_sort_name(), + bday, dday, GrampsCfg.get_display_surname()(self.primary_name)] + + def set_primary_name(self,name): + """sets the primary name of the Person to the specified + Name instance""" + db = self.db + if db: + db.genderStats.uncount_person (self) + self.primary_name = name + if db: + db.genderStats.count_person (self, db) + + def get_primary_name(self): + """returns the Name instance marked as the Person's primary name""" + return self.primary_name + + def get_alternate_names(self): + """returns the list of alternate Names""" + return self.alternate_names + + def set_alternate_names(self,list): + """changes the list of alternate names to the passed list""" + self.alternate_names = list + + def add_alternate_name(self,name): + """adds an alternate Name instance to the list""" + self.alternate_names.append(name) + + def get_url_list(self): + """returns the list of URL instances""" + return self.urls + + def set_url_list(self,list): + """sets the list of URL instances to list""" + self.urls = list + + def add_url(self,url): + """adds a URL instance to the list""" + self.urls.append(url) + + def set_nick_name(self,name): + """sets the nickname for the Person""" + self.nickname = name + + def get_nick_name(self) : + """returns the nickname for the Person""" + return self.nickname + + def set_gender(self,val) : + """sets the gender of the Person""" + db = self.db + if db: + db.genderStats.uncount_person (self) + self.gender = val + if db: + db.genderStats.count_person (self, db) + + def get_gender(self) : + """returns the gender of the Person""" + return self.gender + + def set_birth_handle(self,event_handle) : + """sets the birth event to the passed event""" + self.birth_handle = event_handle + + def set_death_handle(self,event_handle) : + """sets the death event to the passed event""" + self.death_handle = event_handle + + def get_birth_handle(self) : + """returns the birth event""" + return self.birth_handle + + def get_death_handle(self) : + """returns the death event""" + return self.death_handle + + def add_media_reference(self,media_id): + """adds a MediaObject instance to the image list""" + self.media_list.append(media_id) + + def get_media_list(self): + """returns the list of MediaObjects""" + return self.media_list + + def set_media_list(self,list): + """Sets the list of MediaObject objects""" + self.media_list = list + + def add_event_handle(self,event_handle): + """adds an Event to the event list""" + self.event_list.append(event_handle) + + def get_event_list(self): + """returns the list of Event instances""" + return self.event_list + + def set_event_list(self,elist): + """sets the event list to the passed list""" + self.event_list = elist + + def add_family_handle(self,family_handle): + """adds the specified Family instance to the list of + families/marriages/partnerships in which the person is a + parent or spouse""" + + self.family_list.append(family_handle) + + def set_preferred_family_handle(self,family): + if family in self.family_list: + self.family_list.remove(family) + self.family_list = [family] + self.family_list + + def get_family_handle_list(self) : + """returns the list of Family instances in which the + person is a parent or spouse""" + return self.family_list + + def clear_family_handle_list(self) : + """ + Removes all familyts from the family list. + """ + self.family_list = [] + + def remove_family_handle(self,family): + """removes the specified Family instance from the list + of marriages/partnerships""" + if family in self.family_list: + self.family_list.remove(family) + + def add_address(self,address): + """adds the Address instance to the list of addresses""" + self.address_list.append(address) + + def remove_address(self,address): + """removes the Address instance from the list of addresses""" + if address in self.address_list: + self.address_list.remove(address) + + def get_address_list(self): + """returns the list of addresses""" + return self.address_list + + def set_address_list(self,alist): + """sets the address list to the specified list""" + self.address_list = alist + + def add_attribute(self,attribute): + """adds an Attribute instance to the attribute list""" + self.attribute_list.append(attribute) + + def remove_attribute(self,attribute): + """removes the specified Attribute instance from the attribute list""" + if attribute in self.attribute_list: + self.attribute_list.remove(attribute) + + def get_attribute_list(self): + """returns the attribute list""" + return self.attribute_list + + def set_attribute_list(self,list): + """sets the attribute list to the specified list""" + self.attribute_list = list + + def get_parent_family_handle_list(self): + """returns the list of alternate Family instances, in which the Person + is a child of the family, but not a natural child of both parents""" + return self.parent_family_list + + def add_parent_family_handle(self,family,mrel,frel): + """adds a Family to the alternate family list, indicating the + relationship to the mother (mrel) and the father (frel)""" + self.parent_family_list.append((family,mrel,frel)) + + def clear_parent_family_handle_list(self): + self.parent_family_list = [] + + def remove_parent_family_handle(self,family): + """removes a Family instance from the alternate family list""" + for f in self.parent_family_list[:]: + if f[0] == family: + self.parent_family_list.remove(f) + return f + else: + return None + + def change_parent_family_handle(self,family,mrel,frel): + """removes a Family instance from the alternate family list""" + index = 0 + for f in self.parent_family_list[:]: + if f[0] == family: + self.parent_family_list[index] = (family,mrel,frel) + index += 1 + + def has_family(self,family): + for f in self.parent_family_list: + if f[0] == family: + return f + else: + return None + + def set_main_parent_family_handle(self,family): + """sets the main Family of the Person, the Family in which the + Person is a natural born child""" + f = self.remove_parent_family_handle(family) + if f: + self.parent_family_list = [f] + self.parent_family_list + + def get_main_parents_family_handle(self): + """returns the main Family of the Person, the Family in which the + Person is a natural born child""" + if len(self.parent_family_list) == 0: + return None + else: + return self.parent_family_list[0][0] + + def get_main_parents_family_handle(self): + """returns the main Family of the Person, the Family in which the + Person is a natural born child""" + if len(self.parent_family_list) == 0: + return (None,None,None) + else: + return self.parent_family_list[0] + + def set_lds_baptism(self,ord): + """Sets the LDS Baptism ordinance""" + self.lds_bapt = ord + + def get_lds_baptism(self): + """Gets the LDS Baptism ordinance""" + return self.lds_bapt + + def set_lds_endowment(self,ord): + """Sets the LDS Endowment ordinance""" + self.lds_endow = ord + + def get_lds_endowment(self): + """Gets the LDS Endowment ordinance""" + return self.lds_endow + + def set_lds_sealing(self,ord): + """Sets the LDS Sealing ordinance""" + self.lds_seal = ord + + def get_lds_sealing(self): + """Gets the LDS Sealing ordinance""" + return self.lds_seal + + def probably_alive(self,db): + """Returns true if the person may be alive.""" + if self.death_handle: + return 0 + if self.birth_handle: + birth = db.find_event_from_handle(self.birth_handle) + if birth.get_date() != "": + return not_too_old(birth.get_date_object().get_start_date()) + + # 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.find_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.find_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) + if not not_too_old (d): + return 1 + + if child.death_handle: + child_death = db.find_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): + return 1 + + if descendants_too_old (child, years + min_generation): + return 1 + + if descendants_too_old (self, min_generation): + return 0 + + # What about their parents? + def parents_too_old (person, age_difference): + family_handle = person.get_main_parents_family_handle() + if family_handle: + family = db.find_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.find_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 1 + + if parent.death_handle: + parent_death = db.find_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 1 + + if parents_too_old (self, 0): + return 0 + + # As a last resort, trying seeing if their spouse's age gives + # any clue. + for family_handle in self.get_family_handle_list(): + family = db.find_family_from_handle(family_handle) + for spouse_id in [family.get_father_handle(), family.get_mother_handle()]: + if not spouse_id: + continue + if spouse_id == self.handle: + continue + spouse = db.get_person_from_handle(spouse_id) + if spouse.birth_handle: + spouse_birth = db.find_event_from_handle(spouse.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 0 + + if spouse.death_handle: + spouse_death = db.find_event_from_handle(spouse.death_handle) + if spouse_death.get_date() != "": + d = SingleDate (spouse_birth.get_date_object(). + get_start_date()) + d.set_year (d.get_year() - min_generation) + if not not_too_old (d): + return 0 + + if parents_too_old (spouse, max_age_difference): + return 0 + + return 1 + +class Family(PrimaryObject,SourceNote): + """ + GRAMPS Family record. Represents a family unit, which defines the + relationship between people. This can consist of a single person and + a set of children, or two people with a defined relationship and an + optional set of children. The relationship between people may be either + opposite sex or same sex. + """ + + def __init__(self): + """creates a new Family instance""" + PrimaryObject.__init__(self) + SourceNote.__init__(self) + self.father_handle = None + self.mother_handle = None + self.child_list = [] + self.type = const.FAMILY_MARRIED + self.event_list = [] + self.media_list = [] + self.attribute_list = [] + self.lds_seal = None + self.complete = 0 + + + def serialize(self): + """ + Converts the data held in the event to a Python tuple that + represents all the data elements. This method is used to convert + the object into a form that can easily be saved to a database. + + These elements may be primative Python types (string, integers), + complex Python types (lists or tuples, or Python objects. If the + target database cannot handle complex types (such as objectes or + lists), the database is responsible for converting the data into + a form that it can use. + """ + return (self.handle, self.gramps_id, self.father_handle, self.mother_handle, + self.child_list, self.type, self.event_list, + self.media_list, self.attribute_list, self.lds_seal, + self.complete, self.source_list, self.note) + + def unserialize(self, data): + """ + Converts the data held in a tuple created by the serialize method + back into the data in an Event structure. + """ + (self.handle, self.gramps_id, self.father_handle, self.mother_handle, + self.child_list, self.type, self.event_list, + self.media_list, self.attribute_list, self.lds_seal, + self.complete, self.source_list, self.note) = data + + def set_complete_flag(self,val): + self.complete = val + + def get_complete_flag(self): + return self.complete + + def set_lds_sealing(self,ord): + self.lds_seal = ord + + def get_lds_sealing(self): + return self.lds_seal + + def add_attribute(self,attribute) : + """adds an Attribute instance to the attribute list""" + self.attribute_list.append(attribute) + + def remove_attribute(self,attribute): + """removes the specified Attribute instance from the attribute list""" + if attribute in self.attribute_list: + self.attribute_list.remove(attribute) + + def get_attribute_list(self) : + """returns the attribute list""" + return self.attribute_list + + def set_attribute_list(self,list) : + """sets the attribute list to the specified list""" + self.attribute_list = list + + def set_relationship(self,type): + """assigns a string indicating the relationship between the + father and the mother""" + self.type = type + + def get_relationship(self): + """returns a string indicating the relationship between the + father and the mother""" + return self.type + + def set_father_handle(self,person_handle): + """sets the father of the Family to the specfied Person""" + self.father_handle = person_handle + + def get_father_handle(self): + """returns the father of the Family""" + return self.father_handle + + def set_mother_handle(self,person): + """sets the mother of the Family to the specfied Person""" + self.mother_handle = person + + def get_mother_handle(self): + """returns the mother of the Family""" + return self.mother_handle + + def add_child_handle(self,person): + """adds the specfied Person as a child of the Family, adding it + to the child list""" + if person not in self.child_list: + self.child_list.append(person) + + def remove_child_handle(self,person): + """removes the specified Person from the child list""" + if person in self.child_list: + self.child_list.remove(person) + + def get_child_handle_list(self): + """returns the list of children""" + return self.child_list + + def set_child_handle_list(self, list): + """sets the list of children""" + self.child_list = list[:] + + def add_event_handle(self,event_handle): + """adds an Event to the event list""" + self.event_list.append(event_handle) + + def get_event_list(self) : + """returns the list of Event instances""" + return self.event_list + + def set_event_list(self,list) : + """sets the event list to the passed list""" + self.event_list = list + + def add_media_reference(self,media_id): + """Adds a MediaObject object to the Family instance's image list""" + self.media_list.append(media_id) + + def get_media_list(self): + """Returns the list of MediaObject objects""" + return self.media_list + + def set_media_list(self,list): + """Sets the list of MediaObject objects""" + self.media_list = list + +class Event(PrimaryObject,DataObj): + """ + GRAMPS Event record. A GRAMPS event is some type of action that occurred + at a particular place at a particular time, such as a birth, death, or + marriage. + """ + + NAME = 0 + ID = 1 + + def __init__(self,source=None): + """creates a new Event instance, copying from the source if present""" + + PrimaryObject.__init__(self,source) + DataObj.__init__(self,source) + + if source: + self.place = source.place + self.date = Date(source.date) + self.description = source.description + self.name = source.name + self.cause = source.cause + self.media_list = [MediaRef(media_id) for media_id in source.media_list] + self.witness = source.witness[:] + else: + self.place = u'' + self.date = None + self.description = "" + self.name = "" + self.cause = "" + self.witness = None + self.media_list = [] + + def serialize(self): + """ + Converts the data held in the event to a Python tuple that + represents all the data elements. This method is used to convert + the object into a form that can easily be saved to a database. + + These elements may be primative Python types (string, integers), + complex Python types (lists or tuples, or Python objects. If the + target database cannot handle complex types (such as objectes or + lists), the database is responsible for converting the data into + a form that it can use. + """ + return (self.handle, self.gramps_id, self.name, self.date, + self.description, self.place, self.cause, self.private, + self.source_list, self.note, self.witness, self.media_list) + + def unserialize(self,data): + """ + Converts the data held in a tuple created by the serialize method + back into the data in an Event structure. + """ + (self.handle, self.gramps_id, self.name, self.date, self.description, + self.place, self.cause, self.private, self.source_list, + self.note, self.witness, self.media_list) = data + + def add_media_reference(self,media_id): + """Adds a MediaObject object to the Event object's image list""" + self.media_list.append(media_id) + + def get_media_list(self): + """Returns the list of MediaObject objects""" + return self.media_list + + def set_media_list(self,mlist): + """Sets the list of MediaObject objects""" + self.media_list = mlist + + def get_witness_list(self): + """Returns the list of Witness objects associated with the Event""" + return self.witness + + def set_witness_list(self,list): + """ + Sets the Witness list to a copy of the list passed to the method. + """ + if list: + self.witness = list[:] + else: + self.witness = None + + def add_witness(self,value): + """ + Adds a Witness object to the current witness list. + """ + if self.witness: + self.witness.append(value) + else: + self.witness = [value] + + def is_empty(self): + + date = self.get_date_object() + place = self.get_place_handle() + description = self.description + cause = self.cause + name = self.name + return (not name or name == "Birth" or name == "Death") and \ + date.is_empty() and not place and not description and not cause) + + def set(self,name,date,place,description): + """sets the name, date, place, and description of an Event instance""" + self.name = name + self.place = place + self.description = description + self.set_date(date) + + def are_equal(self,other): + """returns 1 if the specified event is the same as the instance""" + if other == None: + return 0 + if (self.name != other.name or self.place != other.place or + self.description != other.description or self.cause != other.cause or + self.private != other.private or + compare_dates(self.get_date_object(),other.get_date_object()) or + len(self.get_source_references()) != len(other.get_source_references())): + return 0 + + index = 0 + olist = other.get_source_references() + for a in self.get_source_references(): + if not a.are_equal(olist[index]): + return 0 + index = index + 1 + + witness_list = self.get_witness_list() + other_list = other.get_witness_list() + if (not witness_list) and (not other_list): + return 1 + elif not (witness_list and other_list): + return 0 + for a in witness_list: + if a in other_list: + other_list.remove(a) + else: + return 0 + if other_list: + return 0 + + return 1 + + def set_name(self,name): + """sets the name of the Event""" + self.name = name + + def get_name(self): + """returns the name of the Event""" + return self.name + + def set_place_handle(self,place): + """sets the Place instance of the Event""" + self.place = place + + def get_place_handle(self): + """returns the Place instance of the Event""" + return self.place + + def set_cause(self,cause): + """sets the cause of the Event""" + self.cause = cause + + def get_cause(self): + """returns the cause of the Event""" + return self.cause + + def set_description(self,description): + """sets the description of the Event instance""" + self.description = description + + def get_description(self) : + """returns the description of the Event instance""" + return self.description + + def set_date(self, date) : + """attempts to sets the date of the Event instance""" + if not self.date: + self.date = Date() + self.date.set(date) + + def get_date(self) : + """returns a string representation of the date of the Event instance""" + if self.date: + return self.date.get_date() + return "" + + def get_preferred_date(self) : + """returns a string representation of the date of the Event instance""" + if self.date: + return self.date.get_date() + return "" + + def get_quote_date(self) : + """returns a string representation of the date of the Event instance, + enclosing the results in quotes if it is not a valid date""" + if self.date: + return self.date.get_quote_date() + return "" + + def get_date_object(self): + """returns the Date object associated with the Event""" + if not self.date: + self.date = Date() + return self.date + + def set_date_object(self,date): + """sets the Date object associated with the Event""" + self.date = date + class Place(PrimaryObject,SourceNote): """Contains information related to a place, including multiple address information (since place names can change with time), longitude, latitude, @@ -342,11 +1035,26 @@ class Place(PrimaryObject,SourceNote): self.media_list = [] def serialize(self): + """ + Converts the data held in the event to a Python tuple that + represents all the data elements. This method is used to convert + the object into a form that can easily be saved to a database. + + These elements may be primative Python types (string, integers), + complex Python types (lists or tuples, or Python objects. If the + target database cannot handle complex types (such as objectes or + lists), the database is responsible for converting the data into + a form that it can use. + """ return (self.handle, self.gramps_id, self.title, self.long, self.lat, self.main_loc, self.alt_loc, self.urls, self.media_list, self.source_list, self.note) def unserialize(self,data): + """ + Converts the data held in a tuple created by the serialize method + back into the data in an Event structure. + """ (self.handle, self.gramps_id, self.title, self.long, self.lat, self.main_loc, self.alt_loc, self.urls, self.media_list, self.source_list, self.note) = data @@ -411,15 +1119,15 @@ class Place(PrimaryObject,SourceNote): self.alt_loc.append(loc) def add_media_reference(self,media_id): - """Adds a Photo object to the place object's image list""" + """Adds a MediaObject object to the place object's image list""" self.media_list.append(media_id) def get_media_list(self): - """Returns the list of Photo objects""" + """Returns the list of MediaObject objects""" return self.media_list def set_media_list(self,list): - """Sets the list of Photo objects""" + """Sets the list of MediaObject objects""" self.media_list = list def get_display_info(self): @@ -440,11 +1148,298 @@ class Place(PrimaryObject,SourceNote): return [self.title,self.gramps_id,'','','','','', self.title.upper(), '','','','',''] -#------------------------------------------------------------------------- -# -# Researcher -# -#------------------------------------------------------------------------- +class MediaObject(PrimaryObject,SourceNote): + """Containter for information about an image file, including location, + description and privacy""" + + def __init__(self,source=None): + """Create a new MediaObject object, copying from the source if provided""" + PrimaryObject.__init__(self,source) + SourceNote.__init__(self,source) + + self.attrlist = [] + if source: + self.path = source.path + self.mime = source.mime + self.desc = source.desc + self.thumb = source.thumb + for attr in source.attrlist: + self.attrlist.append(Attribute(attr)) + else: + self.path = "" + self.mime = "" + self.desc = "" + self.thumb = None + + def serialize(self): + """ + Converts the data held in the event to a Python tuple that + represents all the data elements. This method is used to convert + the object into a form that can easily be saved to a database. + + These elements may be primative Python types (string, integers), + complex Python types (lists or tuples, or Python objects. If the + target database cannot handle complex types (such as objectes or + lists), the database is responsible for converting the data into + a form that it can use. + """ + return (self.handle, self.gramps_id, self.path, self.mime, + self.desc, self.attrlist, self.source_list, self.note) + + def unserialize(self,data): + """ + Converts the data held in a tuple created by the serialize method + back into the data in an Event structure. + """ + (self.handle, self.gramps_id, self.path, self.mime, self.desc, + self.attrlist, self.source_list, self.note) = data + + def set_mime_type(self,type): + self.mime = type + + def get_mime_type(self): + return self.mime + + def set_path(self,path): + """set the file path to the passed path""" + self.path = os.path.normpath(path) + + def get_path(self): + """return the file path""" + return self.path + + def set_description(self,text): + """sets the description of the image""" + self.desc = text + + def get_description(self): + """returns the description of the image""" + return self.desc + + def add_attribute(self,attr): + """Adds a propery to the MediaObject object. This is not used by gramps, + but provides a means for XML users to attach other properties to + the image""" + self.attrlist.append(attr) + + def get_attribute_list(self): + """returns the property list associated with the image""" + return self.attrlist + + def set_attribute_list(self,list): + self.attrlist = list + +class Source(PrimaryObject): + """A record of a source of information""" + + def __init__(self): + """creates a new Source instance""" + PrimaryObject.__init__(self) + self.title = "" + self.author = "" + self.pubinfo = "" + self.note = Note() + self.media_list = [] + self.abbrev = "" + + def serialize(self): + return (self.handle, self.gramps_id, self.title, self.author, + self.pubinfo, self.note, self.media_list, self.abbrev) + + def unserialize(self,data): + """ + Converts the data held in a tuple created by the serialize method + back into the data in an Event structure. + """ + (self.handle, self.gramps_id, self.title, self.author, + self.pubinfo, self.note, self.media_list, self.abbrev) = data + + def get_display_info(self): + return [self.title,self.gramps_id,self.author,self.title.upper(),self.author.upper()] + + def add_media_reference(self,media_id): + """Adds a MediaObject object to the Source instance's image list""" + self.media_list.append(media_id) + + def get_media_list(self): + """Returns the list of MediaObject objects""" + return self.media_list + + def set_media_list(self,list): + """Sets the list of MediaObject objects""" + self.media_list = list + + def set_title(self,title): + """sets the title of the Source""" + self.title = title + + def get_title(self): + """returns the title of the Source""" + return self.title + + def set_note(self,text): + """sets the text of the note attached to the Source""" + self.note.set(text) + + def get_note(self): + """returns the text of the note attached to the Source""" + return self.note.get() + + def set_note_format(self,val): + """Set the note's format to the given value""" + self.note.set_format(val) + + def get_note_format(self): + """Return the current note's format""" + return self.note.get_format() + + def set_note_object(self,obj): + """sets the Note instance attached to the Source""" + self.note = obj + + def get_note_object(self): + """returns the Note instance attached to the Source""" + return self.note + + def unique_note(self): + """Creates a unique instance of the current note""" + self.note = Note(self.note.get()) + + def set_author(self,author): + """sets the author of the Source""" + self.author = author + + def get_author(self): + """returns the author of the Source""" + return self.author + + def set_publication_info(self,text): + """sets the publication information of the Source""" + self.pubinfo = text + + def get_publication_info(self): + """returns the publication information of the Source""" + return self.pubinfo + + def set_abbreviation(self,abbrev): + """sets the title abbreviation of the Source""" + self.abbrev = abbrev + + def get_abbreviation(self): + """returns the title abbreviation of the Source""" + return self.abbrev + +class LdsOrd(SourceNote): + """ + Class that contains information about LDS Ordinances. LDS + ordinances are similar to events, but have very specific additional + information related to data collected by the Church of Jesus Christ + of Latter Day Saints (Morman church). The LDS church is the largest + source of genealogical information in the United States. + """ + def __init__(self,source=None): + """Creates a LDS Ordinance instance""" + SourceNote.__init__(self,source) + if source: + self.famc = source.famc + self.date = Date(source.date) + self.temple = source.temple + self.status = source.status + self.place = source.place + else: + self.famc = None + self.date = None + self.temple = "" + self.status = 0 + self.place = None + + def set_place_handle(self,place): + """sets the Place database handle of the ordinance""" + self.place = place + + def get_place_handle(self): + """returns the Place handle of the ordinance""" + return self.place + + def set_family_handle(self,family): + """Sets the Family database handle associated with the LDS ordinance""" + self.famc = family + + def get_family_handle(self): + """Gets the Family database handle associated with the LDS ordinance""" + return self.famc + + def set_status(self,val): + """ + Sets the status of the LDS ordinance. The status is a text string + that matches a predefined set of strings.""" + self.status = val + + def get_status(self): + """Gets the status of the LDS ordinance""" + return self.status + + def set_date(self, date) : + """attempts to sets the date of the ordinance""" + if not self.date: + self.date = Date() + self.date.set(date) + + def get_date(self) : + """returns a string representation of the date of the ordinance""" + if self.date: + return self.date.get_date() + return "" + + def get_date_object(self): + """returns the Date object associated with the ordinance""" + if not self.date: + self.date = Date() + return self.date + + def set_date_object(self,date): + """sets the Date object associated with the ordinance""" + self.date = date + + def set_temple(self,temple): + """Sets the temple assocated with the ordinance""" + self.temple = temple + + def get_temple(self): + """Gets the temple assocated with the ordinance""" + return self.temple + + def is_empty(self): + """Returns 1 if the ordidance is actually empty""" + if (self.famc or + (self.date and not self.date.is_empty()) or + self.temple or + self.status or + self.place): + return 0 + else: + return 1 + + def are_equal(self,other): + """returns 1 if the specified ordinance is the same as the instance""" + if other == None: + return self.is_empty() + if (self.famc != other.famc or + self.place != other.place or + self.status != other.status or + self.temple != other.temple or + compare_dates(self.get_date_object(),other.get_date_object()) or + len(self.get_source_references()) != len(other.get_source_references())): + return 0 + + index = 0 + olist = other.get_source_references() + for a in self.get_source_references(): + if not a.are_equal(olist[index]): + return 0 + index = index + 1 + return 1 + class Researcher: """Contains the information about the owner of the database""" @@ -510,11 +1505,6 @@ class Researcher: if email: self.email = email.strip() -#------------------------------------------------------------------------- -# -# Location -# -#------------------------------------------------------------------------- class Location: """Provides information about a place, including city, county, state, and country. Multiple Location objects can represent the same place, @@ -600,11 +1590,6 @@ class Location: """returns the country name of the Location object""" return self.country -#------------------------------------------------------------------------- -# -# Note -# -#------------------------------------------------------------------------- class Note: """Provides general text information""" @@ -633,82 +1618,6 @@ class Note: """return the note's format""" return self.format -#------------------------------------------------------------------------- -# -# MediaObject -# -#------------------------------------------------------------------------- -class MediaObject(PrimaryObject,SourceNote): - """Containter for information about an image file, including location, - description and privacy""" - - def __init__(self,source=None): - """Create a new MediaObject object, copying from the source if provided""" - PrimaryObject.__init__(self,source) - SourceNote.__init__(self,source) - - self.attrlist = [] - if source: - self.path = source.path - self.mime = source.mime - self.desc = source.desc - self.thumb = source.thumb - for attr in source.attrlist: - self.attrlist.append(Attribute(attr)) - else: - self.path = "" - self.mime = "" - self.desc = "" - self.thumb = None - - def serialize(self): - return (self.handle, self.gramps_id, self.path, self.mime, - self.desc, self.attrlist, self.source_list, self.note) - - def unserialize(self,data): - (self.handle, self.gramps_id, self.path, self.mime, self.desc, - self.attrlist, self.source_list, self.note) = data - - def set_mime_type(self,type): - self.mime = type - - def get_mime_type(self): - return self.mime - - def set_path(self,path): - """set the file path to the passed path""" - self.path = os.path.normpath(path) - - def get_path(self): - """return the file path""" - return self.path - - def set_description(self,text): - """sets the description of the image""" - self.desc = text - - def get_description(self): - """returns the description of the image""" - return self.desc - - def add_attribute(self,attr): - """Adds a propery to the MediaObject object. This is not used by gramps, - but provides a means for XML users to attach other properties to - the image""" - self.attrlist.append(attr) - - def get_attribute_list(self): - """returns the property list associated with the image""" - return self.attrlist - - def set_attribute_list(self,list): - self.attrlist = list - -#------------------------------------------------------------------------- -# -# MediaRef -# -#------------------------------------------------------------------------- class MediaRef(SourceNote): """Media reference class""" def __init__(self,source=None): @@ -755,11 +1664,6 @@ class MediaRef(SourceNote): """sets the property list associated with the image""" self.attrlist = list -#------------------------------------------------------------------------- -# -# Attribute -# -#------------------------------------------------------------------------- class Attribute(DataObj): """Provides a simple key/value pair for describing properties. Used by the Person and Family objects to store descriptive information.""" @@ -791,11 +1695,6 @@ class Attribute(DataObj): """returns the value of the Attribute instance""" return self.value -#------------------------------------------------------------------------- -# -# Address -# -#------------------------------------------------------------------------- class Address(DataObj): """Provides address information for a person""" @@ -892,11 +1791,6 @@ class Address(DataObj): """returns the postal code of the Address""" return self.postal -#------------------------------------------------------------------------- -# -# Name -# -#------------------------------------------------------------------------- class Name(DataObj): """Provides name information about a person. A person may have more that one name throughout his or her life.""" @@ -1071,11 +1965,6 @@ class Name(DataObj): index = index + 1 return 1 -#------------------------------------------------------------------------- -# -# Url -# -#------------------------------------------------------------------------- class Url: """Contains information related to internet Uniform Resource Locators, allowing gramps to store information about internet resources""" @@ -1125,688 +2014,15 @@ class Url: return 0 return 1 -#------------------------------------------------------------------------- -# -# Person -# -#------------------------------------------------------------------------- -class Person(PrimaryObject,SourceNote): - """Represents an individual person in the gramps database""" - - unknown = 2 - male = 1 - female = 0 - - def __init__(self,handle=""): - """creates a new Person instance""" - PrimaryObject.__init__(self) - SourceNote.__init__(self) - self.primary_name = Name() - self.event_list = [] - self.family_list = [] - self.parent_family_list = [] - self.media_list = [] - self.nickname = "" - self.alternate_names = [] - self.gender = 2 - self.death_handle = None - self.birth_handle = None - self.address_list = [] - self.attribute_list = [] - self.urls = [] - self.ancestor = None - self.lds_bapt = None - self.lds_endow = None - self.lds_seal = None - self.complete = 0 - - # We hold a reference to the GrampsDB so that we can maintain - # its genderStats. It doesn't get set here, but from - # GenderStats.count_person. - self.db = None - - def serialize(self): - return (self.handle, self.gramps_id, self.gender, - self.primary_name, self.alternate_names, self.nickname, - self.death_handle, self.birth_handle, self.event_list, - self.family_list, self.parent_family_list, - self.media_list, - self.address_list, - self.attribute_list, - self.urls, - self.lds_bapt, self.lds_endow, self.lds_seal, - self.complete, - self.source_list, - self.note) - - def unserialize(self,data): - (self.handle, self.gramps_id, self.gender, - self.primary_name, self.alternate_names, self.nickname, - self.death_handle, self.birth_handle, self.event_list, - self.family_list, self.parent_family_list, - self.media_list, - self.address_list, - self.attribute_list, - self.urls, - self.lds_bapt, self.lds_endow, self.lds_seal, - self.complete, self.source_list, self.note) = data - - def set_complete(self,val): - self.complete = val - - def get_complete(self): - return self.complete - - def get_display_info(self): - if self.gender == Person.male: - gender = const.male - elif self.gender == Person.female: - gender = const.female - else: - gender = const.unknown - bday = self.birth_handle - dday = self.death_handle - return [ GrampsCfg.get_display_name()(self), - self.gramps_id, - gender, - bday, - dday, - self.get_primary_name().get_sort_name(), - bday, dday, - GrampsCfg.get_display_surname()(self.primary_name)] - - def set_primary_name(self,name): - """sets the primary name of the Person to the specified - Name instance""" - db = self.db - if db: - db.genderStats.uncount_person (self) - - self.primary_name = name - - if db: - db.genderStats.count_person (self, db) - - def get_primary_name(self): - """returns the Name instance marked as the Person's primary name""" - if not self.primary_name: - self.primary_name = Name() - return self.primary_name - - def get_alternate_names(self): - """returns the list of alternate Names""" - return self.alternate_names - - def set_alternate_names(self,list): - """changes the list of alternate names to the passed list""" - self.alternate_names = list - - def add_alternate_name(self,name): - """adds an alternate Name instance to the list""" - self.alternate_names.append(name) - - def get_url_list(self): - """returns the list of URL instances""" - return self.urls - - def set_url_list(self,list): - """sets the list of URL instances to list""" - self.urls = list - - def add_url(self,url): - """adds a URL instance to the list""" - self.urls.append(url) - - def set_nick_name(self,name): - """sets the nickname for the Person""" - self.nickname = name - - def get_nick_name(self) : - """returns the nickname for the Person""" - return self.nickname - - def set_gender(self,val) : - """sets the gender of the Person""" - db = self.db - if db: - db.genderStats.uncount_person (self) - - self.gender = val - - if db: - db.genderStats.count_person (self, db) - - def get_gender(self) : - """returns the gender of the Person""" - return self.gender - - def set_birth_handle(self,event_handle) : - """sets the birth event to the passed event""" - self.birth_handle = event_handle - - def set_death_handle(self,event_handle) : - """sets the death event to the passed event""" - self.death_handle = event_handle - - def get_birth_handle(self) : - """returns the birth event""" - return self.birth_handle - - def get_death_handle(self) : - """returns the death event""" - return self.death_handle - - def add_media_reference(self,media_id): - """adds a MediaObject instance to the image list""" - self.media_list.append(media_id) - - def get_media_list(self): - """returns the list of MediaObjects""" - return self.media_list - - def set_media_list(self,list): - """Sets the list of MediaObject objects""" - self.media_list = list - - def add_event_handle(self,event_handle): - """adds an Event to the event list""" - self.event_list.append(event_handle) - - def get_event_list(self): - """returns the list of Event instances""" - return self.event_list - - def set_event_list(self,elist): - """sets the event list to the passed list""" - self.event_list = elist - - def add_family_handle(self,family_handle): - """adds the specified Family instance to the list of - families/marriages/partnerships in which the person is a - parent or spouse""" - - self.family_list.append(family_handle) - - def set_preferred_family_handle(self,family): - if family in self.family_list: - self.family_list.remove(family) - self.family_list = [family] + self.family_list - - def get_family_handle_list(self) : - """returns the list of Family instances in which the - person is a parent or spouse""" - return self.family_list - - def clear_family_handle_list(self) : - self.family_list = [] - - def remove_family_handle(self,family): - """removes the specified Family instance from the list - of marriages/partnerships""" - if family in self.family_list: - self.family_list.remove(family) - - def add_address(self,address): - """adds the Address instance to the list of addresses""" - self.address_list.append(address) - - def remove_address(self,address): - """removes the Address instance from the list of addresses""" - if address in self.address_list: - self.address_list.remove(address) - - def get_address_list(self): - """returns the list of addresses""" - return self.address_list - - def set_address_list(self,alist): - """sets the address list to the specified list""" - self.address_list = alist - - def add_attribute(self,attribute): - """adds an Attribute instance to the attribute list""" - self.attribute_list.append(attribute) - - def remove_attribute(self,attribute): - """removes the specified Attribute instance from the attribute list""" - if attribute in self.attribute_list: - self.attribute_list.remove(attribute) - - def get_attribute_list(self): - """returns the attribute list""" - return self.attribute_list - - def set_attribute_list(self,list): - """sets the attribute list to the specified list""" - self.attribute_list = list - - def get_parent_family_handle_list(self): - """returns the list of alternate Family instances, in which the Person - is a child of the family, but not a natural child of both parents""" - return self.parent_family_list - - def add_parent_family_handle(self,family,mrel,frel): - """adds a Family to the alternate family list, indicating the - relationship to the mother (mrel) and the father (frel)""" - self.parent_family_list.append((family,mrel,frel)) - - def clear_parent_family_handle_list(self): - self.parent_family_list = [] - - def remove_parent_family_handle(self,family): - """removes a Family instance from the alternate family list""" - for f in self.parent_family_list[:]: - if f[0] == family: - self.parent_family_list.remove(f) - return f - else: - return None - - def change_parent_family_handle(self,family,mrel,frel): - """removes a Family instance from the alternate family list""" - index = 0 - for f in self.parent_family_list[:]: - if f[0] == family: - self.parent_family_list[index] = (family,mrel,frel) - index += 1 - - def has_family(self,family): - for f in self.parent_family_list: - if f[0] == family: - return f - else: - return None - - def set_main_parent_family_handle(self,family): - """sets the main Family of the Person, the Family in which the - Person is a natural born child""" - f = self.remove_parent_family_handle(family) - if f: - self.parent_family_list = [f] + self.parent_family_list - - def get_main_parents_family_handle(self): - """returns the main Family of the Person, the Family in which the - Person is a natural born child""" - if len(self.parent_family_list) == 0: - return None - else: - return self.parent_family_list[0][0] - - def get_main_parents_family_handleRel(self): - """returns the main Family of the Person, the Family in which the - Person is a natural born child""" - if len(self.parent_family_list) == 0: - return (None,None,None) - else: - return self.parent_family_list[0] - - def set_ancestor(self, value): - """set ancestor flag and recurse""" - self.ancestor = value -# for (fam,m,f) in self.parent_family_list: -# family -# if family.Father: -# # Don't waste time if the ancestor is already flagged. -# # This will happen when cousins marry. -# if not family.Father.get_ancestor(): -# family.Father.set_ancestor(value) -# if family.get_mother_handle(): -# if not family.Mother.get_ancestor(): -# family.Mother.set_ancestor(value) - - def get_ancestor(self): - return self.ancestor - - def set_lds_baptism(self,ord): - self.lds_bapt = ord - - def get_lds_baptism(self): - return self.lds_bapt - - def set_lds_endowment(self,ord): - self.lds_endow = ord - - def get_lds_endowment(self): - return self.lds_endow - - def set_lds_sealing(self,ord): - self.lds_seal = ord - - def get_lds_sealing(self): - return self.lds_seal - - def probably_alive(self,db): - """Returns true if the person may be alive.""" - if self.death_handle: - return 0 - if self.birth_handle: - birth = db.find_event_from_handle(self.birth_handle) - if birth.get_date() != "": - return not_too_old(birth.get_date_object().get_start_date()) - - # 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.find_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.find_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) - if not not_too_old (d): - return 1 - - if child.death_handle: - child_death = db.find_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): - return 1 - - if descendants_too_old (child, years + min_generation): - return 1 - - if descendants_too_old (self, min_generation): - return 0 - - # What about their parents? - def parents_too_old (person, age_difference): - family_handle = person.get_main_parents_family_handle() - if family_handle: - family = db.find_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.find_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 1 - - if parent.death_handle: - parent_death = db.find_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 1 - - if parents_too_old (self, 0): - return 0 - - # As a last resort, trying seeing if their spouse's age gives - # any clue. - for family_handle in self.get_family_handle_list(): - family = db.find_family_from_handle(family_handle) - for spouse_id in [family.get_father_handle(), family.get_mother_handle()]: - if not spouse_id: - continue - if spouse_id == self.handle: - continue - spouse = db.get_person_from_handle(spouse_id) - if spouse.birth_handle: - spouse_birth = db.find_event_from_handle(spouse.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 0 - - if spouse.death_handle: - spouse_death = db.find_event_from_handle(spouse.death_handle) - if spouse_death.get_date() != "": - d = SingleDate (spouse_birth.get_date_object(). - get_start_date()) - d.set_year (d.get_year() - min_generation) - if not not_too_old (d): - return 0 - - if parents_too_old (spouse, max_age_difference): - return 0 - - return 1 - -#------------------------------------------------------------------------- -# -# Event -# -#------------------------------------------------------------------------- -class Event(PrimaryObject,DataObj): - """Event record, recording the event type, description, place, and date - of a particular event""" - - NAME = 0 - ID = 1 - - def __init__(self,source=None): - """creates a new Event instance, copying from the source if present""" - - PrimaryObject.__init__(self,source) - DataObj.__init__(self,source) - - if source: - self.place = source.place - self.date = Date(source.date) - self.description = source.description - self.name = source.name - self.cause = source.cause - self.media_list = [MediaRef(media_id) for media_id in source.media_list] - try: - if source.witness: - self.witness = source.witness[:] - else: - self.witness = None - except: - self.witness = None - else: - self.place = u'' - self.date = None - self.description = "" - self.name = "" - self.cause = "" - self.witness = None - self.media_list = [] - - def clone(self,source): - self.place = source.place - self.date = Date(source.date) - self.description = source.description - self.name = source.name - self.cause = source.cause - self.handle = source.handle - self.gramps_id = source.gramps_id - self.private = source.private - self.source_list = source.source_list[:] - self.note = source.note - self.media_list = [MediaRef(media_id) for media_id in source.media_list] - try: - if source.witness: - self.witness = source.witness[:] - else: - self.witness = None - except: - self.witness = None - - def serialize(self): - return (self.handle, self.gramps_id, self.name, self.date, self.description, - self.place, self.cause, self.private, self.source_list, - self.note, self.witness, self.media_list) - - def unserialize(self,data): - (self.handle, self.gramps_id, self.name, self.date, self.description, - self.place, self.cause, self.private, self.source_list, - self.note, self.witness, self.media_list) = data - - def add_media_reference(self,media_id): - """Adds a Photo object to the Event object's image list""" - self.media_list.append(media_id) - - def get_media_list(self): - """Returns the list of Photo objects""" - return self.media_list - - def set_media_list(self,mlist): - """Sets the list of Photo objects""" - self.media_list = mlist - - def get_witness_list(self): - return self.witness - - def set_witness_list(self,list): - if list: - self.witness = list[:] - else: - self.witness = None - - def add_witness(self,value): - if self.witness: - self.witness.append(value) - else: - self.witness = [value] - - def is_empty(self): - date = self.get_date_object() - place = self.get_place_handle() - description = self.description - cause = self.cause - name = self.name - if (not name or name == "Birth" or name == "Death") and \ - date.is_empty() and not place and not description and not cause: - return 1 - else: - return 0 - - def set(self,name,date,place,description): - """sets the name, date, place, and description of an Event instance""" - self.name = name - self.place = place - self.description = description - self.set_date(date) - - def are_equal(self,other): - """returns 1 if the specified event is the same as the instance""" - if other == None: - return 0 - if (self.name != other.name or self.place != other.place or - self.description != other.description or self.cause != other.cause or - self.private != other.private or - compare_dates(self.get_date_object(),other.get_date_object()) or - len(self.get_source_references()) != len(other.get_source_references())): - return 0 - - index = 0 - olist = other.get_source_references() - for a in self.get_source_references(): - if not a.are_equal(olist[index]): - return 0 - index = index + 1 - - witness_list = self.get_witness_list() - other_list = other.get_witness_list() - if (not witness_list) and (not other_list): - return 1 - elif not (witness_list and other_list): - return 0 - for a in witness_list: - if a in other_list: - other_list.remove(a) - else: - return 0 - if other_list: - return 0 - - return 1 - - def set_name(self,name): - """sets the name of the Event""" - self.name = name - - def get_name(self): - """returns the name of the Event""" - return self.name - - def set_place_handle(self,place): - """sets the Place instance of the Event""" - self.place = place - - def get_place_handle(self): - """returns the Place instance of the Event""" - return self.place - - def set_cause(self,cause): - """sets the cause of the Event""" - self.cause = cause - - def get_cause(self): - """returns the cause of the Event""" - return self.cause - - def set_description(self,description): - """sets the description of the Event instance""" - self.description = description - - def get_description(self) : - """returns the description of the Event instance""" - return self.description - - def set_date(self, date) : - """attempts to sets the date of the Event instance""" - if not self.date: - self.date = Date() - self.date.set(date) - - def get_date(self) : - """returns a string representation of the date of the Event instance""" - if self.date: - return self.date.get_date() - return "" - - def get_preferred_date(self) : - """returns a string representation of the date of the Event instance""" - if self.date: - return self.date.get_date() - return "" - - def get_quote_date(self) : - """returns a string representation of the date of the Event instance, - enclosing the results in quotes if it is not a valid date""" - if self.date: - return self.date.get_quote_date() - return "" - - def get_date_object(self): - """returns the Date object associated with the Event""" - if not self.date: - self.date = Date() - return self.date - - def set_date_object(self,date): - """sets the Date object associated with the Event""" - self.date = date - -#------------------------------------------------------------------------- -# -# Witness -# -#------------------------------------------------------------------------- class Witness: + """ + The Witness class is used to represent a person who may or may + not be in the database. If the person is in the database, the + type will be Event.ID, and the value with be the database handle + for the person. If the person is not in the database, the type + will be Event.NAME, and the value will be a string representing + the person's name. + """ def __init__(self,type=Event.NAME,val="",comment=""): self.set_type(type) self.set_value(val) @@ -1830,280 +2046,6 @@ class Witness: def get_comment(self): return self.comment -#------------------------------------------------------------------------- -# -# Family -# -#------------------------------------------------------------------------- -class Family(PrimaryObject,SourceNote): - """Represents a family unit in the gramps database""" - - def __init__(self): - """creates a new Family instance""" - PrimaryObject.__init__(self) - SourceNote.__init__(self) - self.father_handle = None - self.mother_handle = None - self.child_list = [] - self.type = const.FAMILY_MARRIED - self.event_list = [] - self.media_list = [] - self.attribute_list = [] - self.lds_seal = None - self.complete = 0 - - - def serialize(self): - return (self.handle, self.gramps_id, self.father_handle, self.mother_handle, - self.child_list, self.type, self.event_list, - self.media_list, self.attribute_list, self.lds_seal, - self.complete, self.source_list, self.note) - - def unserialize(self, data): - (self.handle, self.gramps_id, self.father_handle, self.mother_handle, - self.child_list, self.type, self.event_list, - self.media_list, self.attribute_list, self.lds_seal, - self.complete, self.source_list, self.note) = data - - def set_complete(self,val): - self.complete = val - - def get_complete(self): - return self.complete - - def set_lds_sealing(self,ord): - self.lds_seal = ord - - def get_lds_sealing(self): - return self.lds_seal - - def add_attribute(self,attribute) : - """adds an Attribute instance to the attribute list""" - self.attribute_list.append(attribute) - - def remove_attribute(self,attribute): - """removes the specified Attribute instance from the attribute list""" - if attribute in self.attribute_list: - self.attribute_list.remove(attribute) - - def get_attribute_list(self) : - """returns the attribute list""" - return self.attribute_list - - def set_attribute_list(self,list) : - """sets the attribute list to the specified list""" - self.attribute_list = list - - def set_relationship(self,type): - """assigns a string indicating the relationship between the - father and the mother""" - self.type = type - - def get_relationship(self): - """returns a string indicating the relationship between the - father and the mother""" - return self.type - - def set_father_handle(self,person_handle): - """sets the father of the Family to the specfied Person""" -# update = self.some_child_is_ancestor() -# if update and father_handle: -# father_handle.set_ancestor(0) - self.father_handle = person_handle -# if update and father_handle: -# father_handle.set_ancestor(1) - - def get_father_handle(self): - """returns the father of the Family""" - return self.father_handle - - def set_mother_handle(self,person): - """sets the mother of the Family to the specfied Person""" -# update = self.some_child_is_ancestor() -# if self.mother_handle and update: -# self.mother_handle.set_ancestor(0) - self.mother_handle = person -# if update and self.mother_handle: -# self.mother_handle.set_ancestor(1) - - def get_mother_handle(self): - """returns the mother of the Family""" - return self.mother_handle - - def add_child_handle(self,person): - """adds the specfied Person as a child of the Family, adding it - to the child list""" - if person not in self.child_list: - self.child_list.append(person) -# if person.get_ancestor(): -# if father_handle: -# father_handle.set_ancestor(1) -# if self.mother_handle: -# self.mother_handle.set_ancestor(1) - - def remove_child_handle(self,person): - """removes the specified Person from the child list""" - if person in self.child_list: - self.child_list.remove(person) -# if person.get_ancestor(): -# if father_handle: -# father_handle.set_ancestor(0) -# if self.mother_handle: -# self.mother_handle.set_ancestor(0) - - def get_child_handle_list(self): - """returns the list of children""" - return self.child_list - - def set_child_handle_list(self, list): - """sets the list of children""" - self.child_list = list[:] - -# def get_marriage(self): -# """returns the marriage event of the Family. Obsolete""" -# for e in self.event_list: -# if e.get_name() == "Marriage": -# return e -# return None - - def get_divorce(self): - """returns the divorce event of the Family. Obsolete""" - for e in self.event_list: - if e.get_name() == "Divorce": - return e - return None - - def add_event_handle(self,event_handle): - """adds an Event to the event list""" - self.event_list.append(event_handle) - - def get_event_list(self) : - """returns the list of Event instances""" - return self.event_list - - def set_event_list(self,list) : - """sets the event list to the passed list""" - self.event_list = list - - def add_media_reference(self,media_id): - """Adds a MediaObject object to the Family instance's image list""" - self.media_list.append(media_id) - - def get_media_list(self): - """Returns the list of MediaObject objects""" - return self.media_list - - def set_media_list(self,list): - """Sets the list of MediaObject objects""" - self.media_list = list - - def some_child_is_ancestor(self): - for child in self.child_list: - if (child.get_ancestor()): - return 1 - return None - -#------------------------------------------------------------------------- -# -# Source -# -#------------------------------------------------------------------------- -class Source(PrimaryObject): - """A record of a source of information""" - - def __init__(self): - """creates a new Source instance""" - PrimaryObject.__init__(self) - self.title = "" - self.author = "" - self.pubinfo = "" - self.note = Note() - self.media_list = [] - self.abbrev = "" - - def serialize(self): - return (self.handle, self.gramps_id, self.title, self.author, - self.pubinfo, self.note, self.media_list, self.abbrev) - - def unserialize(self,data): - (self.handle, self.gramps_id, self.title, self.author, - self.pubinfo, self.note, self.media_list, self.abbrev) = data - - def get_display_info(self): - return [self.title,self.gramps_id,self.author,self.title.upper(),self.author.upper()] - - def add_media_reference(self,media_id): - """Adds a MediaObject object to the Source instance's image list""" - self.media_list.append(media_id) - - def get_media_list(self): - """Returns the list of MediaObject objects""" - return self.media_list - - def set_media_list(self,list): - """Sets the list of MediaObject objects""" - self.media_list = list - - def set_title(self,title): - """sets the title of the Source""" - self.title = title - - def get_title(self): - """returns the title of the Source""" - return self.title - - def set_note(self,text): - """sets the text of the note attached to the Source""" - self.note.set(text) - - def get_note(self): - """returns the text of the note attached to the Source""" - return self.note.get() - - def set_note_format(self,val): - """Set the note's format to the given value""" - self.note.set_format(val) - - def get_note_format(self): - """Return the current note's format""" - return self.note.get_format() - - def set_note_object(self,obj): - """sets the Note instance attached to the Source""" - self.note = obj - - def get_note_object(self): - """returns the Note instance attached to the Source""" - return self.note - - def unique_note(self): - """Creates a unique instance of the current note""" - self.note = Note(self.note.get()) - - def set_author(self,author): - """sets the author of the Source""" - self.author = author - - def get_author(self): - """returns the author of the Source""" - return self.author - - def set_publication_info(self,text): - """sets the publication information of the Source""" - self.pubinfo = text - - def get_publication_info(self): - """returns the publication information of the Source""" - return self.pubinfo - - def set_abbreviation(self,abbrev): - """sets the title abbreviation of the Source""" - self.abbrev = abbrev - - def get_abbreviation(self): - """returns the title abbreviation of the Source""" - return self.abbrev - class SourceRef: """Source reference, containing detailed information about how a referenced source relates to it""" @@ -2200,12 +2142,12 @@ class SourceRef: """Creates a unique instance of the current note""" self.comments = Note(self.comments.get()) -#------------------------------------------------------------------------- -# -# GenderStats -# -#------------------------------------------------------------------------- class GenderStats: + """ + Class for keeping track of statistics related to Given Name vs. + Gender. This allows the tracking of the liklihood of a person's + given name indicating the gender of the person. + """ def __init__ (self,stats={}): if stats == None: self.stats = {} diff --git a/src/SelectChild.py b/src/SelectChild.py index 6f6f69bd0..121576b44 100644 --- a/src/SelectChild.py +++ b/src/SelectChild.py @@ -195,7 +195,7 @@ class SelectChild: slist[c] = 1 person_list = [] - for key in self.db.sort_person_keys(): + for key in self.db.get_person_handles(sort_handles=True): person = self.db.get_person_from_handle(key) if filter: if slist.has_key(key) or person.get_main_parents_family_handle(): @@ -243,7 +243,7 @@ class SelectChild: iter = None for idval in person_list: - dinfo = self.db.get_person_display(idval) + dinfo = self.db.get_person_from_handle(idval).get_display_info() rdata = [dinfo[0],dinfo[1],dinfo[3],dinfo[5],dinfo[6]] new_iter = self.refmodel.add(rdata) names = dinfo[0].split(',') @@ -282,9 +282,12 @@ class SelectChild: _("A person cannot be linked as his/her own child"), self.top) return + + trans = self.db.transaction_begin() if self.family == None: - self.family = self.db.new_family() + self.family = RelLib.Family() + self.db.add_family(self.family,trans) self.person.add_family_handle(self.family.get_handle()) if self.person.get_gender() == RelLib.Person.male: self.family.set_father_handle(self.person) @@ -313,11 +316,10 @@ class SelectChild: select_child.add_parent_family_handle(self.family.get_handle(),mrel,frel) - trans = self.db.start_transaction() self.db.commit_person(select_child,trans) self.db.commit_family(self.family,trans) n = select_child.get_primary_name().get_regular_name() - self.db.add_transaction(trans,_("Add Child to Family (%s)") % n) + self.db.transaction_commit(trans,_("Add Child to Family (%s)") % n) self.redraw(self.family) self.close(obj) @@ -449,10 +451,10 @@ class EditRel: frel = "Unknown" self.child.change_parent_family_handle(self.family.get_handle(),mrel,frel) - trans = self.db.start_transaction() + trans = self.db.transaction_begin() self.db.commit_person(self.child,trans) n = self.child.get_primary_name().get_regular_name() - self.db.add_transaction(trans,_("Parent Relationships (%s)") % n) + self.db.transaction_commit(trans,_("Parent Relationships (%s)") % n) self.update() self.top.destroy() diff --git a/src/SelectObject.py b/src/SelectObject.py index 370c3d77c..ea4091020 100644 --- a/src/SelectObject.py +++ b/src/SelectObject.py @@ -98,7 +98,7 @@ class SelectObject: self.object_model.clear() self.object_model.new_model() - for key in self.db.get_object_keys(): + for key in self.db.get_media_object_handles(): object = self.db.get_object_from_handle(key) title = object.get_description() the_id = object.get_handle() diff --git a/src/SelectPerson.py b/src/SelectPerson.py index fc9d9ce48..eac773359 100644 --- a/src/SelectPerson.py +++ b/src/SelectPerson.py @@ -115,12 +115,12 @@ class SelectPerson: return - for key in self.db.sort_person_keys(): + for key in self.db.get_person_handles(sort_handles=True): person = self.db.get_person_from_handle(key) if self.use_filter and not self.filter(person): continue - data = self.db.get_person_display(key) + data = self.db.get_person_from_handle(key).get_display_info() gender = person.get_gender() if gender == RelLib.Person.plist: self.mmodel.add([data[0],data[1],data[3],data[5],data[6]],key) diff --git a/src/SourceView.py b/src/SourceView.py index 8440e4481..ed6c5b8bf 100644 --- a/src/SourceView.py +++ b/src/SourceView.py @@ -76,10 +76,7 @@ class SourceView: self.renderer = gtk.CellRendererText() - if const.nosort_tree: - self.model = DisplayModels.SourceModel(self.parent.db) - else: - self.model = gtk.TreeModelSort(DisplayModels.SourceModel(self.parent.db)) + self.model = gtk.TreeModelSort(DisplayModels.SourceModel(self.parent.db)) self.list.set_model(self.model) self.topWindow = self.glade.get_widget("gramps") @@ -92,9 +89,8 @@ class SourceView: column = gtk.TreeViewColumn(_('Title'), self.renderer,text=0) column.set_resizable(gtk.TRUE) - if not const.nosort_tree: - column.set_clickable(gtk.TRUE) - column.set_sort_column_id(0) + column.set_clickable(gtk.TRUE) + column.set_sort_column_id(0) column.set_min_width(225) self.list.append_column(column) self.columns = [column] @@ -106,9 +102,8 @@ class SourceView: name = column_names[pair[1]] column = gtk.TreeViewColumn(name, self.renderer, text=pair[1]) column.set_resizable(gtk.TRUE) - if not const.nosort_tree: - column.set_clickable(gtk.TRUE) - column.set_sort_column_id(index) + column.set_clickable(gtk.TRUE) + column.set_sort_column_id(index) column.set_min_width(75) self.columns.append(column) self.list.append_column(column) @@ -123,10 +118,7 @@ class SourceView: def build_tree(self): self.list.set_model(None) - if const.nosort_tree: - self.model = DisplayModels.SourceModel(self.parent.db) - else: - self.model = gtk.TreeModelSort(DisplayModels.SourceModel(self.parent.db)) + self.model = gtk.TreeModelSort(DisplayModels.SourceModel(self.parent.db)) self.list.set_model(self.model) self.selection = self.list.get_selection() @@ -197,19 +189,19 @@ class SourceView: _('_Delete Source'), ans.query_response,self.topWindow) else: - trans = self.parent.db.start_transaction() - self.parent.db.remove_source_handle(source.get_handle(),trans) + trans = self.parent.db.transaction_begin() + self.parent.db.remove_source(source.get_handle(),trans) n = source.get_title() - self.parent.db.add_transaction(trans,_("Delete Source (%s)") % n) + self.parent.db.transaction_commit(trans,_("Delete Source (%s)") % n) self.build_tree() def is_used(self,source): - for key in self.parent.db.get_place_handle_keys(): + for key in self.parent.db.get_place_handles(): p = self.parent.db.get_place_from_handle(key) for sref in p.get_source_references(): if sref.get_base_handle() == source.get_handle(): return 1 - for key in self.parent.db.get_person_keys(): + for key in self.parent.db.get_person_handles(sort_handles=False): p = self.parent.db.get_person_from_handle(key) for v_id in p.get_event_list() + [p.get_birth_handle(), p.get_death_handle()]: v = self.parent.db.find_event_from_handle(v_id) @@ -229,12 +221,12 @@ class SourceView: for sref in v.get_source_references(): if sref.get_base_handle() == source.get_handle(): return 1 - for p_id in self.parent.db.get_object_keys(): + for p_id in self.parent.db.get_media_object_handles(): p = self.parent.db.get_object_from_handle(p_id) for sref in p.get_source_references(): if sref.get_base_handle() == source.get_handle(): return 1 - for p_id in self.parent.db.get_family_keys(): + for p_id in self.parent.db.get_family_handles(): p = self.parent.db.find_family_from_handle(p_id) for v_id in p.get_event_list(): v = self.parent.db.find_event_from_handle(v_id) diff --git a/src/Sources.py b/src/Sources.py index 2fbc57e0e..774624def 100644 --- a/src/Sources.py +++ b/src/Sources.py @@ -425,7 +425,7 @@ class SourceEditor: self.author_field.set_text("") self.pub_field.set_text("") - keys = self.db.get_source_keys() + keys = self.db.get_source_handles() keys.sort(self.db.sortbysource) sel_child = None diff --git a/src/WriteGedcom.py b/src/WriteGedcom.py index d7ea42500..fd134d98a 100644 --- a/src/WriteGedcom.py +++ b/src/WriteGedcom.py @@ -556,11 +556,11 @@ class GedcomWriter: self.nl = self.option_box.nl if self.option_box.cfilter == None: - for p in self.db.get_person_keys(): + for p in self.db.get_person_handles(sort_handles=False): self.plist[p] = 1 else: try: - for p in self.option_box.cfilter.apply(self.db, self.db.get_person_keys()): + for p in self.option_box.cfilter.apply(self.db, self.db.get_person_handles(sort_handles=False)): self.plist[p] = 1 except Errors.FilterError, msg: (m1,m2) = msg.messages() @@ -582,7 +582,7 @@ class GedcomWriter: self.copy = 0 self.images = 0 - for p in self.db.get_person_keys(): + for p in self.db.get_person_handles(sort_handles=False): self.plist[p] = 1 gedmap = GedcomInfo.GedcomInfoDB() diff --git a/src/WriteXML.py b/src/WriteXML.py index 5f311a7bb..e32a9a0bb 100644 --- a/src/WriteXML.py +++ b/src/WriteXML.py @@ -198,12 +198,12 @@ class XmlWriter: date = string.split(time.ctime(time.time())) owner = self.db.get_researcher() - familyList = self.db.get_family_keys() + familyList = self.db.get_family_handles() person_len = self.db.get_number_of_people() family_len = len(familyList) - source_len = len(self.db.get_source_keys()) - place_len = len(self.db.get_place_handle_keys()) - objList = self.db.get_object_keys() + source_len = len(self.db.get_source_handles()) + place_len = len(self.db.get_place_handles()) + objList = self.db.get_media_object_handles() total = person_len + family_len + place_len + source_len @@ -240,18 +240,14 @@ class XmlWriter: self.g.write(' default="%s"' % person.get_gramps_id()) self.g.write(">\n") - keys = self.db.get_person_keys() + keys = self.db.get_person_handles(sort_handles=False) keys.sort () for key in keys: - try: - person = self.db.get_person_from_handle(key) - except: - print "Key error %s" % key - continue + person = self.db.get_person_from_handle(key) if self.callback and count % delta == 0: self.callback(float(count)/float(total)) - count = count + 1 + count += 1 self.write_id("person",person,2) if person.get_gender() == RelLib.Person.male: @@ -324,7 +320,7 @@ class XmlWriter: self.g.write(" \n") familyList.sort () - for key in self.db.get_family_keys(): + for key in self.db.get_family_handles(): family = self.db.find_family_from_handle(key) if self.callback and count % delta == 0: self.callback(float(count)/float(total)) @@ -354,7 +350,7 @@ class XmlWriter: if source_len > 0: self.g.write(" \n") - keys = self.db.get_source_keys () + keys = self.db.get_source_handles () keys.sort () for key in keys: source = self.db.get_source_from_handle(key) @@ -374,7 +370,7 @@ class XmlWriter: if place_len > 0: self.g.write(" \n") - keys = self.db.get_place_handle_keys() + keys = self.db.get_place_handles() keys.sort () for key in keys: try: @@ -391,7 +387,7 @@ class XmlWriter: if len(objList) > 0: self.g.write(" \n") objList.sort () - for key in self.db.get_object_keys(): + for key in self.db.get_media_object_handles(): object = self.db.get_object_from_handle(key) self.write_object(object) self.g.write(" \n") @@ -536,7 +532,7 @@ class XmlWriter: def write_id(self,label,person,index=1): if person: self.g.write('%s<%s id="%s"' % (" "*index,label,person.get_gramps_id())) - comp = person.get_complete() + comp = person.get_complete_flag() if comp: self.g.write(' complete="1"') self.g.write('>\n') @@ -544,7 +540,7 @@ class XmlWriter: def write_family_handle(self,family,index=1): if family: rel = family.get_relationship() - comp = family.get_complete() + comp = family.get_complete_flag() sp = " " * index self.g.write('%s do nothing, leave as is @@ -1132,7 +1151,7 @@ class Gramps: choose.destroy() #------------------------------------------------------------------------- - for ObjectId in self.db.get_object_keys(): + for ObjectId in self.db.get_media_object_handles(): object = self.db.get_object_from_handle(ObjectId) if 0: oldfile = object.get_path() @@ -1207,12 +1226,12 @@ class Gramps: self.update_display(0) def delete_person_response(self): - trans = self.db.start_transaction() + trans = self.db.transaction_begin() n = self.active_person.get_primary_name().get_regular_name() if self.db.get_default_person() == self.active_person: - self.db.set_default_person(None) + self.db.set_default_person_handle(None) for family_handle in self.active_person.get_family_handle_list(): if not family_handle: @@ -1247,13 +1266,13 @@ class Gramps: id = self.active_person.get_handle() self.people_view.remove_from_person_list(self.active_person) self.people_view.remove_from_history(id) - self.db.remove_person_handle(id, trans) + self.db.remove_person(id, trans) if self.hindex >= 0: self.active_person = self.db.get_person_from_handle(self.history[self.hindex]) else: self.change_active_person(None) - self.db.add_transaction(trans,_("Delete Person (%s)") % n) + self.db.transaction_commit(trans,_("Delete Person (%s)") % n) self.redraw_histmenu() def merge_update(self,p1,p2,old_id): @@ -1516,7 +1535,7 @@ class Gramps: def find_initial_person(self): person = self.db.get_default_person() if not person: - the_ids = self.db.get_person_keys() + the_ids = self.db.get_person_handles(sort_handles=False) if the_ids: the_ids.sort() person = self.db.get_person_from_handle(the_ids[0]) @@ -1533,7 +1552,6 @@ class Gramps: return 0 self.status_text('') - self.db.clear_added_media_objects() return self.post_load(name) def setup_bookmarks(self): @@ -1598,7 +1616,7 @@ class Gramps: self.set_person) def set_person(self): - self.db.set_default_person(self.active_person) + self.db.set_default_person_handle(self.active_person.get_handle()) def export_callback(self,obj,plugin_function): """Call the export plugin, with the active person and database""" diff --git a/src/plugins/ChangeTypes.py b/src/plugins/ChangeTypes.py index 17452ad8d..2f23ad0e3 100644 --- a/src/plugins/ChangeTypes.py +++ b/src/plugins/ChangeTypes.py @@ -54,7 +54,7 @@ class ChangeTypes: def __init__(self,db,person,parent): self.person = person self.db = db - self.trans = db.start_transaction() + self.trans = db.transaction_begin() base = os.path.dirname(__file__) glade_file = "%s/%s" % (base,"changetype.glade") self.glade = gtk.glade.XML(glade_file,"top","gramps") @@ -79,7 +79,7 @@ class ChangeTypes: original = unicode(self.auto1.child.get_text()) new = unicode(self.auto2.child..get_text()) - for person_handle in self.db.get_person_keys(): + for person_handle in self.db.get_person_handles(sort_handles=False): person = self.db.get_person_from_handle(person_handle) for event_handle in person.get_event_list(): if not event_handle: @@ -96,7 +96,7 @@ class ChangeTypes: msg = _("%d event records were modified") % modified OkDialog(_('Change types'),msg) - self.db.add_transaction(self.trans,_('Change types')) + self.db.transaction_commit(self.trans,_('Change types')) Utils.destroy_passed_object(obj) #------------------------------------------------------------------------ diff --git a/src/plugins/Check.py b/src/plugins/Check.py index 5da5acc7d..db4f9d150 100644 --- a/src/plugins/Check.py +++ b/src/plugins/Check.py @@ -58,13 +58,13 @@ from QuestionDialog import OkDialog, MissingMediaDialog def runTool(database,active_person,callback,parent=None): try: - trans = database.start_transaction() + trans = database.transaction_begin() checker = CheckIntegrity(database,parent,trans) checker.check_for_broken_family_links() checker.cleanup_missing_photos(0) checker.check_parent_relationships() checker.cleanup_empty_families(0) - database.add_transaction(trans, _("Check Integrity")) + database.transaction_commit(trans, _("Check Integrity")) errs = checker.build_report(0) if errs: @@ -93,7 +93,7 @@ class CheckIntegrity: def check_for_broken_family_links(self): self.broken_links = [] - for family_handle in self.db.get_family_keys(): + for family_handle in self.db.get_family_handles(): family = self.db.find_family_from_handle(family_handle) father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() @@ -127,7 +127,7 @@ class CheckIntegrity: #------------------------------------------------------------------------- def remove_clicked(): # File is lost => remove all references and the object itself - for person_handle in self.db.get_family_keys(): + for person_handle in self.db.get_family_handles(): p = self.db.get_person_from_handle(person_handle) nl = p.get_media_list() changed = 0 @@ -139,7 +139,7 @@ class CheckIntegrity: p.set_media_list(nl) self.db.commit_person(p,self.trans) - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) nl = p.get_media_list() changed = 0 @@ -151,7 +151,7 @@ class CheckIntegrity: p.set_media_list(nl) self.db.commit_person(p,self.trans) - for key in self.db.get_source_keys(): + for key in self.db.get_source_handles(): p = self.db.get_source_from_handle(key) nl = p.get_media_list() changed = 0 @@ -163,7 +163,7 @@ class CheckIntegrity: p.set_media_list(nl) self.db.commit_source(p,self.trans) - for key in self.db.get_place_handle_keys(): + for key in self.db.get_place_handles(): p = self.db.get_place_handle(key) nl = p.get_media_list() changed = 0 @@ -206,7 +206,7 @@ class CheckIntegrity: #------------------------------------------------------------------------- - for ObjectId in self.db.get_object_keys(): + for ObjectId in self.db.get_media_object_handles(): obj = self.db.get_object_from_handle(ObjectId) photo_name = obj.get_path() if not os.path.isfile(photo_name): @@ -232,21 +232,21 @@ class CheckIntegrity: select_clicked() def cleanup_empty_families(self,automatic): - for family_handle in self.db.get_family_keys(): + for family_handle in self.db.get_family_handles(): family = self.db.find_family_from_handle(family_handle) if not family.get_father_handle() and not family.get_mother_handle(): self.empty_family.append(family_handle) self.delete_empty_family(family_handle) def delete_empty_family(self,family_handle): - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): child = self.db.get_person_from_handle(key) child.remove_parent_family_handle(family_handle) child.remove_family_handle(family_handle) - self.db.delete_family(family_handle,self.trans) + self.db.remove_family_handle(family_handle,self.trans) def check_parent_relationships(self): - for key in self.db.get_family_keys(): + for key in self.db.get_family_handles(): family = self.db.find_family_from_handle(key) mother_handle = family.get_mother_handle() father_handle = family.get_father_handle() diff --git a/src/plugins/DesGraph.py b/src/plugins/DesGraph.py index 59614c99f..a5ee15a30 100644 --- a/src/plugins/DesGraph.py +++ b/src/plugins/DesGraph.py @@ -95,7 +95,7 @@ class DescendantReport: else: self.standalone = 0 - plist = self.database.get_person_keys() + plist = self.database.get_person_handles(sort_handles=False) self.layout = GraphLayout.DescendLine(self.database,plist,person.get_handle()) (self.v,self.e) = self.layout.layout() diff --git a/src/plugins/EventCmp.py b/src/plugins/EventCmp.py index 6a5a8cb5f..a33f6dd9b 100644 --- a/src/plugins/EventCmp.py +++ b/src/plugins/EventCmp.py @@ -206,7 +206,7 @@ class EventComparison: def on_apply_clicked(self,obj): cfilter = self.filter_menu.get_active().get_data("filter") - plist = cfilter.apply(self.db,self.db.get_person_keys()) + plist = cfilter.apply(self.db,self.db.get_person_handles(sort_handles=False)) if len(plist) == 0: WarningDialog(_("No matches were found")) diff --git a/src/plugins/FilterEditor.py b/src/plugins/FilterEditor.py index b54606745..999427f2a 100644 --- a/src/plugins/FilterEditor.py +++ b/src/plugins/FilterEditor.py @@ -355,7 +355,7 @@ class FilterEditor: store,iter = self.clist.get_selected() if iter: filt = self.clist.get_object(iter) - id_list = filt.apply(self.db,self.db.get_person_keys()) + id_list = filt.apply(self.db,self.db.get_person_handles(sort_handles=False)) ShowResults(self,self.db,id_list,filt.get_name()) def delete_filter(self,obj): diff --git a/src/plugins/GraphViz.py b/src/plugins/GraphViz.py index 650f56c9d..e51fd192d 100644 --- a/src/plugins/GraphViz.py +++ b/src/plugins/GraphViz.py @@ -325,7 +325,7 @@ class GraphVizDialog(Report.ReportDialog): file = open(self.target_path,"w") try: - ind_list = self.filter.apply(self.db, self.db.get_person_keys()) + ind_list = self.filter.apply(self.db, self.db.get_person_handles(sort_handles=False)) except Errors.FilterError, msg: from QuestionDialog import ErrorDialog (m1,m2) = msg.messages() diff --git a/src/plugins/IndivComplete.py b/src/plugins/IndivComplete.py index 1a10c0c27..db739741e 100644 --- a/src/plugins/IndivComplete.py +++ b/src/plugins/IndivComplete.py @@ -373,7 +373,7 @@ class IndivComplete(Report.Report): self.d.page_break() #plist = self.database.get_person_handle_map().values() - plist = self.database.get_person_keys() + plist = self.database.get_person_handles(sort_handles=False) if self.filter: ind_list = self.filter.apply(self.database,plist) else: diff --git a/src/plugins/Merge.py b/src/plugins/Merge.py index 796cb2373..adcf9c184 100644 --- a/src/plugins/Merge.py +++ b/src/plugins/Merge.py @@ -85,8 +85,8 @@ class Merge: self.update = callback self.use_soundex = 1 - self.family_list = database.get_family_keys()[:] - self.person_list = database.get_person_keys()[:] + self.family_list = database.get_family_handles()[:] + self.person_list = database.get_person_handles(sort_handles=False)[:] base = os.path.dirname(__file__) self.glade_file = "%s/%s" % (base,"merge.glade") diff --git a/src/plugins/Partition.py b/src/plugins/Partition.py index 9f36f82d3..e20df1a7a 100644 --- a/src/plugins/Partition.py +++ b/src/plugins/Partition.py @@ -185,7 +185,7 @@ def report(db, person): database = RelLib.GrampsDB() work_on_person( database, p ) - person_len = len(database.get_person_keys()) + person_len = len(database.get_person_handles(sort_handles=False)) if person_len > 0: g = WriteXML.XmlWriter(database,None,0,0) g.write(prefix+str(count)+".xml") @@ -194,7 +194,7 @@ def report(db, person): g = WriteXML.XmlWriter(database_for_unlinked_persons,None,0,0) g.write(prefix+".xml") - text += "partition "+prefix+".xml written ( "+str(len(database_for_unlinked_persons.get_person_keys()))+" persons)\n" + text += "partition "+prefix+".xml written ( "+str(len(database_for_unlinked_persons.get_person_handles(sort_handles=False)))+" persons)\n" base = os.path.dirname(__file__) glade_file = "%s/summary.glade" % base diff --git a/src/plugins/PatchNames.py b/src/plugins/PatchNames.py index d630c7490..a0305a47c 100644 --- a/src/plugins/PatchNames.py +++ b/src/plugins/PatchNames.py @@ -81,13 +81,13 @@ class PatchNames: self.cb = callback self.db = db self.parent = parent - self.trans = db.start_transaction() + self.trans = db.transaction_begin() self.win_key = self self.child_windows = {} self.title_list = [] self.nick_list = [] - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): person = self.db.get_person_from_handle(key) first = person.get_primary_name().get_first_name() @@ -221,7 +221,7 @@ class PatchNames: name.set_title(grp[1].strip()) self.db.commit_person(p,self.trans) - self.db.add_transaction(self.trans,_("Extract information from names")) + self.db.transaction_commit(self.trans,_("Extract information from names")) self.close(obj) self.cb(1) diff --git a/src/plugins/RelCalc.py b/src/plugins/RelCalc.py index 1ac06c4cc..1c25da924 100644 --- a/src/plugins/RelCalc.py +++ b/src/plugins/RelCalc.py @@ -93,11 +93,11 @@ class RelCalc: ('',-1,0),('',-1,0)], self.on_apply_clicked) self.clist.new_model() - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) if p == self.person: continue - val = self.db.get_person_display(key) + val = self.db.get_person_from_handle(key).get_display_info() self.clist.add([val[0],val[1],val[3],val[5],val[6]],p.get_handle()) self.clist.connect_model() diff --git a/src/plugins/RelGraph.py b/src/plugins/RelGraph.py index 91da94564..64d6e2039 100644 --- a/src/plugins/RelGraph.py +++ b/src/plugins/RelGraph.py @@ -408,7 +408,7 @@ class RelGraphDialog(Report.ReportDialog): try: self.individual_set =\ - Set(self.filter.apply(self.db, self.db.get_person_keys())) + Set(self.filter.apply(self.db, self.db.get_person_handles(sort_handles=False))) self.individual_set.add(self.person.get_handle()) except Errors.FilterError, msg: from QuestionDialog import ErrorDialog @@ -586,7 +586,7 @@ def _write_graph_record (self): filter = GenericFilter.GenericFilter() filter.add_rule(GenericFilter.IsDescendantOf([self.person.get_handle()])) natural_relatives =\ - Set(filter.apply(self.db, self.db.get_person_keys())) + Set(filter.apply(self.db, self.db.get_person_handles(sort_handles=False))) natural_relatives.add(self.person.get_handle()) else: natural_relatives = self.individual_set diff --git a/src/plugins/SoundGen.py b/src/plugins/SoundGen.py index ef73cbd30..944d59b5a 100644 --- a/src/plugins/SoundGen.py +++ b/src/plugins/SoundGen.py @@ -68,7 +68,7 @@ class SoundGen: self.name.connect('changed',self.on_apply_clicked) names = [] - for person_handle in self.db.get_person_keys(): + for person_handle in self.db.get_person_handles(sort_handles=False): person = self.db.get_person_from_handle(person_handle) lastname = person.get_primary_name().get_surname() if lastname not in names: diff --git a/src/plugins/Summary.py b/src/plugins/Summary.py index d1e52c176..876f968d3 100644 --- a/src/plugins/Summary.py +++ b/src/plugins/Summary.py @@ -55,8 +55,8 @@ from gnome.ui import * #------------------------------------------------------------------------ def build_report(database,person): - personList = database.get_person_keys() - familyList = database.get_family_keys() + personList = database.get_person_handles(sort_handles=False) + familyList = database.get_family_handles() with_photos = 0 total_photos = 0 @@ -69,8 +69,8 @@ def build_report(database,person): namelist = [] notfound = [] - pobjects = len(database.get_object_keys()) - for photo_id in database.get_object_keys(): + pobjects = len(database.get_media_object_handles()) + for photo_id in database.get_media_object_handles(): photo = database.get_object_from_handle(photo_id) try: bytes = bytes + posixpath.getsize(photo.get_path()) diff --git a/src/plugins/TimeLine.py b/src/plugins/TimeLine.py index b2b47fc53..1b3498000 100644 --- a/src/plugins/TimeLine.py +++ b/src/plugins/TimeLine.py @@ -279,7 +279,7 @@ class TimeLine: low = 999999 high = -999999 - self.plist = self.filter.apply(self.db,self.db.get_person_keys()) + self.plist = self.filter.apply(self.db,self.db.get_person_handles(sort_handles=False)) for p_id in self.plist: p = self.db.get_person_from_handle(p_id) @@ -314,7 +314,7 @@ class TimeLine: return (low,high) def name_size(self): - self.plist = self.filter.apply(self.db,self.db.get_person_keys()) + self.plist = self.filter.apply(self.db,self.db.get_person_handles(sort_handles=False)) style_name = self.d.draw_styles['TLG-text'].get_paragraph_style() font = self.d.style_list[style_name].get_font() diff --git a/src/plugins/Verify.py b/src/plugins/Verify.py index f42eafc41..b2381b2c2 100644 --- a/src/plugins/Verify.py +++ b/src/plugins/Verify.py @@ -125,7 +125,7 @@ class Verify: def on_apply_clicked(self,obj): - personList = self.db.get_person_keys() + personList = self.db.get_person_handles(sort_handles=False) oldage = int(self.top.get_widget("oldage").get_text()) hwdif = int(self.top.get_widget("hwdif").get_text()) diff --git a/src/plugins/WebPage.py b/src/plugins/WebPage.py index d165499b1..6b7613479 100644 --- a/src/plugins/WebPage.py +++ b/src/plugins/WebPage.py @@ -1007,7 +1007,7 @@ class WebReport(Report.Report): image_dir_name) return - ind_list = self.filter.apply(self.db,self.db.get_person_keys()) + ind_list = self.filter.apply(self.db,self.db.get_person_handles(sort_handles=False)) self.progress_bar_setup(float(len(ind_list))) doc = HtmlLinkDoc(self.selected_style,None,self.template_name,None) diff --git a/src/plugins/WriteCD.py b/src/plugins/WriteCD.py index 6e9090811..7a09001a9 100644 --- a/src/plugins/WriteCD.py +++ b/src/plugins/WriteCD.py @@ -145,7 +145,7 @@ class PackageWriter: "2 %s " % str(msg)) return - for obj_id in self.db.get_object_keys(): + for obj_id in self.db.get_media_object_handles(): obj = self.db.get_object_from_handle(obj_id) oldfile = obj.get_path() root = os.path.basename(oldfile) @@ -200,7 +200,7 @@ class PackageWriter: #-------------------------------------------------------- def remove_clicked(): # File is lost => remove all references and the object itself - for p_id in self.db.get_family_keys(): + for p_id in self.db.get_family_handles(): p = self.db.find_family_from_handle(p_id) nl = p.get_media_list() for o in nl: @@ -209,7 +209,7 @@ class PackageWriter: p.set_media_list(nl) self.db.commit_family(p,None) - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) nl = p.get_media_list() for o in nl: @@ -217,7 +217,7 @@ class PackageWriter: nl.remove(o) p.set_media_list(nl) self.db.commit_person(p,None) - for key in self.db.get_source_keys(): + for key in self.db.get_source_handles(): p = self.db.get_source_from_handle(key) nl = p.get_media_list() for o in nl: @@ -225,7 +225,7 @@ class PackageWriter: nl.remove(o) p.set_media_list(nl) self.db.commit_source(p,None) - for key in self.db.get_place_handle_keys(): + for key in self.db.get_place_handles(): p = self.db.get_place_from_handle(key) nl = p.get_media_list() for o in nl: @@ -233,7 +233,7 @@ class PackageWriter: nl.remove(o) p.set_media_list(nl) self.db.commit_place(p,None) - for key in self.db.get_event_keys(): + for key in self.db.get_event_handles(): p = self.db.find_event_from_handle(key) nl = p.get_media_list() for o in nl: @@ -272,7 +272,7 @@ class PackageWriter: # Write media files first, since the database may be modified # during the process (i.e. when removing object) - for obj_id in self.db.get_object_keys(): + for obj_id in self.db.get_media_object_handles(): obj = self.db.get_object_from_handle(obj_id) oldfile = obj.get_path() root = os.path.basename(oldfile) diff --git a/src/plugins/WriteFtree.py b/src/plugins/WriteFtree.py index d19dcb441..aa06c06b1 100644 --- a/src/plugins/WriteFtree.py +++ b/src/plugins/WriteFtree.py @@ -149,7 +149,7 @@ class FtreeWriter: def export(self, filename, cfilter, restrict ): if cfilter == None: - for p in self.db.get_person_keys(): + for p in self.db.get_person_handles(sort_handles=False): self.plist[p] = 1 else: try: diff --git a/src/plugins/WritePkg.py b/src/plugins/WritePkg.py index a1f5d5492..d74066ee2 100644 --- a/src/plugins/WritePkg.py +++ b/src/plugins/WritePkg.py @@ -84,7 +84,7 @@ class PackageWriter: #-------------------------------------------------------------- def remove_clicked(): # File is lost => remove all references and the object itself - for p_id in self.db.get_family_keys(): + for p_id in self.db.get_family_handles(): p = self.db.find_family_from_handle(p_id) nl = p.get_media_list() for o in nl: @@ -92,7 +92,7 @@ class PackageWriter: nl.remove(o) p.set_media_list(nl) self.db.commit_family(p,None) - for key in self.db.get_person_keys(): + for key in self.db.get_person_handles(sort_handles=False): p = self.db.get_person_from_handle(key) nl = p.get_media_list() for o in nl: @@ -100,7 +100,7 @@ class PackageWriter: nl.remove(o) p.set_media_list(nl) self.db.commit_person(p,None) - for key in self.db.get_source_keys(): + for key in self.db.get_source_handles(): p = self.db.get_source_from_handle(key) nl = p.get_media_list() for o in nl: @@ -108,7 +108,7 @@ class PackageWriter: nl.remove(o) p.set_media_list(nl) self.db.commit_source(p,None) - for key in self.db.get_place_handle_keys(): + for key in self.db.get_place_handles(): p = self.db.get_place_from_handle(key) nl = p.get_media_list() for o in nl: @@ -116,7 +116,7 @@ class PackageWriter: nl.remove(o) p.set_media_list(nl) self.db.commit_place(p,None) - for key in self.db.get_event_keys(): + for key in self.db.get_event_handles(): p = self.db.find_event_from_handle(key) nl = p.get_media_list() for o in nl: @@ -156,7 +156,7 @@ class PackageWriter: # Write media files first, since the database may be modified # during the process (i.e. when removing object) - for m_id in self.db.get_object_keys(): + for m_id in self.db.get_media_object_handles(): mobject = self.db.get_object_from_handle(m_id) oldfile = mobject.get_path() base = os.path.basename(oldfile)