diff --git a/src/GrampsParser.py b/src/GrampsParser.py index 89bf1cb7b..ec2bd1123 100644 --- a/src/GrampsParser.py +++ b/src/GrampsParser.py @@ -85,6 +85,8 @@ class GrampsParser: self.pmap = {} self.fmap = {} self.smap = {} + self.lmap = {} + self.MediaFileMap = {} self.callback = callback self.entries = 0 @@ -98,6 +100,87 @@ class GrampsParser: self.func_index = 0 self.func = None + self.func_map = { + "address" : (self.start_address, self.stop_address), + "addresses" : (None,None), + "childlist" : (None,None), + "aka" : (self.start_name, self.stop_aka), + "attribute" : (self.start_attribute, self.stop_attribute), + "attr_type" : (None,self.stop_attr_type), + "attr_value" : (None,self.stop_attr_value), + "bookmark" : (self.start_bmark, None), + "witness" : (self.start_witness,self.stop_witness), + "bookmarks" : (None, None), + "child" : (self.start_child,None), + "childof" : (self.start_childof,None), + "city" : (None, self.stop_city), + "country" : (None, self.stop_country), + "created" : (self.start_created, None), + "database" : (None, None), + "date" : (None, self.stop_date), + "cause" : (None, self.stop_cause), + "description": (None, self.stop_description), + "event" : (self.start_event, self.stop_event), + "families" : (None, self.stop_families), + "family" : (self.start_family, None), + "father" : (self.start_father, None), + "first" : (None, self.stop_first), + "gender" : (None, self.stop_gender), + "header" : (None, None), + "last" : (self.start_last, self.stop_last), + "mother" : (self.start_mother,None), + "name" : (self.start_name, self.stop_name), + "nick" : (None, self.stop_nick), + "note" : (self.start_note, self.stop_note), + "p" : (None, self.stop_ptag), + "parentin" : (self.start_parentin,None), + "people" : (self.start_people, self.stop_people), + "person" : (self.start_person, self.stop_person), + "img" : (self.start_photo, self.stop_photo), + "objref" : (self.start_objref, self.stop_objref), + "object" : (self.start_object, self.stop_object), + "place" : (self.start_place, self.stop_place), + "dateval" : (self.start_dateval, None), + "daterange" : (self.start_daterange, None), + "datestr" : (self.start_datestr, None), + "places" : (None, self.stop_places), + "placeobj" : (self.start_placeobj,self.stop_placeobj), + "location" : (self.start_location,None), + "lds_ord" : (self.start_lds_ord, self.stop_lds_ord), + "temple" : (self.start_temple, None), + "status" : (self.start_status, None), + "sealed_to" : (self.start_sealed_to, None), + "coord" : (self.start_coord,None), + "pos" : (self.start_pos, None), + "postal" : (None, self.stop_postal), + "researcher" : (None, self.stop_research), + "resname" : (None, self.stop_resname ), + "resaddr" : (None, self.stop_resaddr ), + "rescity" : (None, self.stop_rescity ), + "resstate" : (None, self.stop_resstate ), + "rescountry" : (None, self.stop_rescountry), + "respostal" : (None, self.stop_respostal), + "resphone" : (None, self.stop_resphone), + "resemail" : (None, self.stop_resemail), + "sauthor" : (None, self.stop_sauthor), + "scallno" : (None, self.stop_scallno), + "scomments" : (None, self.stop_scomments), + "sdate" : (None,self.stop_sdate), + "source" : (self.start_source, self.stop_source), + "sourceref" : (self.start_sourceref, self.stop_sourceref), + "sources" : (None, None), + "spage" : (None, self.stop_spage), + "spubinfo" : (None, self.stop_spubinfo), + "state" : (None, self.stop_state), + "stext" : (None, self.stop_stext), + "stitle" : (None, self.stop_stitle), + "street" : (None, self.stop_street), + "suffix" : (None, self.stop_suffix), + "title" : (None, self.stop_title), + "uid" : (None, self.stop_uid), + "url" : (self.start_url, None) + } + def parse(self,file): p = xml.parsers.expat.ParserCreate() p.StartElementHandler = self.startElement @@ -108,7 +191,7 @@ class GrampsParser: self.db.setResearcher(self.owner) if self.tempDefault != None: id = self.tempDefault - if self.db.personMap.has_key(id): + if self.db.personMap.has_key(id) and self.db.getDefaultPerson() == None: person = self.db.personMap[id] self.db.setDefaultPerson(person) @@ -741,86 +824,6 @@ class GrampsParser: self.name.setType("Also Known As") self.name = None - func_map = { - "address" : (start_address, stop_address), - "addresses" : (None,None), - "childlist" : (None,None), - "aka" : (start_name, stop_aka), - "attribute" : (start_attribute, stop_attribute), - "attr_type" : (None,stop_attr_type), - "attr_value" : (None,stop_attr_value), - "bookmark" : (start_bmark, None), - "witness" : (start_witness,stop_witness), - "bookmarks" : (None, None), - "child" : (start_child,None), - "childof" : (start_childof,None), - "city" : (None, stop_city), - "country" : (None, stop_country), - "created" : (start_created, None), - "database" : (None, None), - "date" : (None, stop_date), - "cause" : (None, stop_cause), - "description": (None, stop_description), - "event" : (start_event, stop_event), - "families" : (None, stop_families), - "family" : (start_family, None), - "father" : (start_father, None), - "first" : (None, stop_first), - "gender" : (None, stop_gender), - "header" : (None, None), - "last" : (start_last, stop_last), - "mother" : (start_mother,None), - "name" : (start_name, stop_name), - "nick" : (None, stop_nick), - "note" : (start_note, stop_note), - "p" : (None, stop_ptag), - "parentin" : (start_parentin,None), - "people" : (start_people, stop_people), - "person" : (start_person, stop_person), - "img" : (start_photo, stop_photo), - "objref" : (start_objref, stop_objref), - "object" : (start_object, stop_object), - "place" : (start_place, stop_place), - "dateval" : (start_dateval, None), - "daterange" : (start_daterange, None), - "datestr" : (start_datestr, None), - "places" : (None, stop_places), - "placeobj" : (start_placeobj,stop_placeobj), - "location" : (start_location,None), - "lds_ord" : (start_lds_ord, stop_lds_ord), - "temple" : (start_temple, None), - "status" : (start_status, None), - "sealed_to" : (start_sealed_to, None), - "coord" : (start_coord,None), - "pos" : (start_pos, None), - "postal" : (None, stop_postal), - "researcher" : (None, stop_research), - "resname" : (None, stop_resname ), - "resaddr" : (None, stop_resaddr ), - "rescity" : (None, stop_rescity ), - "resstate" : (None, stop_resstate ), - "rescountry" : (None, stop_rescountry), - "respostal" : (None, stop_respostal), - "resphone" : (None, stop_resphone), - "resemail" : (None, stop_resemail), - "sauthor" : (None, stop_sauthor), - "scallno" : (None, stop_scallno), - "scomments" : (None, stop_scomments), - "sdate" : (None,stop_sdate), - "source" : (start_source, stop_source), - "sourceref" : (start_sourceref, stop_sourceref), - "sources" : (None, None), - "spage" : (None, stop_spage), - "spubinfo" : (None, stop_spubinfo), - "state" : (None, stop_state), - "stext" : (None, stop_stext), - "stitle" : (None, stop_stitle), - "street" : (None, stop_street), - "suffix" : (None, stop_suffix), - "title" : (None, stop_title), - "uid" : (None, stop_uid), - "url" : (start_url, None) - } def startElement(self,tag,attrs): @@ -829,17 +832,17 @@ class GrampsParser: self.tlist = [] try: - f,self.func = GrampsParser.func_map[tag] + f,self.func = self.func_map[tag] if f: - f(self,attrs) + f(attrs) except KeyError: - GrampsParser.func_map[tag] = (None,None) + self.func_map[tag] = (None,None) self.func = None def endElement(self,tag): if self.func: - self.func(self,string.join(self.tlist,'')) + self.func(string.join(self.tlist,'')) self.func_index = self.func_index - 1 self.func,self.tlist = self.func_list[self.func_index] @@ -854,39 +857,56 @@ class GrampsParser: #------------------------------------------------------------------------- class GrampsImportParser(GrampsParser): + def __init__(self,database,callback,base): + GrampsParser.__init__(self,database,callback,base) + + self.func_map["bookmark"] = (self.start_bmark, None) + self.func_map["child"] = (self.start_child,None) + self.func_map["family"] = (self.start_family, None) + self.func_map["father"] = (self.start_father, None) + self.func_map["mother"] = (self.start_mother,None) + self.func_map["people"] = (self.start_people, self.stop_people) + self.func_map["person"] = (self.start_person, self.stop_person) + self.func_map["objref"] = (self.start_objref, self.stop_objref) + self.func_map["object"] = (self.start_object, self.stop_object) + self.func_map["place"] = (self.start_place, self.stop_place) + self.func_map["placeobj"] = (self.start_placeobj,self.stop_placeobj) + self.func_map["source"] = (self.start_source, self.stop_source) + self.func_map["sourceref"]= (self.start_sourceref, self.stop_sourceref) + def start_bmark(self,attrs): - person = self.db.findPerson("x%s" % attrs["ref"],self.pmap) + person = self.db.findPersonNoConflicts(attrs["ref"],self.pmap) self.db.bookmarks.append(person) def start_person(self,attrs): if self.callback != None and self.count % self.increment == 0: self.callback(float(self.count)/float(self.entries)) self.count = self.count + 1 - self.person = self.db.findPerson("x%s" % attrs["id"],self.pmap) + self.person = self.db.findPersonNoConflicts(attrs["id"],self.pmap) def start_father(self,attrs): - father = self.db.findPerson("x%s" % attrs["ref"],self.pmap) + father = self.db.findPersonNoConflicts(attrs["ref"],self.pmap) self.family.setFather(father) def start_mother(self,attrs): - mother = self.db.findPerson("x%s" % attrs["ref"],self.pmap) + mother = self.db.findPersonNoConflicts(attrs["ref"],self.pmap) self.family.setMother(mother) def start_child(self,attrs): - child = self.db.findPerson("x%s" % attrs["ref"],self.pmap) + child = self.db.findPersonNoConflicts(attrs["ref"],self.pmap) self.family.addChild(child) def start_family(self,attrs): 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.findFamily(attrs["id"],self.fmap) + self.family = self.db.findFamilyNoConflicts(attrs["id"],self.fmap) if attrs.has_key("type"): self.family.setRelationship(attrs["type"]) def start_sourceref(self,attrs): self.source_ref = RelLib.SourceRef() - self.source = self.db.findSource(attrs["ref"],self.smap) + self.source = self.db.findSourceNoConflicts(attrs["ref"],self.smap) self.source_ref.setBase(self.source) if self.address: self.address.addSourceRef(self.source_ref) @@ -902,7 +922,77 @@ class GrampsImportParser(GrampsParser): print "Sorry, I'm lost" def start_source(self,attrs): - self.source = self.db.findSource(attrs["id"],self.smap) + self.source = self.db.findSourceNoConflicts(attrs["id"],self.smap) + + def start_sourceref(self,attrs): + self.source_ref = RelLib.SourceRef() + source = self.db.findSourceNoConflicts(attrs["ref"],self.smap) + if attrs.has_key("conf"): + self.source_ref.confidence = int(attrs["conf"]) + else: + self.source_ref.confidence = self.conf + self.source_ref.setBase(source) + if self.photo: + self.photo.addSourceRef(self.source_ref) + elif self.ord: + self.ord.addSourceRef(self.source_ref) + elif self.object: + self.object.addSourceRef(self.source_ref) + elif self.event: + self.event.addSourceRef(self.source_ref) + elif self.address: + self.address.addSourceRef(self.source_ref) + elif self.name: + self.name.addSourceRef(self.source_ref) + elif self.attribute: + self.attribute.addSourceRef(self.source_ref) + elif self.placeobj: + self.placeobj.addSourceRef(self.source_ref) + + def start_place(self,attrs): + if attrs.has_key('ref'): + self.placeobj = self.db.findPlaceNoConflicts(attrs['ref'],self.lmap) + else: + self.placeobj = None + + def start_placeobj(self,attrs): + self.placeobj = self.db.findPlaceNoConflicts(attrs['id'],self.lmap) + title = attrs['title'] + if title == "": + title = attrs['id'] + self.placeobj.set_title(title) + self.locations = 0 + if self.num_places > 0: + if self.callback != None and self.count % self.increment == 0: + self.callback(float(self.count)/float(self.entries)) + self.count = self.count + 1 + + def start_objref(self,attrs): + self.objref = RelLib.ObjectRef() + self.objref.setReference(self.db.findObjectNoConflicts(attrs['ref'],self.MediaFileMap)) + if attrs.has_key('priv'): + self.objref.setPrivacy(int(attrs['priv'])) + if self.family: + self.family.addPhoto(self.objref) + elif self.source: + self.source.addPhoto(self.objref) + elif self.person: + self.person.addPhoto(self.objref) + elif self.placeobj: + self.placeobj.addPhoto(self.objref) + + def start_object(self,attrs): + self.object = self.db.findObjectNoConflicts(attrs['id'],self.MediaFileMap) + self.object.setMimeType(attrs['mime']) + self.object.setDescription(attrs['description']) + src = attrs["src"] + if src: + if src[0] != '/': + self.object.setPath("%s/%s" % (self.base,src)) + self.object.setLocal(1) + else: + self.object.setPath(src) + self.object.setLocal(0) def append_value(orig,val): diff --git a/src/GrampsXML.py b/src/GrampsXML.py index 361216540..ed0c7d956 100644 --- a/src/GrampsXML.py +++ b/src/GrampsXML.py @@ -38,7 +38,7 @@ class GrampsXML(RelLib.GrampsDB): WriteXML.exportData(self,name,callback) def load(self,name,callback): - ReadXML.importData(self,name,callback) + ReadXML.loadData(self,name,callback) self.personTable = {} for key in self.personMap.keys(): person = self.personMap[key] diff --git a/src/RelLib.py b/src/RelLib.py index 1fdc19652..794681930 100644 --- a/src/RelLib.py +++ b/src/RelLib.py @@ -2189,7 +2189,8 @@ class GrampsDB(Persistent): def addPersonAs(self,person): self.personMap[person.getId()] = person self.personTable[person.getId()] = person.getDisplayInfo() - + return person.getId() + def addPerson(self,person): """adds a Person to the database, assigning a gramps' ID""" index = self.iprefix % self.pmapIndex @@ -2220,16 +2221,6 @@ class GrampsDB(Persistent): self.personTable[map[idVal]] = person.getDisplayInfo() return person - def addPersonNoMap(self,person,id): - """adds a Person to the database if the gramps' ID is known""" - - id = str(id) - person.setId(id) - self.personMap[id] = person - self.pmapIndex = self.pmapIndex+1 - self.personTable[id] = person.getDisplayInfo() - return id - def findPersonNoMap(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.""" @@ -2243,6 +2234,16 @@ class GrampsDB(Persistent): self.personTable[val] = person.getDisplayInfo() return person + def addPersonNoMap(self,person,id): + """adds a Person to the database if the gramps' ID is known""" + + id = str(id) + person.setId(id) + self.personMap[id] = person + self.pmapIndex = self.pmapIndex+1 + self.personTable[id] = person.getDisplayInfo() + return id + def addSource(self,source): """adds a Source instance to the database, assigning it a gramps' ID number""" @@ -2257,6 +2258,14 @@ class GrampsDB(Persistent): self.smapIndex = self.smapIndex + 1 return index + def addSourceNoMap(self,source,index): + """adds a Source to the database if the gramps' ID is known""" + source.setId(index) + self.sourceMap[index] = source + self.smapIndex = self.smapIndex + 1 + self.sourceTable[index] = source.getDisplayInfo() + return index + def findSource(self,idVal,map): """finds a Source in the database using the idVal and map variables to translate between the external ID and gramps' @@ -2271,17 +2280,9 @@ class GrampsDB(Persistent): else: source = Source() map[idVal] = self.addSource(source) - self.sourceTable[map[idVal]] = source.getDisplayInfo() + self.sourceTable[map[idVal]] = source.getDisplayInfo() return source - def addSourceNoMap(self,source,index): - """adds a Source to the database if the gramps' ID is known""" - source.setId(index) - self.sourceMap[index] = source - self.smapIndex = self.smapIndex + 1 - self.sourceTable[index] = source.getDisplayInfo() - return index - def findSourceNoMap(self,val): """finds a Source in the database from the passed gramps' ID. If no such Source exists, a new Source is added to the database.""" @@ -2327,6 +2328,26 @@ class GrampsDB(Persistent): map[idVal] = self.addObject(object) return object + def findObjectNoConflicts(self,idVal,map): + """finds an Object in the database using the idVal and map + variables to translate between the external ID and gramps' + internal ID. If no such Object exists, a new Object instance + is created. + + idVal - external ID number + map - map build by findObject of external to gramp's IDs""" + + idVal = str(idVal) + if map.has_key(idVal): + object = self.objectMap[map[idVal]] + else: + object = Photo() + if self.objectMap.has_key(idVal): + map[idVal] = self.addObject(object) + else: + map[idVal] = self.addObjectNoMap(object,idVal) + return object + def addObjectNoMap(self,object,index): """adds an Object to the database if the gramps' ID is known""" index = str(index) @@ -2392,6 +2413,27 @@ class GrampsDB(Persistent): map[idVal] = self.addPlace(place) return place + def findPlaceNoConflicts(self,idVal,map): + """finds a Place in the database using the idVal and map + variables to translate between the external ID and gramps' + internal ID. If no such Place exists, a new Place instance + is created. + + idVal - external ID number + map - map build by findPlace of external to gramp's IDs""" + + idVal = str(idVal) + if map.has_key(idVal): + place = self.placeMap[map[idVal]] + else: + place = Place() + if self.placeMap.has_key(idVal): + map[idVal] = self.addPlace(place) + else: + place.setid(idVal) + map[idVal] = self.addPlaceAs(place) + return place + def addPlaceNoMap(self,place,index): """adds a Place to the database if the gramps' ID is known""" @@ -2496,5 +2538,61 @@ class GrampsDB(Persistent): if self.familyMap.has_key(family.getId()): del self.familyMap[family.getId()] - + def findPersonNoConflicts(self,idVal,map): + """finds a Person in the database using the idVal and map + variables to translate between the external ID and gramps' + internal ID. If no such Person exists, a new Person instance + is created. + + idVal - external ID number + map - map build by findPerson of external to gramp's IDs""" + + if map.has_key(idVal): + person = self.personMap[map[idVal]] + else: + person = Person() + if self.personMap.has_key(idVal): + map[idVal] = self.addPerson(person) + else: + person.setId(idVal) + map[idVal] = self.addPersonAs(person) + return person + + def findFamilyNoConflicts(self,idVal,map): + """finds a Family in the database using the idVal and map + variables to translate between the external ID and gramps' + internal ID. If no such Family exists, a new Family instance + is created. + + idVal - external ID number + map - map build by findFamily of external to gramp's IDs""" + + if map.has_key(idVal): + family = self.familyMap[map[idVal]] + else: + if self.familyMap.has_key(idVal): + family = self.newFamily() + else: + family = self.newFamilyNoMap(idVal) + map[idVal] = family.getId() + return family + + def findSourceNoConflicts(self,idVal,map): + """finds a Source in the database using the idVal and map + variables to translate between the external ID and gramps' + internal ID. If no such Source exists, a new Source instance + is created. + + idVal - external ID number + map - map build by findSource of external to gramp's IDs""" + + if map.has_key(idVal): + source = self.sourceMap[map[idVal]] + else: + source = Source() + if self.sourceMap.has_key(idVal): + map[idVal] = self.addSource(source) + else: + map[idVal] = self.addSource(source,idVal) + return source diff --git a/src/gramps_main.py b/src/gramps_main.py index 9c0979f9c..875619838 100755 --- a/src/gramps_main.py +++ b/src/gramps_main.py @@ -601,6 +601,11 @@ class Gramps: self.model2page = {} self.model_used = {} + self.pl_page = [ + ListModel.ListModel(self.pl_other, self.pl_titles, self.row_changed, + self.alpha_event, _sel_mode), + ] + self.person_tree = self.pl_page[-1] self.person_list = self.pl_page[-1].tree self.person_model = self.pl_page[-1].model @@ -641,7 +646,19 @@ class Gramps: def tool_callback(self,val): if val: Utils.modified() + for i in range(0,len(self.tab_list)): + self.ptabs.remove_page(0) + self.ptabs.set_show_tabs(0) + + self.pl_page = [ + ListModel.ListModel(self.pl_other, self.pl_titles, self.row_changed, + self.alpha_event, _sel_mode), + ] + + self.tab_list = [] self.alpha_page = {} + self.model2page = {} + self.model_used = {} self.full_update() def full_update(self): @@ -1411,13 +1428,19 @@ class Gramps: self.status_text("") def complete_rebuild(self): + self.topWindow.set_resizable(gtk.FALSE) + for i in range(0,len(self.tab_list)): + self.ptabs.remove_page(0) + self.ptabs.set_show_tabs(0) self.id2col = {} self.model_used = {} - #self.alpha_page = {} + self.model2page = {} + self.alpha_page = {} self.tab_list = [] self.apply_filter() self.goto_active_person() self.modify_statusbar() + self.topWindow.set_resizable(gtk.TRUE) def apply_filter(self,current_model=None): @@ -1541,7 +1564,6 @@ class Gramps: """Call the import plugin""" plugin_function(self.db,self.active_person,self.tool_callback) self.topWindow.set_title("%s - GRAMPS" % self.db.getSavePath()) - self.full_update() def on_preferences_activate(self,obj): GrampsCfg.display_preferences_box(self.db) diff --git a/src/plugins/ReadNative.py b/src/plugins/ReadNative.py index 88db60f12..09a245ba1 100644 --- a/src/plugins/ReadNative.py +++ b/src/plugins/ReadNative.py @@ -46,6 +46,7 @@ class ReadNative: self.top = gtk.FileSelection("%s - GRAMPS" % _("Import from GRAMPS")) self.top.hide_fileop_buttons() + #self.top.set_directory_entry(1) self.top.ok_button.connect('clicked', self.on_ok_clicked) self.top.cancel_button.connect('clicked', self.close_window) self.top.show() @@ -83,9 +84,11 @@ class ReadNative: self.callback(1) def progress(self,val): - self.progress_bar.set_value(val*100.0) - while gtk.events_pending(): - gtk.mainiteration() + pass + +# self.progress_bar.set_percentage(val) +# while gtk.events_pending(): +# gtk.mainiteration() #------------------------------------------------------------------------ #