Fixed GEDCOM import of images

svn: r455
This commit is contained in:
Don Allingham 2001-10-11 13:15:10 +00:00
parent 7aef6c5340
commit d5b51fe57b
4 changed files with 46 additions and 19 deletions

View File

@ -163,6 +163,7 @@ class Gallery(ImageSelect):
t = [ t = [
('STRING', 0, 0), ('STRING', 0, 0),
('text/plain',0,0), ('text/plain',0,0),
('text/uri-list',0,2),
('application/x-rootwin-drop',0,1)] ('application/x-rootwin-drop',0,1)]
icon_list.drag_dest_set(DEST_DEFAULT_ALL, t, GDK.ACTION_COPY) icon_list.drag_dest_set(DEST_DEFAULT_ALL, t, GDK.ACTION_COPY)
@ -240,8 +241,9 @@ class Gallery(ImageSelect):
def on_photolist_drag_data_received(self,w, context, x, y, data, info, time): def on_photolist_drag_data_received(self,w, context, x, y, data, info, time):
if data and data.format == 8: if data and data.format == 8:
if data.data[0:5] == "file:": d = string.strip(string.replace(data.data,'\0',' '))
name = string.strip(data.data[5:]) if d[0:5] == "file:":
name = d[5:]
mime = gnome.mime.type_or_default_of_file(name,"unknown") mime = gnome.mime.type_or_default_of_file(name,"unknown")
if mime[0:5] == "image": if mime[0:5] == "image":
photo = Photo() photo = Photo()

View File

