src/EditSource.py: changed display_references to use find_backlink_handles
svn: r5600
This commit is contained in:
parent
9f31ce3a55
commit
939da0c152
@ -1,3 +1,6 @@
|
|||||||
|
2005-12-21 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
|
||||||
|
* src/EditSource.py: changed display_references to use find_backlink_handles
|
||||||
|
|
||||||
2005-12-21 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
|
2005-12-21 Richard Taylor <rjt-gramps@thegrindstone.me.uk>
|
||||||
* src/EditRepository.py: hack to work with current state of Address
|
* src/EditRepository.py: hack to work with current state of Address
|
||||||
|
|
||||||
|
@ -27,6 +27,9 @@
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
import gc
|
import gc
|
||||||
|
import sys
|
||||||
|
|
||||||
|
log = sys.stderr.write
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -324,11 +327,15 @@ class EditSource:
|
|||||||
# self.top.set_transient_for(parent_window)
|
# self.top.set_transient_for(parent_window)
|
||||||
# self.add_itself_to_menu()
|
# self.add_itself_to_menu()
|
||||||
self.top.show()
|
self.top.show()
|
||||||
|
|
||||||
|
self.model = None # This will hold the model for backreferences once it is complete.
|
||||||
|
|
||||||
if self.ref_not_loaded:
|
if self.ref_not_loaded:
|
||||||
self.ref_not_loaded = 0
|
self.ref_not_loaded = 0
|
||||||
Utils.temp_label(self.refs_label,self.top)
|
Utils.temp_label(self.refs_label,self.top)
|
||||||
self.cursor_type = None
|
self.cursor_type = None
|
||||||
self.idle = gobject.idle_add(self.display_references)
|
self.idle = gobject.idle_add(self.display_references)
|
||||||
|
|
||||||
self.data_sel = self.datalist.get_selection()
|
self.data_sel = self.datalist.get_selection()
|
||||||
|
|
||||||
def on_add_data_clicked(self,widget):
|
def on_add_data_clicked(self,widget):
|
||||||
@ -471,131 +478,82 @@ class EditSource:
|
|||||||
ImageSelect.GlobalMediaProperties(self.db,media,self)
|
ImageSelect.GlobalMediaProperties(self.db,media,self)
|
||||||
|
|
||||||
def display_references(self):
|
def display_references(self):
|
||||||
source_handle = self.source.get_handle()
|
|
||||||
|
|
||||||
# Initialize things if we're entering this functioin
|
|
||||||
# for the first time
|
|
||||||
if not self.cursor_type:
|
|
||||||
self.cursor_type = 'Person'
|
|
||||||
self.cursor = self.db.get_person_cursor()
|
|
||||||
self.data = self.cursor.first()
|
|
||||||
|
|
||||||
|
if not self.model:
|
||||||
self.any_refs = False
|
self.any_refs = False
|
||||||
|
source_handle = self.source.get_handle()
|
||||||
|
|
||||||
slist = self.top_window.get_widget('slist')
|
slist = self.top_window.get_widget('slist')
|
||||||
titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)]
|
titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)]
|
||||||
self.model = ListModel.ListModel(slist,
|
self.model = ListModel.ListModel(slist,
|
||||||
titles,
|
titles,
|
||||||
event_func=self.button_press)
|
event_func=self.button_press)
|
||||||
|
self.backlink_generator = self.db.find_backlink_handles(source_handle)
|
||||||
if self.cursor_type == 'Person':
|
|
||||||
while self.data:
|
|
||||||
handle,val = self.data
|
|
||||||
person = RelLib.Person()
|
|
||||||
person.unserialize(val)
|
|
||||||
if person.has_source_reference(source_handle):
|
|
||||||
name = self.name_display(person)
|
|
||||||
gramps_id = person.get_gramps_id()
|
|
||||||
self.model.add([_("Person"),gramps_id,name],(0,handle))
|
|
||||||
self.any_refs = True
|
|
||||||
self.data = self.cursor.next()
|
|
||||||
if gtk.events_pending():
|
|
||||||
return True
|
|
||||||
self.cursor.close()
|
|
||||||
|
|
||||||
self.cursor_type = 'Family'
|
|
||||||
self.cursor = self.db.get_family_cursor()
|
|
||||||
self.data = self.cursor.first()
|
|
||||||
|
|
||||||
if self.cursor_type == 'Family':
|
|
||||||
while self.data:
|
while True: # The loop is broken when the backlink_generator finishes
|
||||||
handle,val = self.data
|
|
||||||
family = RelLib.Family()
|
try:
|
||||||
family.unserialize(val)
|
reference = self.backlink_generator.next()
|
||||||
if family.has_source_reference(source_handle):
|
except StopIteration:
|
||||||
name = Utils.family_name(family,self.db)
|
# Last reference reached.
|
||||||
gramps_id = family.get_gramps_id()
|
break
|
||||||
self.model.add([_("Family"),gramps_id,name],(1,handle))
|
|
||||||
self.any_refs = True
|
# If we make it here then there is at least one reference
|
||||||
self.data = self.cursor.next()
|
self.any_refs = True
|
||||||
if gtk.events_pending():
|
|
||||||
return True
|
|
||||||
self.cursor.close()
|
|
||||||
|
|
||||||
self.cursor_type = 'Event'
|
cls_name,handle = reference
|
||||||
self.cursor = self.db.get_event_cursor()
|
|
||||||
self.data = self.cursor.first()
|
|
||||||
|
|
||||||
if self.cursor_type == 'Event':
|
|
||||||
while self.data:
|
|
||||||
handle,val = self.data
|
|
||||||
event = RelLib.Event()
|
|
||||||
event.unserialize(val)
|
|
||||||
if event.has_source_reference(source_handle):
|
|
||||||
name = event.get_name()
|
|
||||||
gramps_id = event.get_gramps_id()
|
|
||||||
self.model.add([_("Event"),gramps_id,name],(2,handle))
|
|
||||||
self.any_refs = True
|
|
||||||
self.data = self.cursor.next()
|
|
||||||
if gtk.events_pending():
|
|
||||||
return True
|
|
||||||
self.cursor.close()
|
|
||||||
|
|
||||||
self.cursor_type = 'Place'
|
if cls_name == 'Person':
|
||||||
self.cursor = self.db.get_place_cursor()
|
person = self.db.get_person_from_handle(handle)
|
||||||
self.data = self.cursor.first()
|
name = self.name_display(person)
|
||||||
|
gramps_id = person.get_gramps_id()
|
||||||
|
self.model.add([_("Person"),gramps_id,name],(0,handle))
|
||||||
|
|
||||||
|
elif cls_name == 'Event':
|
||||||
|
event = self.db.get_event_from_handle()
|
||||||
|
name = event.get_name()
|
||||||
|
gramps_id = event.get_gramps_id()
|
||||||
|
self.model.add([_("Event"),gramps_id,name],(2,handle))
|
||||||
|
|
||||||
|
elif cls_name == 'Family':
|
||||||
|
family = self.db.get_family_from_handle(handle)
|
||||||
|
name = Utils.family_name(family,self.db)
|
||||||
|
gramps_id = family.get_gramps_id()
|
||||||
|
self.model.add([_("Family"),gramps_id,name],(1,handle))
|
||||||
|
|
||||||
if self.cursor_type == 'Place':
|
elif cls_name == 'Place':
|
||||||
while self.data:
|
place = self.db.get_place_from_handle(handle)
|
||||||
handle,val = self.data
|
name = place.get_title()
|
||||||
place = RelLib.Place()
|
gramps_id = place.get_gramps_id()
|
||||||
place.unserialize(val)
|
self.model.add([_("Place"),gramps_id,name],(3,handle))
|
||||||
if place.has_source_reference(source_handle):
|
|
||||||
name = place.get_title()
|
elif cls_name == 'Source':
|
||||||
gramps_id = place.get_gramps_id()
|
source = self.db.get_source_from_handle(handle)
|
||||||
self.model.add([_("Place"),gramps_id,name],(3,handle))
|
name = source.get_title()
|
||||||
self.any_refs = True
|
gramps_id = source.get_gramps_id()
|
||||||
self.data = self.cursor.next()
|
self.model.add([_("Source"),gramps_id,name],(4,handle))
|
||||||
if gtk.events_pending():
|
self.any_refs = True
|
||||||
return True
|
|
||||||
self.cursor.close()
|
elif cls_name == 'Media':
|
||||||
|
obj = self.db.get_object_from_handle(handle)
|
||||||
self.cursor_type = 'Source'
|
name = obj.get_description()
|
||||||
self.cursor = self.db.get_source_cursor()
|
gramps_id = obj.get_gramps_id()
|
||||||
self.data = self.cursor.first()
|
self.model.add([_("Media"),gramps_id,name],(5,handle))
|
||||||
|
|
||||||
if self.cursor_type == 'Source':
|
elif cls_name == 'Repository':
|
||||||
while self.data:
|
pass # handled by seperate Repositories tab in UI
|
||||||
handle,val = self.data
|
|
||||||
source = RelLib.Source()
|
|
||||||
source.unserialize(val)
|
|
||||||
if source.has_source_reference(source_handle):
|
|
||||||
name = source.get_title()
|
|
||||||
gramps_id = source.get_gramps_id()
|
|
||||||
self.model.add([_("Source"),gramps_id,name],(4,handle))
|
|
||||||
self.any_refs = True
|
|
||||||
self.data = self.cursor.next()
|
|
||||||
if gtk.events_pending():
|
|
||||||
return True
|
|
||||||
self.cursor.close()
|
|
||||||
|
|
||||||
self.cursor_type = 'Media'
|
|
||||||
self.cursor = self.db.get_media_cursor()
|
|
||||||
self.data = self.cursor.first()
|
|
||||||
|
|
||||||
if self.cursor_type == 'Media':
|
else:
|
||||||
while self.data:
|
# If we get here it means there is a new Primary object type
|
||||||
handle,val = self.data
|
# that has been added to the database. Print a warning
|
||||||
obj = RelLib.MediaObject()
|
# to remind us that this code need updating.
|
||||||
obj.unserialize(val)
|
log("WARNING: Unhandled Primary object type returned from "
|
||||||
if obj.has_source_reference(source_handle):
|
"find_backlink_handles()\n")
|
||||||
name = obj.get_description()
|
|
||||||
gramps_id = obj.get_gramps_id()
|
if gtk.events_pending():
|
||||||
self.model.add([_("Media"),gramps_id,name],(5,handle))
|
return True
|
||||||
self.any_refs = True
|
|
||||||
self.data = self.cursor.next()
|
|
||||||
if gtk.events_pending():
|
|
||||||
return True
|
|
||||||
self.cursor.close()
|
|
||||||
|
|
||||||
if self.any_refs:
|
if self.any_refs:
|
||||||
Utils.bold_label(self.refs_label,self.top)
|
Utils.bold_label(self.refs_label,self.top)
|
||||||
@ -603,7 +561,8 @@ class EditSource:
|
|||||||
Utils.unbold_label(self.refs_label,self.top)
|
Utils.unbold_label(self.refs_label,self.top)
|
||||||
|
|
||||||
self.ref_not_loaded = 0
|
self.ref_not_loaded = 0
|
||||||
self.cursor_type = None
|
self.backlink_generator = None
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def on_source_apply_clicked(self,obj):
|
def on_source_apply_clicked(self,obj):
|
||||||
|
Loading…
Reference in New Issue
Block a user