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

View File

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

View File

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