Package gen :: Package lib :: Module eventref
[frames] | no frames]

Source Code for Module gen.lib.eventref

  1  # 
  2  # Gramps - a GTK+/GNOME based genealogy program 
  3  # 
  4  # Copyright (C) 2000-2007  Donald N. Allingham 
  5  # 
  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. 
 10  # 
 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. 
 15  # 
 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 
 19  # 
 20   
 21  # $Id: eventref.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  Event Reference class for GRAMPS 
 25  """ 
 26   
 27  #------------------------------------------------------------------------ 
 28  # 
 29  # Python modules 
 30  # 
 31  #------------------------------------------------------------------------ 
 32  from types import InstanceType 
 33   
 34  #------------------------------------------------------------------------- 
 35  # 
 36  # GRAMPS modules 
 37  # 
 38  #------------------------------------------------------------------------- 
 39  from gen.lib.secondaryobj import SecondaryObject 
 40  from gen.lib.privacybase import PrivacyBase 
 41  from gen.lib.notebase import NoteBase 
 42  from gen.lib.attrbase import AttributeBase 
 43  from gen.lib.refbase import RefBase 
 44  from gen.lib.eventroletype import EventRoleType 
 45   
 46  #------------------------------------------------------------------------- 
 47  # 
 48  # Event References for Person/Family 
 49  # 
 50  #------------------------------------------------------------------------- 
51 -class EventRef(SecondaryObject, PrivacyBase, NoteBase, AttributeBase, RefBase):
52 """ 53 Event reference class. 54 55 This class is for keeping information about how the person relates 56 to the refereneced event. 57 """ 58
59 - def __init__(self, source=None):
60 """ 61 Create a new EventRef instance, copying from the source if present. 62 """ 63 PrivacyBase.__init__(self, source) 64 NoteBase.__init__(self, source) 65 AttributeBase.__init__(self, source) 66 RefBase.__init__(self, source) 67 if source: 68 self.role = source.role 69 else: 70 self.role = EventRoleType()
71
72 - def serialize(self):
73 """ 74 Convert the object to a serialized tuple of data. 75 """ 76 return ( 77 PrivacyBase.serialize(self), 78 NoteBase.serialize(self), 79 AttributeBase.serialize(self), 80 RefBase.serialize(self), 81 self.role.serialize() 82 )
83
84 - def unserialize(self, data):
85 """ 86 Convert a serialized tuple of data to an object. 87 """ 88 (privacy, note_list, attribute_list, ref, role) = data 89 PrivacyBase.unserialize(self, privacy) 90 NoteBase.unserialize(self, note_list) 91 AttributeBase.unserialize(self, attribute_list) 92 RefBase.unserialize(self, ref) 93 self.role = InstanceType(EventRoleType) 94 self.role.unserialize(role) 95 return self
96
97 - def get_text_data_list(self):
98 """ 99 Return the list of all textual attributes of the object. 100 101 @return: Returns the list of all textual attributes of the object. 102 @rtype: list 103 """ 104 return [str(self.role)]
105
106 - def get_text_data_child_list(self):
107 """ 108 Return the list of child objects that may carry textual data. 109 110 @return: Returns the list of child objects that may carry textual data. 111 @rtype: list 112 """ 113 return self.attribute_list
114
115 - def get_sourcref_child_list(self):
116 """ 117 Return the list of child secondary objects that may refer sources. 118 119 @return: Returns the list of child secondary child objects that may 120 refer sources. 121 @rtype: list 122 """ 123 return self.attribute_list
124
125 - def get_note_child_list(self):
126 """ 127 Return the list of child secondary objects that may refer notes. 128 129 @return: Returns the list of child secondary child objects that may 130 refer notes. 131 @rtype: list 132 """ 133 return self.attribute_list
134
135 - def get_referenced_handles(self):
136 """ 137 Return the list of (classname, handle) tuples for all directly 138 referenced primary objects. 139 140 @return: Returns the list of (classname, handle) tuples for referenced 141 objects. 142 @rtype: list 143 """ 144 ret = self.get_referenced_note_handles() 145 if self.ref: 146 ret += [('Event', self.ref)] 147 return ret
148
149 - def get_handle_referents(self):
150 """ 151 Return the list of child objects which may, directly or through their 152 children, reference primary objects.. 153 154 @return: Returns the list of objects refereincing primary objects. 155 @rtype: list 156 """ 157 return self.get_sourcref_child_list()
158
159 - def has_source_reference(self, src_handle) :
160 """ 161 Return True if any of the child objects has reference to this source 162 handle. 163 164 @param src_handle: The source handle to be checked. 165 @type src_handle: str 166 @return: Returns whether any of it's child objects has reference to 167 this source handle. 168 @rtype: bool 169 """ 170 for item in self.get_sourcref_child_list(): 171 if item.has_source_reference(src_handle): 172 return True 173 174 return False
175
176 - def remove_source_references(self, src_handle_list):
177 """ 178 Remove references to all source handles in the list in all child 179 objects. 180 181 @param src_handle_list: The list of source handles to be removed. 182 @type src_handle_list: list 183 """ 184 for item in self.get_sourcref_child_list(): 185 item.remove_source_references(src_handle_list)
186
187 - def replace_source_references(self, old_handle, new_handle):
188 """ 189 Replace references to source handles in the list in this object and 190 all child objects. 191 192 @param old_handle: The source handle to be replaced. 193 @type old_handle: str 194 @param new_handle: The source handle to replace the old one with. 195 @type new_handle: str 196 """ 197 for item in self.get_sourcref_child_list(): 198 item.replace_source_references(old_handle, new_handle)
199
200 - def get_role(self):
201 """ 202 Return the tuple corresponding to the preset role. 203 """ 204 return self.role
205
206 - def set_role(self, role):
207 """ 208 Set the role according to the given argument. 209 """ 210 self.role.set(role)
211