1
# Gramps - a GTK+/GNOME based genealogy program
3
# Copyright (C) 2011 Nick Hall
4
# Copyright (C) 2011 Tim G L Lyons
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
# $Id: Citations.py 18679 2012-01-01 17:58:33Z nick-h $
23
from gui.editors import EditSource, EditCitation
24
from ListModel import ListModel, NOSORT
25
from gen.plug import Gramplet
26
from gen.ggettext import gettext as _
30
class Citations(Gramplet):
32
Displays the citations for an object.
35
self.gui.WIDGET = self.build_gui()
36
self.gui.get_container_widget().remove(self.gui.textview)
37
self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET)
38
self.gui.WIDGET.show()
42
Build the GUI interface.
44
tip = _('Double-click on a row to edit the selected source/citation.')
47
titles = [('', NOSORT, 50,),
48
(_('Source/Citation'), 1, 350),
49
(_('Author'), 2, 200),
50
(_('Publisher'), 3, 150)]
51
self.model = ListModel(top, titles, list_mode="tree",
52
event_func=self.invoke_editor)
55
def add_citations(self, obj):
56
for citation_handle in obj.get_citation_list():
57
self.add_citation_ref(citation_handle)
59
def add_name_citations(self, obj):
60
names = [obj.get_primary_name()] + obj.get_alternate_names()
62
self.add_citations(name)
64
def add_attribute_citations(self, obj):
65
for attr in obj.get_attribute_list():
66
self.add_citations(attr)
68
def add_mediaref_citations(self, obj):
69
for media_ref in obj.get_media_list():
70
self.add_citations(media_ref)
71
self.add_attribute_citations(media_ref)
72
media = self.dbstate.db.get_object_from_handle(media_ref.ref)
73
self.add_media_citations(media)
75
def add_media_citations(self, media):
76
self.add_citations(media)
77
self.add_attribute_citations(media)
79
def add_eventref_citations(self, obj):
80
for event_ref in obj.get_event_ref_list():
81
self.add_attribute_citations(event_ref)
82
event = self.dbstate.db.get_event_from_handle(event_ref.ref)
83
self.add_event_citations(event)
85
def add_event_citations(self, event):
86
self.add_citations(event)
87
self.add_attribute_citations(event)
88
self.add_mediaref_citations(event)
89
place_handle = event.get_place_handle()
90
place = self.dbstate.db.get_place_from_handle(place_handle)
92
self.add_place_citations(place)
94
def add_place_citations(self, place):
95
self.add_citations(place)
96
self.add_mediaref_citations(place)
98
def add_address_citations(self, obj):
99
for address in obj.get_address_list():
100
self.add_citations(address)
102
def add_lds_citations(self, obj):
103
for lds in obj.get_lds_ord_list():
104
self.add_citations(lds)
105
place_handle = lds.get_place_handle()
106
place = self.dbstate.db.get_place_from_handle(place_handle)
108
self.add_place_citations(place)
110
def add_association_citations(self, obj):
111
for assoc in obj.get_person_ref_list():
112
self.add_citations(assoc)
114
def add_citation_ref(self, citation_handle):
116
Add a citation to the model.
118
citation = self.dbstate.db.get_citation_from_handle(citation_handle)
119
page = citation.get_page()
121
page = _('<No Citation>')
122
source_handle = citation.get_reference_handle()
123
source = self.dbstate.db.get_source_from_handle(source_handle)
124
title = source.get_title()
125
author = source.get_author()
126
publisher = source.get_publication_info()
128
if source_handle not in self.source_nodes:
129
node = self.model.add([source_handle, title, author, publisher])
130
self.source_nodes[source_handle] = node
132
self.model.add([citation_handle, page, '', ''],
133
node=self.source_nodes[source_handle])
135
def check_citations(self, obj):
136
return True if obj.get_citation_list() else False
138
def check_name_citations(self, obj):
139
names = [obj.get_primary_name()] + obj.get_alternate_names()
141
if self.check_citations(name):
145
def check_attribute_citations(self, obj):
146
for attr in obj.get_attribute_list():
147
if self.check_citations(attr):
151
def check_mediaref_citations(self, obj):
152
for media_ref in obj.get_media_list():
153
if self.check_citations(media_ref):
155
if self.check_attribute_citations(media_ref):
157
media = self.dbstate.db.get_object_from_handle(media_ref.ref)
158
if self.check_media_citations(media):
162
def check_media_citations(self, media):
163
if self.check_citations(media):
165
if self.check_attribute_citations(media):
169
def check_eventref_citations(self, obj):
170
for event_ref in obj.get_event_ref_list():
171
if self.check_attribute_citations(event_ref):
173
event = self.dbstate.db.get_event_from_handle(event_ref.ref)
174
if self.check_event_citations(event):
178
def check_event_citations(self, event):
179
if self.check_citations(event):
181
if self.check_attribute_citations(event):
183
if self.check_mediaref_citations(event):
185
place_handle = event.get_place_handle()
186
place = self.dbstate.db.get_place_from_handle(place_handle)
187
if place and self.check_place_citations(place):
191
def check_place_citations(self, place):
192
if self.check_citations(place):
194
if self.check_mediaref_citations(place):
198
def check_address_citations(self, obj):
199
for address in obj.get_address_list():
200
if self.check_citations(address):
204
def check_lds_citations(self, obj):
205
for lds in obj.get_lds_ord_list():
206
if self.check_citations(lds):
208
place_handle = lds.get_place_handle()
209
place = self.dbstate.db.get_place_from_handle(place_handle)
210
if place and self.check_place_citations(place):
214
def check_association_citations(self, obj):
215
for assoc in obj.get_person_ref_list():
216
if self.check_citations(assoc):
220
def invoke_editor(self, treeview):
222
Edit the selected source or citation.
224
model, iter_ = treeview.get_selection().get_selected()
226
handle = model.get_value(iter_, 0)
227
if len(model.get_path(iter_)) == 1:
228
self.edit_source(handle)
230
self.edit_citation(handle)
232
def edit_source(self, handle):
234
Edit the selected source.
237
source = self.dbstate.db.get_source_from_handle(handle)
238
EditSource(self.dbstate, self.uistate, [], source)
239
except Errors.WindowActiveError:
242
def edit_citation(self, handle):
244
Edit the selected citation.
247
citation = self.dbstate.db.get_citation_from_handle(handle)
248
source_handle = citation.get_reference_handle()
249
source = self.dbstate.db.get_source_from_handle(source_handle)
250
EditCitation(self.dbstate, self.uistate, [], citation, source)
251
except Errors.WindowActiveError:
254
class PersonCitations(Citations):
256
Displays the citations for a person.
258
def db_changed(self):
259
self.dbstate.db.connect('person-update', self.update)
261
def active_changed(self, handle):
264
def update_has_data(self):
265
active_handle = self.get_active('Person')
266
active = self.dbstate.db.get_person_from_handle(active_handle)
267
self.set_has_data(self.get_has_data(active))
270
active_handle = self.get_active('Person')
271
active = self.dbstate.db.get_person_from_handle(active_handle)
275
self.display_citations(active)
277
self.set_has_data(False)
279
def display_citations(self, person):
281
Display the citations for the active person.
283
self.source_nodes = {}
284
self.add_citations(person)
285
self.add_eventref_citations(person)
286
for handle in person.get_family_handle_list():
287
family = self.dbstate.db.get_family_from_handle(handle)
288
self.add_eventref_citations(family)
289
self.add_name_citations(person)
290
self.add_attribute_citations(person)
291
self.add_address_citations(person)
292
self.add_mediaref_citations(person)
293
self.add_association_citations(person)
294
self.add_lds_citations(person)
296
self.set_has_data(self.model.count > 0)
297
self.model.tree.expand_all()
299
def get_has_data(self, person):
301
Return True if the gramplet has data, else return False.
305
if self.check_citations(person):
307
if self.check_eventref_citations(person):
309
for handle in person.get_family_handle_list():
310
family = self.dbstate.db.get_family_from_handle(handle)
311
if self.check_eventref_citations(family):
313
if self.check_name_citations(person):
315
if self.check_attribute_citations(person):
317
if self.check_address_citations(person):
319
if self.check_mediaref_citations(person):
321
if self.check_association_citations(person):
323
if self.check_lds_citations(person):
327
class EventCitations(Citations):
329
Displays the citations for an event.
331
def db_changed(self):
332
self.dbstate.db.connect('event-update', self.update)
333
self.connect_signal('Event', self.update)
335
def update_has_data(self):
336
active_handle = self.get_active('Event')
337
active = self.dbstate.db.get_event_from_handle(active_handle)
338
self.set_has_data(self.get_has_data(active))
341
active_handle = self.get_active('Event')
342
active = self.dbstate.db.get_event_from_handle(active_handle)
346
self.display_citations(active)
348
self.set_has_data(False)
350
def display_citations(self, event):
352
Display the citations for the active event.
354
self.source_nodes = {}
355
self.add_event_citations(event)
356
self.set_has_data(self.model.count > 0)
357
self.model.tree.expand_all()
359
def get_has_data(self, event):
361
Return True if the gramplet has data, else return False.
365
if self.check_event_citations(event):
369
class FamilyCitations(Citations):
371
Displays the citations for a family.
373
def db_changed(self):
374
self.dbstate.db.connect('family-update', self.update)
375
self.connect_signal('Family', self.update)
377
def update_has_data(self):
378
active_handle = self.get_active('Family')
379
active = self.dbstate.db.get_family_from_handle(active_handle)
380
self.set_has_data(self.get_has_data(active))
383
active_handle = self.get_active('Family')
384
active = self.dbstate.db.get_family_from_handle(active_handle)
388
self.display_citations(active)
390
self.set_has_data(False)
392
def display_citations(self, family):
394
Display the citations for the active family.
396
self.source_nodes = {}
397
self.add_citations(family)
398
self.add_eventref_citations(family)
399
self.add_attribute_citations(family)
400
self.add_mediaref_citations(family)
401
self.add_lds_citations(family)
403
self.set_has_data(self.model.count > 0)
404
self.model.tree.expand_all()
406
def get_has_data(self, family):
408
Return True if the gramplet has data, else return False.
412
if self.check_citations(family):
414
if self.check_eventref_citations(family):
416
if self.check_attribute_citations(family):
418
if self.check_mediaref_citations(family):
420
if self.check_lds_citations(family):
424
class PlaceCitations(Citations):
426
Displays the citations for a place.
428
def db_changed(self):
429
self.dbstate.db.connect('place-update', self.update)
430
self.connect_signal('Place', self.update)
432
def update_has_data(self):
433
active_handle = self.get_active('Place')
434
active = self.dbstate.db.get_place_from_handle(active_handle)
435
self.set_has_data(self.get_has_data(active))
438
active_handle = self.get_active('Place')
439
active = self.dbstate.db.get_place_from_handle(active_handle)
443
self.display_citations(active)
445
self.set_has_data(False)
447
def display_citations(self, place):
449
Display the citations for the active place.
451
self.source_nodes = {}
452
self.add_place_citations(place)
453
self.set_has_data(self.model.count > 0)
454
self.model.tree.expand_all()
456
def get_has_data(self, place):
458
Return True if the gramplet has data, else return False.
462
if self.check_place_citations(place):
466
class MediaCitations(Citations):
468
Displays the citations for a media object.
470
def db_changed(self):
471
self.dbstate.db.connect('media-update', self.update)
472
self.connect_signal('Media', self.update)
474
def update_has_data(self):
475
active_handle = self.get_active('Media')
476
active = self.dbstate.db.get_object_from_handle(active_handle)
477
self.set_has_data(self.get_has_data(active))
480
active_handle = self.get_active('Media')
481
active = self.dbstate.db.get_object_from_handle(active_handle)
485
self.display_citations(active)
487
self.set_has_data(False)
489
def display_citations(self, media):
491
Display the citations for the active media object.
493
self.source_nodes = {}
494
self.add_media_citations(media)
495
self.set_has_data(self.model.count > 0)
496
self.model.tree.expand_all()
498
def get_has_data(self, media):
500
Return True if the gramplet has data, else return False.
504
if self.check_media_citations(media):