Additional Reference fixes

svn: r2888
This commit is contained in:
Don Allingham 2004-02-22 04:57:06 +00:00
parent 9ae8955fc0
commit 72659f98ac
11 changed files with 104 additions and 94 deletions

View File

@ -67,26 +67,27 @@ class Bookmarks :
"""Create the pulldown menu"""
if len(self.bookmarks) > 0:
self.myMenu = gtk.Menu()
for person in self.bookmarks:
self.add_to_menu(person)
for person_id in self.bookmarks:
self.add_to_menu(person_id)
self.menu.set_submenu(self.myMenu)
self.menu.set_sensitive(1)
else:
self.menu.remove_submenu()
self.menu.set_sensitive(0)
def add(self,person):
def add(self,person_id):
"""appends the person to the bottom of the bookmarks"""
if person not in self.bookmarks:
if person_id not in self.bookmarks:
Utils.modified()
self.bookmarks.append(person)
self.bookmarks.append(person_id)
self.redraw()
def add_to_menu(self,person_id):
"""adds a person's name to the drop down menu"""
person = self.db.find_person_from_id(person_id)
item = gtk.MenuItem(person.get_primary_name().get_name())
item.connect("activate", self.callback, person)
data = self.db.person_map.get(str(person_id))
name = data[2].get_name()
item = gtk.MenuItem(name)
item.connect("activate", self.callback, person_id)
item.show()
self.myMenu.append(item)
@ -143,8 +144,10 @@ class Bookmarks :
self.draw_window()
index = 0
for person in self.bookmarks:
self.namelist.append([person.get_primary_name().get_name()])
self.namelist.set_row_data(index,person)
data = self.db.person_map.get(str(person_id))
name = data[2].get_name()
self.namelist.append([name])
self.namelist.set_row_data(index,person_id)
index = index + 1
self.response = self.top.run()
@ -176,9 +179,9 @@ class Bookmarks :
"""Saves the current bookmarks from the list"""
del self.bookmarks[0:]
for index in range(0,self.namelist.rows):
person = self.namelist.get_row_data(index)
if person:
self.bookmarks.append(person)
person_id = self.namelist.get_row_data(index)
if person_id:
self.bookmarks.append(person_id)
self.redraw()
def help_clicked(self):

View File

@ -355,7 +355,7 @@ class EditPerson:
"on_add_aka_clicked" : self.on_add_aka_clicked,
"on_add_attr_clicked" : self.on_add_attr_clicked,
"on_add_url_clicked" : self.on_add_url_clicked,
"on_addphoto_clicked" : self.gallery.on_add_photo_clicked,
"on_addphoto_clicked" : self.gallery.on_add_media_object_clicked,
"on_selectphoto_clicked" : self.gallery.on_select_photo_clicked,
"on_aka_delete_clicked" : self.on_aka_delete_clicked,
"on_aka_update_clicked" : self.on_aka_update_clicked,

View File

