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

Source Code for Module gen.lib.event

  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: event.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  Event object for GRAMPS. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # GRAMPS modules 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  from gen.lib.primaryobj import PrimaryObject 
 33  from gen.lib.srcbase import SourceBase 
 34  from gen.lib.notebase import NoteBase 
 35  from gen.lib.mediabase import MediaBase 
 36  from gen.lib.attrbase import AttributeBase 
 37  from gen.lib.datebase import DateBase 
 38  from gen.lib.placebase import PlaceBase 
 39  from gen.lib.eventtype import EventType 
 40  from gen.lib.markertype import MarkerType 
 41   
 42  from types import InstanceType 
 43   
 44  #------------------------------------------------------------------------- 
 45  # 
 46  # Event class 
 47  # 
 48  #------------------------------------------------------------------------- 
49 -class Event(SourceBase, NoteBase, MediaBase, AttributeBase, 50 DateBase, PlaceBase, PrimaryObject):
51 """ 52 Introduction 53 ============ 54 The Event record is used to store information about some type of 55 action that occurred at a particular place at a particular time, 56 such as a birth, death, or marriage. 57 """ 58
59 - def __init__(self, source=None):
60 """ 61 Create a new Event instance, copying from the source if present. 62 63 @param source: An event used to initialize the new event 64 @type source: Event 65 """ 66 67 PrimaryObject.__init__(self, source) 68 SourceBase.__init__(self, source) 69 NoteBase.__init__(self, source) 70 MediaBase.__init__(self, source) 71 AttributeBase.__init__(self) 72 DateBase.__init__(self, source) 73 PlaceBase.__init__(self, source) 74 75 if source: 76 self.description = source.description 77 self.type = source.type 78 else: 79 self.description = "" 80 self.type = EventType()
81
82 - def serialize(self, no_text_date = False):
83 """ 84 Convert the data held in the event to a Python tuple that 85 represents all the data elements. 86 87 This method is used to convert the object into a form that can easily 88 be saved to a database. 89 90 These elements may be primative Python types (string, integers), 91 complex Python types (lists or tuples, or Python objects. If the 92 target database cannot handle complex types (such as objectes or 93 lists), the database is responsible for converting the data into 94 a form that it can use. 95 96 @returns: Returns a python tuple containing the data that should 97 be considered persistent. 98 @rtype: tuple 99 """ 100 return (self.handle, self.gramps_id, self.type.serialize(), 101 DateBase.serialize(self, no_text_date), 102 self.description, self.place, 103 SourceBase.serialize(self), 104 NoteBase.serialize(self), 105 MediaBase.serialize(self), 106 AttributeBase.serialize(self), 107 self.change, self.marker.serialize(), self.private)
108
109 - def unserialize(self, data):
110 """ 111 Convert the data held in a tuple created by the serialize method 112 back into the data in an Event structure. 113 114 @param data: tuple containing the persistent data associated the 115 Person object 116 @type data: tuple 117 """ 118 (self.handle, self.gramps_id, the_type, date, 119 self.description, self.place, 120 source_list, note_list, media_list, attribute_list, 121 self.change, marker, self.private) = data 122 123 self.marker = InstanceType(MarkerType) 124 self.marker.unserialize(marker) 125 self.type = InstanceType(EventType) 126 self.type.unserialize(the_type) 127 DateBase.unserialize(self, date) 128 MediaBase.unserialize(self, media_list) 129 AttributeBase.unserialize(self, attribute_list) 130 SourceBase.unserialize(self, source_list) 131 NoteBase.unserialize(self, note_list)
132
133 - def _has_handle_reference(self, classname, handle):
134 """ 135 Return True if the object has reference to a given handle of given 136 primary object type. 137 138 @param classname: The name of the primary object class. 139 @type classname: str 140 @param handle: The handle to be checked. 141 @type handle: str 142 @return: Returns whether the object has reference to this handle of 143 this object type. 144 @rtype: bool 145 """ 146 if classname == 'Place': 147 return self.place == handle 148 return False
149
150 - def _remove_handle_references(self, classname, handle_list):
151 """ 152 Remove all references in this object to object handles in the list. 153 154 @param classname: The name of the primary object class. 155 @type classname: str 156 @param handle_list: The list of handles to be removed. 157 @type handle_list: str 158 """ 159 if classname == 'Place' and self.place in handle_list: 160 self.place = ""
161
162 - def _replace_handle_reference(self, classname, old_handle, new_handle):
163 """ 164 Replace all references to old handle with those to the new handle. 165 166 @param classname: The name of the primary object class. 167 @type classname: str 168 @param old_handle: The handle to be replaced. 169 @type old_handle: str 170 @param new_handle: The handle to replace the old one with. 171 @type new_handle: str 172 """ 173 if classname == 'Place' and self.place == old_handle: 174 self.place = new_handle
175
176 - def get_text_data_list(self):
177 """ 178 Return the list of all textual attributes of the object. 179 180 @return: Returns the list of all textual attributes of the object. 181 @rtype: list 182 """ 183 return [self.description, str(self.type), self.gramps_id]
184
185 - def get_text_data_child_list(self):
186 """ 187 Return the list of child objects that may carry textual data. 188 189 @return: Returns the list of child objects that may carry textual data. 190 @rtype: list 191 """ 192 return self.media_list + self.source_list + self.attribute_list
193
194 - def get_sourcref_child_list(self):
195 """ 196 Return the list of child secondary objects that may refer sources. 197 198 @return: Returns the list of child secondary child objects that may 199 refer sources. 200 @rtype: list 201 """ 202 return self.media_list + self.attribute_list
203
204 - def get_note_child_list(self):
205 """ 206 Return the list of child secondary objects that may refer notes. 207 208 @return: Returns the list of child secondary child objects that may 209 refer notes. 210 @rtype: list 211 """ 212 return self.media_list + self.attribute_list + self.source_list
213
214 - def get_referenced_handles(self):
215 """ 216 Return the list of (classname, handle) tuples for all directly 217 referenced primary objects. 218 219 @return: List of (classname, handle) tuples for referenced objects. 220 @rtype: list 221 """ 222 ret = self.get_referenced_note_handles() 223 if self.place: 224 ret.append(('Place', self.place)) 225 return ret
226
227 - def get_handle_referents(self):
228 """ 229 Return the list of child objects which may, directly or through 230 their children, reference primary objects. 231 232 @return: Returns the list of objects refereincing primary objects. 233 @rtype: list 234 """ 235 return self.get_sourcref_child_list() + self.source_list
236
237 - def is_empty(self):
238 """ 239 Return True if the Event is an empty object (no values set). 240 241 @returns: True if the Event is empty 242 @rtype: bool 243 """ 244 date = self.get_date_object() 245 place = self.get_place_handle() 246 description = self.description 247 the_type = self.type 248 return (the_type == EventType.CUSTOM and date.is_empty() 249 and not place and not description)
250
251 - def are_equal(self, other):
252 """ 253 Return True if the passed Event is equivalent to the current Event. 254 255 @param other: Event to compare against 256 @type other: Event 257 @returns: True if the Events are equal 258 @rtype: bool 259 """ 260 if other == None: 261 other = Event (None) 262 263 if self.type != other.type or \ 264 ((self.place or other.place) and (self.place != other.place)) or \ 265 self.description != other.description \ 266 or self.private != other.private or \ 267 (not self.get_date_object().is_equal(other.get_date_object())) or \ 268 len(self.get_source_references()) != len(other.get_source_references()): 269 return False 270 271 index = 0 272 olist = other.get_source_references() 273 for a in self.get_source_references(): 274 if not a.is_equal(olist[index]): 275 return False 276 index += 1 277 278 return True
279
280 - def set_type(self, the_type):
281 """ 282 Set the type of the Event to the passed (int,str) tuple. 283 284 @param the_type: Type to assign to the Event 285 @type the_type: tuple 286 """ 287 self.type.set(the_type)
288
289 - def get_type(self):
290 """ 291 Return the type of the Event. 292 293 @return: Type of the Event 294 @rtype: tuple 295 """ 296 return self.type
297
298 - def set_description(self, description):
299 """ 300 Set the description of the Event to the passed string. 301 302 The string may contain any information. 303 304 @param description: Description to assign to the Event 305 @type description: str 306 """ 307 self.description = description
308
309 - def get_description(self) :
310 """ 311 Return the description of the Event. 312 313 @return: Returns the description of the Event 314 @rtype: str 315 """ 316 return self.description
317