diff --git a/src/plugins/gramplet/Backlinks.py b/src/plugins/gramplet/Backlinks.py new file mode 100644 index 000000000..d5d58ea12 --- /dev/null +++ b/src/plugins/gramplet/Backlinks.py @@ -0,0 +1,179 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2011 Nick Hall +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id$ +# + +from ListModel import ListModel, NOSORT +from Utils import navigation_label +from gen.plug import Gramplet +from gen.ggettext import gettext as _ +import gtk + +class Backlinks(Gramplet): + """ + Displays the back references for an object. + """ + def init(self): + self.gui.WIDGET = self.build_gui() + self.gui.get_container_widget().remove(self.gui.textview) + self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET) + self.gui.WIDGET.show() + + def build_gui(self): + """ + Build the GUI interface. + """ + top = gtk.TreeView() + titles = [(_('Type'), 1, 100), + (_('Name'), 2, 100)] + self.model = ListModel(top, titles) + return top + + def display_backlinks(self, active_handle): + """ + Display the back references for an object. + """ + for classname, handle in \ + self.dbstate.db.find_backlink_handles(active_handle, + include_classes=None): + name = navigation_label(self.dbstate.db, classname, handle)[0] + self.model.add((classname, name)) + +class PersonBacklinks(Backlinks): + """ + Displays the back references for a person. + """ + def db_changed(self): + self.dbstate.db.connect('person-update', self.update) + self.update() + + def active_changed(self, handle): + self.update() + + def main(self): + active_handle = self.get_active('Person') + self.model.clear() + if active_handle: + self.display_backlinks(active_handle) + +class EventBacklinks(Backlinks): + """ + Displays the back references for an event. + """ + def db_changed(self): + self.dbstate.db.connect('event-update', self.update) + self.connect_signal('Event', self.update) + self.update() + + def main(self): + active_handle = self.get_active('Event') + self.model.clear() + if active_handle: + self.display_backlinks(active_handle) + +class FamilyBacklinks(Backlinks): + """ + Displays the back references for a family. + """ + def db_changed(self): + self.dbstate.db.connect('family-update', self.update) + self.connect_signal('Family', self.update) + self.update() + + def main(self): + active_handle = self.get_active('Family') + self.model.clear() + if active_handle: + self.display_backlinks(active_handle) + +class PlaceBacklinks(Backlinks): + """ + Displays the back references for a place. + """ + def db_changed(self): + self.dbstate.db.connect('place-update', self.update) + self.connect_signal('Place', self.update) + self.update() + + def main(self): + active_handle = self.get_active('Place') + self.model.clear() + if active_handle: + self.display_backlinks(active_handle) + +class SourceBacklinks(Backlinks): + """ + Displays the back references for a source,. + """ + def db_changed(self): + self.dbstate.db.connect('source-update', self.update) + self.connect_signal('Source', self.update) + self.update() + + def main(self): + active_handle = self.get_active('Source') + self.model.clear() + if active_handle: + self.display_backlinks(active_handle) + +class RepositoryBacklinks(Backlinks): + """ + Displays the back references for a repository. + """ + def db_changed(self): + self.dbstate.db.connect('repository-update', self.update) + self.connect_signal('Repository', self.update) + self.update() + + def main(self): + active_handle = self.get_active('Repository') + self.model.clear() + if active_handle: + self.display_backlinks(active_handle) + +class MediaBacklinks(Backlinks): + """ + Displays the back references for a media object. + """ + def db_changed(self): + self.dbstate.db.connect('media-update', self.update) + self.connect_signal('Media', self.update) + self.update() + + def main(self): + active_handle = self.get_active('Media') + self.model.clear() + if active_handle: + self.display_backlinks(active_handle) + +class NoteBacklinks(Backlinks): + """ + Displays the back references for a note. + """ + def db_changed(self): + self.dbstate.db.connect('note-update', self.update) + self.connect_signal('Note', self.update) + self.update() + + def main(self): + active_handle = self.get_active('Note') + self.model.clear() + if active_handle: + self.display_backlinks(active_handle) + diff --git a/src/plugins/gramplet/bottombar.gpr.py b/src/plugins/gramplet/bottombar.gpr.py index 2b1f133a8..029fac268 100644 --- a/src/plugins/gramplet/bottombar.gpr.py +++ b/src/plugins/gramplet/bottombar.gpr.py @@ -391,6 +391,110 @@ register(GRAMPLET, gramplet_title=_("Children"), ) +register(GRAMPLET, + id="Person Backlinks Gramplet", + name=_("Person Backlinks Gramplet"), + description = _("Gramplet showing the backlinks for a person"), + version="1.0.0", + gramps_target_version="3.4", + status = STABLE, + fname="Backlinks.py", + height=200, + gramplet = 'PersonBacklinks', + gramplet_title=_("References"), + ) + +register(GRAMPLET, + id="Event Backlinks Gramplet", + name=_("Event Backlinks Gramplet"), + description = _("Gramplet showing the backlinks for an event"), + version="1.0.0", + gramps_target_version="3.4", + status = STABLE, + fname="Backlinks.py", + height=200, + gramplet = 'EventBacklinks', + gramplet_title=_("References"), + ) + +register(GRAMPLET, + id="Family Backlinks Gramplet", + name=_("Family Backlinks Gramplet"), + description = _("Gramplet showing the backlinks for a family"), + version="1.0.0", + gramps_target_version="3.4", + status = STABLE, + fname="Backlinks.py", + height=200, + gramplet = 'FamilyBacklinks', + gramplet_title=_("References"), + ) + +register(GRAMPLET, + id="Place Backlinks Gramplet", + name=_("Place Backlinks Gramplet"), + description = _("Gramplet showing the backlinks for a place"), + version="1.0.0", + gramps_target_version="3.4", + status = STABLE, + fname="Backlinks.py", + height=200, + gramplet = 'PlaceBacklinks', + gramplet_title=_("References"), + ) + +register(GRAMPLET, + id="Source Backlinks Gramplet", + name=_("Source Backlinks Gramplet"), + description = _("Gramplet showing the backlinks for a source"), + version="1.0.0", + gramps_target_version="3.4", + status = STABLE, + fname="Backlinks.py", + height=200, + gramplet = 'SourceBacklinks', + gramplet_title=_("References"), + ) + +register(GRAMPLET, + id="Repository Backlinks Gramplet", + name=_("Repository Backlinks Gramplet"), + description = _("Gramplet showing the backlinks for a repository"), + version="1.0.0", + gramps_target_version="3.4", + status = STABLE, + fname="Backlinks.py", + height=200, + gramplet = 'RepositoryBacklinks', + gramplet_title=_("References"), + ) + +register(GRAMPLET, + id="Media Backlinks Gramplet", + name=_("Media Backlinks Gramplet"), + description = _("Gramplet showing the backlinks for a media object"), + version="1.0.0", + gramps_target_version="3.4", + status = STABLE, + fname="Backlinks.py", + height=200, + gramplet = 'MediaBacklinks', + gramplet_title=_("References"), + ) + +register(GRAMPLET, + id="Note Backlinks Gramplet", + name=_("Note Backlinks Gramplet"), + description = _("Gramplet showing the backlinks for a note"), + version="1.0.0", + gramps_target_version="3.4", + status = STABLE, + fname="Backlinks.py", + height=200, + gramplet = 'NoteBacklinks', + gramplet_title=_("References"), + ) + register(GRAMPLET, id="Person Filter Gramplet", name=_("Person Filter Gramplet"), diff --git a/src/plugins/lib/libpersonview.py b/src/plugins/lib/libpersonview.py index 65942ae2e..e8a346836 100644 --- a/src/plugins/lib/libpersonview.py +++ b/src/plugins/lib/libpersonview.py @@ -451,4 +451,5 @@ class BasePersonView(ListView): "Person Residence Gramplet", "Person Sources Gramplet", "Person Notes Gramplet", - "Person Attributes Gramplet")) + "Person Attributes Gramplet", + "Person Backlinks Gramplet")) diff --git a/src/plugins/lib/libplaceview.py b/src/plugins/lib/libplaceview.py index 158a6de2b..93c95527b 100644 --- a/src/plugins/lib/libplaceview.py +++ b/src/plugins/lib/libplaceview.py @@ -429,7 +429,8 @@ class PlaceBaseView(ListView): ("Place Details Gramplet", "Place Gallery Gramplet", "Place Sources Gramplet", - "Place Notes Gramplet")) + "Place Notes Gramplet", + "Place Backlinks Gramplet")) def make_callback(func, val): return lambda x: func(val) diff --git a/src/plugins/view/eventview.py b/src/plugins/view/eventview.py index 81d301051..e0e09f22b 100644 --- a/src/plugins/view/eventview.py +++ b/src/plugins/view/eventview.py @@ -293,4 +293,5 @@ class EventView(ListView): ("Event Gallery Gramplet", "Event Sources Gramplet", "Event Notes Gramplet", - "Event Attributes Gramplet")) + "Event Attributes Gramplet", + "Event Backlinks Gramplet")) diff --git a/src/plugins/view/familyview.py b/src/plugins/view/familyview.py index e522b6cc7..38f6bbbd5 100644 --- a/src/plugins/view/familyview.py +++ b/src/plugins/view/familyview.py @@ -347,4 +347,5 @@ class FamilyView(ListView): return (("Family Filter Gramplet",), ("Family Sources Gramplet", "Family Notes Gramplet", - "Family Attributes Gramplet")) + "Family Attributes Gramplet", + "Family Backlinks Gramplet")) diff --git a/src/plugins/view/mediaview.py b/src/plugins/view/mediaview.py index 56ebb7221..235bde7bd 100644 --- a/src/plugins/view/mediaview.py +++ b/src/plugins/view/mediaview.py @@ -440,4 +440,5 @@ class MediaView(ListView): "Exif Viewer Gramplet", "Media Sources Gramplet", "Media Notes Gramplet", - "Media Attributes Gramplet")) + "Media Attributes Gramplet", + "Media Backlinks Gramplet")) diff --git a/src/plugins/view/noteview.py b/src/plugins/view/noteview.py index 2e45b5ac6..d38049421 100644 --- a/src/plugins/view/noteview.py +++ b/src/plugins/view/noteview.py @@ -300,4 +300,4 @@ class NoteView(ListView): Define the default gramplets for the sidebar and bottombar. """ return (("Note Filter Gramplet",), - ()) + ("Note Backlinks Gramplet",)) diff --git a/src/plugins/view/repoview.py b/src/plugins/view/repoview.py index 4851e9203..3ea45be7c 100644 --- a/src/plugins/view/repoview.py +++ b/src/plugins/view/repoview.py @@ -276,4 +276,5 @@ class RepositoryView(ListView): """ return (("Repository Filter Gramplet",), ("Repository Details Gramplet", - "Repository Notes Gramplet")) + "Repository Notes Gramplet", + "Repository Backlinks Gramplet")) diff --git a/src/plugins/view/sourceview.py b/src/plugins/view/sourceview.py index edc2e0d03..9a0c3c535 100644 --- a/src/plugins/view/sourceview.py +++ b/src/plugins/view/sourceview.py @@ -253,4 +253,5 @@ class SourceView(ListView): """ return (("Source Filter Gramplet",), ("Source Gallery Gramplet", - "Source Notes Gramplet")) + "Source Notes Gramplet", + "Source Backlinks Gramplet"))