@ -168,7 +168,7 @@ class EditPlace:
self.top_window.signal_autoconnect({
"on_switch_page" : self.on_switch_page,
"on_addphoto_clicked" : self.glry.on_add_photo_clicked,
"on_addphoto_clicked" : self.glry.on_add_media_object_clicked,
"on_selectphoto_clicked" : self.glry.on_select_photo_clicked,
"on_deletephoto_clicked" : self.glry.on_delete_photo_clicked,
"on_edit_photo_clicked" : self.glry.on_edit_photo_clicked,

View File

@ -189,15 +189,12 @@ class EditSource:
for key in self.db.get_person_keys():
p = self.db.get_person(key)
name = GrampsCfg.nameof(p)
birth_event = self.db.find_event_from_id(p.get_birth_id())
death_event = self.db.find_event_from_id(p.get_death_id())
for v_id in p.get_event_list() + [p.get_birth_id(), p.get_death_id()]:
v = self.db.find_event_from_id(v_id)
if not v:
continue
for sref in v.get_source_references():
if sref.get_base_id() == self.source.get_id():
p_event_list.append((name,v.get_name()))
for event_id in p.get_event_list() + [p.get_birth_id(), p.get_death_id()]:
if event_id:
event = self.db.find_event_from_id(event_id)
for sref in event.get_source_references():
if sref.get_base_id() == self.source.get_id():
p_event_list.append((name,event.get_name()))
for v in p.get_attribute_list():
for sref in v.get_source_references():
if sref.get_base_id() == self.source.get_id():
@ -210,14 +207,16 @@ class EditSource:
for sref in v.get_source_references():
if sref.get_base_id() == self.source.get_id():
p_addr_list.append((name,v.get_street()))
for p in self.db.get_object_map().values():
name = p.get_description()
for sref in p.get_source_references():
for object_id in self.db.get_object_keys():
object = self.db.find_object_from_id(object_id)
name = object.get_description()
for sref in object.get_source_references():
if sref.get_base_id() == self.source.get_id():
m_list.append(name)
for p in self.db.get_family_id_map().values():
f_id = p.get_father_id()
m_id = p.get_mother_id()
for family_id in self.db.get_family_keys():
family = self.db.find_family_from_id(family_id)
f_id = family.get_father_id()
m_id = family.get_mother_id()
f = self.db.find_person_from_id(f_id)
m = self.db.find_person_from_id(m_id)
if f and m:

View File

@ -473,13 +473,13 @@ class GrampsParser:
if attrs.has_key('priv'):
self.objref.set_privacy(int(attrs['priv']))
if self.family:
self.family.add_media_object(self.objref)
self.family.add_media_reference(self.objref)
elif self.source:
self.source.add_media_object(self.objref)
self.source.add_media_reference(self.objref)
elif self.person:
self.person.add_media_object(self.objref)
self.person.add_media_reference(self.objref)
elif self.placeobj:
self.placeobj.add_media_object(self.objref)
self.placeobj.add_media_reference(self.objref)
def start_object(self,attrs):
self.object = self.db.find_object_from_id(attrs['id'])
@ -530,13 +530,13 @@ class GrampsParser:
self.photo.set_mime_type(Utils.get_mime_type(self.photo.get_path()))
self.db.add_object(self.photo)
if self.family:
self.family.add_media_object(self.pref)
self.family.add_media_reference(self.pref)
elif self.source:
self.source.add_media_object(self.pref)
self.source.add_media_reference(self.pref)
elif self.person:
self.person.add_media_object(self.pref)
self.person.add_media_reference(self.pref)
elif self.placeobj:
self.placeobj.add_media_object(self.pref)
self.placeobj.add_media_reference(self.pref)
def start_daterange(self,attrs):
if self.source_ref:
@ -1037,13 +1037,13 @@ class GrampsImportParser(GrampsParser):
if attrs.has_key('priv'):
self.objref.set_privacy(int(attrs['priv']))
if self.family:
self.family.add_media_object(self.objref)
self.family.add_media_reference(self.objref)
elif self.source:
self.source.add_media_object(self.objref)
self.source.add_media_reference(self.objref)
elif self.person:
self.person.add_media_object(self.objref)
self.person.add_media_reference(self.objref)
elif self.placeobj:
self.placeobj.add_media_object(self.objref)
self.placeobj.add_media_reference(self.objref)
def start_object(self,attrs):
self.object = self.db.find_object_no_conflicts(attrs['id'],self.MediaFileMap)

View File

@ -178,7 +178,7 @@ class ImageSelect:
if (already_imported):
oref = RelLib.MediaRef()
oref.set_reference(already_imported)
self.dataobj.add_media_object(oref)
self.dataobj.add_media_reference(oref)
self.add_thumbnail(oref)
else:
type = Utils.get_mime_type(filename)
@ -369,7 +369,7 @@ class Gallery(ImageSelect):
self.db.add_object(photo)
oref = RelLib.MediaRef()
oref.set_reference(photo)
self.dataobj.add_media_object(oref)
self.dataobj.add_media_reference(oref)
def add_thumbnail(self, photo):
"""Scale the image and add it to the IconList."""
@ -510,7 +510,7 @@ class Gallery(ImageSelect):
self.db.add_object(photo)
oref = RelLib.MediaRef()
oref.set_reference(photo)
self.dataobj.add_media_object(oref)
self.dataobj.add_media_reference(oref)
try:
id = photo.get_id()
name = RelImage.import_media_object(tfile,self.path,id)
@ -549,7 +549,7 @@ class Gallery(ImageSelect):
index = index + 1
oref = RelLib.MediaRef()
oref.set_reference(self.db.find_object_from_id(data.data))
self.dataobj.add_media_object(oref)
self.dataobj.add_media_reference(oref)
self.add_thumbnail(oref)
self.parent.lists_changed = 1
if GrampsCfg.globalprop:
@ -578,7 +578,7 @@ class Gallery(ImageSelect):
return
oref = RelLib.MediaRef()
oref.set_reference(object)
self.dataobj.add_media_object(oref)
self.dataobj.add_media_reference(oref)
self.add_thumbnail(oref)
self.parent.lists_changed = 1

View File

@ -335,7 +335,7 @@ class MergePeople:
self.merge_families()
for photo in self.p2.get_media_list():
self.p1.add_media_object(photo)
self.p1.add_media_reference(photo)
if self.p1.get_nick_name() == "":
self.p1.set_nick_name(self.p2.get_nick_name())
@ -860,7 +860,7 @@ class MergePlaces:
# Copy photos from P2 to P1
for photo in self.p2.get_media_list():
self.p1.add_media_object(photo)
self.p1.add_media_reference(photo)
# Copy sources from P2 to P1
for source in self.p2.get_source_references():

View File

@ -278,7 +278,7 @@ class Place(SourceNote):
SourceNote.__init__(self,source)
if source:
self.long = source.log
self.long = source.long
self.lat = source.lat
self.title = source.title
self.main_loc = Location(source.main_loc)
@ -290,8 +290,8 @@ class Place(SourceNote):
for u in source.urls:
self.urls.append(Url(u))
self.media_list = []
for photo in source.media_list:
self.media_list.append(MediaRef(photo))
for media_id in source.media_list:
self.media_list.append(MediaRef(media_id))
else:
self.long = ""
self.lat = ""
@ -377,9 +377,9 @@ class Place(SourceNote):
if loc not in self.alt_loc:
self.alt_loc.append(loc)
def add_media_object(self,photo):
def add_media_reference(self,media_id):
"""Adds a Photo object to the place object's image list"""
self.media_list.append(photo)
self.media_list.append(media_id)
def get_media_list(self):
"""Returns the list of Photo objects"""
@ -1296,9 +1296,9 @@ class Person(SourceNote):
# else:
# return e
def add_media_object(self,photo):
def add_media_reference(self,media_id):
"""adds a MediaObject instance to the image list"""
self.media_list.append(photo)
self.media_list.append(media_id)
def get_media_list(self):
"""returns the list of MediaObjects"""
@ -1970,9 +1970,9 @@ class Family(SourceNote):
"""sets the event list to the passed list"""
self.event_list = list
def add_media_object(self,photo):
def add_media_reference(self,media_id):
"""Adds a MediaObject object to the Family instance's image list"""
self.media_list.append(photo)
self.media_list.append(media_id)
def get_media_list(self):
"""Returns the list of MediaObject objects"""
@ -2018,9 +2018,10 @@ class Source:
"""returns the gramps' ID of the Source instance"""
return self.id
def add_media_object(self,photo):
#EARNEY, this should eventually be a list of ids not objects, right?
def add_media_reference(self,media_id):
"""Adds a MediaObject object to the Source instance's image list"""
self.media_list.append(photo)
self.media_list.append(media_id)
def get_media_list(self):
"""Returns the list of MediaObject objects"""
@ -2306,6 +2307,9 @@ class GrampsDB:
def get_person_keys(self):
return self.person_map.keys()
def get_family_keys(self):
return self.family_map.keys()
def sort_by_name(self,f,s):
n1 = self.person_map.get(str(f))[2].sname
n2 = self.person_map.get(str(s))[2].sname
@ -2441,9 +2445,13 @@ class GrampsDB:
self.place2title = {}
self.genderStats = GenderStats ()
#EARNEY, may eventually be able to use secondary indexes for this
#that way we will not have to track these with code.
def get_surnames(self):
return self.surnames
#this function may eventually become obsolete.. if we use
#secondary indexes.
def add_surname(self,name):
if name and name not in self.surnames:
self.surnames.append(name)
@ -2456,8 +2464,8 @@ class GrampsDB:
def clean_bookmarks(self):
"""cleans up the bookmark list, removing empty slots"""
new_bookmarks = []
for person in self.bookmarks:
new_bookmarks.append(person)
for person_id in self.bookmarks:
new_bookmarks.append(person_id)
self.bookmarks = new_bookmarks
def set_researcher(self,owner):
@ -2489,7 +2497,7 @@ class GrampsDB:
return person
def get_person(self,id):
"""returns a map of gramps's IDs to Person instances"""
"""returns a Person from a GRAMPS's ID"""
p = Person()
data = self.person_map.get(str(id))
p.unserialize(data)
@ -2556,7 +2564,7 @@ class GrampsDB:
def get_place_ids(self):
"""returns a list of Place instances"""
return self.place_map.values()
return self.place_map.keys()
def get_family_relation_types(self):
"""returns a list of all relationship types assocated with Family
@ -2568,13 +2576,13 @@ class GrampsDB:
def remove_person_id(self,id):
# self.genderStats.uncount_person (self.person_map[id])
del self.person_map[str(id)]
self.person_map.delete(str(id))
def remove_source_id(self,id):
del self.source_map[str(id)]
self.source_map.delete(str(id))
def remove_event_id(self,id):
del self.event_map[str(id)]
self.event_map.delete(str(id))
def add_person_as(self,person):
assert(person.get_id())
@ -2614,8 +2622,8 @@ class GrampsDB:
self.genderStats.count_person (person, self)
return person
def has_person_id(self,val):
return self.person_map.get(str(val))
def has_person_id(self,val): #what does this function do?
return self.person_map.get(str(val)) #EARNEY
def find_person_from_id(self,val):
"""finds a Person in the database from the passed gramps' ID.
@ -2661,7 +2669,6 @@ class GrampsDB:
def add_event(self,event):
"""adds a Event instance to the database, assigning it a gramps'
ID number"""
return Event()
index = self.eprefix % self.emap_index
while self.event_map.get(str(index)):
self.emap_index += 1
@ -2835,10 +2842,10 @@ class GrampsDB:
return index
def remove_object(self,id):
del self.media_map[str(id)]
self.media_map.delete(str(id))
def remove_place(self,id):
del self.place_map[str(id)]
self.place_map.delete(str(id))
def add_place_as(self,place):
self.place_map.put(str(place.get_id()),place.serialize())
@ -2876,15 +2883,15 @@ class GrampsDB:
self.lmap_index = self.lmap_index + 1
return index
def find_place_from_id(self,val):
def find_place_from_id(self,id):
"""finds a Place in the database from the passed gramps' ID.
If no such Place exists, a new Place is added to the database."""
data = self.place_map.get(str(val))
data = self.place_map.get(str(id))
place = Place()
if not data:
place.id = val
self.place_map.put(str(val),place.serialize())
place.id = id
self.place_map.put(str(id),place.serialize())
self.lmap_index = self.lmap_index + 1
else:
place.unserialize(data)
@ -2906,7 +2913,7 @@ class GrampsDB:
def get_place_id(self,key):
place = Place()
place.serialize(self.place_map.get(str(key)))
place.unserialize(self.place_map.get(str(key)))
return place
def get_place_display(self,key):
@ -2938,7 +2945,9 @@ class GrampsDB:
return source.get_display_info()
def get_source(self,key):
return self.source_map[key]
source = Source()
source.unserialize(self.source_map[key])
return source
def build_source_display(self,nkey,okey=None):
pass
@ -3012,7 +3021,7 @@ class GrampsDB:
def delete_family(self,family_id):
"""deletes the Family instance from the database"""
if self.family_map.get(str(family_id)):
del self.family_map[str(family_id)]
self.family_map.delete(str(family_id))
def find_person_no_conflicts(self,idVal,map):
"""finds a Person in the database using the idVal and map

View File

@ -188,14 +188,12 @@ class XmlWriter:
date = string.split(time.ctime(time.time()))
owner = self.db.get_researcher()
familyMap = self.db.get_family_id_map()
familyList = familyMap.keys ()
familyList = self.db.get_family_keys()
person_len = self.db.get_number_of_people()
family_len = len(familyMap)
family_len = len(familyList)
source_len = len(self.db.get_source_keys())
place_len = len(self.db.get_place_id_keys())
objMap = self.db.get_object_map()
objList = objMap.keys ()
objList = self.db.get_object_keys()
total = person_len + family_len + place_len + source_len
@ -315,8 +313,8 @@ class XmlWriter:
self.g.write(" <families>\n")
familyList.sort ()
for key in familyList:
family = familyMap[key]
for key in self.db.get_family_keys():
family = self.db.find_family_from_id(key)
if self.callback and count % delta == 0:
self.callback(float(count)/float(total))
count = count + 1
@ -380,15 +378,15 @@ class XmlWriter:
if len(objList) > 0:
self.g.write(" <objects>\n")
objList.sort ()
for key in objList:
object = objMap[key]
for key in self.db.get_object_keys():
object = self.db.find_object_from_id(key)
self.write_object(object)
self.g.write(" </objects>\n")
if len(self.db.get_bookmarks()) > 0:
self.g.write(" <bookmarks>\n")
for person in self.db.get_bookmarks():
self.g.write(' <bookmark ref="%s"/>\n' % person.get_id())
for person_id in self.db.get_bookmarks():
self.g.write(' <bookmark ref="%s"/>\n' % person_id)
self.g.write(" </bookmarks>\n")
self.g.write("</database>\n")

View File

@ -1258,7 +1258,7 @@ class Gramps:
def load_selected_people(self,obj):
"""Display the selected people in the EditPerson display"""
mlist = self.people_view.person_tree.get_selected_objects()
if mlist and self.active_person == self.db.get_person(mlist[0]):
if mlist and self.active_person.get_id() == mlist[0]:
self.load_person(self.active_person)
def load_active_person(self,obj):
@ -1799,8 +1799,9 @@ class Gramps:
def on_edit_bookmarks_activate(self,obj):
self.bookmarks.edit()
def bookmark_callback(self,obj,person):
def bookmark_callback(self,obj,person_id):
old_person = self.active_person
person = self.db.find_person_from_id(person_id)
try:
self.change_active_person(person)
self.update_display(0)

View File

@ -972,7 +972,7 @@ class GedcomParser:
self.db.add_object(photo)
oref = RelLib.MediaRef()
oref.set_reference(photo)
self.person.add_media_object(oref)
self.person.add_media_reference(oref)
def parse_family_object(self,level):
form = ""
@ -1010,7 +1010,7 @@ class GedcomParser:
self.db.add_object(photo)
oref = RelLib.MediaRef()
oref.set_reference(photo)
self.family.add_media_object(photo)
self.family.add_media_reference(photo)
self.db.commit_family(self.family)
def parse_residence(self,address,level):