Enhanced handling of changes

svn: r1000
This commit is contained in:
Don Allingham 2002-05-19 05:21:31 +00:00
parent 55ff500cfe
commit 8e4f5a55ac
6 changed files with 86 additions and 190 deletions

View File

@ -75,6 +75,7 @@ class EditPerson:
def __init__(self,person,db,callback=None):
"""Creates an edit window. Associates a person with the window."""
self.person = person
self.original_id = person.getId()
self.db = db
self.callback = callback
self.path = db.getSavePath()
@ -697,7 +698,7 @@ class EditPerson:
p = self.get_place(self.dplace)
if p:
event.setPlace(p)
EventEdit.EventEditor(self,pname,const.personalEvents,\
EventEdit.EventEditor(self,pname,const.personalEvents,
const.save_fevent,event,def_placename,1,
self.callback)
@ -1159,8 +1160,8 @@ class EditPerson:
Utils.modified()
self.pmap = {}
for p in self.db.getPlaceKeys():
p = db.getPlaceDisplay(key)
for key in self.db.getPlaceKeys():
p = self.db.getPlaceDisplay(key)
self.pmap[p[0]] = key
self.birth.setDate(self.bdate.get_text())

View File

@ -19,7 +19,7 @@
#
from ZODB import Persistent
from ZODB.FileStorage import FileStorage
from ZODB.dbmStorage import gdbmStorage
from ZODB.DB import DB
from BTrees.OOBTree import OOBTree
from UserDict import UserDict
@ -128,6 +128,9 @@ class GrampsZODB(GrampsDB):
self.conn = None
GrampsDB.__init__(self)
def close(self):
self.db.close()
def get_base(self):
return const.zodbFile
@ -153,25 +156,9 @@ class GrampsZODB(GrampsDB):
self.load(name,callback)
def load(self,name,callback):
import time
t = time.time()
print 'opening storage'
s = FileStorage(name)
t1 = time.time()
print t1 - t
print 'getting DB'
self.db = DB(s)
t = time.time()
print t - t1
print 'establishing connect'
self.db = DB(gdbmStorage(name,'w'))
self.conn = self.db.open()
t1 = time.time()
print t1 -t
print 'getting root'
root = self.conn.root()
t = time.time()
print t - t1
print 'family map'
need_commit = 0
if root.has_key('fm'):
self.familyMap = root['fm']
@ -179,20 +166,12 @@ class GrampsZODB(GrampsDB):
self.familyMap = OOBTree()
root['fm'] = self.familyMap
need_commit = 1
t1 = time.time()
print t1 - t
print 'person map'
if root.has_key('pm'):
self.personMap = root['pm']
else:
self.personMap = PersonMap()
root['pm'] = self.personMap
need_commit = 1
t = time.time()
print t - t1
print 'person index table'
if root.has_key('pmt'):
self.personTable = root['pmt']
else:
@ -201,10 +180,6 @@ class GrampsZODB(GrampsDB):
self.personTable[key] = person.getDisplayInfo()
root['pmt'] = self.personTable
need_commit = 1
t1 = time.time()
print t1 - t
print 'surnames'
if root.has_key('surnames'):
self.surnames = root['surnames']
else:
@ -213,20 +188,12 @@ class GrampsZODB(GrampsDB):
self.addSurname(person.getPrimaryName().getSurname())
root['surnames'] = self.surnames
need_commit = 1
t = time.time()
print t - t1
print 'source map'
if root.has_key('sm'):
self.sourceMap = root['sm']
else:
self.sourceMap = OOBTree()
root['sm'] = self.sourceMap
need_commit = 1
t1 = time.time()
print t1 - t
print 'source index table'
if root.has_key('smt'):
self.sourceTable = root['smt']
else:
@ -235,20 +202,12 @@ class GrampsZODB(GrampsDB):
self.sourceTable[key] = src.getDisplayInfo()
root['smt'] = self.sourceTable
need_commit = 1
t = time.time()
print t - t1
print 'place map'
if root.has_key('plm'):
self.placeMap = root['plm']
else:
self.placeMap = OOBTree()
root['plm'] = self.placeMap
need_commit = 1
t1 = time.time()
print t1 - t
print 'place index'
if root.has_key('plmt'):
self.placeTable = root['plmt']
else:
@ -257,35 +216,20 @@ class GrampsZODB(GrampsDB):
self.placeTable[key] = place.getDisplayInfo()
root['plmt'] = self.placeTable
need_commit = 1
t = time.time()
print t - t1
print 'default person'
if root.has_key('default'):
self.default = root['default']
else:
self.default = None
root['default'] = self.default
need_commit = 1
t1 = time.time()
print t1 - t
print 'bookmarks'
if root.has_key('bookmarks'):
self.bookmarks = root['bookmarks']
else:
self.bookmarks = []
root['bookmarks'] = self.bookmarks
need_commit = 1
t = time.time()
print t - t1
if need_commit:
print 'committing'
get_transaction().commit()
t1 = time.time()
print t1 - t
print 'done'
return 1
def setDefaultPerson(self,person):
@ -293,82 +237,3 @@ class GrampsZODB(GrampsDB):
GrampsDB.setDefaultPerson(self,person)
self.conn.root()['default'] = person
def removePerson(self,id):
GrampsDB.removePerson(self,id)
del self.personTable[id]
def removeSource(self,id):
GrampsDB.removeSource(self,id)
del self.sourceTable[id]
def removePlace(self,id):
GrampsDB.removePlace(self,id)
del self.placeTable[id]
def addPersonAs(self,person):
GrampsDB.addPersonAs(self,person)
self.personTable[person.getId()] = person.getDisplayInfo()
def addPlaceAs(self,place):
GrampsDB.addPlaceAs(self,place)
self.placeTable[place.getId()] = place.getDisplayInfo()
def addPerson(self,person):
i = GrampsDB.addPerson(self,person)
self.personTable[i] = person.getDisplayInfo()
return i
def addPlace(self,place):
i = GrampsDB.addPlace(self,place)
self.placeTable[i] = place.getDisplayInfo()
return i
def addPersonNoMap(self,person,id):
GrampsDB.addPersonNoMap(self,person,id)
self.personTable[id] = person.getDisplayInfo()
return id
def addPlaceNoMap(self,place,id):
GrampsDB.addPlaceNoMap(self,place,id)
self.placeTable[id] = place.getDisplayInfo()
return id
def findPersonNoMap(self,val):
p = GrampsDB.findPersonNoMap(self,val)
self.personTable[p.getId()] = p.getDisplayInfo()
return p
def findPlaceNoMap(self,val):
p = GrampsDB.findPlaceNoMap(self,val)
self.placeTable[p.getId()] = p.getDisplayInfo()
return p
def findPerson(self,idVal,map):
p = GrampsDB.findPerson(self,idVal,map)
self.personTable[p.getId()] = p.getDisplayInfo()
return p
def findPlace(self,idVal,map):
p = GrampsDB.findPlace(self,idVal,map)
self.placeTable[p.getId()] = p.getDisplayInfo()
return p
def addSource(self,source):
i = GrampsDB.addSource(self,source)
self.sourceTable[i] = source.getDisplayInfo()
return i
def addSourceNoMap(self,source,id):
GrampsDB.addSourceNoMap(self,source,id)
self.sourceTable[id] = source.getDisplayInfo()
return id
def findSourceNoMap(self,val):
p = GrampsDB.findSourceNoMap(self,val)
self.sourceTable[p.getId()] = p.getDisplayInfo()
return p
def findSource(self,idVal,map):
p = GrampsDB.findSource(self,idVal,map)
self.sourceTable[p.getId()] = p.getDisplayInfo()
return p

View File

@ -165,7 +165,7 @@ class PlaceView:
obj.freeze()
if len(obj.selection):
id = obj.get_row_data(obj.selection[0])
sel = self.db.getPlaceMap()[id]
sel = id
else:
sel = None
@ -191,7 +191,7 @@ class PlaceView:
def insert_place(self,place):
self.place_list.append(place.getDisplayInfo())
self.place_list.set_row_data(self.place_list.rows-1,place)
self.place_list.set_row_data(self.place_list.rows-1,place.getId())
def new_place_after_edit(self,place):
self.place_list.freeze()
@ -202,7 +202,13 @@ class PlaceView:
def update_display_after_edit(self,place):
self.place_list.freeze()
index = self.place_list.find_row_from_data(place)
val = place.getId()
for index in range(0,self.place_list.rows):
if self.place_list.get_row_data(index) == val:
break
else:
index = -1
self.place_list.remove(index)
self.insert_place(place)
self.place_list.sort()
@ -256,8 +262,9 @@ class PlaceView:
gnome.ui.GnomeErrorDialog(msg)
else:
for p in obj.selection:
place = obj.get_row_data(p)
EditPlace.EditPlace(place,self.db,self.update_display_after_edit)
place = self.db.getPlaceMap()[obj.get_row_data(p)]
EditPlace.EditPlace(place,self.db,
self.update_display_after_edit)

View File

@ -992,8 +992,9 @@ class Person(Persistent):
gender = const.unknown
bday = self.getBirth().getDateObj()
dday = self.getDeath().getDateObj()
return [self.PrimaryName.getName(),self.id,gender,bday.getQuoteDate(),
dday.getQuoteDate(),sort.build_sort_name(self.PrimaryName),
return [self.getPrimaryName().getName(),self.id,gender,
bday.getQuoteDate(), dday.getQuoteDate(),
sort.build_sort_name(self.getPrimaryName()),
sort.build_sort_date(bday),sort.build_sort_date(dday)]
@ -1834,6 +1835,9 @@ class GrampsDB(Persistent):
self.placeMap = {}
self.new()
def close(self):
pass
def get_base(self):
return ""
@ -1845,6 +1849,11 @@ class GrampsDB(Persistent):
def getPersonDisplay(self,key):
return self.personTable[key]
def buildPersonDisplay(self,nkey,okey=None):
if nkey != okey and okey != None:
del self.personTable[okey]
self.personTable[nkey] = self.personMap[nkey].getDisplayInfo()
def set_iprefix(self,val):
if _id_reg.search(val):
@ -2038,9 +2047,15 @@ class GrampsDB(Persistent):
def removePerson(self,id):
del self.personMap[id]
del self.personTable[id]
def removeSource(self,id):
del self.sourceMap[id]
del self.sourceTable[id]
def addPersonAs(self,person):
self.personMap[person.getId()] = person
self.personTable[person.getId()] = person.getDisplayInfo()
def addPerson(self,person):
"""adds a Person to the database, assigning a gramps' ID"""
@ -2050,6 +2065,7 @@ class GrampsDB(Persistent):
index = self.iprefix % self.pmapIndex
person.setId(index)
self.personMap[index] = person
self.personTable[index] = person.getDisplayInfo()
self.pmapIndex = self.pmapIndex + 1
return index
@ -2068,6 +2084,7 @@ class GrampsDB(Persistent):
else:
person = Person()
map[idVal] = self.addPerson(person)
self.personTable[map[idVal]] = person.getDisplayInfo()
return person
def addPersonNoMap(self,person,id):
@ -2077,6 +2094,7 @@ class GrampsDB(Persistent):
person.setId(id)
self.personMap[id] = person
self.pmapIndex = self.pmapIndex+1
self.personTable[id] = person.getDisplayInfo()
return id
def findPersonNoMap(self,val):
@ -2089,6 +2107,7 @@ class GrampsDB(Persistent):
person.id = val
self.personMap[val] = person
self.pmapIndex = self.pmapIndex+1
self.personTable[val] = person.getDisplayInfo()
return person
def addSource(self,source):
@ -2101,6 +2120,7 @@ class GrampsDB(Persistent):
index = self.sprefix % self.smapIndex
source.setId(index)
self.sourceMap[index] = source
self.sourceTable[index] = source.getDisplayInfo()
self.smapIndex = self.smapIndex + 1
return index
@ -2118,6 +2138,7 @@ class GrampsDB(Persistent):
else:
source = Source()
map[idVal] = self.addSource(source)
self.sourceTable[map[idVal]] = source.getDisplayInfo()
return source
def addSourceNoMap(self,source,index):
@ -2125,6 +2146,7 @@ class GrampsDB(Persistent):
source.setId(index)
self.sourceMap[index] = source
self.smapIndex = self.smapIndex + 1
self.sourceTable[index] = source.getDisplayInfo()
return index
def findSourceNoMap(self,val):
@ -2136,6 +2158,7 @@ class GrampsDB(Persistent):
else:
source = Source()
self.addSourceNoMap(source,val)
self.sourceTable[val] = source.getDisplayInfo()
return source
def addObject(self,object):
@ -2199,13 +2222,16 @@ class GrampsDB(Persistent):
place.setId(index)
self.placeMap[index] = place
self.lmapIndex = self.lmapIndex + 1
self.placeTable[index] = place.getDisplayInfo()
return index
def removePlace(self,id):
del self.placeMap[id]
del self.placeTable[id]
def addPlaceAs(self,place):
self.placeMap[place.getId()] = place
self.placeTable[place.getId()] = place.getDisplayInfo()
def findPlace(self,idVal,map):
"""finds a Place in the database using the idVal and map
@ -2222,6 +2248,7 @@ class GrampsDB(Persistent):
else:
place = Place()
map[idVal] = self.addPlace(place)
self.placeTable[map[idVal]] = p.getDisplayInfo()
return place
def addPlaceNoMap(self,place,index):
@ -2231,6 +2258,7 @@ class GrampsDB(Persistent):
place.setId(index)
self.placeMap[index] = place
self.lmapIndex = self.lmapIndex + 1
self.placeTable[index] = place.getDisplayInfo()
return index
def findPlaceNoMap(self,val):
@ -2243,6 +2271,7 @@ class GrampsDB(Persistent):
place.id = val
self.placeMap[val] = place
self.lmapIndex = self.lmapIndex + 1
self.placeTable[val] = place.getDisplayInfo()
return place
def getPlaceKeys(self):

View File

@ -400,8 +400,8 @@ class Gramps:
gnome.ui.GnomeErrorDialog(msg)
else:
import MergeData
(p1,x) = self.person_list.get_row_data(self.person_list.selection[0])
(p2,x) = self.person_list.get_row_data(self.person_list.selection[1])
p1 = self.person_list.get_row_data(self.person_list.selection[0])
p2 = self.person_list.get_row_data(self.person_list.selection[1])
p1 = self.db.getPersonMap()[p1]
p2 = self.db.getPersonMap()[p2]
MergeData.MergePeople(self.db,p1,p2,self.merge_update,
@ -424,16 +424,19 @@ class Gramps:
"Do you wish to save the changes?"),
_("Save Changes"), self.save_query,
_("Abandon Changes"), self.quit)
else:
else:
self.db.close()
gtk.mainquit()
def save_query(self):
"""Catch the reponse to the save on exit question"""
self.on_save_activate_quit()
self.db.close()
gtk.mainquit()
def quit(self):
"""Catch the reponse to the save on exit question"""
self.db.close()
gtk.mainquit()
def on_about_activate(self,obj):
@ -656,29 +659,17 @@ class Gramps:
self.id2col = {}
self.person_list.clear()
self.notebook.set_show_tabs(GrampsCfg.usetabs)
self.child_list.set_column_visibility(self.c_details,GrampsCfg.show_detail)
self.child_list.set_column_visibility(self.c_details,
GrampsCfg.show_detail)
self.child_list.set_column_visibility(self.c_id,GrampsCfg.id_visible)
self.child_list.set_column_visibility(self.c_birth_order,GrampsCfg.index_visible)
import time
t = time.time()
self.child_list.set_column_visibility(self.c_birth_order,
GrampsCfg.index_visible)
self.apply_filter()
print 'people',time.time() - t
t = time.time()
self.load_family()
print 'family',time.time() -t
t = time.time()
self.source_view.load_sources()
print 'sources',time.time() -t
t = time.time()
self.place_view.load_places()
print 'places',time.time() -t
t = time.time()
self.pedigree_view.load_canvas(self.active_person)
print 'pedegree',time.time() -t
t = time.time()
self.media_view.load_media()
print 'media',time.time() -t
t = time.time()
self.toolbar.set_style(GrampsCfg.toolbar)
def update_display(self,changed):
@ -875,7 +866,7 @@ class Gramps:
gnome.ui.GnomeErrorDialog(msg)
else:
for p in self.person_list.selection:
(person,x) = self.person_list.get_row_data(p)
person = self.person_list.get_row_data(p)
self.load_person(self.db.getPersonMap()[person])
def load_active_person(self,obj):
@ -937,19 +928,23 @@ class Gramps:
self.update_display(0)
Utils.modified()
def remove_from_person_list(self,person):
def remove_from_person_list(self,person,old_id=None):
self.person_list.freeze()
pid = person.getId()
if self.id2col.has_key(pid):
for id in self.id2col[pid]:
row = self.person_list.find_row_from_data(id)
self.person_list.remove(row)
del self.id2col[pid]
if old_id:
del_id = old_id
else:
del_id = pid
if self.id2col.has_key(del_id):
row = self.person_list.find_row_from_data(del_id)
self.person_list.remove(row)
del self.id2col[del_id]
if row > self.person_list.rows:
(p,x) = self.person_list.get_row_data(row)
p = self.person_list.get_row_data(row)
self.active_person = self.db.getPersonMap()[p]
self.person_list.thaw()
@ -968,8 +963,7 @@ class Gramps:
def on_person_list_select_row(self,obj,row,b,c):
if row == obj.selection[0]:
(id,x) = obj.get_row_data(row)
person = self.db.getPersonMap()[id]
person = self.db.getPersonMap()[obj.get_row_data(row)]
self.change_active_person(person)
def on_person_list_click_column(self,obj,column):
@ -1060,8 +1054,7 @@ class Gramps:
return
id = self.active_person.getId()
if self.id2col.has_key(id):
pos = self.id2col[id]
column = self.person_list.find_row_from_data(pos)
column = self.person_list.find_row_from_data(id)
if column != -1:
self.person_list.unselect_all()
self.person_list.select_row(column,0)
@ -1071,8 +1064,8 @@ class Gramps:
self.person_list.unselect_all()
self.person_list.select_row(0,0)
self.person_list.moveto(0)
(person,x) = self.person_list.get_row_data(0)
person = self.db.getPersonMap()[person]
pid = self.person_list.get_row_data(0)
person = self.db.getPersonMap()[pid]
self.change_active_person(person)
def change_active_person(self,person):
@ -1418,6 +1411,7 @@ class Gramps:
self.db.addPerson(epo.person)
else:
self.db.addPersonNoMap(epo.person,epo.person.getId())
self.db.buildPersonDisplay(epo.person.getId())
self.change_active_person(epo.person)
self.redisplay_person_list(epo.person)
for p in plist:
@ -1431,19 +1425,19 @@ class Gramps:
def update_after_edit(self,epo,plist):
if epo:
self.remove_from_person_list(epo.person)
self.db.buildPersonDisplay(epo.person.getId(),epo.original_id)
self.remove_from_person_list(epo.person,epo.original_id)
self.redisplay_person_list(epo.person)
for p in plist:
self.place_view.new_place_after_edit(p)
self.update_display(0)
def redisplay_person_list(self,person):
pos = (person,0)
self.id2col[person.getId()] = pos
self.id2col[person.getId()] = 1
if self.DataFilter.compare(person):
self.person_list.insert(0,person.getDisplayInfo())
self.person_list.set_row_data(0,pos)
self.person_list.set_row_data(0,person.getId())
self.sort_person_list()
def load_person(self,person):
@ -1843,11 +1837,10 @@ class Gramps:
if datacomp(person):
if self.id2col.has_key(key):
continue
pos = (key,0)
self.id2col[key] = pos
self.id2col[key] = 1
self.person_list.insert(0,self.db.getPersonDisplay(key))
self.person_list.set_row_data(0,pos)
self.person_list.set_row_data(0,person.getId())
else:
if self.id2col.has_key(key):
del self.id2col[key]

View File

@ -425,6 +425,7 @@ class GedcomParser:
self.person = self.db.findPerson(matches[1],self.pmap)
self.added[self.person.getId()] = self.person
self.parse_individual()
self.db.buildPersonDisplay(self.person.getId())
elif matches[2] in ["SUBM","SUBN"]:
self.ignore_sub_junk(1)
elif matches[1] in ["SUBM","SUBN"]: