GEP 18: fixes with citedintab.

*show unused citations also
 *correct switching between citation by updating citation displaytabs
 *backref, correct handling of connectid


svn: r22496
This commit is contained in:
Benny Malengier 2013-06-12 08:48:48 +00:00
parent 5ffcd383ac
commit 5ee5ef158e
7 changed files with 82 additions and 17 deletions

View File

@ -65,10 +65,10 @@ class BackRefList(EmbeddedList):
def __init__(self, dbstate, uistate, track, obj, refmodel, callback=None): def __init__(self, dbstate, uistate, track, obj, refmodel, callback=None):
self.obj = obj self.obj = obj
self.connectid = None
EmbeddedList.__init__(self, dbstate, uistate, track, EmbeddedList.__init__(self, dbstate, uistate, track,
_('_References'), refmodel) _('_References'), refmodel)
self._callback = callback self._callback = callback
self.connectid = self.model.connect('row-inserted', self.update_label)
self.track_ref_for_deletion("model") self.track_ref_for_deletion("model")
def update_label(self, *obj): def update_label(self, *obj):
@ -124,6 +124,12 @@ class BackRefList(EmbeddedList):
def get_data(self): def get_data(self):
return self.obj return self.obj
def _set_data(self, new_backref_list):
"""
Reset data associated with display tab. Only called in rebuild_callback!
"""
self.obj = new_backref_list
def column_order(self): def column_order(self):
return ((1, 0), (1, 1), (1, 2)) return ((1, 0), (1, 1), (1, 2))
@ -207,3 +213,13 @@ class BackRefList(EmbeddedList):
EditRepository(self.dbstate, self.uistate, [], repo) EditRepository(self.dbstate, self.uistate, [], repo)
except WindowActiveError: except WindowActiveError:
pass pass
def rebuild(self):
"""
Rebuild the view. This remakes the model, so we need to reconnect the
signal
"""
if not self.connectid is None:
self.model.disconnect(self.connectid)
EmbeddedList.rebuild(self)
self.connectid = self.model.connect('row-inserted', self.update_label)

View File

@ -176,8 +176,10 @@ class CitedInTab(GrampsTab):
##print ('t1', cobjclass, chandle) ##print ('t1', cobjclass, chandle)
if cobjclass == 'Citation': if cobjclass == 'Citation':
cite = db.get_citation_from_handle(chandle) cite = db.get_citation_from_handle(chandle)
has_backlink = False
for (objclass, handle) in db.find_backlink_handles(chandle): for (objclass, handle) in db.find_backlink_handles(chandle):
##print ('t2', objclass, handle) ##print ('t2', objclass, handle)
has_backlink = True
if objclass == 'Person': if objclass == 'Person':
ref = db.get_person_from_handle(handle) ref = db.get_person_from_handle(handle)
self.__add_person(ref, cite) self.__add_person(ref, cite)
@ -199,18 +201,31 @@ class CitedInTab(GrampsTab):
else: else:
#most strange, not possible for citation there! #most strange, not possible for citation there!
print ("Error in citedintab.py: citation referenced " print ("Error in citedintab.py: citation referenced "
"outside citation") "outside citation. Run rebuild reference tables")
if not has_backlink:
self.__add_cite(cite)
else: else:
#most strange, not possible ! #most strange, not possible !
print ("Error in citedintab.py: source referenced " print ("Error in citedintab.py: source referenced "
"outside citation") "outside citation. Run rebuild reference tables")
self.srtdata = sorted(self.srtdata, key=lambda x: glocale.sort_key(x[0])) self.srtdata = sorted(self.srtdata, key=lambda x: glocale.sort_key(x[0]))
def __add_object(self, obj, cite, descr_obj, shortdescr, objname): def __add_object(self, obj, cite, descr_obj, shortdescr, objname):
""" """
obtain citation data of the object and store here so it can be shown obtain citation data of the object and store here so it can be shown
in a treeview in a treeview. If obj=None, an unused citation...
""" """
if obj is None:
#adding of a citation which is part of not a singel object. The
#citation is added under None.
if not None in self.obj2citemap:
self.obj2citemap[None] = {'prim': [], 'sec': [], 'subsec': []}
#add for sorting in the treeview to map
self.srtdata.append((descr_obj, None, shortdescr, objname))
#add this citation
self.obj2citemap[None]['prim'].append(cite.handle)
return
if not obj.handle in self.obj2citemap: if not obj.handle in self.obj2citemap:
self.obj2citemap[obj.handle] = {'prim': [], 'sec': [], 'subsec': []} self.obj2citemap[obj.handle] = {'prim': [], 'sec': [], 'subsec': []}
#add for sorting in the treeview to map #add for sorting in the treeview to map
@ -307,6 +322,13 @@ class CitedInTab(GrampsTab):
'id': obj.get_gramps_id(), 'id': obj.get_gramps_id(),
'descr': name}, _("Cited in Media"), "Media") 'descr': name}, _("Cited in Media"), "Media")
def __add_cite(self, cite):
"""
see __add_object
"""
self.__add_object(None, cite, _('Unused Citations'),
_('Unused Citation'), "Citation")
def format_sec_obj(self, objsec): def format_sec_obj(self, objsec):
""" """
text for treeview on citation in secondary object text for treeview on citation in secondary object