@ -71,7 +71,7 @@ def write_note(g,val,note,indent=0):
g.write(" " * indent) g.write(" " * indent)
g.write("<" + val + ">") g.write("<" + val + ">")
g.write(fix(note)) g.write(fix(string.rstrip(note)))
g.write("</" + val + ">\n") g.write("</" + val + ">\n")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -282,7 +282,8 @@ def write_attribute_list(g, list, indent=3):
def write_photo_list(g,list,indent=3): def write_photo_list(g,list,indent=3):
sp = ' '*indent sp = ' '*indent
for photo in list: for photo in list:
g.write('%s<objref ref="%s"' % (sp,photo.getReference().getId())) mobj = photo.getReference()
g.write('%s<objref ref="%s"' % (sp,mobj.getId()))
if photo.getPrivacy(): if photo.getPrivacy():
g.write(' priv="1"') g.write(' priv="1"')
proplist = photo.getAttributeList() proplist = photo.getAttributeList()
@ -296,7 +297,6 @@ def write_photo_list(g,list,indent=3):
dump_source_ref(g,s,indent+1) dump_source_ref(g,s,indent+1)
g.write('%s</objref>\n' % sp) g.write('%s</objref>\n' % sp)
def write_url_list(g, list): def write_url_list(g, list):
for url in list: for url in list:
g.write(' <url priv="%d" href="%s"' % \ g.write(' <url priv="%d" href="%s"' % \
@ -305,7 +305,6 @@ def write_url_list(g, list):
g.write(' description="%s"' % fix(url.get_description())) g.write(' description="%s"' % fix(url.get_description()))
g.write('/>\n') g.write('/>\n')
def write_place_obj(g,place): def write_place_obj(g,place):
title = place.get_title() title = place.get_title()

View File

@ -2544,19 +2544,35 @@ def change_parents(family):
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def find_tree(person,index,depth,list): def find_tree(person,index,depth,list,val=0):
if depth > 5 or person == None: if depth > 5 or person == None:
return return
family = person.getMainFamily() family = person.getMainFamily()
list[index] = person frel = 0
mrel = 0
if family == None:
l = person.getAltFamilyList()
if len(l) > 0:
f = l[0]
family = f[0]
if f[1] == "Birth":
mrel = 0
else:
mrel = 1
if f[2] == "Birth":
frel = 0
else:
frel = 1
list[index] = (person,val)
if family != None: if family != None:
father = family.getFather() father = family.getFather()
if father != None: if father != None:
find_tree(father,(2*index)+1,depth+1,list) find_tree(father,(2*index)+1,depth+1,list,frel)
mother = family.getMother() mother = family.getMother()
if mother != None: if mother != None:
find_tree(mother,(2*index)+2,depth+1,list) find_tree(mother,(2*index)+2,depth+1,list,mrel)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -2588,11 +2604,11 @@ def load_canvas():
find_tree(active_person,0,1,list) find_tree(active_person,0,1,list)
for t in list: for t in list:
if t: if t:
n = t.getPrimaryName().getName() n = t[0].getPrimaryName().getName()
h = max(h,font.height(n)+2*PAD) h = max(h,font.height(n)+2*PAD)
w = max(w,font.width(n)+2*PAD) w = max(w,font.width(n)+2*PAD)
w = max(w,font.width("d. %s" % t.getDeath().getDate())+2*PAD) w = max(w,font.width("d. %s" % t[0].getDeath().getDate())+2*PAD)
w = max(w,font.width("b. %s" % t.getBirth().getDate())+2*PAD) w = max(w,font.width("b. %s" % t[0].getBirth().getDate())+2*PAD)
cpad = max(h+4,CANVASPAD) cpad = max(h+4,CANVASPAD)
cw = (cx2-cx1-(2*cpad)) cw = (cx2-cx1-(2*cpad))
@ -2641,10 +2657,12 @@ def load_canvas():
canvas_items = [] canvas_items = []
if list[1]: if list[1]:
l = add_parent_button(root,canvas_items,list[1],cx2-PAD,ypts[1],h) p = list[1]
l = add_parent_button(root,canvas_items,p[0],cx2-PAD,ypts[1],h)
if list[2]: if list[2]:
l = add_parent_button(root,canvas_items,list[2],cx2-PAD,ypts[2],h) p = list[2]
l = add_parent_button(root,canvas_items,p[0],cx2-PAD,ypts[2],h)
for i in range(gen): for i in range(gen):
if list[i]: if list[i]:
@ -2652,12 +2670,15 @@ def load_canvas():
findex = (2*i)+1 findex = (2*i)+1
mindex = findex+1 mindex = findex+1
if list[findex]: if list[findex]:
p = list[findex]
draw_canvas_line(root, xpts[i], ypts[i], xpts[findex], draw_canvas_line(root, xpts[i], ypts[i], xpts[findex],
ypts[findex], h, w, list[findex], style) ypts[findex], h, w, p[0], style, p[1])
if list[mindex]: if list[mindex]:
p = list[mindex]
draw_canvas_line(root,xpts[i],ypts[i], xpts[mindex], draw_canvas_line(root,xpts[i],ypts[i], xpts[mindex],
ypts[mindex], h, w, list[mindex], style) ypts[mindex], h, w, p[0], style, p[1])
add_box(root,xpts[i],ypts[i],w,h,list[i],style) p = list[i]
add_box(root,xpts[i],ypts[i],w,h,p[0],style)
def add_parent_button(root,item_list,parent,x,y,h): def add_parent_button(root,item_list,parent,x,y,h):
@ -2685,12 +2706,13 @@ def change_to_parent(obj):
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def draw_canvas_line(root,x1,y1,x2,y2,h,w,data,style): def draw_canvas_line(root,x1,y1,x2,y2,h,w,data,style,ls):
startx = x1+(w/2.0) startx = x1+(w/2.0)
pts = [startx,y1, startx,y2+(h/2.0), x2,y2+(h/2.0)] pts = [startx,y1, startx,y2+(h/2.0), x2,y2+(h/2.0)]
item = root.add("line", item = root.add("line",
width_pixels=2, width_pixels=2,
points=pts, points=pts,
line_style=ls,
fill_color_gdk=style.black) fill_color_gdk=style.black)
item.set_data("p",data) item.set_data("p",data)
item.connect("event",line_event) item.connect("event",line_event)

View File

@ -783,6 +783,10 @@ class GedcomParser:
photo = Photo() photo = Photo()
photo.setPath(path) photo.setPath(path)
photo.setDescription(title) photo.setDescription(title)
photo.setMimeType(gnome.mime.type_or_default_of_file(name,"unknown"))
db.addObject(photo)
oref = ObjectRef()
oref.setReference(photo)
self.person.addPhoto(photo) self.person.addPhoto(photo)
else: else:
self.warn(_("Could not import %s: currently an unknown file type") % \ self.warn(_("Could not import %s: currently an unknown file type") % \