2
# Gramps - a GTK+/GNOME based genealogy program
4
# Copyright (C) 2000-2007 Donald N. Allingham
5
# Copyright (C) 2010 Michiel D. Nauta
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
# $Id: srcref.py 15645 2010-07-22 02:16:32Z dsblank $
25
Source Reference class for GRAMPS.
28
#-------------------------------------------------------------------------
32
#-------------------------------------------------------------------------
33
from warnings import warn
35
#-------------------------------------------------------------------------
39
#-------------------------------------------------------------------------
40
from gen.lib.secondaryobj import SecondaryObject
41
from gen.lib.datebase import DateBase
42
from gen.lib.privacybase import PrivacyBase
43
from gen.lib.notebase import NoteBase
44
from gen.lib.refbase import RefBase
45
from gen.lib.const import IDENTICAL, EQUAL, DIFFERENT
47
#-------------------------------------------------------------------------
49
# Source References for all primary objects
51
#-------------------------------------------------------------------------
52
class SourceRef(SecondaryObject, DateBase, PrivacyBase, NoteBase, RefBase):
54
Source reference, containing detailed information about how a referenced
64
def __init__(self, source=None):
65
"""Create a new SourceRef, copying from the source if present."""
66
DateBase.__init__(self, source)
67
PrivacyBase.__init__(self, source)
68
NoteBase.__init__(self, source)
69
RefBase.__init__(self, source)
71
self.confidence = source.confidence
72
self.page = source.page
74
self.confidence = SourceRef.CONF_NORMAL
79
Convert the object to a serialized tuple of data.
81
return (DateBase.serialize(self),
82
PrivacyBase.serialize(self),
83
NoteBase.serialize(self),
85
RefBase.serialize(self),
88
def unserialize(self, data):
90
Convert a serialized tuple of data to an object.
92
(date, privacy, note_list,
93
self.confidence, ref, self.page) = data
94
DateBase.unserialize(self, date)
95
PrivacyBase.unserialize(self, privacy)
96
NoteBase.unserialize(self, note_list)
97
RefBase.unserialize(self, ref)
100
def get_text_data_list(self):
102
Return the list of all textual attributes of the object.
104
:returns: Returns the list of all textual attributes of the object.
109
def get_referenced_handles(self):
111
Return the list of (classname, handle) tuples for all directly
112
referenced primary objects.
114
:returns: List of (classname, handle) tuples for referenced objects.
117
ret = self.get_referenced_note_handles()
119
ret += [('Source', self.ref)]
122
def is_equivalent(self, other):
124
Return if this source reference is equivalent, that is agreees in
125
reference, source page and date, to other.
127
:param other: The source reference to compare this one to.
128
:rtype other: SourceRef
129
;returns: Constant indicating degree of equivalence.
132
if self.ref != other.ref or \
133
self.page != other.page or \
134
self.get_date_object() != other.get_date_object():
137
if self.is_equal(other):
142
def merge(self, acquisition):
144
Merge the content of acquisition into this source reference.
146
:param acquisition: The source reference to merge with the present one.
147
:rtype acquisition: SourceRef
149
self._merge_privacy(acquisition)
150
self._merge_note_list(acquisition)
152
level_priority = [0, 4, 1, 3, 2]
153
idx = min(level_priority.index(self.confidence),
154
level_priority.index(acquisition.confidence))
155
self.confidence = level_priority[idx]
157
def set_confidence_level(self, val):
158
"""Set the confidence level."""
159
self.confidence = val
161
def get_confidence_level(self):
162
"""Return the confidence level."""
163
return self.confidence
165
def set_page(self, page):
166
"""Set the page indicator of the SourceRef."""
170
"""Get the page indicator of the SourceRef."""
173
def are_equal(self, other):
174
"""Deprecated function - use is_equal instead."""
175
warn( "Use is_equal instead of are_equal", DeprecationWarning, 2)
176
return self.is_equal(other)