diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 24549c5ef..ef640ff33 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,4 +1,10 @@ 2005-11-06 Alex Roitman + * src/EditSource.py (display_references): Return control if the + events are pending, not every 0.1 sec; Draw references as they + are found instead of deferring. + * src/EditPlace.py (display_references): Make nice. + * src/ImageSelect.py (GlobalMediaProperties.display_refs): Make nice. + * src/EditSource.py (display_references): Check for elapsed time and return control to the main loop after 0.1 sec from the idle callback; convert callback to being able to store its state and diff --git a/gramps2/src/EditPlace.py b/gramps2/src/EditPlace.py index 972d900ca..634dc9339 100644 --- a/gramps2/src/EditPlace.py +++ b/gramps2/src/EditPlace.py @@ -50,6 +50,7 @@ import ImageSelect import NameDisplay import Spell import GrampsDisplay +import RelLib from DdTargets import DdTargets from WindowUtils import GladeIf @@ -251,7 +252,8 @@ class EditPlace: if self.ref_not_loaded: Utils.temp_label(self.refs_label,self.top) - gobject.idle_add(self.display_references) + self.cursor_type = None + self.idle = gobject.idle_add(self.display_references) self.ref_not_loaded = 0 def build_pdmap(self): @@ -277,6 +279,7 @@ class EditPlace: self.remove_itself_from_menu() self.gladeif.close() self.top.destroy() + gobject.source_remove(self.idle) gc.collect() def close_child_windows(self): @@ -442,7 +445,7 @@ class EditPlace: elif page == 6 and self.ref_not_loaded: self.ref_not_loaded = 0 Utils.temp_label(self.refs_label,self.top) - gobject.idle_add(self.display_references) + self.idle = gobject.idle_add(self.display_references) text = unicode(self.note_buffer.get_text(self.note_buffer.get_start_iter(), self.note_buffer.get_end_iter(),False)) if text: @@ -531,57 +534,95 @@ class EditPlace: self.loc_country.set_text(loc.get_country()) def display_references(self): - pevent = [] - fevent = [] - msg = "" - for key in self.db.get_person_handles(sort_handles=False): - p = self.db.get_person_from_handle(key) - for event_handle in [p.get_birth_handle(), p.get_death_handle()] + p.get_event_list(): - event = self.db.get_event_from_handle(event_handle) - if event and event.get_place_handle() == self.place.get_handle(): - pevent.append((p,event)) - for family_handle in self.db.get_family_handles(): - f = self.db.get_family_from_handle(family_handle) - for event_handle in f.get_event_list(): - event = self.db.get_event_from_handle(event_handle) - if event and event.get_place_handle() == self.place.get_handle(): - fevent.append((f,event)) + place_handle = self.place.get_handle() + t = _("%s [%s]: event %s\n") - any = 0 - if len(pevent) > 0: - any = 1 - msg = msg + _("People") + "\n" - msg = msg + "_________________________\n\n" - t = _("%s [%s]: event %s\n") + # 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() + + self.msg_people = "" + self.msg_families = "" - for e in pevent: - msg = msg + ( t % (self.name_display(e[0]),e[0].get_gramps_id(),_(e[1].get_name()))) + if self.cursor_type == 'Person': + while self.data: + handle,val = self.data + person = RelLib.Person() + person.unserialize(val) + for event_handle in [person.get_birth_handle(), + person.get_death_handle()] \ + + person.get_event_list(): + event = self.db.get_event_from_handle(event_handle) + if event and event.get_place_handle() == place_handle: + self.msg_people = self.msg_people + \ + ( t % (self.name_display(person), + person.get_gramps_id(), + _(event.get_name()))) + 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 len(fevent) > 0: - any = 1 - msg = msg + "\n%s\n" % _("Families") - msg = msg + "_________________________\n\n" - t = _("%s [%s]: event %s\n") + if self.cursor_type == 'Family': + while self.data: + handle,val = self.data + family = RelLib.Family() + family.unserialize(val) + for event_handle in family.get_event_list(): + event = self.db.get_event_from_handle(event_handle) + if event and event.get_place_handle() == place_handle: + father = family.get_father_handle() + mother = family.get_mother_handle() + if father and mother: + fname = _("%(father)s and %(mother)s") % { + "father" : self.name_display( + self.db.get_person_from_handle(father)), + "mother" : self.name_display( + self.db.get_person_from_handle(mother)) + } + elif father: + fname = self.name_display( + self.db.get_person_from_handle(father)) + else: + fname = self.name_display( + self.db.get_person_from_handle(mother)) - for e in fevent: - father = e[0].get_father_handle() - mother = e[0].get_mother_handle() - if father and mother: - fname = _("%(father)s and %(mother)s") % { - "father" : self.name_display( self.db.get_person_from_handle( father)), - "mother" : self.name_display( self.db.get_person_from_handle( mother)) } - elif father: - fname = self.name_display( self.db.get_person_from_handle( father)) - else: - fname = self.name_display( self.db.get_person_from_handle( mother)) + self.msg_families = self.msg_families + \ + ( t % (fname, + family.get_gramps_id(), + _(event.get_name()))) + self.data = self.cursor.next() + if gtk.events_pending(): + return True + self.cursor.close() - msg = msg + ( t % (fname,e[0].get_gramps_id(),_(e[1].get_name()))) + if self.msg_people: + self.msg_people = _("People") + "\n" \ + + "_________________________\n\n" \ + + self.msg_people + + if self.msg_families: + self.msg_families = "\n%s\n" % _("Families") \ + + "_________________________\n\n" \ + + self.msg_families - self.refinfo.get_buffer().set_text(msg) - if any: + self.refinfo.get_buffer().set_text(self.msg_people + self.msg_families) + + if self.msg_people or self.msg_families: Utils.bold_label(self.refs_label,self.top) else: Utils.unbold_label(self.refs_label,self.top) + + self.ref_not_loaded = 0 + self.cursor_type = None + return False #------------------------------------------------------------------------- # diff --git a/gramps2/src/EditSource.py b/gramps2/src/EditSource.py index d4be7af30..cf538c444 100644 --- a/gramps2/src/EditSource.py +++ b/gramps2/src/EditSource.py @@ -27,7 +27,6 @@ #------------------------------------------------------------------------- from gettext import gettext as _ import gc -import time #------------------------------------------------------------------------- # @@ -305,30 +304,34 @@ class EditSource: ImageSelect.GlobalMediaProperties(self.db,media,self) def display_references(self): - ct = time.time() source_handle = self.source.get_handle() + # Initialize things if we're entering this functioin + # for the first time if not self.cursor_type: - self.person_list = [] - self.family_list = [] - self.event_list = [] - self.place_list = [] - self.source_list = [] - self.media_list = [] - self.cursor_type = 'Person' self.cursor = self.db.get_person_cursor() self.data = self.cursor.first() + self.any_refs = False + slist = self.top_window.get_widget('slist') + titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)] + self.model = ListModel.ListModel(slist, + titles, + event_func=self.button_press) + if self.cursor_type == 'Person': while self.data: handle,val = self.data - obj = RelLib.Person() - obj.unserialize(val) - if obj.has_source_reference(source_handle): - self.person_list.append(handle) + 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 time.time() - ct > 0.1: + if gtk.events_pending(): return True self.cursor.close() @@ -339,12 +342,15 @@ class EditSource: if self.cursor_type == 'Family': while self.data: handle,val = self.data - obj = RelLib.Family() - obj.unserialize(val) - if obj.has_source_reference(source_handle): - self.family_list.append(handle) + family = RelLib.Family() + family.unserialize(val) + if family.has_source_reference(source_handle): + name = Utils.family_name(family,self.db) + gramps_id = family.get_gramps_id() + self.model.add([_("Family"),gramps_id,name],(1,handle)) + self.any_refs = True self.data = self.cursor.next() - if time.time() - ct > 0.1: + if gtk.events_pending(): return True self.cursor.close() @@ -355,12 +361,15 @@ class EditSource: if self.cursor_type == 'Event': while self.data: handle,val = self.data - obj = RelLib.Event() - obj.unserialize(val) - if obj.has_source_reference(source_handle): - self.event_list.append(handle) + 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 time.time() - ct > 0.1: + if gtk.events_pending(): return True self.cursor.close() @@ -371,12 +380,15 @@ class EditSource: if self.cursor_type == 'Place': while self.data: handle,val = self.data - obj = RelLib.Place() - obj.unserialize(val) - if obj.has_source_reference(source_handle): - self.place_list.append(handle) + place = RelLib.Place() + place.unserialize(val) + if place.has_source_reference(source_handle): + name = place.get_title() + gramps_id = place.get_gramps_id() + self.model.add([_("Place"),gramps_id,name],(3,handle)) + self.any_refs = True self.data = self.cursor.next() - if time.time() - ct > 0.1: + if gtk.events_pending(): return True self.cursor.close() @@ -387,12 +399,15 @@ class EditSource: if self.cursor_type == 'Source': while self.data: handle,val = self.data - obj = RelLib.Source() - obj.unserialize(val) - if obj.has_source_reference(source_handle): - self.source_list.append(handle) + 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 time.time() - ct > 0.1: + if gtk.events_pending(): return True self.cursor.close() @@ -406,70 +421,22 @@ class EditSource: obj = RelLib.MediaObject() obj.unserialize(val) if obj.has_source_reference(source_handle): - self.media_list.append(handle) + name = obj.get_description() + gramps_id = obj.get_gramps_id() + self.model.add([_("Media"),gramps_id,name],(5,handle)) + self.any_refs = True self.data = self.cursor.next() - if time.time() - ct > 0.1: + if gtk.events_pending(): return True self.cursor.close() - any = self.person_list or self.family_list or self.event_list \ - or self.place_list or self.source_list or self.media_list - - slist = self.top_window.get_widget('slist') - - titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)] - - self.model = ListModel.ListModel(slist,titles,event_func=self.button_press) - - for handle in self.person_list: - person = self.db.get_person_from_handle(handle) - name = self.name_display(person) - gramps_id = person.get_gramps_id() - self.model.add([_("Person"),gramps_id,name],(0,handle)) - - for handle in self.family_list: - 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)) - - for handle in self.event_list: - event = self.db.get_event_from_handle(handle) - name = event.get_name() - gramps_id = event.get_gramps_id() - self.model.add([_("Event"),gramps_id,name],(2,handle)) - - for handle in self.place_list: - place = self.db.get_place_from_handle(handle) - name = place.get_title() - gramps_id = place.get_gramps_id() - self.model.add([_("Place"),gramps_id,name],(3,handle)) - - for handle in self.source_list: - source = self.db.get_source_from_handle(handle) - name = source.get_title() - gramps_id = source.get_gramps_id() - self.model.add([_("Source"),gramps_id,name],(4,handle)) - - for handle in self.media_list: - media = self.db.get_object_from_handle(handle) - name = media.get_description() - gramps_id = media.get_gramps_id() - self.model.add([_("Media"),gramps_id,name],(5,handle)) - - if any: + if self.any_refs: Utils.bold_label(self.refs_label,self.top) else: Utils.unbold_label(self.refs_label,self.top) self.ref_not_loaded = 0 - - self.person_list = [] - self.family_list = [] - self.event_list = [] - self.place_list = [] - self.source_list = [] - self.media_list = [] + self.cursor_type = None return False def on_source_apply_clicked(self,obj): @@ -478,8 +445,10 @@ class EditSource: author = unicode(self.author.get_text()) pubinfo = unicode(self.pubinfo.get_text()) abbrev = unicode(self.abbrev.get_text()) - note = unicode(self.notes_buffer.get_text(self.notes_buffer.get_start_iter(), - self.notes_buffer.get_end_iter(),False)) + note = unicode( + self.notes_buffer.get_text(self.notes_buffer.get_start_iter(), + self.notes_buffer.get_end_iter(), + False)) format = self.preform.get_active() if author != self.source.get_author(): @@ -528,8 +497,11 @@ class EditSource: self.ref_not_loaded = 0 Utils.temp_label(self.refs_label,self.top) self.idle = gobject.idle_add(self.display_references) - text = unicode(self.notes_buffer.get_text(self.notes_buffer.get_start_iter(), - self.notes_buffer.get_end_iter(),False)) + text = unicode( + self.notes_buffer.get_text(self.notes_buffer.get_start_iter(), + self.notes_buffer.get_end_iter(), + False) + ) if text: Utils.bold_label(self.notes_label) else: diff --git a/gramps2/src/ImageSelect.py b/gramps2/src/ImageSelect.py index fce047751..204f4b1e9 100644 --- a/gramps2/src/ImageSelect.py +++ b/gramps2/src/ImageSelect.py @@ -1018,7 +1018,8 @@ class GlobalMediaProperties: self.slist = self.change_dialog.get_widget("src_list") self.sources_label = self.change_dialog.get_widget("sourcesGlobal") if self.obj: - self.srcreflist = [RelLib.SourceRef(ref) for ref in self.obj.get_source_references()] + self.srcreflist = [RelLib.SourceRef(ref) + for ref in self.obj.get_source_references()] else: self.srcreflist = [] @@ -1054,11 +1055,13 @@ class GlobalMediaProperties: else: self.flowed.set_active(1) - self.gladeif.connect('change_global','delete_event',self.on_delete_event) + self.gladeif.connect('change_global','delete_event', + self.on_delete_event) self.gladeif.connect('button91','clicked',self.close) self.gladeif.connect('ok','clicked',self.on_ok_clicked) self.gladeif.connect('button102','clicked',self.on_help_clicked) - self.gladeif.connect('notebook2','switch_page',self.on_notebook_switch_page) + self.gladeif.connect('notebook2','switch_page', + self.on_notebook_switch_page) self.gladeif.connect('add_attr','clicked',self.on_add_attr_clicked) self.gladeif.connect('button101','clicked',self.on_update_attr_clicked) self.gladeif.connect('del_attr','clicked',self.on_delete_attr_clicked) @@ -1073,7 +1076,8 @@ class GlobalMediaProperties: self.window.show() if not self.refs: Utils.temp_label(self.refs_label,self.window) - gobject.idle_add(self.display_refs) + self.cursor_type = None + self.idle = gobject.idle_add(self.display_refs) def on_delete_event(self,obj,b): self.close_child_windows() @@ -1084,6 +1088,7 @@ class GlobalMediaProperties: self.close_child_windows() self.remove_itself_from_menu() self.window.destroy() + gobject.source_remove(self.idle) gc.collect() def close_child_windows(self): @@ -1149,57 +1154,135 @@ class GlobalMediaProperties: return def display_refs(self): + media_handle = self.obj.get_handle() self.refs = 1 - (person_list,family_list,event_list,place_list,source_list - ) = Utils.get_media_referents(self.obj.get_handle(),self.db) + # 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() - any = person_list or family_list or event_list or place_list or source_list + self.any_refs = False + titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)] + self.refmodel = ListModel.ListModel( + self.change_dialog.get_widget("refinfo"), + titles, + event_func=self.button_press) - titles = [(_('Type'),0,150),(_('ID'),1,75),(_('Name'),2,150)] - self.refmodel = ListModel.ListModel( - self.change_dialog.get_widget("refinfo"), - titles,event_func=self.button_press) + # (person_list,family_list,event_list,place_list,source_list + # ) = Utils.get_media_referents(self.obj.get_handle(),self.db) - for handle in person_list: - person = self.db.get_person_from_handle(handle) - name = NameDisplay.displayer.display(person) - gramps_id = person.get_gramps_id() - self.refmodel.add([_("Person"),gramps_id,name]) - for handle in family_list: - family = self.db.get_family_from_handle(handle) - name = Utils.family_name(family,self.db) - gramps_id = family.get_gramps_id() - self.refmodel.add([_("Family"),gramps_id,name]) + if self.cursor_type == 'Person': + while self.data: + handle,val = self.data + person = RelLib.Person() + person.unserialize(val) + if media_handle in [photo.get_reference_handle() + for photo in person.get_media_list()]: + name = NameDisplay.displayer.display(person) + gramps_id = person.get_gramps_id() + self.refmodel.add([_("Person"),gramps_id,name]) + 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() - for handle in event_list: - event = self.db.get_event_from_handle(handle) - name = event.get_name() - gramps_id = event.get_gramps_id() - self.refmodel.add([_("Event"),gramps_id,name]) + if self.cursor_type == 'Family': + while self.data: + handle,val = self.data + family = RelLib.Family() + family.unserialize(val) + if media_handle in [photo.get_reference_handle() + for photo in family.get_media_list()]: + name = Utils.family_name(family,self.db) + gramps_id = family.get_gramps_id() + self.refmodel.add([_("Family"),gramps_id,name]) + self.any_refs = True + self.data = self.cursor.next() + if gtk.events_pending(): + return True + self.cursor.close() + + self.cursor_type = 'Event' + self.cursor = self.db.get_event_cursor() + self.data = self.cursor.first() - for handle in place_list: - place = self.db.get_place_from_handle(handle) - name = place.get_title() - gramps_id = place.get_gramps_id() - self.refmodel.add([_("Place"),gramps_id,name]) + if self.cursor_type == 'Event': + while self.data: + handle,val = self.data + event = RelLib.Event() + event.unserialize(val) + if media_handle in [photo.get_reference_handle() + for photo in event.get_media_list()]: + name = event.get_name() + gramps_id = event.get_gramps_id() + self.refmodel.add([_("Event"),gramps_id,name]) + self.any_refs = True + self.data = self.cursor.next() + if gtk.events_pending(): + return True + self.cursor.close() + + self.cursor_type = 'Place' + self.cursor = self.db.get_place_cursor() + self.data = self.cursor.first() - for handle in source_list: - source = self.db.get_source_from_handle(handle) - name = source.get_title() - gramps_id = source.get_gramps_id() - self.refmodel.add([_("Source"),gramps_id,name]) + if self.cursor_type == 'Place': + while self.data: + handle,val = self.data + place = RelLib.Place() + place.unserialize(val) + if media_handle in [photo.get_reference_handle() + for photo in place.get_media_list()]: + name = place.get_title() + gramps_id = place.get_gramps_id() + self.refmodel.add([_("Place"),gramps_id,name]) + self.any_refs = True + self.data = self.cursor.next() + if gtk.events_pending(): + return True + self.cursor.close() + + self.cursor_type = 'Source' + self.cursor = self.db.get_source_cursor() + self.data = self.cursor.first() - if any: + if self.cursor_type == 'Source': + while self.data: + handle,val = self.data + source = RelLib.Source() + source.unserialize(val) + if media_handle in [photo.get_reference_handle() + for photo in source.get_media_list()]: + name = source.get_title() + gramps_id = source.get_gramps_id() + self.refmodel.add([_("Source"),gramps_id,name]) + self.any_refs = True + self.data = self.cursor.next() + if gtk.events_pending(): + return True + self.cursor.close() + + if self.any_refs: Utils.bold_label(self.refs_label,self.window) else: Utils.unbold_label(self.refs_label,self.window) + + self.cursor_type = None + return False def on_notebook_switch_page(self,obj,junk,page): if page == 3 and not self.refs: Utils.temp_label(self.refs_label,self.window) - gobject.idle_add(self.display_refs) + self.idle = gobject.idle_add(self.display_refs) t = self.notes.get_buffer() text = unicode(t.get_text(t.get_start_iter(),t.get_end_iter(),False)) if text: