* src/DisplayModels.py: don't access db maps directly

* src/PeopleModel.py: don't access db maps directly
* src/FamilyView.py: add gender symbol to primary person
* src/GrampsDb/_GrampsBSDDB.py: provide access functions to avoid
redirect map access
* src/GrampsDb/_GrampsDbBase.py: provide access functions to avoid
redirect map access
* src/GrampsDb/_ReadGedcom.py: don't access db maps directly


svn: r5689
This commit is contained in:
Don Allingham 2006-01-06 22:08:40 +00:00
parent b7d493d92a
commit 636d0df973
7 changed files with 140 additions and 25 deletions

View File

@ -1,3 +1,13 @@
2006-01-06 Don Allingham <don@gramps-project.org>
* src/DisplayModels.py: don't access db maps directly
* src/PeopleModel.py: don't access db maps directly
* src/FamilyView.py: add gender symbol to primary person
* src/GrampsDb/_GrampsBSDDB.py: provide access functions to avoid
redirect map access
* src/GrampsDb/_GrampsDbBase.py: provide access functions to avoid
redirect map access
* src/GrampsDb/_ReadGedcom.py: don't access db maps directly
2006-01-06 Alex Roitman <shura@gramps-project.org> 2006-01-06 Alex Roitman <shura@gramps-project.org>
* src/GrampsLogger/.cvsignore: Add to CVS. * src/GrampsLogger/.cvsignore: Add to CVS.
* src/const.py.in: Add directory for the db environment. * src/const.py.in: Add directory for the db environment.

View File

@ -157,7 +157,7 @@ class BaseModel(gtk.GenericTreeModel):
def on_get_value(self,node,col): def on_get_value(self,node,col):
try: try:
return self.fmap[col](self.map[str(node)]) return self.fmap[col](self.map(str(node)))
except: except:
return u'' return u''
@ -283,7 +283,7 @@ class ChildModel(gtk.ListStore):
class SourceModel(BaseModel): class SourceModel(BaseModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING):
self.map = db.source_map self.map = db.get_raw_source_data
self.gen_cursor = db.get_source_cursor self.gen_cursor = db.get_source_cursor
self.fmap = [ self.fmap = [
self.column_title, self.column_title,
@ -346,7 +346,7 @@ class PlaceModel(BaseModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING):
self.gen_cursor = db.get_place_cursor self.gen_cursor = db.get_place_cursor
self.map = db.place_map self.map = db.get_raw_place_data
self.fmap = [ self.fmap = [
self.column_name, self.column_name,
self.column_id, self.column_id,
@ -455,7 +455,7 @@ class MediaModel(BaseModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING):
self.gen_cursor = db.get_media_cursor self.gen_cursor = db.get_media_cursor
self.map = db.media_map self.map = db.get_raw_object_data
self.fmap = [ self.fmap = [
self.column_description, self.column_description,
@ -533,7 +533,7 @@ class EventModel(BaseModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING):
self.gen_cursor = db.get_event_cursor self.gen_cursor = db.get_event_cursor
self.map = db.event_map self.map = db.get_raw_event_data
self.fmap = [ self.fmap = [
self.column_description, self.column_description,
@ -619,7 +619,7 @@ class RepositoryModel(BaseModel):
def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING): def __init__(self,db,scol=0,order=gtk.SORT_ASCENDING):
self.gen_cursor = db.get_repository_cursor self.gen_cursor = db.get_repository_cursor
self.get_handles = db.get_repository_handles self.get_handles = db.get_repository_handles
self.map = db.repository_map self.map = db.get_raw_repository_data
self.fmap = [ self.fmap = [
self.column_name, self.column_name,
self.column_id, self.column_id,

View File

@ -32,6 +32,12 @@ import ImgManip
import ReportUtils import ReportUtils
import GrampsKeys import GrampsKeys
_GenderCode = {
RelLib.Person.MALE : u'\u2642',
RelLib.Person.FEMALE : u'\u2640',
RelLib.Person.UNKNOWN : u'\u2650',
}
class LinkLabel(gtk.EventBox): class LinkLabel(gtk.EventBox):
def __init__(self,label,func,handle): def __init__(self,label,func,handle):
@ -40,7 +46,7 @@ class LinkLabel(gtk.EventBox):
self.gender = label[1] self.gender = label[1]
text = '<span underline="single">%s</span>' % self.orig_text text = '<span underline="single">%s</span>' % self.orig_text
if label[1]: if label[1]:
text += u" %s" % label[1] text += u' %s' % label[1]
self.label = gtk.Label(text) self.label = gtk.Label(text)
self.label.set_use_markup(True) self.label.set_use_markup(True)
@ -198,14 +204,10 @@ class FamilyView(PageView.PersonNavView):
if handle: if handle:
p = self.dbstate.db.get_person_from_handle(handle) p = self.dbstate.db.get_person_from_handle(handle)
name = NameDisplay.displayer.display(p) name = NameDisplay.displayer.display(p)
gender = ""
if use_gender: if use_gender:
if p.gender == RelLib.Person.MALE: gender = _GenderCode[p.gender]
gender = u' <span weight="bold">\u2642</span>' else:
elif p.gender == RelLib.Person.FEMALE: gender = ""
gender = u" \u2640"
else:
gender = u" \u2650"
return (name,gender) return (name,gender)
else: else:
return (_(u"Unknown"),"") return (_(u"Unknown"),"")
@ -241,7 +243,8 @@ class FamilyView(PageView.PersonNavView):
# name and edit button # name and edit button
name = NameDisplay.displayer.display(person) name = NameDisplay.displayer.display(person)
text = '<span size="larger" weight="bold">%s</span>' % cgi.escape(name) text = '<span size="larger" weight="bold">%s %s</span>' % (cgi.escape(name),
_GenderCode[person.gender])
label = MarkupLabel(text) label = MarkupLabel(text)
button = IconButton(self.edit_button_press,person.handle) button = IconButton(self.edit_button_press,person.handle)

View File

@ -155,6 +155,69 @@ class GrampsBSDDB(GrampsDbBase):
def get_repository_cursor(self): def get_repository_cursor(self):
return GrampsBSDDBCursor(self.repository_map,self.txn) return GrampsBSDDBCursor(self.repository_map,self.txn)
def has_person_handle(self,handle):
"""
returns True if the handle exists in the current Person database.
"""
return self.person_map.get(str(handle),txn=self.txn) != None
def has_family_handle(self,handle):
"""
returns True if the handle exists in the current Family database.
"""
return self.family_map.get(str(handle),txn=self.txn) != None
def has_object_handle(self,handle):
"""
returns True if the handle exists in the current MediaObjectdatabase.
"""
return self.media_map.get(str(handle),txn=self.txn) != None
def has_repository_handle(self,handle):
"""
returns True if the handle exists in the current Repository database.
"""
return self.repository_map.get(str(handle),txn=self.txn) != None
def has_event_handle(self,handle):
"""
returns True if the handle exists in the current Repository database.
"""
return self.event_map.get(str(handle),txn=self.txn) != None
def has_place_handle(self,handle):
"""
returns True if the handle exists in the current Repository database.
"""
return self.place_map.get(str(handle),txn=self.txn) != None
def has_source_handle(self,handle):
"""
returns True if the handle exists in the current Repository database.
"""
return self.source_map.get(str(handle),txn=self.txn) != None
def get_raw_person_data(self,handle):
return self.person_map.get(str(handle),txn=self.txn)
def get_raw_family_data(self,handle):
return self.family_map.get(str(handle),txn=self.txn)
def get_raw_object_data(self,handle):
return self.media_map.get(str(handle),txn=self.txn)
def get_raw_place_data(self,handle):
return self.place_map.get(str(handle),txn=self.txn)
def get_raw_event_data(self,handle):
return self.event_map.get(str(handle),txn=self.txn)
def get_raw_source_data(self,handle):
return self.source_map.get(str(handle),txn=self.txn)
def get_raw_repository_data(self,handle):
return self.repository_map.get(str(handle),txn=self.txn)
# cursors for lookups in the reference_map for back reference # cursors for lookups in the reference_map for back reference
# lookups. The reference_map has three indexes: # lookups. The reference_map has three indexes:
# the main index: a tuple of (primary_handle,referenced_handle) # the main index: a tuple of (primary_handle,referenced_handle)
@ -759,7 +822,7 @@ class GrampsBSDDB(GrampsDbBase):
if data: if data:
obj = class_init() obj = class_init()
obj.unserialize(cPickle.loads(data)) obj.unserialize(cPickle.loads(data))
return person return obj
else: else:
return None return None

View File

@ -1370,12 +1370,51 @@ class GrampsDbBase(GrampsDBCallback):
self._do_remove_object(handle,transaction,self.repository_map, self._do_remove_object(handle,transaction,self.repository_map,
REPOSITORY_KEY, transaction.repository_del) REPOSITORY_KEY, transaction.repository_del)
def get_raw_person_data(self,handle):
return self.person_map.get(str(handle))
def get_raw_family_data(self,handle):
return self.family_map.get(str(handle))
def get_raw_object_data(self,handle):
return self.media_map.get(str(handle))
def get_raw_place_data(self,handle):
return self.place_map.get(str(handle))
def get_raw_event_data(self,handle):
return self.event_map.get(str(handle))
def get_raw_source_data(self,handle):
return self.source_map.get(str(handle))
def get_raw_repository_data(self,handle):
return self.repository_map.get(str(handle))
def has_person_handle(self,handle): def has_person_handle(self,handle):
""" """
returns True if the handle exists in the current Person database. returns True if the handle exists in the current Person database.
""" """
return self.person_map.has_key(str(handle)) return self.person_map.has_key(str(handle))
def has_event_handle(self,handle):
"""
returns True if the handle exists in the current Event database.
"""
return self.event_map.has_key(str(handle))
def has_source_handle(self,handle):
"""
returns True if the handle exists in the current Source database.
"""
return self.source_map.has_key(str(handle))
def has_place_handle(self,handle):
"""
returns True if the handle exists in the current Place database.
"""
return self.place_map.has_key(str(handle))
def has_family_handle(self,handle): def has_family_handle(self,handle):
""" """
returns True if the handle exists in the current Family database. returns True if the handle exists in the current Family database.

View File

@ -778,8 +778,8 @@ class GedcomParser:
def find_or_create_person(self,gramps_id): def find_or_create_person(self,gramps_id):
person = RelLib.Person() person = RelLib.Person()
intid = self.gid2id.get(gramps_id) intid = self.gid2id.get(gramps_id)
if self.db.person_map.has_key(intid): if self.db.has_person_handle(intid):
person.unserialize(self.db.person_map.get(intid)) person.unserialize(self.db.get_raw_person_data(intid))
else: else:
intid = self.find_person_handle(gramps_id) intid = self.find_person_handle(gramps_id)
person.set_handle(intid) person.set_handle(intid)
@ -796,8 +796,8 @@ class GedcomParser:
def find_or_create_family(self,gramps_id): def find_or_create_family(self,gramps_id):
family = RelLib.Family() family = RelLib.Family()
intid = self.fid2id.get(gramps_id) intid = self.fid2id.get(gramps_id)
if self.db.family_map.has_key(intid): if self.db.has_family_handle(intid):
family.unserialize(self.db.family_map.get(intid)) family.unserialize(self.db.get_raw_family_data(intid))
else: else:
intid = self.find_family_handle(gramps_id) intid = self.find_family_handle(gramps_id)
family.set_handle(intid) family.set_handle(intid)
@ -814,8 +814,8 @@ class GedcomParser:
def find_or_create_source(self,gramps_id): def find_or_create_source(self,gramps_id):
source = RelLib.Source() source = RelLib.Source()
intid = self.sid2id.get(gramps_id) intid = self.sid2id.get(gramps_id)
if self.db.source_map.has_key(intid): if self.db.has_source_handle(intid):
source.unserialize(self.db.source_map.get(intid)) source.unserialize(self.db.get_raw_source_data(intid))
else: else:
intid = create_id() intid = create_id()
source.set_handle(intid) source.set_handle(intid)
@ -846,8 +846,8 @@ class GedcomParser:
else: else:
pname = title pname = title
if self.db.place_map.has_key(intid): if self.db.has_place_handle(intid):
place.unserialize(self.db.place_map.get(intid)) place.unserialize(self.db.get_raw_place_data(intid))
else: else:
intid = create_id() intid = create_id()
place.set_handle(intid) place.set_handle(intid)

View File

@ -236,7 +236,7 @@ class PeopleModel(gtk.GenericTreeModel):
# return values for 'data' row, calling a function # return values for 'data' row, calling a function
# according to column_defs table # according to column_defs table
try: try:
return COLUMN_DEFS[col][COLUMN_DEF_LIST](self,self.db.person_map[str(node)],node) return COLUMN_DEFS[col][COLUMN_DEF_LIST](self,self.db.get_raw_person_data(str(node)),node)
except: except:
print "".join(traceback.format_exception(*sys.exc_info())) print "".join(traceback.format_exception(*sys.exc_info()))
return u'error' return u'error'