6336: Convert to use DbGUIElement

svn: r21655
This commit is contained in:
Nick Hall 2013-03-15 21:02:44 +00:00
parent b885391182
commit 063efad45f

View File

@ -23,12 +23,18 @@
from gramps.gui.editors import EditSource, EditCitation
from gramps.gui.listmodel import ListModel, NOSORT
from gramps.gen.plug import Gramplet
from gramps.gui.dbguielement import DbGUIElement
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.get_translation().gettext
from gramps.gen.errors import WindowActiveError
from gi.repository import Gtk
class Citations(Gramplet):
class Citations(Gramplet, DbGUIElement):
def __init__(self, gui, nav_group=0):
Gramplet.__init__(self, gui, nav_group)
DbGUIElement.__init__(self, self.dbstate.db)
"""
Displays the citations for an object.
"""
@ -38,6 +44,19 @@ class Citations(Gramplet):
self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET)
self.gui.WIDGET.show()
def _connect_db_signals(self):
"""
called on init of DbGUIElement, connect to db as required.
"""
self.callman.register_callbacks({'citation-update': self.changed})
self.callman.connect_all(keys=['citation'])
def changed(self, handle):
"""
Called when a registered citation is updated.
"""
self.update()
def build_gui(self):
"""
Build the GUI interface.
@ -116,6 +135,7 @@ class Citations(Gramplet):
"""
Add a citation to the model.
"""
self.callman.register_handles({'citation': [citation_handle]})
citation = self.dbstate.db.get_citation_from_handle(citation_handle)
page = citation.get_page()
if not page:
@ -256,9 +276,6 @@ class PersonCitations(Citations):
"""
Displays the citations for a person.
"""
def db_changed(self):
self.dbstate.db.connect('person-update', self.update)
def active_changed(self, handle):
self.update()
@ -272,6 +289,8 @@ class PersonCitations(Citations):
active = self.dbstate.db.get_person_from_handle(active_handle)
self.model.clear()
self.callman.unregister_all()
self.callman.register_obj(active)
if active:
self.display_citations(active)
else:
@ -330,7 +349,6 @@ class EventCitations(Citations):
Displays the citations for an event.
"""
def db_changed(self):
self.dbstate.db.connect('event-update', self.update)
self.connect_signal('Event', self.update)
def update_has_data(self):
@ -343,6 +361,8 @@ class EventCitations(Citations):
active = self.dbstate.db.get_event_from_handle(active_handle)
self.model.clear()
self.callman.unregister_all()
self.callman.register_obj(active)
if active:
self.display_citations(active)
else:
@ -372,7 +392,6 @@ class FamilyCitations(Citations):
Displays the citations for a family.
"""
def db_changed(self):
self.dbstate.db.connect('family-update', self.update)
self.connect_signal('Family', self.update)
def update_has_data(self):
@ -385,6 +404,8 @@ class FamilyCitations(Citations):
active = self.dbstate.db.get_family_from_handle(active_handle)
self.model.clear()
self.callman.unregister_all()
self.callman.register_obj(active)
if active:
self.display_citations(active)
else:
@ -427,7 +448,6 @@ class PlaceCitations(Citations):
Displays the citations for a place.
"""
def db_changed(self):
self.dbstate.db.connect('place-update', self.update)
self.connect_signal('Place', self.update)
def update_has_data(self):
@ -440,6 +460,8 @@ class PlaceCitations(Citations):
active = self.dbstate.db.get_place_from_handle(active_handle)
self.model.clear()
self.callman.unregister_all()
self.callman.register_obj(active)
if active:
self.display_citations(active)
else:
@ -469,7 +491,6 @@ class MediaCitations(Citations):
Displays the citations for a media object.
"""
def db_changed(self):
self.dbstate.db.connect('media-update', self.update)
self.connect_signal('Media', self.update)
def update_has_data(self):
@ -482,6 +503,8 @@ class MediaCitations(Citations):
active = self.dbstate.db.get_object_from_handle(active_handle)
self.model.clear()
self.callman.unregister_all()
self.callman.register_obj(active)
if active:
self.display_citations(active)
else: