David Hampton's changes to remove duplicate code in WriteXML and to condense gallery code

svn: r443
This commit is contained in:
Don Allingham 2001-10-04 04:51:06 +00:00
parent 0bc491fbc1
commit d771637140
5 changed files with 174 additions and 362 deletions

View File

@ -48,6 +48,7 @@ import Config
from RelLib import *
import RelImage
import Sources
import ImageSelect
_ = intl.gettext
@ -398,6 +399,35 @@ class EditPerson:
self.person.setAddressList(self.plist)
utils.modified()
#-------------------------------------------------------------------------
#
# PersonImageSelect class
#
#-------------------------------------------------------------------------
class PersonImageSelect(ImageSelect.ImageSelect):
#---------------------------------------------------------------------
#
# __init__ - Sub-class an ImageSelect window. The only differences
# between the various subclasses are the initializer arguments, and
# the type of object for which an image is being selected.
#
#---------------------------------------------------------------------
def __init__(self, epo):
ImageSelect.ImageSelect.__init__(self, epo.path, "i%s" % epo.person.getId())
self.epo = epo;
#---------------------------------------------------------------------
#
# savephoto - Override the savephoto method to store the selected
# photo in a person object
#
#---------------------------------------------------------------------
def savephoto(self, photo):
self.epo.person.addPhoto(photo)
self.epo.add_thumbnail(photo)
#-------------------------------------------------------------------------
#
#
@ -1053,36 +1083,7 @@ def update_name(name,first,last,suffix,note,priv):
#
#-------------------------------------------------------------------------
def on_add_photo_clicked(obj):
edit_person = obj.get_data(EDITPERSON)
image_select = libglade.GladeXML(const.imageselFile,"imageSelect")
edit_person.isel = image_select
window = image_select.get_widget("imageSelect")
image_select.signal_autoconnect({
"on_savephoto_clicked" : on_savephoto_clicked,
"on_name_changed" : on_name_changed,
"destroy_passed_object" : utils.destroy_passed_object
})
edit_person.fname = image_select.get_widget("fname")
edit_person.add_image = image_select.get_widget("image")
edit_person.external = image_select.get_widget("private")
window.editable_enters(image_select.get_widget("photoDescription"))
window.set_data(EDITPERSON,edit_person)
window.show()
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_name_changed(obj):
edit_person = obj.get_data(EDITPERSON)
file = edit_person.fname.get_text()
if os.path.isfile(file):
image = RelImage.scale_image(file,const.thumbScale)
edit_person.add_image.load_imlib(image)
PersonImageSelect(obj.get_data(EDITPERSON))
#-------------------------------------------------------------------------
#
@ -1197,44 +1198,6 @@ def save_person(obj):
epo.update_lists()
epo.callback(epo)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_savephoto_clicked(obj):
epo = obj.get_data(EDITPERSON)
image_select = epo.isel
filename = image_select.get_widget("photosel").get_full_path(0)
description = image_select.get_widget("photoDescription").get_text()
if os.path.exists(filename) == 0:
return
prefix = "i%s" % epo.person.getId()
if epo.external.get_active() == 1:
if os.path.isfile(filename):
name = filename
thumb = "%s%s.thumb.jpg" % (path,os.sep,os.path.basename(filename))
RelImage.mk_thumb(filename,thumb,const.thumbScale)
else:
return
else:
name = RelImage.import_photo(filename,epo.path,prefix)
if name == None:
return
photo = Photo()
photo.setPath(name)
photo.setDescription(description)
epo.person.addPhoto(photo)
epo.add_thumbnail(photo)
utils.modified()
utils.destroy_passed_object(obj)
#-------------------------------------------------------------------------
#
#

View File