View File

@ -448,6 +448,17 @@ class EmbeddedList(ButtonTab):
""" """
raise NotImplementedError raise NotImplementedError
def _set_data(self):
"""
Reset the data associated with the list. This is typically
a list of objects.
This should be overridden in the derived classes. This method should
only be given if it is needed to call rebuild_callback with new_list
parameter. Don't use it otherwise!
"""
raise NotImplementedError
def column_order(self): def column_order(self):
""" """
Specifies the column order for the columns. This should be Specifies the column order for the columns. This should be
@ -610,12 +621,14 @@ class EmbeddedList(ButtonTab):
""" """
pass pass
def rebuild_callback(self): def rebuild_callback(self, new_list=None):
""" """
The view must be remade when data changes outside this tab. The view must be remade when data changes outside this tab.
Use this method to connect to after a db change. It makes sure the Use this method to connect to after a db change. It makes sure the
data is obtained again from the present object and the db what is not data is obtained again from the present object and the db what is not
present in the obj, and the view rebuild present in the obj, and the view rebuild
""" """
if new_list is not None:
self._set_data(new_list)
self.changed = True self.changed = True
self.rebuild() self.rebuild()

View File

@ -365,13 +365,15 @@ class GalleryTab(ButtonTab, DbGUIElement):
""" """
self.rebuild() self.rebuild()
def rebuild_callback(self): def rebuild_callback(self, new_list=None):
""" """
The view must be remade when data changes outside this tab. The view must be remade when data changes outside this tab.
Use this method to connect to after a db change. It makes sure the Use this method to connect to after a db change. It makes sure the
data is obtained again from the present object and the db what is not data is obtained again from the present object and the db what is not
present in the obj, and the view rebuild present in the obj, and the view rebuild
""" """
if new_list is not None:
self.media_list = new_list
self.changed = True self.changed = True
self.rebuild() self.rebuild()

View File

@ -115,6 +115,12 @@ class NoteTab(EmbeddedList, DbGUIElement):
""" """
return self.data return self.data
def _set_data(self, new_data):
"""
Reset data associated with display tab. Only called in rebuild_callback!
"""
self.data = new_data
def column_order(self): def column_order(self):
""" """
Return the column order of the columns in the display tab. Return the column order of the columns in the display tab.

View File

@ -91,6 +91,12 @@ class SrcAttrEmbedList(EmbeddedList):
def get_data(self): def get_data(self):
return self.data return self.data
def _set_data(self, new_data):
"""
Reset data associated with display tab. Only called in rebuild_callback!
"""
self.data = new_data
def column_order(self): def column_order(self):
return ((1, 2), (1, 0), (1, 1)) return ((1, 2), (1, 0), (1, 1))

View File

@ -690,7 +690,8 @@ class EditSource(EditPrimary):
msg = _("Edit Source (%s)") % self.obj.get_title() msg = _("Edit Source (%s)") % self.obj.get_title()
else: else:
msg = '' msg = ''
# Make sure citation references this source
self.citation.set_reference_handle(self.obj.handle)
# Now commit the Citation Primary object if needed # Now commit the Citation Primary object if needed
if self.citation_loaded: if self.citation_loaded:
if not self.citation.get_handle(): if not self.citation.get_handle():
@ -719,12 +720,9 @@ class EditSource(EditPrimary):
self.__base_save() self.__base_save()
if self.callback and self.citation_loaded: if self.callback and self.citation_loaded:
#new calling sequence of callback #callback only returns the citation handle. Source can be determined
# of this if needed.
self.callback(self.citation.get_handle()) self.callback(self.citation.get_handle())
elif self.callback:
#user closed citation, but a callback is needed. We don't know
#what citatin to return, so return None. Caller should handle this!
self.callback(None)
self.close() self.close()
@ -747,8 +745,8 @@ class EditSource(EditPrimary):
# CITATION PART # CITATION PART
def cite_apply_callback(self, citation_handle): def cite_apply_callback(self, citation_handle):
if self.citation: if self.citation_loaded:
self.unload_citation() self.close_citation()
self.load_citation(citation_handle) self.load_citation(citation_handle)
def unload_citation(self): def unload_citation(self):
@ -794,9 +792,11 @@ class EditSource(EditPrimary):
for field in [self.gid, self.type_mon, self.tags2, self.ref_privacy]: for field in [self.gid, self.type_mon, self.tags2, self.ref_privacy]:
field.update() field.update()
#trigger update of the tab fields #trigger update of the tab fields
for tab in [self.comment_tab, self.gallery_tab, self.attr_tab, self.comment_tab.rebuild_callback(self.citation.get_note_list())
self.citationref_list]: self.gallery_tab.rebuild_callback(self.citation.get_media_list())
tab.rebuild_callback() self.attr_tab.rebuild_callback(self.citation.get_attribute_list())
self.citationref_list.rebuild_callback(
self.db.find_backlink_handles(self.citation.handle))
def data_has_changed(self): def data_has_changed(self):
return self.citation_data_has_changed() or \ return self.citation_data_has_changed() or \