1# 2# Gramps - a GTK+/GNOME based genealogy program 3# 4# Copyright (C) 2000-2007 Donald N. Allingham 5# Copyright (C) 2009-2011 Gary Burton 6# Copyright (C) 2011 Tim G L Lyons 7# 8# This program is free software; you can redistribute it and/or modify 9# it under the terms of the GNU General Public License as published by 10# the Free Software Foundation; either version 2 of the License, or 11# (at your option) any later version. 12# 13# This program is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16# GNU General Public License for more details. 17# 18# You should have received a copy of the GNU General Public License 19# along with this program; if not, write to the Free Software 20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21# 22 23#------------------------------------------------------------------------- 24# 25# Python classes 26# 27#------------------------------------------------------------------------- 28from gramps.gen.const import GRAMPS_LOCALE as glocale 29_ = glocale.translation.gettext 30 31#------------------------------------------------------------------------- 32# 33# GTK libraries 34# 35#------------------------------------------------------------------------- 36from gi.repository import Gtk 37 38#------------------------------------------------------------------------- 39# 40# Gramps classes 41# 42#------------------------------------------------------------------------- 43from ...widgets import SimpleButton 44from .embeddedlist import EmbeddedList, TEXT_COL, MARKUP_COL, ICON_COL 45from ...utils import edit_object 46 47#------------------------------------------------------------------------- 48# 49# BackRefList 50# 51#------------------------------------------------------------------------- 52class BackRefList(EmbeddedList): 53 54 _HANDLE_COL = 3 55 56 #index = column in model. Value = 57 # (name, sortcol in model, width, markup/text, weigth_col 58 _column_names = [ 59 (_('Type'), 0, 100, TEXT_COL, -1, None), 60 (_('ID'), 1, 75, TEXT_COL, -1, None), 61 (_('Name'), 2, 250, TEXT_COL, -1, None), 62 ] 63 64 def __init__(self, dbstate, uistate, track, obj, refmodel, callback=None): 65 self.obj = obj 66 EmbeddedList.__init__(self, dbstate, uistate, track, 67 _('_References'), refmodel) 68 self._callback = callback 69 self.connectid = self.model.connect('row-inserted', self.update_label) 70 self.db_connect = [] 71 for item in ['person', 'family', 'source', 'citation', 'event', 72 'media', 'place', 'repository', 'note']: 73 self.db_connect.append(self.dbstate.db.connect( 74 '%s-delete' % item, self.model.delete_row)) 75 self.tree.set_reorderable(False) 76 self.track_ref_for_deletion("model") 77 78 def update_label(self, *obj): 79 if self.model.count > 0: 80 self._set_label() 81 if self._callback and self.model.count > 1: 82 self._callback() 83 84 def right_click(self, obj, event): 85 return 86 87 def _cleanup_local_connects(self): 88 self.model.disconnect(self.connectid) 89 for item in self.db_connect: 90 self.dbstate.db.disconnect(item) 91 92 def _cleanup_on_exit(self): 93 # model may be destroyed already in closing managedwindow 94 if hasattr(self, 'model'): 95 self.model.destroy() 96 97 def is_empty(self): 98 return self.model.count == 0 99 100 def _create_buttons(self, share=False, move=False, jump=False, top_label=None): 101 """ 102 Create a button box consisting of one button: Edit. 103 This button box is then appended hbox (self). 104 Method has signature of, and overrides create_buttons from _ButtonTab.py 105 """ 106 self.edit_btn = SimpleButton('gtk-edit', self.edit_button_clicked) 107 self.edit_btn.set_tooltip_text(_('Edit reference')) 108 109 hbox = Gtk.Box() 110 hbox.set_spacing(6) 111 hbox.pack_start(self.edit_btn, False, True, 0) 112 hbox.show_all() 113 self.pack_start(hbox, False, True, 0) 114 115 self.add_btn = None 116 self.del_btn = None 117 118 self.track_ref_for_deletion("edit_btn") 119 self.track_ref_for_deletion("add_btn") 120 self.track_ref_for_deletion("del_btn") 121 122 def _selection_changed(self, obj=None): 123 if self.dirty_selection: 124 return 125 if self.get_selected(): 126 self.edit_btn.set_sensitive(True) 127 else: 128 self.edit_btn.set_sensitive(False) 129 130 def get_data(self): 131 return self.obj 132 133 def column_order(self): 134 return ((1, 0), (1, 1), (1, 2)) 135 136 def find_node(self): 137 (model, node) = self.selection.get_selected() 138 try: 139 return (model.get_value(node, 4), model.get_value(node, 3)) 140 except: 141 return (None, None) 142 143 def edit_button_clicked(self, obj): 144 (reftype, ref) = self.find_node() 145 edit_object(self.dbstate, self.uistate, reftype, ref) 146