@ -47,6 +47,7 @@ import utils
from RelLib import *
import RelImage
import Sources
import ImageSelect
_ = intl.gettext
@ -205,7 +206,7 @@ class EditPlace:
thumb = "%s%s.thumb%s%s" % (self.path,os.sep,os.sep,src)
else:
thumb = "%s%s.thumb%s%s.jpg" % (self.path,os.sep,os.sep,os.path.basename(src))
RelImage.check_thumb(phto.getPath(),thumb,const.thumbScale)
RelImage.check_thumb(photo.getPath(),thumb,const.thumbScale)
self.photo_list.append(thumb,photo.getDescription())
#-------------------------------------------------------------------------
@ -222,6 +223,35 @@ class EditPlace:
self.add_thumbnail(photo)
self.photo_list.thaw()
#-------------------------------------------------------------------------
#
# PlaceImageSelect class
#
#-------------------------------------------------------------------------
class PlaceImageSelect(ImageSelect.ImageSelect):
#---------------------------------------------------------------------
#
# __init__ - Sub-class an ImageSelect window. The only differences
# between the various subclasses are the initializer arguments, and
# the type of object for which an image is being selected.
#
#---------------------------------------------------------------------
def __init__(self, epo):
ImageSelect.ImageSelect.__init__(self, epo.path, "p%s" % epo.place.getId())
self.epo = epo;
#---------------------------------------------------------------------
#
# savephoto - Override the savephoto method to store the selected
# photo in a place object
#
#---------------------------------------------------------------------
def savephoto(self, photo):
self.epo.place.addPhoto(photo)
self.epo.add_thumbnail(photo)
def on_web_go_clicked(obj):
import gnome.url
@ -326,60 +356,7 @@ def on_delete_photo_clicked(obj):
#
#-------------------------------------------------------------------------
def on_add_photo_clicked(obj):
edit_place = obj.get_data(_PLACE)
image_select = libglade.GladeXML(const.imageselFile,"imageSelect")
edit_place.isel = image_select
image_select.signal_autoconnect({
"on_savephoto_clicked" : on_savephoto_clicked,
"on_name_changed" : on_name_changed,
"destroy_passed_object" : utils.destroy_passed_object
})
edit_place.fname = image_select.get_widget("fname")
edit_place.add_image = image_select.get_widget("image")
edit_place.external = image_select.get_widget("private")
window = image_select.get_widget("imageSelect")
window.editable_enters(image_select.get_widget("photoDescription"))
window.set_data(_PLACE,edit_place)
window.show()
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_savephoto_clicked(obj):
edit_place_obj = obj.get_data(_PLACE)
image_select = edit_place_obj.isel
filename = image_select.get_widget("photosel").get_full_path(0)
description = image_select.get_widget("photoDescription").get_text()
if os.path.exists(filename) == 0:
return
prefix = "p%s" % edit_place_obj.place.getId()
if edit_place_obj.external.get_active() == 1:
if os.path.isfile(filename):
name = filename
else:
return
else:
name = RelImage.import_photo(filename,edit_place_obj.path,prefix)
if name == None:
return
photo = Photo()
photo.setPath(name)
photo.setDescription(description)
edit_place_obj.place.addPhoto(photo)
edit_place_obj.add_thumbnail(photo)
utils.modified()
utils.destroy_passed_object(obj)
PlaceImageSelect(obj.get_data(_PLACE))
#-------------------------------------------------------------------------
#
@ -493,18 +470,6 @@ def on_apply_clicked(obj):
edit_window.load_images()
utils.modified()
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_name_changed(obj):
edit_person = obj.get_data(_PLACE)
file = edit_person.fname.get_text()
if os.path.isfile(file):
image = RelImage.scale_image(file,const.thumbScale)
edit_person.add_image.load_imlib(image)
#-------------------------------------------------------------------------
#
#

View File

@ -45,6 +45,7 @@ import const
import utils
from RelLib import *
import RelImage
import ImageSelect
_ = intl.gettext
@ -132,6 +133,35 @@ class EditSource:
self.add_thumbnail(photo)
self.photo_list.thaw()
#-------------------------------------------------------------------------
#
# SourceImageSelect class
#
#-------------------------------------------------------------------------
class SourceImageSelect(ImageSelect.ImageSelect):
#---------------------------------------------------------------------
#
# __init__ - Sub-class an ImageSelect window. The only differences
# between the various subclasses are the initializer arguments, and
# the type of object for which an image is being selected.
#
#---------------------------------------------------------------------
def __init__(self, eso):
ImageSelect.ImageSelect.__init__(self, eso.path, "s%s" % eso.source.getId())
self.eso = eso;
#---------------------------------------------------------------------
#
# savephoto - Override the savephoto method to store the selected
# photo in a source object
#
#---------------------------------------------------------------------
def savephoto(self, photo):
self.eso.source.addPhoto(photo)
self.eso.add_thumbnail(photo)
#-----------------------------------------------------------------------------
#
#
@ -202,60 +232,7 @@ def on_delete_photo_clicked(obj):
#
#-------------------------------------------------------------------------
def on_add_photo_clicked(obj):
edit_source = obj.get_data(SOURCE)
image_select = libglade.GladeXML(const.imageselFile,"imageSelect")
edit_source.isel = image_select
image_select.signal_autoconnect({
"on_savephoto_clicked" : on_savephoto_clicked,
"on_name_changed" : on_name_changed,
"destroy_passed_object" : utils.destroy_passed_object
})
edit_source.fname = image_select.get_widget("fname")
edit_source.add_image = image_select.get_widget("image")
edit_source.external = image_select.get_widget("private")
window = image_select.get_widget("imageSelect")
window.editable_enters(image_select.get_widget("photoDescription"))
window.set_data(SOURCE,edit_source)
window.show()
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_savephoto_clicked(obj):
eso = obj.get_data(SOURCE)
image_select = eso.isel
filename = image_select.get_widget("photosel").get_full_path(0)
description = image_select.get_widget("photoDescription").get_text()
if os.path.exists(filename) == 0:
return
prefix = "s%s" % eso.source.getId()
if eso.external.get_active() == 1:
if os.path.isfile(filename):
name = filename
else:
return
else:
name = RelImage.import_photo(filename,eso.path,prefix)
if name == None:
return
photo = Photo()
photo.setPath(name)
photo.setDescription(description)
eso.source.addPhoto(photo)
eso.add_thumbnail(photo)
utils.modified()
utils.destroy_passed_object(obj)
SourceImageSelect(obj.get_data(SOURCE))
#-------------------------------------------------------------------------
#
@ -368,15 +345,3 @@ def on_apply_clicked(obj):
edit_window = obj.get_data("m")
edit_window.load_images()
utils.modified()
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_name_changed(obj):
edit_person = obj.get_data(SOURCE)
file = edit_person.fname.get_text()
if os.path.isfile(file):
image = RelImage.scale_image(file,const.thumbScale)
edit_person.add_image.load_imlib(image)

View File

@ -44,6 +44,7 @@ import Config
import utils
from RelLib import *
import RelImage
import ImageSelect
#-------------------------------------------------------------------------
#
@ -216,6 +217,35 @@ class Marriage:
def get_widget(self,name):
return self.top.get_widget(name)
#-------------------------------------------------------------------------
#
# MarriageImageSelect class
#
#-------------------------------------------------------------------------
class MarriageImageSelect(ImageSelect.ImageSelect):
#---------------------------------------------------------------------
#
# __init__ - Sub-class an ImageSelect window. The only differences
# between the various subclasses are the initializer arguments, and
# the type of object for which an image is being selected.
#
#---------------------------------------------------------------------
def __init__(self, efo):
ImageSelect.ImageSelect.__init__(self, efo.path, "f%s" % efo.family.getId())
self.efo = efo;
#---------------------------------------------------------------------
#
# savephoto - Override the savephoto method to store the selected
# photo in a family object
#
#---------------------------------------------------------------------
def savephoto(self, photo):
self.efo.family.addPhoto(photo)
self.efo.add_thumbnail(photo)
#-------------------------------------------------------------------------
#
#
@ -545,79 +575,7 @@ def on_delete_photo_clicked(obj):
#
#-------------------------------------------------------------------------
def on_add_photo_clicked(obj):
marriage_obj = obj.get_data(MARRIAGE)
imageSelect = libglade.GladeXML(const.imageselFile,"imageSelect")
marriage_obj.imageSelect = imageSelect
imageSelect.signal_autoconnect({
"on_savephoto_clicked" : on_savephoto_clicked,
"on_name_changed" : on_name_changed,
"destroy_passed_object" : utils.destroy_passed_object
})
marriage_obj.fname = image_select.get_widget("fname")
marriage_obj.add_image = image_select.get_widget("image")
marriage_obj.external = image_select.get_widget("private")
window = imageSelect.get_widget("imageSelect")
window.editable_enters(image_select.get_widget("photoDescription"))
window.set_data(MARRIAGE,marriage_obj)
window.show()
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_name_changed(obj):
edit_person = obj.get_data(MARRIAGE_OBJ)
file = edit_person.fname.get_text()
if os.path.isfile(file):
image = RelImage.scale_image(file,const.thumbScale)
edit_person.add_image.load_imlib(image)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def on_savephoto_clicked(obj):
marriage_obj = obj.get_data(MARRIAGE)
photo_name_obj = marriage_obj.imageSelect.get_widget("photosel")
description_obj = marriage_obj.imageSelect.get_widget("photoDescription")
filename = photo_name_obj.get_full_path(0)
description = description_obj.get_text()
if os.path.exists(filename) == 0:
return
prefix = "f%s" % marriage_obj.family.getId()
name = RelImage.import_photo(filename,marriage_obj.path,prefix)
if name == None:
return
if marriage_obj.external.get_active() == 1:
if os.path.isfile(filename):
name = filename
thumb = "%s%s.thumb.jpg" % (path,os.sep,os.path.basename(filename))
RelImage.mk_thumb(filename,thumb,const.thumbScale)
else:
return
else:
name = RelImage.import_photo(filename,marriage_obj.path,prefix)
if name == None:
return
photo = Photo()
photo.setPath(name)
photo.setDescription(description)
marriage_obj.family.addPhoto(photo)
marriage_obj.add_thumbnail(photo)
utils.modified()
utils.destroy_passed_object(obj)
MarriageImageSelect(obj.get_data(MARRIAGE))
#-------------------------------------------------------------------------
#

View File

