Added attributes to photos.

svn: r451
This commit is contained in:
Don Allingham 2001-10-07 02:58:29 +00:00
parent b7bc7a37e0
commit 2b594e1e2b
3 changed files with 42 additions and 42 deletions

View File

@ -86,6 +86,7 @@ class GrampsParser(handler.ContentHandler):
self.in_scomments = 0
self.db = database
self.base = base
self.photo = None
self.person = None
self.family = None
self.address = None
@ -230,7 +231,9 @@ class GrampsParser(handler.ContentHandler):
self.attribute.setType(u2l(attrs["type"]))
else:
self.in_old_attr = 0
if self.person:
if self.photo:
self.photo.addAttribute(self.attribute)
elif self.person:
self.person.addAttribute(self.attribute)
elif self.family:
self.family.addAttribute(self.attribute)
@ -440,28 +443,31 @@ class GrampsParser(handler.ContentHandler):
#
#---------------------------------------------------------------------
def start_photo(self,attrs):
photo = Photo()
self.photo = Photo()
for key in attrs.keys():
if key == "descrip" or key == "description":
photo.setDescription(u2l(attrs[key]))
self.photo.setDescription(u2l(attrs[key]))
elif key == "src":
src = u2l(attrs["src"])
if src[0] != os.sep:
photo.setPath("%s%s%s" % (self.base,os.sep,src))
photo.setPrivate(1)
self.photo.setPath("%s%s%s" % (self.base,os.sep,src))
self.photo.setPrivate(1)
else:
photo.setPath(src)
photo.setPrivate(0)
self.photo.setPath(src)
self.photo.setPrivate(0)
if self.family:
self.family.addPhoto(photo)
self.family.addPhoto(self.photo)
elif self.source:
self.source.addPhoto(photo)
self.source.addPhoto(self.photo)
elif self.person:
self.person.addPhoto(photo)
self.person.addPhoto(self.photo)
elif self.placeobj:
self.placeobj.addPhoto(photo)
self.placeobj.addPhoto(self.photo)
else:
photo.addProperty(key,u2l(attrs[key]))
a = Attribute()
a.setType(key)
a.setValue(u2l(attrs[key]))
self.photo.addAttribute(a)
#---------------------------------------------------------------------
#
@ -514,14 +520,12 @@ class GrampsParser(handler.ContentHandler):
def stop_address(self,tag):
self.address = None
#---------------------------------------------------------------------
#
#
#
#---------------------------------------------------------------------
def stop_places(self,tag):
self.placeobj = None
def stop_photo(self,tag):
self.photo = None
def stop_placeobj(self,tag):
if self.placeobj.get_title() == "":
loc = self.placeobj.get_main_location()
@ -951,7 +955,7 @@ class GrampsParser(handler.ContentHandler):
"parentin" : (start_parentin,None),
"people" : (start_people, stop_people),
"person" : (start_person, None),
"img" : (start_photo, None),
"img" : (start_photo, stop_photo),
"place" : (start_place, stop_place),
"places" : (None, stop_places),
"placeobj" : (start_placeobj,stop_placeobj),

View File

@ -342,21 +342,17 @@ class Photo:
def __init__(self,source=None):
"""Create a new Photo object, copying from the source if provided"""
self.attrlist = []
if source:
self.path = source.path
self.desc = source.desc
self.private = source.private
if self.proplist != None:
self.proplist = {}
for p in source.proplist.keys():
self.proplist[p] = source.proplist[p]
else:
self.proplist = None
for attr in source.attrlist:
self.attrlist.append(Attribute(attr))
else:
self.path = ""
self.desc = ""
self.private = 0
self.proplist = None
def setPath(self,path):
"""set the file path to the passed path"""
@ -382,18 +378,15 @@ class Photo:
"""returns the description of the image"""
return self.desc
def addProperty(self,key,value):
def addAttribute(self,attr):
"""Adds a propery to the Photo object. This is not used by gramps,
but provides a means for XML users to attach other properties to
the image"""
if self.proplist == None:
self.proplist = { key: value}
else:
self.proplist[key] = value;
self.attrlist.append(attr)
def getPropertyList(self):
def getAttributeList(self):
"""returns the property list associated with the image"""
return self.proplist
return self.attrlist
class Attribute(DataObj):
"""Provides a simple key/value pair for describing properties. Used

View File

@ -268,18 +268,19 @@ def dump_location(g,loc):
g.write('/>\n')
def write_attribute_list(g, list):
def write_attribute_list(g, list, indent=3):
sp = ' ' * indent
for attr in list:
if len(attr.getSourceRef()) > 0 or attr.getNote():
g.write(' <attribute%s>\n' % conf_priv(attr))
if len(attr.getSourceRefList()) > 0 or attr.getNote():
g.write('%s<attribute%s>\n' % (sp,conf_priv(attr)))
write_line(g,"attr_type",attr.getType(),4)
write_line(g,"attr_value",attr.getValue(),4)
for s in attr.getSourceRefList():
dump_source_ref(g,s,index+1)
writeNote(g,"note",attr.getNote(),4)
g.write(' </attribute>\n')
g.write('%s</attribute>\n' % sp)
else:
g.write(' <attribute type="%s">' % attr.getType())
g.write('%s<attribute type="%s">' % (sp,attr.getType()))
g.write(fix(attr.getValue()))
g.write('</attribute>\n')
@ -296,11 +297,13 @@ def write_photo_list(g,list):
path = path[l+1:]
g.write(' <img src="%s"' % fix(path) )
g.write(' description="%s"' % fix(photo.getDescription()))
proplist = photo.getPropertyList()
if proplist:
for key in proplist.keys():
g.write(' %s="%s"' % (key,fix(proplist[key])))
proplist = photo.getAttributeList()
if len(proplist) == 0:
g.write("/>\n")
else:
g.write(">\n")
write_attribute_list(g,proplist,4)
g.write(' </img>\n')
def write_url_list(g, list):