[faed8a]: src / gui / editors / displaytabs / backrefmodel.py Maximize Restore History

Download this file

backrefmodel.py    147 lines (136 with data), 5.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2011 Tim G L Lyons
#
# 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$
#-------------------------------------------------------------------------
#
# GTK libraries
#
#-------------------------------------------------------------------------
from gi.repository import GObject
from gi.repository import Gtk
from gen.ggettext import gettext as _
#-------------------------------------------------------------------------
#
# GRAMPS classes
#
#-------------------------------------------------------------------------
from gen.display.name import displayer as name_displayer
import Utils
#-------------------------------------------------------------------------
#
# BackRefModel
#
#-------------------------------------------------------------------------
class BackRefModel(Gtk.ListStore):
dispstr = _('%(part1)s - %(part2)s')
def __init__(self, sref_list, db):
GObject.GObject.__init__(self, str, str, str, str, str)
self.db = db
self.sref_list = sref_list
self.count = 0
self.idle = GObject.idle_add(self.load_model().next)
def destroy(self):
GObject.source_remove(self.idle)
def load_model(self):
"""
Objects can have very large backreferences. To avoid blocking the
interface up to the moment that the model is created, this method is
called via GObject.idle_add.
WARNING: a consequence of above is that loading can still be happening
while the GUI using this model is no longer used. Disconnect any
methods before closing the GUI.
"""
self.count = 0
for ref in self.sref_list:
self.count += 1
dtype = ref[0]
if dtype == 'Person':
p = self.db.get_person_from_handle(ref[1])
if not p:
continue
gid = p.gramps_id
handle = p.handle
name = name_displayer.display(p)
elif dtype == 'Family':
p = self.db.get_family_from_handle(ref[1])
if not p:
continue
gid = p.gramps_id
handle = p.handle
name = Utils.family_name(p, self.db)
elif dtype == 'Source':
p = self.db.get_source_from_handle(ref[1])
if not p:
continue
gid = p.gramps_id
handle = p.handle
name = p.get_title()
elif dtype == 'Citation':
p = self.db.get_citation_from_handle(ref[1])
if not p:
continue
gid = p.gramps_id
handle = p.handle
name = p.get_page()
elif dtype == 'Event':
p = self.db.get_event_from_handle(ref[1])
if not p:
continue
gid = p.gramps_id
handle = p.handle
name = p.get_description()
if name:
name = self.dispstr % {'part1': str(p.get_type()),
'part2': name}
else:
name = str(p.get_type())
part = Utils.get_participant_from_event(self.db, ref[1])
if part :
name = self.dispstr % {'part1': name,
'part2': part}
elif dtype == 'Place':
p = self.db.get_place_from_handle(ref[1])
if not p:
continue
name = p.get_title()
gid = p.gramps_id
handle = p.handle
elif dtype == 'Repository':
p = self.db.get_repository_from_handle(ref[1])
if not p:
continue
name = p.get_name()
gid = p.gramps_id
handle = p.handle
else:
p = self.db.get_object_from_handle(ref[1])
if not p:
continue
name = p.get_description()
gid = p.gramps_id
handle = p.handle
# dtype is the class name, i.e. is English
# We need to use localized string in the model.
# we also need to keep class names to get the object type,
# but we don't need to show that in the view.
self.append(row=[_(dtype), gid, name, handle, dtype])
yield True
yield False