@ -267,6 +267,46 @@ def dump_location(g,loc):
g.write('/>\n')
def write_attribute_list(g, list):
for attr in list:
if attr.getSourceRef() or attr.getNote():
g.write(' <attribute%s>\n' % conf_priv(attr))
write_line(g,"attr_type",attr.getType(),4)
write_line(g,"attr_value",attr.getValue(),4)
dump_source_ref(g,attr.getSourceRef(),4)
writeNote(g,"note",attr.getNote(),4)
g.write(' </attribute>\n')
else:
g.write(' <attribute type="%s">' % attr.getType())
g.write(fix(attr.getValue()))
g.write('</attribute>\n')
def write_photo_list(g,list):
for photo in list:
path = photo.getPath()
l = len(fileroot)
if len(path) >= l:
if fileroot == path[0:l]:
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])))
g.write("/>\n")
def write_url_list(g, list):
for url in list:
g.write(' <url priv="%d" href="%s"' % \
(url.getPrivacy(),fix(url.get_path())))
if url.get_description() != "":
g.write(' description="%s"' % fix(url.get_description()))
g.write('/>\n')
def write_place_obj(g,place):
title = place.get_title()
@ -281,26 +321,8 @@ def write_place_obj(g,place):
dump_location(g,place.get_main_location())
for loc in place.get_alternate_locations():
dump_location(g,loc)
for photo in place.getPhotoList():
path = photo.getPath()
l = len(fileroot)
if len(path) >= l:
if fileroot == path[0:l]:
path = path[l+1:]
g.write(" <img src=\"" + fix(path) + "\"")
g.write(" description=\"" + fix(photo.getDescription()) + "\"")
proplist = photo.getPropertyList()
if proplist:
for key in proplist.keys():
g.write(' %s="%s"' % (key,fix(proplist[key])))
g.write("/>\n")
for url in place.getUrlList():
g.write(' <url href="%s"' % fix(url.get_path()))
if url.getPrivacy() == 1:
g.write(' priv="1"')
if url.get_description() != "":
g.write(' description="%s"' % fix(url.get_description()))
g.write('/>\n')
write_photo_list(g,place.getPhotoList())
write_url_list(g, place.getUrlList())
if place.getNote() != "":
writeNote(g,"note",place.getNote(),3)
dump_source_ref(g,place.getSourceRef(),3)
@ -314,6 +336,7 @@ def write_place_obj(g,place):
def exportData(database, filename, callback):
global fileroot
date = string.split(time.ctime(time.time()))
fileroot = os.path.dirname(filename)
owner = database.getResearcher()
@ -393,19 +416,7 @@ def exportData(database, filename, callback):
for event in person.getEventList():
dump_event(g,event,3)
for photo in person.getPhotoList():
path = photo.getPath()
l = len(fileroot)
if len(path) >= l:
if fileroot == path[0:l]:
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,proplist[key]))
g.write("/>\n")
write_photo_list(g,person.getPhotoList())
if len(person.getAddressList()) > 0:
for address in person.getAddressList():
@ -421,27 +432,8 @@ def exportData(database, filename, callback):
dump_source_ref(g,address.getSourceRef(),4)
g.write(' </address>\n')
if len(person.getAttributeList()) > 0:
for attr in person.getAttributeList():
if attr.getSourceRef() or attr.getNote():
g.write(' <attribute%s>\n' % conf_priv(attr))
write_line(g,"attr_type",attr.getType(),4)
write_line(g,"attr_value",attr.getValue(),4)
dump_source_ref(g,attr.getSourceRef(),4)
writeNote(g,"note",attr.getNote(),4)
g.write(' </attribute>\n')
else:
g.write(' <attribute type="%s">' % attr.getType())
g.write(fix(attr.getValue()))
g.write('</attribute>\n')
if len(person.getUrlList()) > 0:
for url in person.getUrlList():
g.write(' <url priv="%d" href="%s"' % \
(url.getPrivacy(),url.get_path()))
if url.get_description() != "":
g.write(' description="' + url.get_description() + '"')
g.write('/>\n')
write_attribute_list(g,person.getAttributeList())
write_url_list(g,person.getUrlList())
write_ref(g,"childof",person.getMainFamily(),3)
for alt in person.getAltFamilyList():
@ -482,31 +474,12 @@ def exportData(database, filename, callback):
for event in family.getEventList():
dump_event(g,event,3)
for photo in family.getPhotoList():
path = photo.getPath()
l = len(fileroot)
if len(path) >= l:
if fileroot == path[0:l]:
path = path[l+1:]
g.write(" <img src=\"" + fix(path) + "\"")
g.write(" description=\"" + fix(photo.getDescription()) + "\"")
proplist = photo.getPropertyList()
if proplist:
for key in proplist.keys():
g.write(' %s="%s"' % (key,proplist[key]))
g.write("/>\n")
write_photo_list(g,family.getPhotoList())
if len(family.getChildList()) > 0:
for person in family.getChildList():
write_ref(g,"child",person,3)
if len(family.getAttributeList()) > 0:
for attr in family.getAttributeList():
g.write(' <attribute>\n')
write_line(g,"attr_type",attr.getType(),4)
write_line(g,"attr_value",attr.getValue(),4)
dump_source_ref(g,attr.getSourceRef(),4)
writeNote(g,"note",attr.getNote(),4)
g.write(' </attribute>\n')
write_attribute_list(g,family.getAttributeList())
writeNote(g,"note",family.getNote(),3)
g.write(" </family>\n")
g.write(" </families>\n")
@ -521,19 +494,7 @@ def exportData(database, filename, callback):
write_line(g,"scallno",source.getCallNumber(),3)
if source.getNote() != "":
writeNote(g,"note",source.getNote(),3)
for photo in source.getPhotoList():
path = photo.getPath()
l = len(fileroot)
if len(path) >= l:
if fileroot == path[0:l]:
path = path[l+1:]
g.write(" <img src=\"" + fix(path) + "\"")
g.write(" description=\"" + fix(photo.getDescription()) + "\"")
proplist = photo.getPropertyList()
if proplist:
for key in proplist.keys():
g.write(' %s="%s"' % (key,proplist[key]))
g.write("/>\n")
write_photo_list(g,source.getPhotoList())
g.write(" </source>\n")
g.write(" </sources>\n")