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

Source Code for Module gen.lib.primaryobj

  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: primaryobj.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  Basic Primary Object class for GRAMPS. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # standard python modules 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  import time 
 33  import locale 
 34   
 35  #------------------------------------------------------------------------- 
 36  # 
 37  # GRAMPS modules 
 38  # 
 39  #------------------------------------------------------------------------- 
 40  from gen.lib.baseobj import BaseObject 
 41  from gen.lib.privacybase import PrivacyBase 
 42  from gen.lib.markertype import MarkerType 
 43  from gen.lib.srcbase import SourceBase 
 44  from gen.lib.mediabase import MediaBase 
 45   
 46  #------------------------------------------------------------------------- 
 47  # 
 48  # Localized constants 
 49  # 
 50  #------------------------------------------------------------------------- 
 51  try: 
 52      CODESET = locale.nl_langinfo(locale.CODESET) 
 53  except: 
 54      CODESET = locale.getpreferredencoding() 
 55   
 56  #------------------------------------------------------------------------- 
 57  # 
 58  # Basic Primary Object class 
 59  # 
 60  #------------------------------------------------------------------------- 
61 -class BasicPrimaryObject(BaseObject, PrivacyBase):
62 """ 63 The BasicPrimaryObject is the base class for Note objects. 64 65 It is also the base class for the PrimaryObject class. 66 67 The PrimaryObject is the base class for all other primary objects in the 68 database. Primary objects are the core objects in the database. 69 Each object has a database handle and a GRAMPS ID value. The database 70 handle is used as the record number for the database, and the GRAMPS 71 ID is the user visible version. 72 """ 73
74 - def __init__(self, source=None):
75 """ 76 Initialize a PrimaryObject. 77 78 If source is None, both the ID and handle are assigned as empty 79 strings. If source is not None, then object is initialized from values 80 of the source object. 81 82 @param source: Object used to initialize the new object 83 @type source: PrimaryObject 84 """ 85 PrivacyBase.__init__(self, source) 86 if source: 87 self.gramps_id = source.gramps_id 88 self.handle = source.handle 89 self.change = source.change 90 self.marker = source.marker 91 else: 92 self.gramps_id = None 93 self.handle = None 94 self.change = 0 95 self.marker = MarkerType()
96
97 - def get_change_time(self):
98 """ 99 Return the time that the data was last changed. 100 101 The value in the format returned by the time.time() command. 102 103 @returns: Time that the data was last changed. The value in the format 104 returned by the time.time() command. 105 @rtype: int 106 """ 107 return self.change
108
109 - def get_change_display(self):
110 """ 111 Return the string representation of the last change time. 112 113 @returns: string representation of the last change time. 114 @rtype: str 115 116 """ 117 if self.change: 118 return unicode(time.strftime('%x %X', time.localtime(self.change)), 119 CODESET) 120 else: 121 return u''
122
123 - def set_handle(self, handle):
124 """ 125 Set the database handle for the primary object. 126 127 @param handle: object database handle 128 @type handle: str 129 """ 130 self.handle = handle
131
132 - def get_handle(self):
133 """ 134 Return the database handle for the primary object. 135 136 @returns: database handle associated with the object 137 @rtype: str 138 """ 139 return self.handle
140
141 - def set_gramps_id(self, gramps_id):
142 """ 143 Set the GRAMPS ID for the primary object. 144 145 @param gramps_id: GRAMPS ID 146 @type gramps_id: str 147 """ 148 self.gramps_id = gramps_id
149
150 - def get_gramps_id(self):
151 """ 152 Return the GRAMPS ID for the primary object. 153 154 @returns: GRAMPS ID associated with the object 155 @rtype: str 156 """ 157 return self.gramps_id
158
159 - def has_handle_reference(self, classname, handle):
160 """ 161 Return True if the object has reference to a given handle of given 162 primary object type. 163 164 @param classname: The name of the primary object class. 165 @type classname: str 166 @param handle: The handle to be checked. 167 @type handle: str 168 @return: Returns whether the object has reference to this handle of 169 this object type. 170 @rtype: bool 171 """ 172 return False
173
174 - def remove_handle_references(self, classname, handle_list):
175 """ 176 Remove all references in this object to object handles in the list. 177 178 @param classname: The name of the primary object class. 179 @type classname: str 180 @param handle_list: The list of handles to be removed. 181 @type handle_list: str 182 """ 183 pass
184
185 - def replace_handle_reference(self, classname, old_handle, new_handle):
186 """ 187 Replace all references to old handle with those to the new handle. 188 189 @param classname: The name of the primary object class. 190 @type classname: str 191 @param old_handle: The handle to be replaced. 192 @type old_handle: str 193 @param new_handle: The handle to replace the old one with. 194 @type new_handle: str 195 """ 196 pass
197
198 - def set_marker(self, marker):
199 """ 200 Set the marker for the object. 201 202 @param marker: marker assigned to the object 203 @type marker: MarkerType 204 """ 205 self.marker.set(marker)
206
207 - def get_marker(self):
208 """ 209 Return the marker for the object. 210 211 The exact type depends on the derived class type. 212 213 @return: Returns the marker for the object. 214 @rtype: MarkerType 215 """ 216 return self.marker
217
218 - def has_source_reference(self, handle):
219 """ 220 Indicate if the object has a source references. 221 222 In the base class, no such references exist. Derived classes should 223 override this if they provide source references. 224 """ 225 return False
226
227 - def has_media_reference(self, handle):
228 """ 229 Indicate if the object has a media references. 230 231 In the base class, no such references exist. Derived classes should 232 override this if they provide media references. 233 """ 234 return False
235
236 - def remove_source_references(self, handle_list):
237 """ 238 Remove the specified source references from the object. 239 240 In the base class no such references exist. Derived classes should 241 override this if they provide source references. 242 """ 243 pass
244
245 - def remove_media_references(self, handle_list):
246 """ 247 Remove the specified media references from the object. 248 249 In the base class no such references exist. Derived classes should 250 override this if they provide media references. 251 """ 252 pass
253
254 - def replace_source_references(self, old_handle, new_handle):
255 pass
256
257 - def replace_media_references(self, old_handle, new_handle):
258 pass
259 260 #------------------------------------------------------------------------- 261 # 262 # Primary Object class 263 # 264 #-------------------------------------------------------------------------
265 -class PrimaryObject(BasicPrimaryObject):
266 """ 267 The PrimaryObject is the base class for all primary objects in the 268 database. 269 270 Primary objects are the core objects in the database. 271 Each object has a database handle and a GRAMPS ID value. The database 272 handle is used as the record number for the database, and the GRAMPS 273 ID is the user visible version. 274 """ 275
276 - def __init__(self, source=None):
277 """ 278 Initialize a PrimaryObject. 279 280 If source is None, both the ID and handle are assigned as empty 281 strings. If source is not None, then object is initialized from values 282 of the source object. 283 284 @param source: Object used to initialize the new object 285 @type source: PrimaryObject 286 """ 287 BasicPrimaryObject.__init__(self, source)
288
289 - def has_handle_reference(self, classname, handle):
290 """ 291 Return True if the object has reference to a given handle of given 292 primary object type. 293 294 @param classname: The name of the primary object class. 295 @type classname: str 296 @param handle: The handle to be checked. 297 @type handle: str 298 @return: Returns whether the object has reference to this handle 299 of this object type. 300 @rtype: bool 301 """ 302 if classname == 'Source' and isinstance(self, SourceBase): 303 return self.has_source_reference(handle) 304 elif classname == 'MediaObject' and isinstance(self, MediaBase): 305 return self.has_media_reference(handle) 306 else: 307 return self._has_handle_reference(classname, handle)
308
309 - def remove_handle_references(self, classname, handle_list):
310 """ 311 Remove all references in this object to object handles in the list. 312 313 @param classname: The name of the primary object class. 314 @type classname: str 315 @param handle_list: The list of handles to be removed. 316 @type handle_list: str 317 """ 318 if classname == 'Source' and isinstance(self, SourceBase): 319 self.remove_source_references(handle_list) 320 elif classname == 'MediaObject' and isinstance(self, MediaBase): 321 self.remove_media_references(handle_list) 322 else: 323 self._remove_handle_references(classname, handle_list)
324
325 - def replace_handle_reference(self, classname, old_handle, new_handle):
326 """ 327 Replace all references to old handle with those to the new handle. 328 329 @param classname: The name of the primary object class. 330 @type classname: str 331 @param old_handle: The handle to be replaced. 332 @type old_handle: str 333 @param new_handle: The handle to replace the old one with. 334 @type new_handle: str 335 """ 336 if classname == 'Source' and isinstance(self, SourceBase): 337 self.replace_source_references(old_handle, new_handle) 338 elif classname == 'MediaObject' and isinstance(self, MediaBase): 339 self.replace_media_references(old_handle, new_handle) 340 else: 341 self._replace_handle_reference(classname, old_handle, new_handle)
342
343 - def _has_handle_reference(self, classname, handle):
344 """ 345 Return True if the handle is referenced by the object. 346 """ 347 return False
348
349 - def _remove_handle_references(self, classname, handle_list):
350 """ 351 Remove the handle references from the object. 352 """ 353 pass
354
355 - def _replace_handle_reference(self, classname, old_handle, new_handle):
356 """ 357 Replace the handle reference with the new reference. 358 """ 359 pass
360
361 - def set_marker(self, marker):
362 self.marker.set(marker)
363
364 - def get_marker(self):
365 return self.marker
366