diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 780c1b7b2..3960513a4 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,7 @@ +2004-08-10 Don Allingham + * src/RelLib.py: rework of the API + * src/*.py: rework of the api + 2004-08-06 Don Allingham * various: change try_to_find_*_from_handle to get_*_from_handle diff --git a/gramps2/gramps-mdk.spec b/gramps2/gramps-mdk.spec index 9480296a8..3393d73fa 100644 --- a/gramps2/gramps-mdk.spec +++ b/gramps2/gramps-mdk.spec @@ -1,5 +1,5 @@ %define ver 1.1.1 -%define rel 0.CVS20040730 +%define rel 0.CVS20040806 %define prefix /usr %define localstatedir /var/lib # Ensure that internal RPM macros for configure & makeinstall diff --git a/gramps2/gramps.spec b/gramps2/gramps.spec index ea3df2b27..9162d78d8 100644 --- a/gramps2/gramps.spec +++ b/gramps2/gramps.spec @@ -1,5 +1,5 @@ %define ver 1.1.1 -%define rel 0.CVS20040730 +%define rel 0.CVS20040806 %define prefix /usr %define localstatedir /var/lib # Ensure that internal RPM macros for configure & makeinstall diff --git a/gramps2/src/AddSpouse.py b/gramps2/src/AddSpouse.py index b983945c0..51f928818 100644 --- a/gramps2/src/AddSpouse.py +++ b/gramps2/src/AddSpouse.py @@ -213,17 +213,12 @@ class AddSpouse: """ person = epo.person trans = self.db.start_transaction() - id = person.get_handle() - if id == "": - id = self.db.add_person(person,trans) - else: - self.db.add_person_no_map(person,id,trans) + handle = self.db.add_person(person,trans) - person = self.db.get_person_from_handle(id) n = person.get_primary_name().get_name() self.db.add_transaction(trans,_('Add Person (%s)' % n)) self.addperson(person) - self.update_data(id) + self.update_data(handle) self.slist = PeopleModel.PeopleModel(self.db) self.slist.rebuild_data() diff --git a/gramps2/src/AutoComp.py b/gramps2/src/AutoComp.py index eb9212664..284f32b55 100644 --- a/gramps2/src/AutoComp.py +++ b/gramps2/src/AutoComp.py @@ -55,7 +55,6 @@ def fill_entry(entry,data_list): entry.set_completion(completion) def fill_option_text(combobox,data): - typelist = [] store = gtk.ListStore(gobject.TYPE_STRING) cell = gtk.CellRendererText() combobox.pack_start(cell,gtk.TRUE) diff --git a/gramps2/src/Calendar.py b/gramps2/src/Calendar.py index a56937baa..10ca647d2 100644 --- a/gramps2/src/Calendar.py +++ b/gramps2/src/Calendar.py @@ -68,7 +68,6 @@ fmt7 = re.compile(_start+r"([?\d]+)\s*[./-]\s*([?\d]+)\s*$", re.IGNORECASE) fmt4 = re.compile(_start+"(\S+)\s+(\d+)\s*$", re.IGNORECASE) fmt5 = re.compile(_start+"(\d+)\s*$", re.IGNORECASE) - #------------------------------------------------------------------------- # # diff --git a/gramps2/src/ChooseParents.py b/gramps2/src/ChooseParents.py index 11bc547b7..764ff847c 100644 --- a/gramps2/src/ChooseParents.py +++ b/gramps2/src/ChooseParents.py @@ -306,7 +306,7 @@ class ChooseParents: fam = self.db.find_family_from_handle(family_handle) for handle in [fam.get_father_handle(), fam.get_mother_handle()] + \ fam.get_child_handle_list(): - if id: + if handle: self.exclude[handle] = 1 def redrawf(self): @@ -569,28 +569,23 @@ class ChooseParents: depending on the gender of the person.""" person = epo.person - id = person.get_handle() + handle = person.get_handle() name = person.get_primary_name().get_surname() - - if id == "": - id = self.db.add_person(person,trans) - else: - self.db.add_person_no_map(person,id,trans) - + self.db.add_person(person,trans) self.type = self.prel.get_active() if self.type == const.FAMILY_CIVIL_UNION: self.parent_relation_changed(self.prel) elif person.get_gender() == RelLib.Person.male: self.redrawf() - path = self.father_nsort.on_get_path(id) + path = self.father_nsort.on_get_path(handle) top_path = self.father_nsort.on_get_path(name) self.father_list.expand_row(top_path,0) self.father_selection.select_path(path) self.father_list.scroll_to_cell(path,None,1,0.5,0) else: self.redrawm() - path = self.mother_nsort.on_get_path(id) + path = self.mother_nsort.on_get_path(handle) top_path = self.mother_nsort.on_get_path(name) self.mother_list.expand_row(top_path,0) self.mother_selection.select_path(path) diff --git a/gramps2/src/ColumnOrder.py b/gramps2/src/ColumnOrder.py index f183e3495..b657020a6 100644 --- a/gramps2/src/ColumnOrder.py +++ b/gramps2/src/ColumnOrder.py @@ -61,15 +61,15 @@ class ColumnOrder: self.glade.get_widget('cancelbutton').connect('clicked',self.cancel_clicked) for item in self.arglist: - iter = self.model.append() - self.model.set(iter,0,item[0],1,column_names[item[1]],2,item[1]) + node = self.model.append() + self.model.set(node,0,item[0],1,column_names[item[1]],2,item[1]) def ok_clicked(self,obj): newlist = [] for i in range(0,len(self.arglist)): - iter = self.model.get_iter((int(i),)) - newlist.append((self.model.get_value(iter,0), - self.model.get_value(iter,2))) + node = self.model.get_iter((int(i),)) + newlist.append((self.model.get_value(node,0), + self.model.get_value(node,2))) self.callback(newlist) self.top.destroy() @@ -77,7 +77,7 @@ class ColumnOrder: self.top.destroy() def toggled(self, cell, path, model): - iter = model.get_iter((int(path),)) - value = model.get_value(iter,0) + node = model.get_iter((int(path),)) + value = model.get_value(node,0) value = not value - model.set(iter,0,value) + model.set(node,0,value) diff --git a/gramps2/src/DbPrompter.py b/gramps2/src/DbPrompter.py index bbf7fda14..d53304545 100644 --- a/gramps2/src/DbPrompter.py +++ b/gramps2/src/DbPrompter.py @@ -128,32 +128,32 @@ class ExistingDbPrompter: gtk.RESPONSE_OK)) choose.set_local_only(gtk.FALSE) # Always add automatic (macth all files) filter - filter = gtk.FileFilter() - filter.set_name(_('Automatic')) - filter.add_pattern('*') - choose.add_filter(filter) + mime_filter = gtk.FileFilter() + mime_filter.set_name(_('Automatic')) + mime_filter.add_pattern('*') + choose.add_filter(mime_filter) # Always add native format filter - filter = gtk.FileFilter() - filter.set_name(_('GRAMPS databases')) - filter.add_mime_type(const.app_gramps) - choose.add_filter(filter) + mime_filter = gtk.FileFilter() + mime_filter.set_name(_('GRAMPS databases')) + mime_filter.add_mime_type(const.app_gramps) + choose.add_filter(mime_filter) # Always add native format filter - filter = gtk.FileFilter() - filter.set_name(_('GRAMPS XML databases')) - filter.add_mime_type(const.app_gramps_xml) - choose.add_filter(filter) + mime_filter = gtk.FileFilter() + mime_filter.set_name(_('GRAMPS XML databases')) + mime_filter.add_mime_type(const.app_gramps_xml) + choose.add_filter(mime_filter) # Always add native format filter - filter = gtk.FileFilter() - filter.set_name(_('GEDCOM')) - filter.add_mime_type(const.app_gedcom) - choose.add_filter(filter) + mime_filter = gtk.FileFilter() + mime_filter.set_name(_('GEDCOM')) + mime_filter.add_mime_type(const.app_gedcom) + choose.add_filter(mime_filter) # Add more data type selections if opening existing db - for (importData,filter,mime_type) in Plugins._imports: - choose.add_filter(filter) + for (importData,mime_filter,mime_type) in Plugins._imports: + choose.add_filter(mime_filter) response = choose.run() if response == gtk.RESPONSE_OK: @@ -176,7 +176,7 @@ class ExistingDbPrompter: self.parent.read_file(filename) return 1 (junk,the_file) = os.path.split(filename) - for (importData,filter,mime_type) in Plugins._imports: + for (importData,mime_filter,mime_type) in Plugins._imports: if filetype == mime_type or the_file == mime_type: choose.destroy() QuestionDialog.OkDialog( _("Opening non-native format"), @@ -234,10 +234,10 @@ class ImportDbPrompter: gtk.RESPONSE_OK)) choose.set_local_only(gtk.FALSE) # Always add automatic (macth all files) filter - filter = gtk.FileFilter() - filter.set_name(_('Automatic')) - filter.add_pattern('*') - choose.add_filter(filter) + mime_filter = gtk.FileFilter() + mime_filter.set_name(_('Automatic')) + mime_filter.add_pattern('*') + choose.add_filter(mime_filter) # FIXME: Uncomment when we have grdb importer # @@ -248,8 +248,8 @@ class ImportDbPrompter: # choose.add_filter(filter) # Add more data type selections if opening existing db - for (importData,filter,mime_type) in Plugins._imports: - choose.add_filter(filter) + for (importData,mime_filter,mime_type) in Plugins._imports: + choose.add_filter(mime_filter) response = choose.run() if response == gtk.RESPONSE_OK: @@ -262,7 +262,7 @@ class ImportDbPrompter: # self.parent.read_file(filename) # return 1 (junk,the_file) = os.path.split(filename) - for (importData,filter,mime_type) in Plugins._imports: + for (importData,mime_filter,mime_type) in Plugins._imports: if filetype == mime_type or the_file == mime_type: choose.destroy() importData(self.parent.db,filename) @@ -308,16 +308,16 @@ class NewNativeDbPrompter: self.parent.clear_database() # Always add automatic (macth all files) filter - filter = gtk.FileFilter() - filter.set_name(_('Automatic')) - filter.add_pattern('*') - choose.add_filter(filter) + mime_filter = gtk.FileFilter() + mime_filter.set_name(_('Automatic')) + mime_filter.add_pattern('*') + choose.add_filter(mime_filter) # Always add native format filter - filter = gtk.FileFilter() - filter.set_name(_('GRAMPS databases')) - filter.add_mime_type('application/x-gramps') - choose.add_filter(filter) + mime_filter = gtk.FileFilter() + mime_filter.set_name(_('GRAMPS databases')) + mime_filter.add_mime_type('application/x-gramps') + choose.add_filter(mime_filter) new_filename = Utils.get_new_filename('grdb') diff --git a/gramps2/src/DisplayModels.py b/gramps2/src/DisplayModels.py index 223366cbe..327f6d837 100644 --- a/gramps2/src/DisplayModels.py +++ b/gramps2/src/DisplayModels.py @@ -133,24 +133,28 @@ class SourceModel(BaseModel): self.column_author, self.column_abbrev, self.column_pubinfo, + self.column_handle, ] BaseModel.__init__(self,db) def column_title(self,data): - return unicode(data[1]) - - def column_author(self,data): return unicode(data[2]) - def column_abbrev(self,data): - return unicode(data[3]) - - def column_id(self,data): + def column_handle(self,data): return unicode(data[0]) - def column_pubinfo(self,data): + def column_author(self,data): + return unicode(data[3]) + + def column_abbrev(self,data): return unicode(data[4]) + def column_id(self,data): + return unicode(data[1]) + + def column_pubinfo(self,data): + return unicode(data[5]) + #------------------------------------------------------------------------- # # PlaceModel @@ -171,48 +175,52 @@ class PlaceModel(BaseModel): self.column_country, self.column_longitude, self.column_latitude, + self.column_handle, ] BaseModel.__init__(self,db) def column_name(self,data): - return unicode(data[1]) - - def column_longitude(self,data): return unicode(data[2]) - def column_latitude(self,data): + def column_handle(self,data): + return unicode(data[0]) + + def column_longitude(self,data): return unicode(data[3]) + def column_latitude(self,data): + return unicode(data[4]) + def column_id(self,data): - return unicode(data[0]) + return unicode(data[1]) def column_parish(self,data): try: - return data[4].get_parish() + return data[5].get_parish() except: return u'' def column_city(self,data): try: - return data[4].get_city() + return data[5].get_city() except: return u'' def column_county(self,data): try: - return data[4].get_county() + return data[5].get_county() except: return u'' def column_state(self,data): try: - return data[4].get_state() + return data[5].get_state() except: return u'' def column_country(self,data): try: - return data[4].get_country() + return data[5].get_country() except: return u'' @@ -236,13 +244,13 @@ class MediaModel(BaseModel): BaseModel.__init__(self,db) def column_description(self,data): - return unicode(data[3]) + return unicode(data[4]) def column_path(self,data): - return unicode(data[1]) - - def column_mime(self,data): return unicode(data[2]) + def column_mime(self,data): + return unicode(data[3]) + def column_id(self,data): - return unicode(data[0]) + return unicode(data[1]) diff --git a/gramps2/src/EditPerson.py b/gramps2/src/EditPerson.py index ced5717e9..e7395a23e 100644 --- a/gramps2/src/EditPerson.py +++ b/gramps2/src/EditPerson.py @@ -484,13 +484,13 @@ class EditPerson: cnum = cnum + 1 tree.append_column(column) - def lds_field(self,ord,combo,date,place): + def lds_field(self,lds_ord,combo,date,place): AutoComp.fill_combo(combo,_temple_names) - if not ord.is_empty(): - stat = ord.get_status() - date.set_text(ord.get_date()) - if ord.get_temple() != "": - name = const.lds_temple_to_abrev[ord.get_temple()] + if not lds_ord.is_empty(): + stat = lds_ord.get_status() + date.set_text(lds_ord.get_date()) + if lds_ord.get_temple() != "": + name = const.lds_temple_to_abrev[lds_ord.get_temple()] else: name = "" combo.child.set_text(name) @@ -499,9 +499,9 @@ class EditPerson: combo.child.set_text("") build_dropdown(place,self.place_list) - if ord and ord.get_place_handle(): - ord_place = self.db.get_place_from_handle(ord.get_place_handle()) - place.set_text(ord_place.get_title()) + if lds_ord and lds_ord.get_place_handle(): + lds_ord_place = self.db.get_place_from_handle(lds_ord.get_place_handle()) + place.set_text(lds_ord_place.get_title()) return stat def draw_lds(self): @@ -793,8 +793,8 @@ class EditPerson: self.ntree.clear() self.nmap = {} for name in self.nlist: - iter = self.ntree.add([name.get_name(),_(name.get_type())],name) - self.nmap[str(name)] = iter + node = self.ntree.add([name.get_name(),_(name.get_type())],name) + self.nmap[str(name)] = node if self.nlist: self.ntree.select_row(0) Utils.bold_label(self.names_label) @@ -807,8 +807,8 @@ class EditPerson: self.wtree.clear() self.wmap = {} for url in self.ulist: - iter = self.wtree.add([url.get_path(),url.get_description()],url) - self.wmap[str(url)] = iter + node = self.wtree.add([url.get_path(),url.get_description()],url) + self.wmap[str(url)] = node if len(self.ulist) > 0: self.web_go.set_sensitive(0) @@ -827,8 +827,8 @@ class EditPerson: for addr in self.plist: location = "%s %s %s %s" % (addr.get_street(),addr.get_city(), addr.get_state(),addr.get_country()) - iter = self.ptree.add([addr.get_date(),location],addr) - self.pmap[str(addr)] = iter + node = self.ptree.add([addr.get_date(),location],addr) + self.pmap[str(addr)] = node if self.plist: self.ptree.select_row(0) Utils.bold_label(self.addr_label) @@ -840,8 +840,8 @@ class EditPerson: self.atree.clear() self.amap = {} for attr in self.alist: - iter = self.atree.add([const.display_pattr(attr.get_type()),attr.get_value()],attr) - self.amap[str(attr)] = iter + node = self.atree.add([const.display_pattr(attr.get_type()),attr.get_value()],attr) + self.amap[str(attr)] = node if self.alist: self.atree.select_row(0) Utils.bold_label(self.attr_label) @@ -885,9 +885,9 @@ class EditPerson: for event_handle in self.elist: event = self.db.find_event_from_handle(event_handle) pname = place_title(self.db,event) - iter = self.etree.add([const.display_pevent(event.get_name()),event.get_description(), + node = self.etree.add([const.display_pevent(event.get_name()),event.get_description(), event.get_quote_date(),pname],event) - self.emap[str(event)] = iter + self.emap[str(event)] = node if self.elist: self.etree.select_row(0) Utils.bold_label(self.events_label) @@ -939,16 +939,16 @@ class EditPerson: def on_up_clicked(self,obj): sel = obj.get_selection() - store,iter = sel.get_selected() - if iter: - row = store.get_path(iter) + store,node = sel.get_selected() + if node: + row = store.get_path(node) sel.select_path((row[0]-1)) def on_down_clicked(self,obj): sel = obj.get_selection() - store,iter = sel.get_selected() - if iter: - row = store.get_path(iter) + store,node = sel.get_selected() + if node: + row = store.get_path(node) sel.select_path((row[0]+1)) def on_event_add_clicked(self,obj): @@ -996,33 +996,33 @@ class EditPerson: def on_aka_delete_clicked(self,obj): """Deletes the selected name from the name list""" - store,iter = self.ntree.get_selected() - if iter: - self.nlist.remove(self.ntree.get_object(iter)) + store,node = self.ntree.get_selected() + if node: + self.nlist.remove(self.ntree.get_object(node)) self.lists_changed = 1 self.redraw_name_list() def on_delete_url_clicked(self,obj): """Deletes the selected URL from the URL list""" - store,iter = self.wtree.get_selected() - if iter: - self.ulist.remove(self.wtree.get_object(iter)) + store,node = self.wtree.get_selected() + if node: + self.ulist.remove(self.wtree.get_object(node)) self.lists_changed = 1 self.redraw_url_list() def on_delete_attr_clicked(self,obj): """Deletes the selected attribute from the attribute list""" - store,iter = self.atree.get_selected() - if iter: - self.alist.remove(self.atree.get_object(iter)) + store,node = self.atree.get_selected() + if node: + self.alist.remove(self.atree.get_object(node)) self.lists_changed = 1 self.redraw_attr_list() def on_delete_addr_clicked(self,obj): """Deletes the selected address from the address list""" - store,iter = self.ptree.get_selected() - if iter: - self.plist.remove(self.ptree.get_object(iter)) + store,node = self.ptree.get_selected() + if node: + self.plist.remove(self.ptree.get_object(node)) self.lists_changed = 1 self.redraw_addr_list() @@ -1207,44 +1207,44 @@ class EditPerson: def on_update_attr_clicked(self,obj): import AttrEdit - store,iter = self.atree.get_selected() - if iter: - attr = self.atree.get_object(iter) + store,node = self.atree.get_selected() + if node: + attr = self.atree.get_object(node) pname = self.person.get_primary_name().get_name() AttrEdit.AttributeEditor(self,attr,pname,const.personalAttributes, self.attr_edit_callback,self.window) def on_update_addr_clicked(self,obj): import AddrEdit - store,iter = self.ptree.get_selected() - if iter: - AddrEdit.AddressEditor(self,self.ptree.get_object(iter), + store,node = self.ptree.get_selected() + if node: + AddrEdit.AddressEditor(self,self.ptree.get_object(node), self.addr_edit_callback,self.window) def on_update_url_clicked(self,obj): import UrlEdit - store,iter = self.wtree.get_selected() - if iter: + store,node = self.wtree.get_selected() + if node: pname = self.person.get_primary_name().get_name() - url = self.wtree.get_object(iter) + url = self.wtree.get_object(node) UrlEdit.UrlEditor(self,pname,url,self.url_edit_callback,self.window) def on_event_update_clicked(self,obj): import EventEdit - store,iter = self.etree.get_selected() - if not iter: + store,node = self.etree.get_selected() + if not node: return pname = self.person.get_primary_name().get_name() - event = self.etree.get_object(iter) + event = self.etree.get_object(node) EventEdit.EventEditor(self,pname,const.personalEvents, const.save_event,event,None,0, self.event_edit_callback) def on_event_select_row(self,obj): - store,iter = obj.get_selected() - if iter: - row = store.get_path(iter) + store,node = obj.get_selected() + if node: + row = store.get_path(node) event = self.db.find_event_from_handle(self.elist[row[0]]) self.event_date_field.set_text(event.get_date()) self.event_place_field.set_text(place_title(self.db,event)) @@ -1274,9 +1274,9 @@ class EditPerson: self.event_edit_btn.set_sensitive(0) def on_addr_select_row(self,obj): - store,iter = self.ptree.get_selected() - if iter: - addr = self.ptree.get_object(iter) + store,node = self.ptree.get_selected() + if node: + addr = self.ptree.get_object(node) self.addr_start.set_text(addr.get_date()) self.addr_street.set_text(addr.get_street()) self.addr_city.set_text(addr.get_city()) @@ -1309,9 +1309,9 @@ class EditPerson: self.addr_edit_btn.set_sensitive(0) def on_name_select_row(self,obj): - store,iter = self.ntree.get_selected() - if iter: - name = self.ntree.get_object(iter) + store,node = self.ntree.get_selected() + if node: + name = self.ntree.get_object(node) self.alt_given_field.set_text(name.get_first_name()) self.alt_title_field.set_text(name.get_title()) self.alt_last_field.set_text(name.get_surname()) @@ -1342,9 +1342,9 @@ class EditPerson: self.name_edit_btn.set_sensitive(0) def on_web_select_row(self,obj): - store,iter = self.wtree.get_selected() - if iter: - url = self.wtree.get_object(iter) + store,node = self.wtree.get_selected() + if node: + url = self.wtree.get_object(node) path = url.get_path() self.web_url.set_text(path) self.web_description.set_text(url.get_description()) @@ -1360,9 +1360,9 @@ class EditPerson: self.web_edit_btn.set_sensitive(0) def on_attr_select_row(self,obj): - store,iter = self.atree.get_selected() - if iter: - attr = self.atree.get_object(iter) + store,node = self.atree.get_selected() + if node: + attr = self.atree.get_object(node) self.attr_type.set_text(const.display_pattr(attr.get_type())) self.attr_value.set_text(short(attr.get_value())) if len(attr.get_source_references()) > 0: @@ -1398,9 +1398,9 @@ class EditPerson: def on_aka_update_clicked(self,obj): import NameEdit - store,iter = self.ntree.get_selected() - if iter: - NameEdit.NameEditor(self,self.ntree.get_object(iter), + store,node = self.ntree.get_selected() + if node: + NameEdit.NameEditor(self,self.ntree.get_object(node), self.name_edit_callback,self.window) def load_photo(self,photo): @@ -1509,11 +1509,11 @@ class EditPerson: # change in ordering due to the new birth date family = self.person.get_main_parents_family_handle() if (family): - f = self.db.find_family_no_map(family,trans) + f = self.db.find_family_from_handle(family,trans) new_order = self.reorder_child_list(self.person,f.get_child_handle_list()) f.set_child_handle_list(new_order) for (family, rel1, rel2) in self.person.get_parent_family_handle_list(): - f = self.db.find_family_no_map(family,trans) + f = self.db.find_family_from_handle(family,trans) new_order = self.reorder_child_list(self.person,f.get_child_handle_list()) f.set_child_handle_list(new_order) @@ -1586,16 +1586,16 @@ class EditPerson: if self.lds_not_loaded == 0: self.check_lds() - ord = RelLib.LdsOrd(self.person.get_lds_baptism()) - if not self.lds_baptism.are_equal(ord): + lds_ord = RelLib.LdsOrd(self.person.get_lds_baptism()) + if not self.lds_baptism.are_equal(lds_ord): self.person.set_lds_baptism(self.lds_baptism) - ord = RelLib.LdsOrd(self.person.get_lds_endowment()) - if not self.lds_endowment.are_equal(ord): + lds_ord = RelLib.LdsOrd(self.person.get_lds_endowment()) + if not self.lds_endowment.are_equal(lds_ord): self.person.set_lds_endowment(self.lds_endowment) - ord = RelLib.LdsOrd(self.person.get_lds_sealing()) - if not self.lds_sealing.are_equal(ord): + lds_ord = RelLib.LdsOrd(self.person.get_lds_sealing()) + if not self.lds_sealing.are_equal(lds_ord): self.person.set_lds_sealing(self.lds_sealing) if self.lists_changed: @@ -1682,10 +1682,10 @@ class EditPerson: if media_list: ph = media_list[0] object_handle = ph.get_reference_handle() - object = self.db.get_object_from_handle(object_handle) - if self.load_obj != object.get_path(): - if object.get_mime_type()[0:5] == "image": - self.load_photo(object.get_path()) + obj = self.db.get_object_from_handle(object_handle) + if self.load_obj != obj.get_path(): + if obj.get_mime_type()[0:5] == "image": + self.load_photo(obj.get_path()) else: self.load_photo(None) else: @@ -1843,8 +1843,8 @@ def place_title(db,event): def build_dropdown(entry,strings): store = gtk.ListStore(gobject.TYPE_STRING) for value in strings: - iter = store.append() - store.set(iter,0,value) + node = store.append() + store.set(node,0,value) completion = gtk.EntryCompletion() completion.set_text_column(0) completion.set_model(store) diff --git a/gramps2/src/EditPlace.py b/gramps2/src/EditPlace.py index 8d9f421ab..9a8185677 100644 --- a/gramps2/src/EditPlace.py +++ b/gramps2/src/EditPlace.py @@ -82,7 +82,6 @@ class EditPlace: self.not_loaded = 1 self.ref_not_loaded = 1 self.lists_changed = 0 - self.gallery_ok = 0 if place: self.srcreflist = place.get_source_references() else: @@ -224,12 +223,12 @@ class EditPlace: self.top.show() def on_delete_event(self,obj,b): - self.glry.close(self.gallery_ok) + self.glry.close() self.close_child_windows() self.remove_itself_from_menu() def close(self,obj): - self.glry.close(self.gallery_ok) + self.glry.close() self.close_child_windows() self.remove_itself_from_menu() self.top.destroy() @@ -367,7 +366,6 @@ class EditPlace: if format != self.place.get_note_format(): self.place.set_note_format(format) - self.gallery_ok = 1 self.update_lists() trans = self.db.start_transaction() @@ -486,7 +484,7 @@ class EditPlace: if event and event.get_place_handle() == self.place: pevent.append((p,event)) for family_handle in self.db.get_family_keys(): - f = self.db.find_family_from_handle(family_handle) + 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) if event and event.get_place_handle() == self.place: @@ -570,7 +568,7 @@ class DeletePlaceQuery: self.db.commit_event(event,trans) for fid in self.db.get_family_keys(): - f = self.db.find_family_from_handle(fid) + 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) if event and event.get_place_handle() == self.place.get_handle(): diff --git a/gramps2/src/EditSource.py b/gramps2/src/EditSource.py index e2a0c10ef..ca3da863c 100644 --- a/gramps2/src/EditSource.py +++ b/gramps2/src/EditSource.py @@ -191,7 +191,7 @@ class EditSource: f_attr_list = [] p_list = [] for key in self.db.get_place_handle_keys(): - p = self.db.get_place_handle(key) + 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(): @@ -201,7 +201,7 @@ class EditSource: name = GrampsCfg.get_nameof()(p) for event_handle in p.get_event_list() + [p.get_birth_handle(), p.get_death_handle()]: if event_handle: - event = self.db.find_event_from_handle(event_handle) + event = self.db.get_event_from_handle(event_handle) for sref in event.get_source_references(): if sref.get_base_handle() == self.source.get_handle(): p_event_list.append((name,event.get_name())) @@ -224,7 +224,7 @@ class EditSource: if sref.get_base_handle() == self.source.get_handle(): m_list.append(name) for family_handle in self.db.get_family_keys(): - family = self.db.find_family_from_handle(family_handle) + family = self.db.get_family_from_handle(family_handle) f_id = family.get_father_handle() m_id = family.get_mother_handle() if f_id: diff --git a/gramps2/src/FamilyView.py b/gramps2/src/FamilyView.py index 31433b1fc..b9489a078 100644 --- a/gramps2/src/FamilyView.py +++ b/gramps2/src/FamilyView.py @@ -631,11 +631,7 @@ class FamilyView: def new_spouse_after_edit(self,epo,trans): - if epo.person.get_handle() == "": - self.parent.db.add_person(epo.person,trans) - else: - self.parent.db.add_person_no_map(epo.person,epo.person.get_handle(),trans) - + self.parent.db.add_person(epo.person,trans) self.family = self.parent.db.new_family(trans) self.parent.people_view.add_to_person_list(epo.person,0) @@ -700,11 +696,7 @@ class FamilyView: def new_child_after_edit(self,epo,trans): - if epo.person.get_handle() == "": - self.parent.db.add_person(epo.person,trans) - else: - self.parent.db.add_person_no_map(epo.person,epo.person.get_handle(),trans) - + self.parent.db.add_person(epo.person,trans) self.parent.people_view.add_to_person_list(epo.person,0) if not self.family: @@ -796,8 +788,9 @@ class FamilyView: self.parent.db.commit_person(self.person,trans) self.parent.db.delete_family(self.family.get_handle(),trans) if len(self.person.get_family_handle_list()) > 0: - family_handle = self.person.get_family_handle_list()[0] - self.load_family(self.parent.db.find_family_from_handle(family_handle)) + handle = self.person.get_family_handle_list()[0] + family = self.parent.db.find_family_from_handle(handle,trans) + self.load_family(family) else: self.load_family(self.family) else: @@ -906,7 +899,7 @@ class FamilyView: for f in splist: if not f: continue - fm = self.parent.db.find_family_no_map(f,None) + fm = self.parent.db.find_family_from_handle(f,None) if fm.get_father_handle() == self.person.get_handle(): sp_id = fm.get_mother_handle() @@ -937,7 +930,7 @@ class FamilyView: self.spouse_selection.select_iter(iter) elif len(flist) > 0: fid = splist[0] - fam = self.parent.db.find_family_from_handle(fid) + fam = self.parent.db.get_family_from_handle(fid) self.display_marriage(fam) iter = flist[fid] self.spouse_selection.select_iter(iter) @@ -961,7 +954,7 @@ class FamilyView: list = person.get_parent_family_handle_list() for (f,mrel,frel) in list: - fam = self.parent.db.find_family_from_handle(f) + fam = self.parent.db.get_family_from_handle(f) father_handle = fam.get_father_handle() mother_handle = fam.get_mother_handle() f = self.parent.db.get_person_from_handle(father_handle) @@ -1006,7 +999,7 @@ class FamilyView: if not family: self.family = None return - self.family = self.parent.db.find_family_from_handle(family.get_handle()) + self.family = self.parent.db.get_family_from_handle(family.get_handle()) if self.family.get_father_handle() == self.person.get_handle(): sp_id = self.family.get_mother_handle() diff --git a/gramps2/src/GrampsDbBase.py b/gramps2/src/GrampsDbBase.py index 82ef94877..2999b2936 100644 --- a/gramps2/src/GrampsDbBase.py +++ b/gramps2/src/GrampsDbBase.py @@ -74,103 +74,33 @@ class GrampsDbBase: self.redolabel = None self.modified = 0 - def set_undo_label(self,label): - self.undolabel = label - self.undolabel.set_sensitive(0) + def new(self): + """initializes the GrampsDB to empty values""" - def set_redo_label(self,label): - self.redolabel = label - self.redolabel.set_sensitive(0) + 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): assert(0,"Needs to be overridden in the derived class") - def find_next_gramps_id(self): - index = self.iprefix % self.pmap_index - while self.id_trans.get(str(index)): - self.pmap_index += 1 - index = self.iprefix % self.pmap_index - self.pmap_index += 1 - return index - - def get_people_view_maps(self): - if self.metadata: - return (self.metadata.get('tp_iter'), - self.metadata.get('tp_path'), - self.metadata.get('p_iter'), - self.metadata.get('p_path'), - self.metadata.get('sname')) - else: - return (None,None,None,None,None) - - def set_people_view_maps(self,maps): - if self.metadata: - self.metadata['tp_iter'] = maps[0] - self.metadata['tp_path'] = maps[1] - self.metadata['p_iter'] = maps[2] - self.metadata['p_path'] = maps[3] - self.metadata['sname'] = maps[4] - def close(self): assert(0,"Needs to be overridden in the derived class") def is_open(self): return self.person_map != None - 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): - return len(self.person_map) - - def get_person_keys(self): - if self.person_map: - return self.person_map.keys() - else: - return [] - - def get_family_keys(self): - if self.family_map: - return self.family_map.keys() - else: - 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 - else: - 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 commit_person(self,person,transaction): handle = person.get_handle() if transaction != None: @@ -213,6 +143,350 @@ class GrampsDbBase: transaction.add(FAMILY_KEY,handle,old_data) self.family_map[str(family.get_handle())] = family.serialize() + def find_next_gramps_id(self): + index = self.iprefix % self.pmap_index + while self.id_trans.get(str(index)): + self.pmap_index += 1 + index = self.iprefix % self.pmap_index + self.pmap_index += 1 + return index + + def find_next_place_gramps_id(self): + index = self.pprefix % self.lmap_index + while self.id_trans.get(str(index)): + self.lmap_index += 1 + index = self.pprefix % self.lmap_index + self.lmap_index += 1 + return index + + def find_next_event_gramps_id(self): + index = self.eprefix % self.emap_index + while self.id_trans.get(str(index)): + self.emap_index += 1 + index = self.eprefix % self.emap_index + self.emap_index += 1 + return index + + def find_next_object_gramps_id(self): + index = self.oprefix % self.omap_index + while self.id_trans.get(str(index)): + self.omap_index += 1 + index = self.oprefix % self.omap_index + self.omap_index += 1 + return index + + def find_next_source_gramps_id(self): + index = self.sprefix % self.smap_index + while self.source_map.get(str(index)): + self.smap_index += 1 + index = self.sprefix % self.smap_index + self.fmap_index += 1 + return index + + def find_next_family_gramps_id(self): + index = self.fprefix % self.fmap_index + while self.family_map.get(str(index)): + self.fmap_index += 1 + index = self.fprefix % self.fmap_index + self.fmap_index += 1 + return index + + def get_person_from_handle(self,val): + """finds a Person in the database from the passed gramps' ID. + If no such Person exists, a new Person is added to the database.""" + + data = self.person_map.get(val) + if data: + person = Person() + person.unserialize(data) + return person + return None + + def get_source_from_handle(self,val): + """finds a Source in the database from the passed gramps' ID. + If no such Source exists, None is returned.""" + + data = self.source_map.get(val) + if data: + source = Source() + source.unserialize(data) + return source + return None + + def get_object_from_handle(self,handle): + """finds an Object in the database from the passed gramps' ID. + If no such Object exists, None is returned.""" + data = self.media_map.get(handle) + if data: + mobject = MediaObject() + mobject.unserialize(data) + return mobject + return None + + def get_place_from_handle(self,handle): + """finds a Place in the database from the passed gramps' ID. + If no such Place exists, None is returned.""" + data = self.place_map.get(handle) + if data: + place = Place() + place.unserialize(data) + return place + return None + + def get_event_from_handle(self,handle): + """finds a Place in the database from the passed gramps' ID. + If no such Place exists, None is returned.""" + + data = self.event_map.get(handle) + if data: + event = Event() + event.unserialize(data) + return event + return None + + def get_family_from_handle(self,handle): + """finds a Place in the database from the passed gramps' ID. + If no such Place exists, None is returned.""" + + data = self.family_map.get(str(handle)) + if data: + family = Family() + family.unserialize(data) + 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.""" + + person = Person() + data = self.person_map.get(val) + if data: + person.unserialize(data) + else: + person.set_handle(val) + if trans != None: + trans.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.""" + + 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) + 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.""" + data = self.event_map.get(str(val)) + if data: + event = Event() + event.unserialize(data) + return event + 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.""" + + 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) + 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.""" + + data = self.place_map.get(str(handle)) + place = Place() + if not data: + place.handle = handle + if trans != None: + trans.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): + """finds a Family in the database from the passed gramps' ID. + If no such Family exists, a new Family is added to the database.""" + + family = Family() + data = self.family_map.get(str(val)) + if data: + family.unserialize(data) + else: + family.handle = val + if trans: + trans.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() == "": + 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.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() == "": + family.set_gramps_id(self.find_next_family_gramps_id()) + if family.get_handle() == "": + 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() + 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() == "": + source.set_handle(Utils.create_id()) + if source.get_gramps_id() == "": + 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() + 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() == "": + event.set_handle(Utils.create_id()) + if event.get_gramps_id() == "": + 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() + 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() == "": + index = Utils.create_id() + place.set_handle(index) + if place.get_gramps_id() == "": + 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() + return place.get_handle() + + def add_object(self,obj,trans): + """adds an Object instance to the database, assigning it a gramps' + ID number""" + + index = obj.get_handle() + if index == "": + index = Utils.create_id() + obj.set_handle(index) + if obj.get_gramps_id() == "": + 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) + return index + + def get_people_view_maps(self): + if self.metadata: + return (self.metadata.get('tp_iter'), + self.metadata.get('tp_path'), + self.metadata.get('p_iter'), + self.metadata.get('p_path'), + self.metadata.get('sname')) + else: + return (None,None,None,None,None) + + def set_people_view_maps(self,maps): + if self.metadata: + self.metadata['tp_iter'] = maps[0] + self.metadata['tp_path'] = maps[1] + self.metadata['p_iter'] = maps[2] + 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): + return len(self.person_map) + + def get_person_keys(self): + if self.person_map: + return self.person_map.keys() + return [] + + def get_family_keys(self): + 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): if val: if _id_reg.search(val): @@ -267,24 +541,6 @@ class GrampsDbBase: else: self.eprefix = "E%04d" - 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 start_transaction(self,msg=""): return Transaction(msg,self.undodb) @@ -316,34 +572,34 @@ class GrampsDbBase: (key, handle, data) = transaction.get_record(record_id) if key == PERSON_KEY: if data == None: - del self.person_map[handle] + del self.person_map[str(handle)] else: - self.person_map[handle] = data + self.person_map[str(handle)] = data elif key == FAMILY_KEY: if data == None: - del self.family_map[handle] + del self.family_map[str(handle)] else: - self.family_map[handle] = data + self.family_map[str(handle)] = data elif key == SOURCE_KEY: if data == None: - del self.source_map[handle] + del self.source_map[str(handle)] else: - self.source_map[handle] = data + self.source_map[str(handle)] = data elif key == EVENT_KEY: if data == None: - del self.event_map[handle] + del self.event_map[str(handle)] else: - self.event_map[handle] = data + self.event_map[str(handle)] = data elif key == PLACE_KEY: if data == None: - del self.place_map[handle] + del self.place_map[str(handle)] else: - self.place_map[handle] = data + self.place_map[str(handle)] = data elif key == MEDIA_KEY: if data == None: - del self.media_map[handle] + del self.media_map[str(handle)] else: - self.media_map[handle] = data + self.media_map[str(handle)] = data if self.undolabel: label = self.undolabel.get_children()[0] @@ -356,6 +612,14 @@ class GrampsDbBase: self.undolabel.set_sensitive(1) label.set_use_underline(1) + def set_undo_label(self,label): + self.undolabel = label + self.undolabel.set_sensitive(0) + + def set_redo_label(self,label): + self.redolabel = label + self.redolabel.set_sensitive(0) + def get_surnames(self): assert(0,"Needs to be overridden in the derived class") @@ -401,7 +665,7 @@ class GrampsDbBase: if self.metadata and self.metadata.has_key('default'): person = Person() handle = self.metadata['default'] - data = self.person_map.get(handle) + data = self.person_map.get(str(handle)) person.unserialize(data) return person return None @@ -409,7 +673,7 @@ class GrampsDbBase: def get_person(self,handle): """returns a Person from a GRAMPS's ID""" p = Person() - data = self.person_map.get(handle) + data = self.person_map.get(str(handle)) p.unserialize(data) return p @@ -476,41 +740,12 @@ class GrampsDbBase: def remove_event_handle(self,handle,transaction): assert(0,"Needs to be overridden in the derived class") - def add_person_as(self,person,trans): - if trans != None: - trans.add(PERSON_KEY, person.get_handle(),None) - self.person_map[person.get_handle()] = person.serialize() - self.genderStats.count_person (person, self) - return person.get_handle() - - def add_person(self,person,trans): - """adds a Person to the database, assigning a gramps' ID""" - person.set_gramps_id(self.find_next_gramps_id()) - 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.genderStats.count_person (person, self) - return person.get_handle() - def has_person_handle(self,val): return self.person_map.has_key(str(val)) def has_family_handle(self,val): return self.family_map.has_key(str(val)) - def get_person_from_handle(self,val): - """finds a Person in the database from the passed gramps' ID. - If no such Person exists, a new Person is added to the database.""" - - data = self.person_map.get(val) - if data: - person = Person() - person.unserialize(data) - return person - else: - return None - def get_person_from_gramps_id(self,val): """finds a Person in the database from the passed gramps' ID. If no such Person exists, a new Person is added to the database.""" @@ -535,243 +770,15 @@ class GrampsDbBase: intid = Utils.create_id() person.set_handle(intid) person.set_gramps_id(val) - self.add_person_as(person,trans) + self.add_person(person,trans) return person - 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.""" - - person = Person() - data = self.person_map.get(val) - if data: - person.unserialize(data) - else: - person.set_handle(val) - if trans != None: - trans.add(PERSON_KEY, val, None) - self.person_map[val] = person.serialize() - self.genderStats.count_person (person, self) - return person - - def add_person_no_map(self,person,handle,trans): - """adds a Person to the database if the gramps' ID is known""" - - person.set_handle(handle) - if trans != None: - trans.add(PERSON_KEY, handle, None) - self.person_map.set(handle,person.serialize()) - self.genderStats.count_person (person, self) - return handle - - def add_source(self,source,trans): - """adds a Source instance to the database, assigning it a gramps' - ID number""" - - index = self.sprefix % self.smap_index - while self.source_map.get(str(index)): - self.smap_index = self.smap_index + 1 - index = self.sprefix % self.smap_index - source.set_handle(index) - if trans != None: - trans.add(SOURCE_KEY,index,None) - self.source_map[str(index)] = source.serialize() - self.smap_index = self.smap_index + 1 - return index - - def add_event(self,event,trans): - """adds a Event instance to the database, assigning it a gramps' - ID number""" - index = self.eprefix % self.emap_index - while self.event_map.get(str(index)): - self.emap_index += 1 - index = self.eprefix % self.emap_index - event.set_handle(index) - if trans != None: - trans.add(EVENT_KEY,index,None) - self.event_map[str(index)] = event.serialize() - self.emap_index += 1 - return index - - def add_source_no_map(self,source,index,trans): - """adds a Source to the database if the gramps' ID is known""" - source.set_handle(index) - if trans != None: - trans.add(SOURCE_KEY,index,None) - self.source_map[str(index)] = source.serialize() - self.smap_index = self.smap_index + 1 - return index - - def add_event_no_map(self,event,index,trans): - """adds a Source to the database if the gramps' ID is known""" - event.set_handle(index) - if trans != None: - trans.add(EVENT_KEY,index,None) - self.event_map[str(index)] = event.serialize() - self.emap_index += 1 - return index - - def find_source(self,handle,map,trans): - """finds a Source in the database using the handle and map - variables to translate between the external ID and gramps' - internal ID. If no such Source exists, a new Source instance - is created. - - handle - external ID number - map - map build by find_source of external to gramp's IDs""" - - if map.has_key(handle): - data = self.source_map.get(str(map[handle])) - source = Source() - source.unserialize(data) - else: - source = Source() - map[handle] = self.add_source(source,trans) - return source - - def find_event(self,handle,map,trans): - """finds a Event in the database using the handle and map - variables to translate between the external ID and gramps' - internal ID. If no such Event exists, a new Event instance - is created. - - handle - external ID number - map - map build by find_source of external to gramp's IDs""" - - event = Event() - if map.has_key(handle): - data = self.event_map.get(str(map[handle])) - event.unserialize(data) - else: - map[handle] = self.add_event(event,trans) - return event - - def get_source_from_handle(self,val): - """finds a Source in the database from the passed gramps' ID. - If no such Source exists, None is returned.""" - - data = self.source_map.get(str(val)) - if data: - source = Source() - source.unserialize(data) - return source - else: - return None - - 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.""" - - source = Source() - if self.source_map.get(str(val)): - source.unserialize(self.source_map.get(str(val))) - else: - self.add_source_no_map(source,val,trans) - 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.""" - data = self.event_map.get(str(val)) - if data: - event = Event() - event.unserialize(data) - return event - else: - return None - - def add_object(self,obj,trans): - """adds an Object instance to the database, assigning it a gramps' - ID number""" - - index = self.oprefix % self.omap_index - while self.media_map.get(str(index)): - self.omap_index = self.omap_index + 1 - index = self.oprefix % self.omap_index - obj.set_handle(index) - if trans != None: - trans.add(MEDIA_KEY,index,None) - self.media_map[str(index)] = obj.serialize() - self.omap_index = self.omap_index + 1 - self.added_files.append(obj) - - return index - - def find_object_no_conflicts(self,handle,map,trans): - """finds an Object in the database using the handle and map - variables to translate between the external ID and gramps' - internal ID. If no such Object exists, a new Object instance - is created. - - handle - external ID number - map - map build by find_object of external to gramp's IDs""" - - handle = str(handle) - obj = MediaObject() - if map.has_key(handle): - obj.unserialize(self.media_map.get(str(map[handle]))) - else: - if self.media_map.get(str(handle)): - map[handle] = self.add_object(obj,trans) - else: - map[handle] = self.add_object_no_map(obj,handle,trans) - return obj - - def add_object_no_map(self,obj,index,trans): - """adds an Object to the database if the gramps' ID is known""" - index = str(index) - obj.set_handle(index) - if trans != None: - trans.add(MEDIA_KEY,index,None) - self.media_map[str(index)] = obj.serialize() - self.omap_index = self.omap_index + 1 - self.added_files.append(obj) - return index - - def get_object_from_handle(self,handle): - """finds an Object in the database from the passed gramps' ID. - If no such Object exists, None is returned.""" - - data = self.media_map.get(str(handle)) - if data: - mobject = MediaObject() - mobject.unserialize(data) - return mobject - 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.""" - - obj = MediaObject() - if self.media_map.get(str(handle)): - obj.unserialize(self.media_map.get(str(handle))) - else: - self.add_object_no_map(obj,handle,trans) - return obj - 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.""" return self.media_map.get(str(handle)) != None - def add_place(self,place,trans): - """adds a Place instance to the database, assigning it a gramps' - ID number""" - - index = self.pprefix % self.lmap_index - while self.place_map.get(str(index)): - self.lmap_index = self.lmap_index + 1 - index = self.pprefix % self.lmap_index - place.set_handle(index) - if trans != None: - trans.add(PLACE_KEY,index,None) - self.place_map[str(index)] = place.serialize() - self.lmap_index = self.lmap_index + 1 - return index - def remove_object(self,handle,transaction): assert(0,"Needs to be overridden in the derived class") @@ -783,88 +790,25 @@ class GrampsDbBase: trans.add(PLACE_KEY,place.get_handle(),None) self.place_map[str(place.get_handle())] = place.serialize() return place.get_handle() - - def find_place_no_conflicts(self,handle,map,trans): - """finds a Place in the database using the handle and map - variables to translate between the external ID and gramps' - internal ID. If no such Place exists, a new Place instance - is created. - - handle - external ID number - map - map build by findPlace of external to gramp's IDs""" - - if map.has_key(str(handle)): - place = Place() - data = self.place_map[str(map[handle])] - place.unserialize(data) - else: - place = Place() - if self.place_map.has_key(str(handle)): - map[handle] = self.add_place(place,trans) - else: - place.set_handle(str(handle)) - map[str(handle)] = self.add_place_as(place,trans) - self.place_map[str(handle)] = place.serialize() - return place - - def add_place_no_map(self,place,index,trans): - """adds a Place to the database if the gramps' ID is known""" - - index = str(index) - place.set_handle(index) - if trans != None: - trans.add(PLACE_KEY,index,None) - self.place_map[str(index)] = place.serialize() - self.lmap_index = self.lmap_index + 1 - return index - - 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.""" - - data = self.place_map.get(str(handle)) - place = Place() - if not data: - place.handle = handle - if trans != None: - trans.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 get_place_from_handle(self,handle): - """finds a Place in the database from the passed gramps' ID. - If no such Place exists, None is returned.""" - - data = self.place_map.get(str(handle)) - - if data: - place = Place() - place.unserialize(data) - return place - else: - return None def sortbyplace(self,f,s): return cmp(self.placesortmap[f], self.placesortmap[s]) def sortbysource(self,f,s): - fp = self.source_map[f][1].upper() - sp = self.source_map[s][1].upper() + fp = self.source_map[f][2].upper() + sp = self.source_map[s][2].upper() return cmp(fp,sp) def sortbymedia(self,f,s): - fp = self.media_map[f][3].upper() - sp = self.media_map[s][3].upper() + 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][1].upper() + self.placesortmap[key] = self.place_map[key][2].upper() keys = self.placesortmap.keys() keys.sort(self.sortbyplace) del self.placesortmap @@ -942,69 +886,12 @@ class GrampsDbBase: index = self.fprefix % self.fmap_index self.fmap_index = self.fmap_index + 1 family = Family() - family.set_handle(unicode(index)) + family.set_handle(index) if trans != None: trans.add(FAMILY_KEY, index, None) self.family_map[str(index)] = family.serialize() return family - def new_family_no_map(self,handle,trans): - """finds a Family in the database from the passed gramps' ID. - If no such Family exists, a new Family is added to the database.""" - - family = Family() - family.set_handle(handle) - if trans != None: - trans.add(FAMILY_KEY, handle, None) - self.family_map[str(handle)] = family.serialize() - self.fmap_index = self.fmap_index + 1 - return family - - def find_family_with_map(self,handle,map,trans): - """finds a Family in the database using the handle and map - variables to translate between the external ID and gramps' - internal ID. If no such Family exists, a new Family instance - is created. - - handle - external ID number - map - map build by find_family_with_map of external to gramp's IDs""" - - if map.has_key(handle): - family = Family() - data = self.family_map.get(str(map[handle])) - family.unserialize(data) - else: - family = self.new_family(trans) - map[handle] = family.get_handle() - return family - - def find_family_no_map(self,val,trans): - """finds a Family in the database from the passed gramps' ID. - If no such Family exists, a new Family is added to the database.""" - - family = Family() - data = self.family_map.get(str(val)) - if data: - family.unserialize(data) - else: - family.handle = val - if trans: - trans.add(FAMILY_KEY,val,None) - self.family_map[str(val)] = family.serialize() - self.fmap_index = self.fmap_index + 1 - return family - - def find_family_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.""" - data = self.family_map.get(str(val)) - if data: - family = Family() - family.unserialize(data) - return family - else: - return None - def delete_family(self,family_handle,trans): """deletes the Family instance from the database""" if self.family_map.get(str(family_handle)): @@ -1013,45 +900,6 @@ class GrampsDbBase: trans.add(FAMILY_KEY,family_handle,old_data) del self.family_map[str(family_handle)] - def find_family_no_conflicts(self,handle,map,trans): - """finds a Family in the database using the handle and map - variables to translate between the external ID and gramps' - internal ID. If no such Family exists, a new Family instance - is created. - - handle - external ID number - map - map build by findFamily of external to gramp's IDs""" - - if map.has_key(str(handle)): - family = Family() - family.unserialize(self.family_map.get(str(map[str(handle)]))) - else: - if self.family_map.has_key(str(handle)): - family = self.new_family(trans) - else: - family = self.new_family_no_map(str(handle),trans) - map[handle] = family.get_handle() - return family - - def find_source_no_conflicts(self,handle,map,trans): - """finds a Source in the database using the handle and map - variables to translate between the external ID and gramps' - internal ID. If no such Source exists, a new Source instance - is created. - - handle - external ID number - map - map build by findSource of external to gramp's IDs""" - - source = Source() - if map.has_key(handle): - source.unserialize(self.source_map.get(str(map[handle]))) - else: - if self.source_map.get(str(handle)): - map[handle] = self.add_source(source,trans) - else: - map[handle] = self.add_source(source,trans) - return source - def set_column_order(self,list): if self.metadata != None: self.metadata['columns'] = list @@ -1179,3 +1027,4 @@ class Transaction: else: print "PLACE %s remove" % handle + diff --git a/gramps2/src/ImageSelect.py b/gramps2/src/ImageSelect.py index b38212309..da1bcfe5a 100644 --- a/gramps2/src/ImageSelect.py +++ b/gramps2/src/ImageSelect.py @@ -239,7 +239,7 @@ class Gallery(ImageSelect): self.dataobj = dataobj; self.iconlist = icon_list; self.root = self.iconlist.root() - self.old_media_list = [RelLib.MediaRef(ref) for ref in self.dataobj.get_media_list()] + self.old_media_list = [RelLib.MediaRef(ref) for ref in dataobj.get_media_list()] # Local object variables self.y = 0 diff --git a/gramps2/src/ListModel.py b/gramps2/src/ListModel.py index 03b1d7c33..37cd46077 100644 --- a/gramps2/src/ListModel.py +++ b/gramps2/src/ListModel.py @@ -27,7 +27,8 @@ import gtk # #------------------------------------------------------------------------- class ListModel: - def __init__(self,tree,dlist,select_func=None,event_func=None,mode=gtk.SELECTION_SINGLE): + def __init__(self,tree,dlist,select_func=None, + event_func=None,mode=gtk.SELECTION_SINGLE): self.tree = tree l = len(dlist) self.mylist = [TYPE_STRING]*l + [TYPE_PYOBJECT] diff --git a/gramps2/src/PedView.py b/gramps2/src/PedView.py index f25c3d6e4..408fff5bc 100644 --- a/gramps2/src/PedView.py +++ b/gramps2/src/PedView.py @@ -268,7 +268,7 @@ class PedigreeView: self.canvas_items.append(self.anchor_txt) for family_handle in self.active_person.get_family_handle_list(): - family = self.parent.db.find_family_from_handle(family_handle) + family = self.parent.db.get_family_from_handle(family_handle) if len(family.get_child_handle_list()) > 0: button,arrow = self.make_arrow_button(gtk.ARROW_LEFT, self.on_show_child_menu) @@ -490,7 +490,7 @@ class PedigreeView: mrel = (m != "Birth") frel = (f != "Birth") - family = self.parent.db.find_family_from_handle(family_handle) + family = self.parent.db.get_family_from_handle(family_handle) list[index] = (person,val) if family != None: father_handle = family.get_father_handle() @@ -573,7 +573,7 @@ class PedigreeView: fam_list = person.get_family_handle_list() no_spouses = 1 for fam_id in fam_list: - family = self.parent.db.find_family_from_handle(fam_id) + family = self.parent.db.get_family_from_handle(fam_id) if family.get_father_handle() == person.get_handle(): sp_id = family.get_mother_handle() else: @@ -604,7 +604,7 @@ class PedigreeView: pfam_list = person.get_parent_family_handle_list() no_siblings = 1 for (f,mrel,frel) in pfam_list: - fam = self.parent.db.find_family_from_handle(f) + fam = self.parent.db.get_family_from_handle(f) sib_list = fam.get_child_handle_list() for sib_id in sib_list: if sib_id == person.get_handle(): @@ -774,7 +774,7 @@ def find_children(db,p): """ childlist = [] for family_handle in p.get_family_handle_list(): - family = db.find_family_from_handle(family_handle) + family = db.get_family_from_handle(family_handle) for child_handle in family.get_child_handle_list(): childlist.append(child_handle) return childlist @@ -790,7 +790,7 @@ def find_parents(db,p): """ parentlist = [] for (f,mrel,frel) in p.get_parent_family_handle_list(): - family = db.find_family_from_handle(f) + family = db.get_family_from_handle(f) father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() if father_handle not in parentlist: diff --git a/gramps2/src/PlaceView.py b/gramps2/src/PlaceView.py index 200b40fba..2593117ba 100644 --- a/gramps2/src/PlaceView.py +++ b/gramps2/src/PlaceView.py @@ -60,6 +60,8 @@ column_names = [ _('Latitude'), ] +_HANDLE_COL = len(column_names) + #------------------------------------------------------------------------- # # PlaceView class @@ -70,7 +72,6 @@ class PlaceView: def __init__(self,parent,db,glade,update): self.parent = parent self.glade = glade - self.db = db self.list = glade.get_widget("place_list") self.list.connect('button-press-event',self.button_press) self.list.connect('key-press-event',self.key_press) @@ -79,7 +80,7 @@ class PlaceView: self.renderer = gtk.CellRendererText() - self.model = gtk.TreeModelSort(DisplayModels.PlaceModel(self.db)) + self.model = gtk.TreeModelSort(DisplayModels.PlaceModel(self.parent.db)) self.list.set_model(self.model) self.topWindow = self.glade.get_widget("gramps") @@ -176,7 +177,7 @@ class PlaceView: EditPlace.EditPlace(self.parent,RelLib.Place(),self.new_place_after_edit) def new_place_after_edit(self,place): - self.db.add_place(place) + self.parent.db.add_place(place) def update_display(self,place): self.build_tree() @@ -185,15 +186,15 @@ class PlaceView: mlist = [] self.selection.selected_foreach(self.blist,mlist) - trans = self.db.start_transaction() + trans = self.parent.db.start_transaction() for place in mlist: used = 0 - for key in self.db.get_person_keys(): - p = self.db.get_person_from_handle(key) + for key in self.parent.db.get_person_keys(): + 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(): - event = self.db.find_event_from_handle(e) + event = self.parent.db.find_event_from_handle(e) if event: event_list.append(event) if p.get_lds_baptism(): @@ -206,11 +207,11 @@ class PlaceView: if event.get_place_handle() == place.get_handle(): used = 1 - for fid in self.db.get_family_keys(): - f = self.db.find_family_from_handle(fid) + for fid in self.parent.db.get_family_keys(): + f = self.parent.db.find_family_from_handle(fid) event_list = [] for e in f.get_event_list(): - event = self.db.find_event_from_handle(e) + event = self.parent.db.find_event_from_handle(e) if event: event_list.append(event) if f.get_lds_sealing(): @@ -220,7 +221,7 @@ class PlaceView: used = 1 if used == 1: - ans = EditPlace.DeletePlaceQuery(place,self.db,self.update_display) + ans = EditPlace.DeletePlaceQuery(place,self.parent.db,self.update_display) QuestionDialog(_('Delete %s?') % place.get_title(), _('This place is currently being used by at least one ' 'record in the database. Deleting it will remove it ' @@ -229,9 +230,9 @@ class PlaceView: _('_Delete Place'), ans.query_response) else: - trans = self.db.start_transaction() - self.db.remove_place(place.get_handle(),trans) - self.db.add_transaction(trans,_("Delete Place (%s)") % place.title()) + trans = self.parent.db.start_transaction() + self.parent.db.remove_place(place.get_handle(),trans) + self.parent.db.add_transaction(trans,_("Delete Place (%s)") % place.title()) self.build_tree() def on_edit_clicked(self,obj): @@ -243,7 +244,7 @@ class PlaceView: EditPlace.EditPlace(self.parent, place, self.update_display) def blist(self,store,path,iter,list): - id = self.db.get_place_from_handle(store.get_value(iter,1)) + id = self.parent.db.get_place_from_handle(store.get_value(iter,_HANDLE_COL)) list.append(id) def merge(self): @@ -258,5 +259,5 @@ class PlaceView: ErrorDialog(msg,msg2) else: import MergeData - MergeData.MergePlaces(self.db,mlist[0],mlist[1],self.build_tree) + MergeData.MergePlaces(self.parent.db,mlist[0],mlist[1],self.build_tree) diff --git a/gramps2/src/ReadGedcom.py b/gramps2/src/ReadGedcom.py index 992d6ec7a..b001017a6 100644 --- a/gramps2/src/ReadGedcom.py +++ b/gramps2/src/ReadGedcom.py @@ -222,6 +222,9 @@ class GedcomParser: self.is_ftw = 0 self.idswap = {} self.gid2id = {} + self.sid2id = {} + self.lid2id = {} + self.fid2id = {} self.f = open(file,"rU") self.filename = file @@ -442,7 +445,7 @@ class GedcomParser: self.ignore_sub_junk(1) def parse_source(self,name,level): - self.source = self.db.find_source(name,self.smap, self.trans) + self.source = self.find_or_create_source(name[1:-1]) note = "" while 1: @@ -495,7 +498,7 @@ class GedcomParser: if self.fam_count % UPDATE == 0 and self.window: self.update(self.families_obj,str(self.fam_count)) self.fam_count = self.fam_count + 1 - self.family = self.db.find_family_with_map(matches[1],self.fmap, self.trans) + self.family = self.find_or_create_family(matches[1]) self.parse_family() if self.addr != None: father = self.family.get_father_handle() @@ -563,10 +566,51 @@ class GedcomParser: intid = Utils.create_id() person.set_handle(intid) person.set_gramps_id(gramps_id) - self.db.add_person_as(person,self.trans) + self.db.add_person(person,self.trans) self.gid2id[gramps_id] = intid return person + def find_or_create_source(self,gramps_id): + source = RelLib.Source() + intid = self.sid2id.get(gramps_id) + if self.db.source_map.has_key(intid): + source.unserialize(self.db.source_map.get(intid)) + else: + intid = Utils.create_id() + source.set_handle(intid) + source.set_gramps_id(gramps_id) + self.db.add_source(source,self.trans) + self.sid2id[gramps_id] = intid + return source + + def find_or_create_place(self,gramps_id): + place = RelLib.Place() + intid = self.lid2id.get(gramps_id) + if self.db.place_map.has_key(intid): + place.unserialize(self.db.place_map.get(intid)) + else: + intid = Utils.create_id() + place.set_handle(intid) + place.set_title(gramps_id) + place.set_gramps_id(self.db.find_next_place_gramps_id()) + print place.get_gramps_id() + self.db.add_place(place,self.trans) + self.lid2id[gramps_id] = intid + return place + + def find_or_create_family(self,gramps_id): + family = RelLib.Family() + intid = self.fid2id.get(gramps_id) + if self.db.family_map.has_key(intid): + family.unserialize(self.db.family_map.get(intid)) + else: + intid = Utils.create_id() + family.set_handle(intid) + family.set_gramps_id(gramps_id) + self.db.add_family(family,self.trans) + self.fid2id[gramps_id] = intid + return family + def parse_cause(self,event,level): while 1: matches = self.get_next() @@ -793,7 +837,7 @@ class GedcomParser: self.person.set_lds_sealing(ord) self.parse_ord(ord,2) elif matches[1] == "FAMS": - family = self.db.find_family_with_map(matches[2],self.fmap, self.trans) + family = self.find_or_create_family(matches[2]) self.person.add_family_handle(family.get_handle()) if note == "": note = self.parse_optional_note(2) @@ -802,7 +846,7 @@ class GedcomParser: self.db.commit_family(family, self.trans) elif matches[1] == "FAMC": type,note = self.parse_famc_type(2) - family = self.db.find_family_with_map(matches[2],self.fmap, self.trans) + family = self.find_or_create_family(matches[2]) for f in self.person.get_parent_family_handle_list(): if f[0] == family.get_handle(): @@ -1115,18 +1159,13 @@ class GedcomParser: elif matches[1] == "DATE": ord.set_date_object(self.extract_date(matches[2])) elif matches[1] == "FAMC": - ord.set_family_handle(self.db.find_family_with_map(matches[2],self.fmap,self.trans)) + ord.set_family_handle(self.find_or_create_family(matches[2])) elif matches[1] == "PLAC": try: val = matches[2] - if self.placemap.has_key(val): - place_handle = self.placemap[val] - else: - place = RelLib.Place() - place.set_title(matches[2]) - self.db.add_place(place, self.trans) - place_handle = place.get_handle() - self.placemap[val] = place_handle + place = self.find_or_create_place(matches[2]) + place.set_title(matches[2]) + place_handle = place.get_handle() ord.set_place_handle(place_handle) self.ignore_sub_junk(level+1) except NameError: @@ -1172,14 +1211,9 @@ class GedcomParser: event.set_description(val) self.ignore_sub_junk(level+1) else: - if self.placemap.has_key(val): - place_handle = self.placemap[val] - else: - place = RelLib.Place() - place.set_title(matches[2]) - self.db.add_place(place, self.trans) - place_handle = place.get_handle() - self.placemap[val] = place_handle + place = self.find_or_create_place(val) + place_handle = place.get_handle() + place.set_title(matches[2]) event.set_place_handle(place_handle) self.ignore_sub_junk(level+1) elif matches[1] == "CAUS": @@ -1221,21 +1255,16 @@ class GedcomParser: elif matches[1] == "SOUR": event.add_source_reference(self.handle_source(matches,level+1)) elif matches[1] == "FAMC": - family = self.db.find_family_with_map(matches[2],self.fmap,self.trans) + family = self.find_or_create_family(matches[2]) mrel,frel = self.parse_adopt_famc(level+1); if self.person.get_main_parents_family_handle() == family.get_handle(): self.person.set_main_parent_family_handle(None) self.person.add_parent_family_handle(family.get_handle(),mrel,frel) elif matches[1] == "PLAC": val = matches[2] - if self.placemap.has_key(val): - place_handle = self.placemap[val] - else: - place = RelLib.Place() - place.set_title(matches[2]) - self.db.add_place(place, self.trans) - place_handle = place.get_handle() - self.placemap[val] = place_handle + place = self.find_or_create_place(val) + place_handle = place.get_handle() + place.set_title(matches[2]) event.set_place_handle(place_handle) self.ignore_sub_junk(level+1) elif matches[1] == "TYPE": @@ -1356,14 +1385,9 @@ class GedcomParser: event.add_source_reference(self.handle_source(matches,level+1)) elif matches[1] == "PLAC": val = matches[2] - if self.placemap.has_key(val): - place_handle = self.placemap[val] - else: - place = RelLib.Place() - place.set_title(matches[2]) - self.db.add_place(place, self.trans) - place_handle = place.get_handle() - self.placemap[val] = place_handle + place = self.find_or_create_place(val) + place_handle = place.get_handle() + place.set_title(matches[2]) event.set_place_handle(place_handle) self.ignore_sub_junk(level+1) elif matches[1] == 'OFFI': @@ -1722,13 +1746,13 @@ class GedcomParser: if matches[2] and matches[2][0] != "@": self.localref = self.localref + 1 ref = "gsr%d" % self.localref - s = self.db.find_source(ref,self.smap, self.trans) + s = self.find_or_create_source(ref) source_ref.set_base_handle(s.get_handle()) s.set_title('Imported Source #%d' % self.localref) s.set_note(matches[2] + self.parse_continue_data(level)) self.ignore_sub_junk(level+1) else: - source_ref.set_base_handle(self.db.find_source(matches[2],self.smap,self.trans).get_handle()) + source_ref.set_base_handle(self.find_or_create_source(matches[2][1:-1])) self.parse_source_reference(source_ref,level) return source_ref @@ -1761,7 +1785,7 @@ class GedcomParser: self.db.remove_person_handle(pid,self.trans) person.set_handle(new_key) person.set_gramps_id(new_key) - self.db.add_person_as(person,self.trans) + self.db.add_person(person,self.trans) # give up trying to use the refn as a key else: pass diff --git a/gramps2/src/ReadXML.py b/gramps2/src/ReadXML.py index fe1fbd194..bc60b947d 100644 --- a/gramps2/src/ReadXML.py +++ b/gramps2/src/ReadXML.py @@ -422,7 +422,7 @@ class GrampsParser: intid = Utils.create_id() person.set_handle(intid) person.set_gramps_id(gramps_id) - self.db.add_person_as(person,self.trans) + self.db.add_person(person,self.trans) self.gid2id[gramps_id] = intid return person @@ -478,15 +478,13 @@ class GrampsParser: def start_sealed_to(self,attrs): id = self.map_gid(attrs['ref']) - self.ord.set_family_handle(self.db.find_family_no_map(id,self.trans)) + self.ord.set_family_handle(self.db.find_family_from_handle(id,self.trans)) def start_place(self,attrs): - self.placeobj = self.db.find_place_no_conflicts(attrs['ref'], - self.lmap, self.trans) - + self.placeobj = self.db.find_place_from_handle(attrs['ref'],self.trans) + def start_placeobj(self,attrs): - self.placeobj = self.db.find_place_no_conflicts(attrs['id'], - self.lmap,self.trans) + self.placeobj = self.db.find_place_from_handle(attrs['id'],self.trans) title = attrs['title'] if title == "": title = attrs['id'] @@ -637,18 +635,18 @@ class GrampsParser: if self.callback != None and self.count % self.increment == 0: self.callback(float(self.count)/float(self.entries)) self.count = self.count + 1 - self.family = self.db.find_family_no_conflicts(attrs["id"], - self.fmap,self.trans) + self.family = self.db.find_family_from_handle(attrs["id"],self.trans) + if attrs.has_key("type"): - self.family.set_relationship(_FAMILY_TRANS.get(attrs["type"],const.FAMILY_UNKNOWN)) + self.family.set_relationship(_FAMILY_TRANS.get(attrs["type"], + const.FAMILY_UNKNOWN)) if attrs.has_key("complete"): self.family.set_complete(int(attrs['complete'])) else: self.family.set_complete(0) def start_childof(self,attrs): - family = self.db.find_family_no_conflicts(attrs["ref"], - self.fmap,self.trans) + family = self.db.find_family_from_handle(attrs["ref"],self.trans) if attrs.has_key("mrel"): mrel = attrs["mrel"] else: @@ -686,8 +684,7 @@ class GrampsParser: def start_sourceref(self,attrs): self.source_ref = RelLib.SourceRef() - source = self.db.find_source_no_conflicts(attrs["ref"], - self.smap,self.trans) + source = self.db.find_source_from_handle(attrs["ref"],self.trans) if attrs.has_key("conf"): self.source_ref.confidence = int(attrs["conf"]) else: @@ -717,13 +714,13 @@ class GrampsParser: self.person.add_source_reference(self.source_ref) def start_source(self,attrs): - self.source = self.db.find_source_no_conflicts(attrs["id"], - self.smap,self.trans) + self.source = self.db.find_source_from_handle(attrs["id"],self.trans) def start_objref(self,attrs): self.objref = RelLib.MediaRef() - id = self.db.find_object_no_conflicts(attrs['ref'], - self.media_file_map,self.trans).get_handle() + obj = self.db.find_object_from_handle(attrs['ref'],self.trans) + id = obj.get_handle() + self.objref.set_reference_handle(id) if attrs.has_key('priv'): self.objref.set_privacy(int(attrs['priv'])) @@ -739,9 +736,7 @@ class GrampsParser: self.placeobj.add_media_reference(self.objref) def start_object(self,attrs): - self.object = self.db.find_object_no_conflicts(attrs['id'], - self.media_file_map, - self.trans) + self.object = self.db.find_object_from_handle(attrs['id'],self.trans) self.object.set_mime_type(attrs['mime']) self.object.set_description(attrs['description']) src = attrs["src"] diff --git a/gramps2/src/RelLib.py b/gramps2/src/RelLib.py index 56732969c..775c40c97 100644 --- a/gramps2/src/RelLib.py +++ b/gramps2/src/RelLib.py @@ -302,6 +302,7 @@ class Place(SourceNote): for loc in source.alt_loc: self.alt_loc = Location(loc) self.handle = source.handle + self.gramps_id = source.gramps_id self.urls = [] for u in source.urls: self.urls.append(Url(u)) @@ -315,15 +316,17 @@ class Place(SourceNote): self.main_loc = None self.alt_loc = [] self.handle = "" + self.gramps_id = "" self.urls = [] self.media_list = [] def serialize(self): - return (self.handle, self.title, self.long, self.lat, self.main_loc, - self.alt_loc, self.urls, self.media_list, self.source_list, self.note) + 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): - (self.handle, self.title, self.long, self.lat, self.main_loc, + (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 @@ -347,6 +350,14 @@ class Place(SourceNote): """Returns the database handle for the place object""" return self.handle + def set_gramps_id(self,gramps_id): + """Sets the GRAMPS ID for the place object""" + self.gramps_id = gramps_id + + def get_gramps_id(self): + """Returns the GRAMPS ID for the place object""" + return self.gramps_id + def set_title(self,name): """Sets the title of the place object""" self.title = name @@ -415,13 +426,14 @@ class Place(SourceNote): case city, upper case county, upper case state, upper case country""" if self.main_loc: - return [self.title,self.handle,self.main_loc.parish,self.main_loc.city, + return [self.title,self.gramps_id,self.main_loc.parish,self.main_loc.city, self.main_loc.county,self.main_loc.state,self.main_loc.country, self.title.upper(), self.main_loc.parish.upper(), self.main_loc.city.upper(), self.main_loc.county.upper(), self.main_loc.state.upper(), self.main_loc.country.upper()] else: - return [self.title,self.handle,'','','','','',self.title.upper(), '','','','',''] + return [self.title,self.gramps_id,'','','','','', + self.title.upper(), '','','','',''] #------------------------------------------------------------------------- # @@ -636,23 +648,25 @@ class MediaObject(SourceNote): self.mime = source.mime self.desc = source.desc self.handle = source.handle + self.gramps_id = source.gramps_id self.thumb = source.thumb for attr in source.attrlist: self.attrlist.append(Attribute(attr)) else: self.handle = "" + self.gramps_id = "" self.path = "" self.mime = "" self.desc = "" self.thumb = None def serialize(self): - return (self.handle, self.path, self.mime, self.desc, self.attrlist, - self.source_list, self.note) + 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.path, self.mime, self.desc, self.attrlist, - self.source_list, self.note) = data + (self.handle, self.gramps_id, self.path, self.mime, self.desc, + self.attrlist, self.source_list, self.note) = data def set_handle(self,handle): """Sets the database handle for the place object""" @@ -662,6 +676,14 @@ class MediaObject(SourceNote): """Returns the database handle for the place object""" return self.handle + def set_gramps_id(self,gramps_id): + """Sets the GRAMPS ID for the place object""" + self.gramps_id = gramps_id + + def get_gramps_id(self): + """Returns the GRAMPS ID for the place object""" + return self.gramps_id + def set_mime_type(self,type): self.mime = type @@ -1267,6 +1289,14 @@ class Person(SourceNote): """returns the database handle for the Person""" return self.handle + def set_gramps_id(self,gramps_id): + """Sets the GRAMPS ID for the place object""" + self.gramps_id = gramps_id + + def get_gramps_id(self): + """Returns the GRAMPS ID for the place object""" + return self.gramps_id + def set_nick_name(self,name): """sets the nickname for the Person""" self.nickname = name @@ -1617,6 +1647,7 @@ class Event(DataObj): self.name = source.name self.cause = source.cause self.handle = source.handle + self.gramps_id = source.gramps_id self.media_list = [MediaRef(media_id) for media_id in source.media_list] try: if source.witness: @@ -1632,7 +1663,8 @@ class Event(DataObj): self.name = "" self.cause = "" self.witness = None - self.handle = None + self.handle = "" + self.gramps_id = "" self.media_list = [] def clone(self,source): @@ -1642,6 +1674,7 @@ class Event(DataObj): 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 @@ -1655,12 +1688,12 @@ class Event(DataObj): self.witness = None def serialize(self): - return (self.handle, self.name, self.date, self.description, + 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.name, self.date, self.description, + (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 @@ -1684,6 +1717,14 @@ class Event(DataObj): """Returns the database handle for the place object""" return self.handle + def set_gramps_id(self,gramps_id): + """Sets the GRAMPS ID for the place object""" + self.gramps_id = gramps_id + + def get_gramps_id(self): + """Returns the GRAMPS ID for the place object""" + return self.gramps_id + def get_witness_list(self): return self.witness @@ -1865,6 +1906,7 @@ class Family(SourceNote): self.type = const.FAMILY_MARRIED self.event_list = [] self.handle = "" + self.gramps_id = "" self.media_list = [] self.attribute_list = [] self.lds_seal = None @@ -1872,20 +1914,16 @@ class Family(SourceNote): def serialize(self): - return (self.handle, self.father_handle, self.mother_handle, + 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) + self.complete, self.source_list, self.note) def unserialize(self, data): - (self.handle, self.father_handle, self.mother_handle, + (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 + self.complete, self.source_list, self.note) = data def set_complete(self,val): self.complete = val @@ -1924,6 +1962,14 @@ class Family(SourceNote): """returns the database handle for the Family""" return unicode(self.handle) + def set_gramps_id(self,gramps_id): + """Sets the GRAMPS ID for the place object""" + self.gramps_id = gramps_id + + def get_gramps_id(self): + """Returns the GRAMPS ID for the place object""" + return self.gramps_id + def set_relationship(self,type): """assigns a string indicating the relationship between the father and the mother""" @@ -2049,18 +2095,19 @@ class Source: self.note = Note() self.media_list = [] self.handle = "" + self.gramps_id = "" self.abbrev = "" def serialize(self): - return (self.handle,self.title,self.author,self.pubinfo, - self.note,self.media_list,self.abbrev) + 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.title,self.author,self.pubinfo, - self.note,self.media_list,self.abbrev) = 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.handle,self.author,self.title.upper(),self.author.upper()] + return [self.title,self.gramps_id,self.author,self.title.upper(),self.author.upper()] def set_handle(self,handle): """sets the gramps' ID for the Source instance""" @@ -2070,6 +2117,14 @@ class Source: """returns the gramps' ID of the Source instance""" return self.handle + def set_gramps_id(self,gramps_id): + """Sets the GRAMPS ID for the place object""" + self.gramps_id = gramps_id + + def get_gramps_id(self): + """Returns the GRAMPS ID for the place object""" + return self.gramps_id + def add_media_reference(self,media_id): """Adds a MediaObject object to the Source instance's image list""" self.media_list.append(media_id) diff --git a/gramps2/src/SelectChild.py b/gramps2/src/SelectChild.py index ffb41dbaa..6f6f69bd0 100644 --- a/gramps2/src/SelectChild.py +++ b/gramps2/src/SelectChild.py @@ -186,7 +186,7 @@ class SelectChild: slist = {} for f in self.person.get_parent_family_handle_list(): if f: - family = self.db.find_family_no_map(f[0]) + family = self.db.find_family_from_handle(f[0]) if family.get_father_handle(): slist[family.get_father_handle()] = 1 elif family.get_mother_handle(): diff --git a/gramps2/src/SourceView.py b/gramps2/src/SourceView.py index 9664e7ce4..8440e4481 100644 --- a/gramps2/src/SourceView.py +++ b/gramps2/src/SourceView.py @@ -42,6 +42,8 @@ import const from QuestionDialog import QuestionDialog +_HANDLE_COL = 5 + #------------------------------------------------------------------------- # # internationalization @@ -131,7 +133,7 @@ class SourceView: def button_press(self,obj,event): if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1: store,iter = self.selection.get_selected() - id = store.get_value(iter,1) + id = store.get_value(iter,_HANDLE_COL) source = self.parent.db.get_source_from_handle(id) EditSource.EditSource(source,self.parent.db,self.parent, self.topWindow,self.update_display) @@ -182,7 +184,7 @@ class SourceView: if not iter: return - id = store.get_value(iter,1) + id = store.get_value(iter,_HANDLE_COL) source = self.parent.db.get_source_from_handle(id) if self.is_used(source): @@ -249,7 +251,7 @@ class SourceView: def on_edit_clicked(self,obj): list_store, iter = self.selection.get_selected() if iter: - id = list_store.get_value(iter,1) + id = list_store.get_value(iter,_HANDLE_COL) source = self.parent.db.get_source_from_handle(id) EditSource.EditSource(source, self.parent.db, self.parent, self.topWindow, self.update_display) diff --git a/gramps2/src/data/gramps.schemas b/gramps2/src/data/gramps.schemas index dfa29a04c..0d885895f 100644 --- a/gramps2/src/data/gramps.schemas +++ b/gramps2/src/data/gramps.schemas @@ -138,7 +138,7 @@ /apps/gramps/preferences/oprefix gramps string - F%04d + O%04d Default media object GRAMPS ID pattern The new GRAMPS IDs for the media object are generated @@ -151,7 +151,7 @@ /apps/gramps/preferences/pprefix gramps string - F%04d + P%04d Default place GRAMPS ID pattern The new GRAMPS IDs for the place are generated according @@ -164,7 +164,7 @@ /apps/gramps/preferences/sprefix gramps string - F%04d + S%04d Default source GRAMPS ID pattern The new GRAMPS IDs for the source are generated according diff --git a/gramps2/src/gramps_main.py b/gramps2/src/gramps_main.py index d5452fecb..4a16bcee3 100755 --- a/gramps2/src/gramps_main.py +++ b/gramps2/src/gramps_main.py @@ -1427,10 +1427,7 @@ class Gramps: def new_after_edit(self,epo,trans): if epo: - if epo.person.get_handle() == "": - self.db.add_person(epo.person,trans) - else: - self.db.add_person_no_map(epo.person,epo.person.get_handle(),trans) + self.db.add_person(epo.person,trans) self.change_active_person(epo.person) self.people_view.add_to_person_list(epo.person) if self.views.get_current_page() in [FAMILY_VIEW1,FAMILY_VIEW2]: