Remove getting values from maps. Use the key lists instead

svn: r1027
This commit is contained in:
Don Allingham 2002-06-14 04:30:20 +00:00
parent 7d8b6bbb16
commit aed5a10637
7 changed files with 53 additions and 44 deletions

View File

@ -131,12 +131,12 @@ class ChooseParents:
self.mother_list.append(["Unknown","",""]) self.mother_list.append(["Unknown","",""])
self.mother_list.set_row_data(0,None) self.mother_list.set_row_data(0,None)
people = self.db.getPersonMap().values()
father_index = 1 father_index = 1
mother_index = 1 mother_index = 1
fsel = 0 fsel = 0
msel = 0 msel = 0
for person in people: for key in self.db.getPersonKeys():
person = self.db.getPerson(key)
if person == self.person: if person == self.person:
continue continue
if person.getGender() == RelLib.Person.unknown: if person.getGender() == RelLib.Person.unknown:
@ -180,7 +180,6 @@ class ChooseParents:
self.mlabel.set_label(_("Mother")) self.mlabel.set_label(_("Mother"))
self.flabel.set_label(_("Father")) self.flabel.set_label(_("Father"))
def parent_relation_changed(self,obj): def parent_relation_changed(self,obj):
self.old_type = self.type self.old_type = self.type
self.type = const.save_frel(obj.get_text()) self.type = const.save_frel(obj.get_text())

View File

@ -324,7 +324,8 @@ class EditPlace:
def display_references(self): def display_references(self):
pevent = [] pevent = []
fevent = [] fevent = []
for p in self.db.getPersonMap().values(): for key in self.db.getPersonKeys():
p = self.db.getPerson(key)
for event in [p.getBirth(), p.getDeath()] + p.getEventList(): for event in [p.getBirth(), p.getDeath()] + p.getEventList():
if event.getPlace() == self.place: if event.getPlace() == self.place:
pevent.append((p,event)) pevent.append((p,event))
@ -403,7 +404,8 @@ class DeletePlaceQuery:
del self.db.getPlaceMap()[self.place.getId()] del self.db.getPlaceMap()[self.place.getId()]
Utils.modified() Utils.modified()
for p in self.db.getPersonMap().values(): for key in self.db.getPersonKeys():
p = self.db.getPerson(key)
for event in [p.getBirth(), p.getDeath()] + p.getEventList(): for event in [p.getBirth(), p.getDeath()] + p.getEventList():
if event.getPlace() == self.place: if event.getPlace() == self.place:
event.setPlace(None) event.setPlace(None)

View File

@ -103,12 +103,14 @@ class EditSource:
f_event_list = [] f_event_list = []
f_attr_list = [] f_attr_list = []
p_list = [] p_list = []
for p in self.db.getPlaceMap().values(): for key in self.db.getPlaceKeys():
p = self.db.getPlace(key)
name = p.get_title() name = p.get_title()
for sref in p.getSourceRefList(): for sref in p.getSourceRefList():
if sref.getBase() == self.source: if sref.getBase() == self.source:
p_list.append(name) p_list.append(name)
for p in self.db.getPersonMap().values(): for key in self.db.getPersonKeys():
p = self.db.getPerson(key)
name = GrampsCfg.nameof(p) name = GrampsCfg.nameof(p)
for v in p.getEventList() + [p.getBirth(), p.getDeath()]: for v in p.getEventList() + [p.getBirth(), p.getDeath()]:
for sref in v.getSourceRefList(): for sref in v.getSourceRefList():
@ -235,7 +237,8 @@ class DelSrcQuery:
del self.db.getSourceMap()[self.source.getId()] del self.db.getSourceMap()[self.source.getId()]
Utils.modified() Utils.modified()
for p in self.db.getPersonMap().values(): for key in self.db.getPersonKeys():
p = self.getPerson(key)
for v in p.getEventList() + [p.getBirth(), p.getDeath()]: for v in p.getEventList() + [p.getBirth(), p.getDeath()]:
self.delete_source(v) self.delete_source(v)
@ -258,8 +261,8 @@ class DelSrcQuery:
for p in self.db.getObjectMap().values(): for p in self.db.getObjectMap().values():
self.delete_source(p) self.delete_source(p)
for p in self.db.getPlaceMap().values(): for key in self.db.getPlaceKeys():
self.delete_source(p) self.delete_source(self.db.getPlace(key))
self.update(0) self.update(0)

View File

@ -632,7 +632,8 @@ class GlobalMediaProperties:
index = 0 index = 0
ref = self.change_dialog.get_widget("refinfo") ref = self.change_dialog.get_widget("refinfo")
ref.connect('button-press-event',self.button_press) ref.connect('button-press-event',self.button_press)
for p in self.db.getPersonMap().values(): for key in self.db.getPersonKeys():
p = self.db.getPerson(key)
for o in p.getPhotoList(): for o in p.getPhotoList():
if o.getReference() == self.object: if o.getReference() == self.object:
ref.append([_("Person"),p.getId(),GrampsCfg.nameof(p)]) ref.append([_("Person"),p.getId(),GrampsCfg.nameof(p)])
@ -644,13 +645,15 @@ class GlobalMediaProperties:
ref.append([_("Family"),p.getId(),Utils.family_name(p)]) ref.append([_("Family"),p.getId(),Utils.family_name(p)])
ref.set_row_data(index,(Marriage.Marriage,p,self.db)) ref.set_row_data(index,(Marriage.Marriage,p,self.db))
index = index + 1 index = index + 1
for p in self.db.getSourceMap().values(): for key in self.db.getSourceKeys():
p = self.db.getSource(key)
for o in p.getPhotoList(): for o in p.getPhotoList():
if o.getReference() == self.object: if o.getReference() == self.object:
ref.append([_("Source"),p.getId(),p.getTitle()]) ref.append([_("Source"),p.getId(),p.getTitle()])
ref.set_row_data(index,(EditSource.EditSource,p,self.db)) ref.set_row_data(index,(EditSource.EditSource,p,self.db))
index = index + 1 index = index + 1
for p in self.db.getPlaceMap().values(): for key in self.db.getPlaceKeys():
p = self.db.getPlace(key)
for o in p.getPhotoList(): for o in p.getPhotoList():
if o.getReference() == self.object: if o.getReference() == self.object:
ref.append([_("Place"),p.getId(),p.get_title()]) ref.append([_("Place"),p.getId(),p.get_title()])

View File

@ -2024,7 +2024,8 @@ class GrampsDB(Persistent):
"""returns a list of all Attribute types assocated with Person """returns a list of all Attribute types assocated with Person
instances in the database""" instances in the database"""
map = {} map = {}
for person in self.personMap.values(): for key in self.personTable.keys():
person = self.personMap[key]
for attr in person.getAttributeList(): for attr in person.getAttributeList():
map[attr.getType()] = 1 map[attr.getType()] = 1
return map.keys() return map.keys()
@ -2290,7 +2291,10 @@ class GrampsDB(Persistent):
def getPlaceKeys(self): def getPlaceKeys(self):
return self.placeTable.keys() return self.placeTable.keys()
def getPlace(self,key):
return self.placeMap[key]
def getPlaceDisplay(self,key): def getPlaceDisplay(self,key):
return self.placeTable[key] return self.placeTable[key]
@ -2300,6 +2304,9 @@ class GrampsDB(Persistent):
def getSourceDisplay(self,key): def getSourceDisplay(self,key):
return self.sourceTable[key] return self.sourceTable[key]
def getSource(self,key):
return self.sourceMap[key]
def buildSourceDisplay(self,nkey,okey=None): def buildSourceDisplay(self,nkey,okey=None):
if nkey != okey and okey != None: if nkey != okey and okey != None:
del self.sourceTable[okey] del self.sourceTable[okey]

View File

@ -72,15 +72,9 @@ def exportData(database, filename, callback):
g.write(filename) g.write(filename)
except: except:
from gnome.ui import GnomeErrorDialog from gnome.ui import GnomeErrorDialog
import traceback import DisplayTrace
traceback.print_exc()
fname = os.path.expanduser("~/gramps.err")
errfile = open(fname,"w")
traceback.print_exc(file=errfile)
errfile.close()
DisplayTrace.DisplayTrace()
GnomeErrorDialog(_("Failure writing %s, original file restored") % filename) GnomeErrorDialog(_("Failure writing %s, original file restored") % filename)
shutil.copy(filename + ".bak", filename) shutil.copy(filename + ".bak", filename)
@ -156,17 +150,14 @@ class XmlWriter:
date = string.split(time.ctime(time.time())) date = string.split(time.ctime(time.time()))
owner = self.db.getResearcher() owner = self.db.getResearcher()
personList = self.db.getPersonMap().values()
#personList.sort(sortById)
familyList = self.db.getFamilyMap().values() familyList = self.db.getFamilyMap().values()
#familyList.sort(sortById) person_len = len(self.db.getPersonKeys())
sourceList = self.db.getSourceMap().values() family_len = len(familyList)
placeList = self.db.getPlaceMap().values() source_len = len(self.db.getSourceKeys())
#placeList.sort(sortById) place_len = len(self.db.getPlaceKeys())
objList = self.db.getObjectMap().values() objList = self.db.getObjectMap().values()
#objList.sort(sortById)
total = len(personList) + len(familyList) + len(placeList) + len(sourceList) total = person_len + family_len + place_len + source_len
self.g.write('<?xml version="1.0" encoding="iso-8859-1"?>\n') self.g.write('<?xml version="1.0" encoding="iso-8859-1"?>\n')
self.g.write('<!DOCTYPE database SYSTEM "gramps.dtd" []>\n') self.g.write('<!DOCTYPE database SYSTEM "gramps.dtd" []>\n')
@ -174,10 +165,10 @@ class XmlWriter:
self.g.write(" <header>\n") self.g.write(" <header>\n")
self.g.write(" <created date=\"%s %s %s\"" % (date[2],string.upper(date[1]),date[4])) self.g.write(" <created date=\"%s %s %s\"" % (date[2],string.upper(date[1]),date[4]))
self.g.write(" version=\"" + const.version + "\"") self.g.write(" version=\"" + const.version + "\"")
self.g.write(" people=\"%d\"" % (len(self.db.getPersonMap().values()))) self.g.write(" people=\"%d\"" % person_len)
self.g.write(" families=\"%d\"" % len(self.db.getFamilyMap().values())) self.g.write(" families=\"%d\"" % family_len)
self.g.write(" sources=\"%d\"" % len(self.db.getSourceMap().values())) self.g.write(" sources=\"%d\"" % source_len)
self.g.write(" places=\"%d\"/>\n" % len(self.db.getPlaceMap().values())) self.g.write(" places=\"%d\"/>\n" % place_len)
self.g.write(" <researcher>\n") self.g.write(" <researcher>\n")
self.write_line("resname",owner.getName(),3) self.write_line("resname",owner.getName(),3)
self.write_line("resaddr",owner.getAddress(),3) self.write_line("resaddr",owner.getAddress(),3)
@ -190,7 +181,7 @@ class XmlWriter:
self.g.write(" </researcher>\n") self.g.write(" </researcher>\n")
self.g.write(" </header>\n") self.g.write(" </header>\n")
if len(personList) > 0: if person_len > 0:
self.g.write(" <people") self.g.write(" <people")
person = self.db.getDefaultPerson() person = self.db.getDefaultPerson()
if person: if person:
@ -200,7 +191,8 @@ class XmlWriter:
delta = max(int(total/50),1) delta = max(int(total/50),1)
count = 0 count = 0
for person in personList: for key in self.db.getPersonKeys():
person = self.db.getPerson(key)
if self.callback and count % delta == 0: if self.callback and count % delta == 0:
self.callback(float(count)/float(total)) self.callback(float(count)/float(total))
count = count + 1 count = count + 1
@ -270,7 +262,7 @@ class XmlWriter:
self.g.write(" </person>\n") self.g.write(" </person>\n")
self.g.write(" </people>\n") self.g.write(" </people>\n")
if len(familyList) > 0: if family_len > 0:
self.g.write(" <families>\n") self.g.write(" <families>\n")
for family in familyList: for family in familyList:
@ -299,9 +291,10 @@ class XmlWriter:
self.g.write(" </family>\n") self.g.write(" </family>\n")
self.g.write(" </families>\n") self.g.write(" </families>\n")
if len(sourceList) > 0: if source_len > 0:
self.g.write(" <sources>\n") self.g.write(" <sources>\n")
for source in sourceList: for key in self.db.getSourceKeys():
source = self.db.getSource(key)
if self.callback and count % delta == 0: if self.callback and count % delta == 0:
self.callback(float(count)/float(total)) self.callback(float(count)/float(total))
count = count + 1 count = count + 1
@ -316,9 +309,10 @@ class XmlWriter:
self.g.write(" </source>\n") self.g.write(" </source>\n")
self.g.write(" </sources>\n") self.g.write(" </sources>\n")
if len(placeList) > 0: if place_len > 0:
self.g.write(" <places>\n") self.g.write(" <places>\n")
for place in placeList: for key in self.db.getPlaceKeys():
place = self.db.getPlace(key)
if self.callback and count % delta == 0: if self.callback and count % delta == 0:
self.callback(float(count)/float(total)) self.callback(float(count)/float(total))
count = count + 1 count = count + 1

View File

@ -560,14 +560,15 @@ class GedcomParser:
self.parse_family_event(event,2) self.parse_family_event(event,2)
def parse_note(self,matches,obj,level,old_note): def parse_note(self,matches,obj,level,old_note):
note = old_note
if matches[2] and matches[2][0] == "@": if matches[2] and matches[2][0] == "@":
if self.nmap.has_key(matches[2]): if self.nmap.has_key(matches[2]):
self.share_note.append(obj) self.share_note.append(obj)
self.family.setNoteObj(self.nmap[matches[2]]) obj.setNoteObj(self.nmap[matches[2]])
else: else:
noteobj = Note() noteobj = Note()
self.nmap[matches[2]] = noteobj self.nmap[matches[2]] = noteobj
self.share_note.append(self.family) self.share_note.append(obj)
obj.setNoteObj(noteobj) obj.setNoteObj(noteobj)
else: else:
if old_note: if old_note: