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

Source Code for Module gen.lib.place

  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: place.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  Place object 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.primaryobj import PrimaryObject 
 40  from gen.lib.srcbase import SourceBase 
 41  from gen.lib.notebase import NoteBase 
 42  from gen.lib.mediabase import MediaBase 
 43  from gen.lib.urlbase import UrlBase 
 44  from gen.lib.location import Location 
 45  from gen.lib.markertype import MarkerType 
 46   
 47  _EMPTY_LOC = Location().serialize() 
 48   
 49  #------------------------------------------------------------------------- 
 50  # 
 51  # Place class 
 52  # 
 53  #------------------------------------------------------------------------- 
54 -class Place(SourceBase, NoteBase, MediaBase, UrlBase, PrimaryObject):
55 """ 56 Contains information related to a place, including multiple address 57 information (since place names can change with time), longitude, latitude, 58 a collection of images and URLs, a note and a source. 59 """ 60
61 - def __init__(self, source=None):
62 """ 63 Create a new Place object, copying from the source if present. 64 65 @param source: A Place object used to initialize the new Place 66 @type source: Place 67 """ 68 PrimaryObject.__init__(self, source) 69 SourceBase.__init__(self, source) 70 NoteBase.__init__(self, source) 71 MediaBase.__init__(self, source) 72 UrlBase.__init__(self, source) 73 if source: 74 self.long = source.long 75 self.lat = source.lat 76 self.title = source.title 77 self.main_loc = Location(source.main_loc) 78 self.alt_loc = [Location(loc) for loc in source.alt_loc] 79 else: 80 self.long = "" 81 self.lat = "" 82 self.title = "" 83 self.main_loc = None 84 self.alt_loc = []
85
86 - def serialize(self):
87 """ 88 Convert the data held in the Place to a Python tuple that 89 represents all the data elements. 90 91 This method is used to convert the object into a form that can easily 92 be saved to a database. 93 94 These elements may be primative Python types (string, integers), 95 complex Python types (lists or tuples, or Python objects. If the 96 target database cannot handle complex types (such as objectes or 97 lists), the database is responsible for converting the data into 98 a form that it can use. 99 100 @returns: Returns a python tuple containing the data that should 101 be considered persistent. 102 @rtype: tuple 103 """ 104 105 if self.main_loc == None or self.main_loc.serialize() == _EMPTY_LOC: 106 main_loc = None 107 else: 108 main_loc = self.main_loc.serialize() 109 110 return (self.handle, self.gramps_id, self.title, self.long, self.lat, 111 main_loc, [al.serialize() for al in self.alt_loc], 112 UrlBase.serialize(self), 113 MediaBase.serialize(self), 114 SourceBase.serialize(self), 115 NoteBase.serialize(self), 116 self.change, self.marker.serialize() ,self.private)
117
118 - def unserialize(self, data):
119 """ 120 Convert the data held in a tuple created by the serialize method 121 back into the data in a Place object. 122 123 @param data: tuple containing the persistent data associated the 124 Person object 125 @type data: tuple 126 """ 127 (self.handle, self.gramps_id, self.title, self.long, self.lat, 128 main_loc, alt_loc, urls, media_list, source_list, note_list, 129 self.change, marker, self.private) = data 130 131 if main_loc == None: 132 self.main_loc = None 133 else: 134 self.main_loc = InstanceType(Location).unserialize(main_loc) 135 self.alt_loc = [InstanceType(Location).unserialize(al) 136 for al in alt_loc] 137 self.marker = InstanceType(MarkerType) 138 self.marker.unserialize(marker) 139 UrlBase.unserialize(self, urls) 140 MediaBase.unserialize(self, media_list) 141 SourceBase.unserialize(self, source_list) 142 NoteBase.unserialize(self, note_list)
143
144 - def get_text_data_list(self):
145 """ 146 Return the list of all textual attributes of the object. 147 148 @return: Returns the list of all textual attributes of the object. 149 @rtype: list 150 """ 151 return [self.long, self.lat, self.title, self.gramps_id]
152
153 - def get_text_data_child_list(self):
154 """ 155 Return the list of child objects that may carry textual data. 156 157 @return: Returns the list of child objects that may carry textual data. 158 @rtype: list 159 """ 160 161 ret = self.media_list + self.source_list + self.alt_loc + self.urls 162 if self.main_loc: 163 ret.append(self.main_loc) 164 return ret
165
166 - def get_sourcref_child_list(self):
167 """ 168 Return the list of child secondary objects that may refer sources. 169 170 @return: List of child secondary child objects that may refer sources. 171 @rtype: list 172 """ 173 return self.media_list
174
175 - def get_note_child_list(self):
176 """ 177 Return the list of child secondary objects that may refer notes. 178 179 @return: Returns the list of child secondary child objects that may 180 refer notes. 181 @rtype: list 182 """ 183 return self.media_list + self.source_list
184
185 - def get_handle_referents(self):
186 """ 187 Return the list of child objects which may, directly or through 188 their children, reference primary objects. 189 190 @return: Returns the list of objects refereincing primary objects. 191 @rtype: list 192 """ 193 return self.media_list + self.source_list
194
195 - def get_referenced_handles(self):
196 """ 197 Return the list of (classname, handle) tuples for all directly 198 referenced primary objects. 199 200 @return: List of (classname, handle) tuples for referenced objects. 201 @rtype: list 202 """ 203 return self.get_referenced_note_handles()
204
205 - def set_title(self, title):
206 """ 207 Set the descriptive title of the Place object. 208 209 @param title: descriptive title to assign to the Place 210 @type title: str 211 """ 212 self.title = title
213
214 - def get_title(self):
215 """ 216 Return the descriptive title of the Place object. 217 218 @returns: Returns the descriptive title of the Place 219 @rtype: str 220 """ 221 return self.title
222
223 - def set_longitude(self, longitude):
224 """ 225 Set the longitude of the Place object. 226 227 @param longitude: longitude to assign to the Place 228 @type longitude: str 229 """ 230 self.long = longitude
231
232 - def get_longitude(self):
233 """ 234 Return the longitude of the Place object. 235 236 @returns: Returns the longitude of the Place 237 @rtype: str 238 """ 239 return self.long
240
241 - def set_latitude(self, latitude):
242 """ 243 Set the latitude of the Place object. 244 245 @param latitude: latitude to assign to the Place 246 @type latitude: str 247 """ 248 self.lat = latitude
249
250 - def get_latitude(self):
251 """ 252 Return the latitude of the Place object. 253 254 @returns: Returns the latitude of the Place 255 @rtype: str 256 """ 257 return self.lat
258
259 - def get_main_location(self):
260 """ 261 Return the L{Location} object representing the primary information for 262 the Place instance. 263 264 If a L{Location} hasn't been assigned yet, an empty one is created. 265 266 @returns: Returns the L{Location} instance representing the primary 267 location information about the Place. 268 @rtype: L{Location} 269 """ 270 if not self.main_loc: 271 self.main_loc = Location() 272 return self.main_loc
273
274 - def set_main_location(self, location):
275 """ 276 Assign the main location information about the Place to the L{Location} 277 object passed. 278 279 @param location: L{Location} instance to assign to as the main 280 information for the Place. 281 @type location: L{Location} 282 """ 283 self.main_loc = location
284
285 - def get_alternate_locations(self):
286 """ 287 Return a list of alternate L{Location} objects the present alternate 288 information about the current Place. 289 290 A Place can have more than one L{Location}, since names and 291 jurisdictions can change over time for the same place. 292 293 @returns: Returns the alternate L{Location}s for the Place 294 @rtype: list of L{Location} objects 295 """ 296 return self.alt_loc
297
298 - def set_alternate_locations(self, location_list):
299 """ 300 Replace the current alternate L{Location} object list with the new one. 301 302 @param location_list: The list of L{Location} objects to assign to the 303 Place's internal list. 304 @type location_list: list of L{Location} objects 305 """ 306 self.alt_loc = location_list
307
308 - def add_alternate_locations(self, location):
309 """ 310 Add a L{Location} object to the alternate location list. 311 312 @param location: L{Location} instance to add 313 @type location: L{Location} 314 """ 315 if location not in self.alt_loc: 316 self.alt_loc.append(location)
317
318 - def get_display_info(self):
319 """ 320 Get the display information associated with the object. 321 322 This includes the information that is used for display and for sorting. 323 Returns a list consisting of 13 strings. These are: 324 325 Place Title, Place ID, Main Location Parish, Main Location County, 326 Main Location City, Main Location State/Province, 327 Main Location Country, upper case Place Title, upper case Parish, 328 upper case city, upper case county, upper case state, 329 upper case country. 330 """ 331 332 if self.main_loc: 333 return [self.title, self.gramps_id, self.main_loc.parish, 334 self.main_loc.city, self.main_loc.county, 335 self.main_loc.state, self.main_loc.country, 336 self.title.upper(), self.main_loc.parish.upper(), 337 self.main_loc.city.upper(), self.main_loc.county.upper(), 338 self.main_loc.state.upper(), self.main_loc.country.upper()] 339 else: 340 return [self.title, self.gramps_id, u'', u'', u'', u'', u'', 341 self.title.upper(), u'', u'', u'', u'', u'']
342